From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229360; cv=none; d=zohomail.com; s=zohoarc; b=bU0+AWinVlqNOx+l8PTReusqEkJtkWU9TKj6PZjwlYB8YReFQVnX/NVdxPiNicFi1nmtLFi0zNJdOC2vwcLvUX+/Krpzki1jarfvj9dRvNBjnk4162RJIzpSpWbCMWv4TVGUz+zVNL9h7l3J+dznoUfBJg2+Dw9HTPxF7ryCsik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229360; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4k/+bnAkcVWWnge1tksP6C9R9PJwMJ2ldDSyF+VBEP0=; b=Z5jnrRMJYYed7LwpBIKBq7f51UTQ+G854a4liQp5J9mgUU84ZYJaHMt4ScyMMbc3p35RYSPVckDZDe17n7sTOQMt/SaDjOyieZaY74NuCnqNXWXMOB0YQYD5mPcthtOwQ1bV1HP4pjFOxdFirtjurJfN1d5neaXP+OQoSp5CQKM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229360191685.4610311855591; Wed, 2 Mar 2022 05:56:00 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-395-sYC_N8Z8MGmi8pnPVLgWPw-1; Wed, 02 Mar 2022 08:55:58 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 359DD8031E1; Wed, 2 Mar 2022 13:55:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 135E97D879; Wed, 2 Mar 2022 13:55:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DBA684ED79; Wed, 2 Mar 2022 13:55:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DtWhq017394 for ; Wed, 2 Mar 2022 08:55:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2F8AB8359C; Wed, 2 Mar 2022 13:55:32 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 950878359B for ; Wed, 2 Mar 2022 13:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229359; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4k/+bnAkcVWWnge1tksP6C9R9PJwMJ2ldDSyF+VBEP0=; b=NMpPBFVFXr4bRp1BQQIK6eEn2ccXac4O1Q9+8Rus+G4AkZSBHkUXGJl/IPdw4j0J2aXLEL oebIj3GlFNK6eNf5SNRMUyFHoC5ZTXcZbADUfRAULWZqSi9zpiWZHk8I/WOhHNgC6ky4MA SWlPlw6zZsiFNpAu3h0eI0EkMYKKOKw= X-MC-Unique: sYC_N8Z8MGmi8pnPVLgWPw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/23] virsh: cmdBlockcopy: Use virXMLFormatElement Date: Wed, 2 Mar 2022 14:55:00 +0100 Message-Id: <079ce2500ad2db7a5f01c8588fd5bfedf3fe9c2a.1646229193.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229362438100003 Content-Type: text/plain; charset="utf-8" Rewrite the formatting of the block copy target xml using virXMLFormatElement. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 9b1b14cdc2..6f0c063438 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2475,14 +2475,20 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd) if (!xmlstr) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - virBufferAsprintf(&buf, "\n", - blockdev ? "block" : "file"); - virBufferAdjustIndent(&buf, 2); - virBufferAsprintf(&buf, "\n", dest); + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INITIALIZER; + + if (blockdev) { + virBufferAddLit(&attrBuf, " type=3D'block'"); + virBufferAddLit(&childBuf, "\n", dest); virBufferEscapeString(&buf, "\n", format); - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virXMLFormatElement(&buf, "disk", &attrBuf, &childBuf); xmlstr =3D virBufferContentAndReset(&buf); } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229363; cv=none; d=zohomail.com; s=zohoarc; b=ep6rfk3Rk3UIlZOiKNNklhBDOsMTF2d7L3ya27i3+9t9uXfXIFSSryHvYv9jaILnmMWNr1bKpFP4lZmsy7rvE2mxiNlUEzz29ZeJm1g+E76IRrJVODIk9mekaWRMyxSf8I6pw/xxtZ980ZpkgjAhrR3zFdvkqHJ+ZNZ+fxxSJJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229363; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IT/cmEMO9I0M1v2SBhd0OSMQjNJwZRvhZnF2VjfUB7o=; b=RYr9gwbpyh8tKvqSOD/NASAhlhf19XTyWejSiuVBB7/kXyF2GUp+61p5pc7GHDJTs8oCvRUuTsuj96TxVNS3XfZTG3V/Gl51H3hnmBo6thU6GDS9gMNDuqEKMsQu/EZgR4DjzW2mGwy10V3oevPpKZAwhUcsLsmtOItqJAA5Us4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229363292911.7626488286328; Wed, 2 Mar 2022 05:56:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-421-hXbf5Gw3M8ym0d0LKSFztw-1; Wed, 02 Mar 2022 08:56:00 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C0B721091DA1; Wed, 2 Mar 2022 13:55:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A05B37C0F5; Wed, 2 Mar 2022 13:55:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 719BD1807D62; Wed, 2 Mar 2022 13:55:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DtXMH017404 for ; Wed, 2 Mar 2022 08:55:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3E2EC8359C; Wed, 2 Mar 2022 13:55:33 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D9DF8359B for ; Wed, 2 Mar 2022 13:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229362; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=IT/cmEMO9I0M1v2SBhd0OSMQjNJwZRvhZnF2VjfUB7o=; b=SZjyyfn0/HUzXyJMpppG/blujBOYzRmxaIbm8PgKo3whBR0FOiFCtqx9yIGqvPE5znmKEY RhmObPu+DXiYoaikiqvADCa0xO/axJAibpzkNLVL0WyFd/IQpx1bz5IocAX2GhqyWB7Ucr C0+2Em1DOHzrDZyIrDTDgB0JmD2TSPE= X-MC-Unique: hXbf5Gw3M8ym0d0LKSFztw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/23] virsh: cmdStart: Rewrite ternary operator use to standard if conditions Date: Wed, 2 Mar 2022 14:55:01 +0100 Message-Id: <756a37ae960f53e31f8364b98c981a7d86edef9d.1646229193.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229364497100007 Content-Type: text/plain; charset="utf-8" Rewrite the invocation of the virDomainCreate(WithFiles/Flags) APIs based on the arguments into if-else instead of (nested) ternary operators. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 6f0c063438..4c90f40f86 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4104,10 +4104,15 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) /* We can emulate force boot, even for older servers that reject it. = */ if (flags & VIR_DOMAIN_START_FORCE_BOOT) { - if ((nfds ? - virDomainCreateWithFiles(dom, nfds, fds, flags) : - virDomainCreateWithFlags(dom, flags)) =3D=3D 0) + if (nfds > 0) { + rc =3D virDomainCreateWithFiles(dom, nfds, fds, flags); + } else { + rc =3D virDomainCreateWithFlags(dom, flags); + } + + if (rc =3D=3D 0) goto started; + if (last_error->code !=3D VIR_ERR_NO_SUPPORT && last_error->code !=3D VIR_ERR_INVALID_ARG) { vshReportError(ctl); @@ -4128,9 +4133,15 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) } /* Prefer older API unless we have to pass a flag. */ - if ((nfds ? virDomainCreateWithFiles(dom, nfds, fds, flags) : - (flags ? virDomainCreateWithFlags(dom, flags) - : virDomainCreate(dom))) < 0) { + if (nfds > 0) { + rc =3D virDomainCreateWithFiles(dom, nfds, fds, flags); + } else if (flags !=3D 0) { + rc =3D virDomainCreateWithFlags(dom, flags); + } else { + rc =3D virDomainCreate(dom); + } + + if (rc < 0) { vshError(ctl, _("Failed to start domain '%s'"), virDomainGetName(d= om)); return false; } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229346; cv=none; d=zohomail.com; s=zohoarc; b=hSni6aBoCWBUMvs9UVhEtxxHDYAkrZCfQambRMM34O43YH0n/jX1qGmII3TJ+BapQvOXneKREyrJ97vXQNbwfYquGlOh2+Xzuc9FnMe0+Zkt22ezJdVnY8FfkJXcolhyE+ibpxK9Vb5arUw8ScNqwh3am7+iV4Vg7ZKZWC9G3Ho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229346; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5CGCyHDnc4aNNgi/O9epoHR5UPHxB6eTMVPmqduJ+ag=; b=OA6o8CL99stT5Q4xEjb83BKW2CpMqeLy6vTia4D89TAYgtcfd2Ein1G53canrzj74VmsiiEMQcisB1EV+bme9Vool/goAKuoNlVgX6d+milWNPOQFrfT7q9QveWUgK/cs9W13JIBtULY47AuC2qKQJ9nIb8FkpH78xCpehUQkuI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229346157568.5733657999925; Wed, 2 Mar 2022 05:55:46 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-623-FEGeG9ezPSiHHB03LNKZeQ-1; Wed, 02 Mar 2022 08:55:43 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 95ED51091DA7; Wed, 2 Mar 2022 13:55:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3EFC47C0F7; Wed, 2 Mar 2022 13:55:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DBA571809C98; Wed, 2 Mar 2022 13:55:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DtZ9t017414 for ; Wed, 2 Mar 2022 08:55:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5431B17B7D; Wed, 2 Mar 2022 13:55:35 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9BE0832B4 for ; Wed, 2 Mar 2022 13:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229345; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5CGCyHDnc4aNNgi/O9epoHR5UPHxB6eTMVPmqduJ+ag=; b=iUclm6zvg/b1cwWW1aI9jdFU/u+TW8K0C9+8J/6auGiQweV0eiODeGO+VXw0ccYG+Y+CiA 0Rdl5Hgsut8A4N/KM52g7ucqnGEqgjxKlPtjAKJQj3ZRh5fdYdhVEk8yZ/pi21IW58jz/E sH+4+LbWCGJDaHp0wEFlx5OmGHLZxOk= X-MC-Unique: FEGeG9ezPSiHHB03LNKZeQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/23] virsh: doSave: Use if-else instead of ternary operator Date: Wed, 2 Mar 2022 14:55:02 +0100 Message-Id: <1005cdd4e4f279e5878fa2c9b2e97c3547d61be6.1646229193.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229348318100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 4c90f40f86..607eb973ac 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4213,6 +4213,7 @@ doSave(void *opaque) unsigned int flags =3D 0; const char *xmlfile =3D NULL; g_autofree char *xml =3D NULL; + int rc; #ifndef WIN32 sigset_t sigmask, oldsigmask; @@ -4244,9 +4245,13 @@ doSave(void *opaque) goto out; } - if (((flags || xml) - ? virDomainSaveFlags(dom, to, xml, flags) - : virDomainSave(dom, to)) < 0) { + if (flags || xml) { + rc =3D virDomainSaveFlags(dom, to, xml, flags); + } else { + rc =3D virDomainSave(dom, to); + } + + if (rc < 0) { vshError(ctl, _("Failed to save domain '%s' to %s"), name, to); goto out; } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229543; cv=none; d=zohomail.com; s=zohoarc; b=DkYEGq1Tu112rzzJhmfnpM+TgzV6wNE8GRaFAYCREH+nX7Id+Oq4pInnKehVJBCK4pAqSR7t9zMTFC5UhrcKDqyLel83eoPS4Bs645uV6zDerhWGMaAFCU0adKZ7fqudBiBGDjRCXuQQtQWQ1EV2S5VTDBL3Tq1lv2zZCBVErpE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229543; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5d/+c2TcJ+58bRAiQe9x0qthMGzQg9VO6+5r5+tvjec=; b=XZc6aDxl5wKBOUzh4DDuvmx3Yqnm7xUp0WmktoiWkTub6B9k6Jzq74Mp5A67u052Dq6vxsoZXqRwr0FDuNS/9QNsPWE0fiz84ins4tGp/d1RDjZ4riBSGSVF4pkNgNR5XtZSowewXjaI01/iY+eNckOMyTEI73Z6QB1jzdNoNvw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229543545449.96072166268095; Wed, 2 Mar 2022 05:59:03 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-470-NCgYgfFVOiKw7NQPSNc10Q-1; Wed, 02 Mar 2022 08:56:03 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CEB5E1006AAF; Wed, 2 Mar 2022 13:55:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B1D278495E; Wed, 2 Mar 2022 13:55:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7190846F98; Wed, 2 Mar 2022 13:55:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222Dtaul017419 for ; Wed, 2 Mar 2022 08:55:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6660A17B7D; Wed, 2 Mar 2022 13:55:36 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C19AE8359B for ; Wed, 2 Mar 2022 13:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229542; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5d/+c2TcJ+58bRAiQe9x0qthMGzQg9VO6+5r5+tvjec=; b=UGHdAZeyAE7e0tRaiL6tB8WTBQePcH0Uxib+RQ7a9sfel6KsEY7KA6LbbxjWgpdg/xhOVN VPDkLI4NdVpHTB11rIdW1WiqL0D7twzf+bwMXPZ2BM2KjqVg5/9r1effEoCmwls97wxDf9 I2nul5enbjzt7F739Bm7AZBVtKsRclk= X-MC-Unique: NCgYgfFVOiKw7NQPSNc10Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/23] virsh: cmdRestore: Use if-else instead of ternary operator Date: Wed, 2 Mar 2022 14:55:03 +0100 Message-Id: <5041c763c672b2001b52d4883e03c3c2e2a396a5.1646229193.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229544398100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 607eb973ac..732690ec44 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5313,6 +5313,7 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) const char *xmlfile =3D NULL; g_autofree char *xml =3D NULL; virshControl *priv =3D ctl->privData; + int rc; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; @@ -5333,9 +5334,13 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0) return false; - if (((flags || xml) - ? virDomainRestoreFlags(priv->conn, from, xml, flags) - : virDomainRestore(priv->conn, from)) < 0) { + if (flags || xml) { + rc =3D virDomainRestoreFlags(priv->conn, from, xml, flags); + } else { + rc =3D virDomainRestore(priv->conn, from); + } + + if (rc < 0) { vshError(ctl, _("Failed to restore domain from %s"), from); return false; } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229370; cv=none; d=zohomail.com; s=zohoarc; b=PT/iFs0I6pnPtPzRwBXhb8n7CoaKbzU442lp+ZuXob4Uu//MswDyAuJmO+EM4tppc9DfqH8dvaUVS1Om9Iwj+030MNyPEHRiMHZRlL4lN5zbmAlGDd+ozw9BOvIQiaVUN2T1MZOL9BCa5SyUA0QZFVtvOtxdD08MEUX61Qek7h8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229370; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LTJes5ewdbYD6cec5EgOeWGF65YMih1TvcDcV78iZRs=; b=V5O+YhhUQjKolN80GpEa+SxBZc2msGePM9d+c7fuLnSROYyx1CZCgGMtZaJ1v0PEWc4EiUEicf0OTLp0y0af/Se0ND0qKf3alw4wAeoBkbvBUO/qhZ+4++t/lsBRskpKvJ32vDEPoJN4VlI1RgIjAk1KX8R23OOvWl43lNZVxEQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1646229370781361.16852634905354; Wed, 2 Mar 2022 05:56:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-510-LuV4027kOrKly6a40w6sjQ-1; Wed, 02 Mar 2022 08:56:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7332D824FAA; Wed, 2 Mar 2022 13:56:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 568C78494F; Wed, 2 Mar 2022 13:56:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2B61044A5A; Wed, 2 Mar 2022 13:56:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DtbhD017429 for ; Wed, 2 Mar 2022 08:55:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7348C17B7D; Wed, 2 Mar 2022 13:55:37 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D57EB83581 for ; Wed, 2 Mar 2022 13:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229369; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=LTJes5ewdbYD6cec5EgOeWGF65YMih1TvcDcV78iZRs=; b=DevqHsterjV2d7B3dwwLULxZMhRCS0kgeJzScW9GMZ25+5vJxaPSMrR1rCEnDvMfIRAFy+ UHQWI0XdnT3K83KzitU7RZfWlgqg6Gb2L67oWHMUkBei9nP+y0chi+pQU0BRWyPnIkKyBi yAFX9sdAxEG5YvHvb0DE8EX9Q5D01z8= X-MC-Unique: LuV4027kOrKly6a40w6sjQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/23] virsh: virshVcpuinfoPrintAffinity: Use if-else instead of ternary operator Date: Wed, 2 Mar 2022 14:55:04 +0100 Message-Id: <793ca7787140a5fa14dae8a4554b74c271e998a4.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229372495100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 732690ec44..73f05ce7f9 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6721,8 +6721,12 @@ virshVcpuinfoPrintAffinity(vshControl *ctl, return -1; vshPrint(ctl, _("%s (out of %d)"), str, maxcpu); } else { - for (i =3D 0; i < maxcpu; i++) - vshPrint(ctl, "%c", VIR_CPU_USED(cpumap, i) ? 'y' : '-'); + for (i =3D 0; i < maxcpu; i++) { + if (VIR_CPU_USED(cpumap, i)) + vshPrint(ctl, "y"); + else + vshPrint(ctl, "-"); + } } vshPrint(ctl, "\n"); --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229428; cv=none; d=zohomail.com; s=zohoarc; b=aokLCzzd3XlVrX3vS2WVxWkdypeImug/Xskk51b0LTQRJXoACy8GLt/ounVmNzgnhwOlYSO8yksnMI3sX4u1o407rezydOrLm1pSzA20AQ8Zl1eug4g/lvx3UQZ9xB/iFnHmF6VxxjCLrLwo4w1DrlVUdvQrmTl7bmf5TtyWM7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229428; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qqyjECTADDVTz8Pay/CCKEy16FlJy0LtdRENZYix59E=; b=fUg7S9BIXOCm/U/xFzrH+fetcrXpn6KNR8qQa0VLuv3ZH54YknCbfJAsDR0jlsI5RUAjD3acUcGZVfBPanOni60aL+uxOnjMY+lTQcDiPqpBd02HPB/uo9xAvbYJKtws+8ChhtL7FXC0Mc7weg4GcwKYVUyDjqwLqiiVo9CaMes= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 164622942885034.79798326663399; Wed, 2 Mar 2022 05:57:08 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-FIh4VdqLPn2k8EkOy0gnPQ-1; Wed, 02 Mar 2022 08:56:08 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EB489824FAC; Wed, 2 Mar 2022 13:56:03 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C569D26E4B; Wed, 2 Mar 2022 13:56:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 954CF44A5E; Wed, 2 Mar 2022 13:56:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222Dtcx3017439 for ; Wed, 2 Mar 2022 08:55:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8370A832B4; Wed, 2 Mar 2022 13:55:38 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA87A17B7D for ; Wed, 2 Mar 2022 13:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229427; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=qqyjECTADDVTz8Pay/CCKEy16FlJy0LtdRENZYix59E=; b=YXalH/kP5BTt8DVOEinq/3NGfS+P9+i7GnSIVcu5j7UlvFSV7QTrlJomVTqPibtIo7kO71 Uo7HLFnAv9n0PuA5ZXwk0QKGqlnqJxMKJvZPU9GOZRWr9XN7xlzsn6VKevVZUsHReZSjMQ K2XyOL9Sm3mLZUHWUDiB4HPnNRb0yWo= X-MC-Unique: FIh4VdqLPn2k8EkOy0gnPQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/23] virsh: Use NULLSTR_EMPTY instead of ternary operator Date: Wed, 2 Mar 2022 14:55:05 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229429634100009 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 73f05ce7f9..25097627ac 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -7601,7 +7601,7 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd) ignore_value(pinInfo =3D virBitmapDataFormat(info[i]->cpumap, info= [i]->cpumaplen)); - if (vshTableRowAppend(table, iothreadIdStr, pinInfo ? pinInfo : ""= , NULL) < 0) + if (vshTableRowAppend(table, iothreadIdStr, NULLSTR_EMPTY(pinInfo)= , NULL) < 0) goto cleanup; } @@ -14211,7 +14211,7 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) info[i]->mountpoint, info[i]->name, info[i]->fstype, - targets ? targets : "", + NULLSTR_EMPTY(targets), NULL) < 0) goto cleanup; } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229374; cv=none; d=zohomail.com; s=zohoarc; b=E1xYigB8oiUM9Recgr4ofcr9/ERlEQX6JWA6Th69RRamPKQbP0pLvnPi9/8BTiiohWM7xNtKA8CBN9XdFDqeUT0xS9Vm4uxf0lr3QLN0MW/I4euRdaiuxraqxYdpkOhdyVV3P+A8y45cQu4DRgZr+JmblNnBP/RMJ5AUr9LvXT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229374; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AQ3ns3VQJUBoeqeshQvsu/kCXeMwsUiwNE3tw55dYgM=; b=JC9vCm07p5swIrX2btw12jiMitTun5CZcgigZzPwOBgoLudyQ094eaYR5MtC+2PWARgnXvtBroocgtyePFLBoqLRIjZRoT9ebxEJOuOcuRFNzyONAuc+RRiuAJXS/5IHmL6STdYby8m+GLKY29atFJIZUGJIUKgZMPuZ+dmxmhw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229374656194.23893120120601; Wed, 2 Mar 2022 05:56:14 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-675-HX-ODGrUOTmYsnI8MRttkw-1; Wed, 02 Mar 2022 08:56:12 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB7491091DA4; Wed, 2 Mar 2022 13:56:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A42B84952; Wed, 2 Mar 2022 13:56:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3F4721807D65; Wed, 2 Mar 2022 13:56:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222Dtdjg017449 for ; Wed, 2 Mar 2022 08:55:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9884517B7D; Wed, 2 Mar 2022 13:55:39 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0ADAE83577 for ; Wed, 2 Mar 2022 13:55:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229373; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=AQ3ns3VQJUBoeqeshQvsu/kCXeMwsUiwNE3tw55dYgM=; b=QCD/izPo4wT+ASFKxrJGV6AAGNDdzQE7FtFk1QXu1zHw0zPAGvEO9XRcrWqb0cgKzIHrWh f/yIrJZGSpY7wkZWI+X0jg3shORg/lscyGOwvd3I3bTuSkH4VF5aaX9MSWpBG1d4U3ofuY RpA1S6nuYmRE8hwFvfkD0PpSDwirVb0= X-MC-Unique: HX-ODGrUOTmYsnI8MRttkw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/23] virshEventPrint: Use automatic memory clearing Date: Wed, 2 Mar 2022 14:55:06 +0100 Message-Id: <2f41a70a955d2fd2ac6c5e403f650de074f72378.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229376488100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 25097627ac..33984618eb 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -13166,13 +13166,13 @@ static void virshEventPrint(virshDomEventData *data, virBuffer *buf) { - char *msg; + g_autofree char *msg =3D NULL; if (!(msg =3D virBufferContentAndReset(buf))) return; if (!data->loop && *data->count) - goto cleanup; + return; if (data->timestamp) { char timestamp[VIR_TIME_STRING_BUFLEN]; @@ -13188,9 +13188,6 @@ virshEventPrint(virshDomEventData *data, (*data->count)++; if (!data->loop) vshEventDone(data->ctl); - - cleanup: - VIR_FREE(msg); } static void --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229349; cv=none; d=zohomail.com; s=zohoarc; b=QMZMickyREcS3imdbryhRf3BNPMcjR5mHBu9Mpn+o9/Qrptot5D/ryJyufMrMbChK2c0Z8lz3T4X5HVuUxuuaugf61Lb51g8WEEA5GEEgnMDxL3vmJV6GGmKzyh7ht/YhftwusAZkL8Kq4/1ll9FfsFwIsbwoOrj0fkw1G2O3c0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229349; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=i3IHH1G6imDxzv3vp/InxO2CJdAwcDBARfolooJsWFc=; b=LuEuGWYfmqYrmmEeRvYBvpoXRq5Z+NBQutLmlp/kFOUXZXRqGRscaodxORmAyyom8lociGLfQlhQq2ULFd5KGYsgDCSdr2hkJ5V4lOSSIZ8SRfQrdAuLJ6ksNpdAFOiLcjm7nfxqZtKM8yFNlquAjhBvxcEYISMq5LY9KUUiKvM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1646229349653311.3799852546839; Wed, 2 Mar 2022 05:55:49 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-446-74ssv447PtSalrE83g8B6g-1; Wed, 02 Mar 2022 08:55:47 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 632021091DA2; Wed, 2 Mar 2022 13:55:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 432248495C; Wed, 2 Mar 2022 13:55:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1634F1809CB3; Wed, 2 Mar 2022 13:55:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222Dtexe017454 for ; Wed, 2 Mar 2022 08:55:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id AB87A832B4; Wed, 2 Mar 2022 13:55:40 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1078017B7D for ; Wed, 2 Mar 2022 13:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229349; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=i3IHH1G6imDxzv3vp/InxO2CJdAwcDBARfolooJsWFc=; b=OLo2SCNtPTQ7JxXZELMi3D9vKdDrN430vTgGosxKkxIRuQMoJukSLHS9G8NVKLJDqiGJfN X+txI1+jL3Et622jwPumQx/quaDgtuXmR4BbcDHU55BdH7C41j9jET0notCmJwG9SJSKyO IoeBs9hTHgBvchdHf02HTXTg7PQ2W8s= X-MC-Unique: 74ssv447PtSalrE83g8B6g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/23] virsh: Move 'virshDomainBlockJobToString' to virsh-util Date: Wed, 2 Mar 2022 14:55:07 +0100 Message-Id: <234cfcee30194db08b56ef85c511685193e25e5d.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229361482100001 Content-Type: text/plain; charset="utf-8" The helper function is used in virshBlockJobInfo and also in the callbacks of cmdEvent. Upcoming patch is going to move out the event code into a helper so this needs to be in a shared place. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 19 ------------------- tools/virsh-util.c | 19 +++++++++++++++++++ tools/virsh-util.h | 5 +++++ 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 33984618eb..9c304dbf78 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2614,25 +2614,6 @@ static const vshCmdOptDef opts_blockjob[] =3D { {.name =3D NULL} }; -VIR_ENUM_DECL(virshDomainBlockJob); -VIR_ENUM_IMPL(virshDomainBlockJob, - VIR_DOMAIN_BLOCK_JOB_TYPE_LAST, - N_("Unknown job"), - N_("Block Pull"), - N_("Block Copy"), - N_("Block Commit"), - N_("Active Block Commit"), - N_("Backup"), -); - -static const char * -virshDomainBlockJobToString(int type) -{ - const char *str =3D virshDomainBlockJobTypeToString(type); - return str ? _(str) : _("Unknown job"); -} - - static bool virshBlockJobInfo(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 8fb617fa3c..dc6ed7a86d 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -418,3 +418,22 @@ virshDomainGetXML(vshControl *ctl, return ret; } + + +VIR_ENUM_IMPL(virshDomainBlockJob, + VIR_DOMAIN_BLOCK_JOB_TYPE_LAST, + N_("Unknown job"), + N_("Block Pull"), + N_("Block Copy"), + N_("Block Commit"), + N_("Active Block Commit"), + N_("Backup"), +); + + +const char * +virshDomainBlockJobToString(int type) +{ + const char *str =3D virshDomainBlockJobTypeToString(type); + return str ? _(str) : _("Unknown job"); +} diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 838935d5e8..4d4fe6c01e 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -151,3 +151,8 @@ virshDomainGetXML(vshControl *ctl, xmlXPathContextPtr *ctxt) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) G_GNUC_WARN_UNUSED_RESULT; + +VIR_ENUM_DECL(virshDomainBlockJob); + +const char * +virshDomainBlockJobToString(int type); --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229360; cv=none; d=zohomail.com; s=zohoarc; b=CFptdiVumoQHZnuJ4BeeMRwfhF0mSDovzNUlH1qwTXupb6CXkxHSx1rGtus5PDgtmdU/rBaDnz8PjrN/kQfYWC68GVF5DAs1ItPAAm9795fZl4FToGK+oSo6e3qQmNbMxLsxklj5Nx4rD6OAihm7dRiD3fpoR4eNpwfvoS5/nIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229360; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=By2BmARVPxpQ47B8oNMn4IkrCf1rDtqrgmrOf5IKjiI=; b=N0GrJqLZ/HHXX5RzGIPdCsgZUAAF9uV+uIIdqAolZdGks6Ce5axgFfnwIkgfd+BoZneqKAaNx5aeZFoI0VAduWBJtL38eE+OokhDfEngd8CREekccdt+GhI/8GM4QLc1CmLqP1P4mk4NaZQNgGHesANoYOtMlhwTdAIu7AruACg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229360978719.0746105382369; Wed, 2 Mar 2022 05:56:00 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-163-uDvQ9oM4NkuoJ84bRyZTrw-1; Wed, 02 Mar 2022 08:55:58 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C9885220; Wed, 2 Mar 2022 13:55:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 199B779900; Wed, 2 Mar 2022 13:55:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DF1C04EE45; Wed, 2 Mar 2022 13:55:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DtgE1017474 for ; Wed, 2 Mar 2022 08:55:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 46A4E17B7D; Wed, 2 Mar 2022 13:55:42 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A43883581 for ; Wed, 2 Mar 2022 13:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229359; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=By2BmARVPxpQ47B8oNMn4IkrCf1rDtqrgmrOf5IKjiI=; b=T9XymkkE14tlJ0CJoVQLywh7833q0YBOqOn2Xj+TXWBy0+XwgWUt/bBuYEMuWFZDZc5wU+ UjdmPk+GfoMrsPEPgFRb5GgLsKr8Zm+eYtNy49oJ2XAXzy7fVRs1GPISfGSAlcI5hkw4la AO0FzsOI6hqgfR1Fhldh/hyO3jgifWQ= X-MC-Unique: uDvQ9oM4NkuoJ84bRyZTrw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/23] virsh: Move 'cmdEvent' and all of it's machinery to virsh-domain-event.c Date: Wed, 2 Mar 2022 14:55:08 +0100 Message-Id: <3fa9d193c98b8833ae49de483e2159d4dc985f1c.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229362530100005 Content-Type: text/plain; charset="utf-8" 'cmdEvent' along with all the helper functions it needs is ~950 LOC. Move it out from virsh-domain.c to virsh-domain-event.c along with the completer function so that the new module doesn't have to expose any new types. Semantically this creates a new category in 'virsh help' but all other behaviour stays the same. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- po/POTFILES.in | 1 + tools/meson.build | 1 + tools/virsh-completer-domain.c | 19 - tools/virsh-completer-domain.h | 5 - tools/virsh-domain-event.c | 1007 ++++++++++++++++++++++++++++++++ tools/virsh-domain-event.h | 23 + tools/virsh-domain.c | 946 ------------------------------ tools/virsh.c | 2 + tools/virsh.h | 1 + 9 files changed, 1035 insertions(+), 970 deletions(-) create mode 100644 tools/virsh-domain-event.c create mode 100644 tools/virsh-domain-event.h diff --git a/po/POTFILES.in b/po/POTFILES.in index 1fd3afdd6f..0d9adb0758 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -354,6 +354,7 @@ @SRCDIR@tools/virsh-checkpoint.c @SRCDIR@tools/virsh-completer-host.c @SRCDIR@tools/virsh-console.c +@SRCDIR@tools/virsh-domain-event.c @SRCDIR@tools/virsh-domain-monitor.c @SRCDIR@tools/virsh-domain.c @SRCDIR@tools/virsh-edit.c diff --git a/tools/meson.build b/tools/meson.build index f4b4a16c29..ac714e6425 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -174,6 +174,7 @@ executable( 'virsh-completer-volume.c', 'virsh-console.c', 'virsh-domain.c', + 'virsh-domain-event.c', 'virsh-domain-monitor.c', 'virsh-host.c', 'virsh-interface.c', diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 321c47ef65..250dd8b21a 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -357,25 +357,6 @@ virshDomainBlockjobBaseTopCompleter(vshControl *ctl, return ret; } -char ** -virshDomainEventNameCompleter(vshControl *ctl G_GNUC_UNUSED, - const vshCmd *cmd G_GNUC_UNUSED, - unsigned int flags) -{ - size_t i =3D 0; - g_auto(GStrv) tmp =3D NULL; - - virCheckFlags(0, NULL); - - tmp =3D g_new0(char *, VIR_DOMAIN_EVENT_ID_LAST + 1); - - for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) - tmp[i] =3D g_strdup(virshDomainEventCallbacks[i].name); - - return g_steal_pointer(&tmp); -} - - char ** virshDomainInterfaceStateCompleter(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 044c675842..27cf963912 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -41,11 +41,6 @@ virshDomainDiskTargetCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); -char ** -virshDomainEventNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshDomainInterfaceStateCompleter(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-domain-event.c b/tools/virsh-domain-event.c new file mode 100644 index 0000000000..51571dffad --- /dev/null +++ b/tools/virsh-domain-event.c @@ -0,0 +1,1007 @@ +/* + * virsh-domain-event.c: Domain event listening commands + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include +#include "virsh-domain-event.h" +#include "virsh-util.h" + +#include "internal.h" +#include "viralloc.h" +#include "virenum.h" +#include "virutil.h" +#include "virtime.h" +#include "virtypedparam.h" + +/* + * "event" command + */ + +VIR_ENUM_DECL(virshDomainEvent); +VIR_ENUM_IMPL(virshDomainEvent, + VIR_DOMAIN_EVENT_LAST, + N_("Defined"), + N_("Undefined"), + N_("Started"), + N_("Suspended"), + N_("Resumed"), + N_("Stopped"), + N_("Shutdown"), + N_("PMSuspended"), + N_("Crashed")); + +static const char * +virshDomainEventToString(int event) +{ + const char *str =3D virshDomainEventTypeToString(event); + return str ? _(str) : _("unknown"); +} + +VIR_ENUM_DECL(virshDomainEventDefined); +VIR_ENUM_IMPL(virshDomainEventDefined, + VIR_DOMAIN_EVENT_DEFINED_LAST, + N_("Added"), + N_("Updated"), + N_("Renamed"), + N_("Snapshot")); + +VIR_ENUM_DECL(virshDomainEventUndefined); +VIR_ENUM_IMPL(virshDomainEventUndefined, + VIR_DOMAIN_EVENT_UNDEFINED_LAST, + N_("Removed"), + N_("Renamed")); + +VIR_ENUM_DECL(virshDomainEventStarted); +VIR_ENUM_IMPL(virshDomainEventStarted, + VIR_DOMAIN_EVENT_STARTED_LAST, + N_("Booted"), + N_("Migrated"), + N_("Restored"), + N_("Snapshot"), + N_("Event wakeup")); + +VIR_ENUM_DECL(virshDomainEventSuspended); +VIR_ENUM_IMPL(virshDomainEventSuspended, + VIR_DOMAIN_EVENT_SUSPENDED_LAST, + N_("Paused"), + N_("Migrated"), + N_("I/O Error"), + N_("Watchdog"), + N_("Restored"), + N_("Snapshot"), + N_("API error"), + N_("Post-copy"), + N_("Post-copy Error")); + +VIR_ENUM_DECL(virshDomainEventResumed); +VIR_ENUM_IMPL(virshDomainEventResumed, + VIR_DOMAIN_EVENT_RESUMED_LAST, + N_("Unpaused"), + N_("Migrated"), + N_("Snapshot"), + N_("Post-copy")); + +VIR_ENUM_DECL(virshDomainEventStopped); +VIR_ENUM_IMPL(virshDomainEventStopped, + VIR_DOMAIN_EVENT_STOPPED_LAST, + N_("Shutdown"), + N_("Destroyed"), + N_("Crashed"), + N_("Migrated"), + N_("Saved"), + N_("Failed"), + N_("Snapshot")); + +VIR_ENUM_DECL(virshDomainEventShutdown); +VIR_ENUM_IMPL(virshDomainEventShutdown, + VIR_DOMAIN_EVENT_SHUTDOWN_LAST, + N_("Finished"), + N_("Finished after guest request"), + N_("Finished after host request")); + +VIR_ENUM_DECL(virshDomainEventPMSuspended); +VIR_ENUM_IMPL(virshDomainEventPMSuspended, + VIR_DOMAIN_EVENT_PMSUSPENDED_LAST, + N_("Memory"), + N_("Disk")); + +VIR_ENUM_DECL(virshDomainEventCrashed); +VIR_ENUM_IMPL(virshDomainEventCrashed, + VIR_DOMAIN_EVENT_CRASHED_LAST, + N_("Panicked"), + N_("Crashloaded")); + +static const char * +virshDomainEventDetailToString(int event, int detail) +{ + const char *str =3D NULL; + switch ((virDomainEventType) event) { + case VIR_DOMAIN_EVENT_DEFINED: + str =3D virshDomainEventDefinedTypeToString(detail); + break; + case VIR_DOMAIN_EVENT_UNDEFINED: + str =3D virshDomainEventUndefinedTypeToString(detail); + break; + case VIR_DOMAIN_EVENT_STARTED: + str =3D virshDomainEventStartedTypeToString(detail); + break; + case VIR_DOMAIN_EVENT_SUSPENDED: + str =3D virshDomainEventSuspendedTypeToString(detail); + break; + case VIR_DOMAIN_EVENT_RESUMED: + str =3D virshDomainEventResumedTypeToString(detail); + break; + case VIR_DOMAIN_EVENT_STOPPED: + str =3D virshDomainEventStoppedTypeToString(detail); + break; + case VIR_DOMAIN_EVENT_SHUTDOWN: + str =3D virshDomainEventShutdownTypeToString(detail); + break; + case VIR_DOMAIN_EVENT_PMSUSPENDED: + str =3D virshDomainEventPMSuspendedTypeToString(detail); + break; + case VIR_DOMAIN_EVENT_CRASHED: + str =3D virshDomainEventCrashedTypeToString(detail); + break; + case VIR_DOMAIN_EVENT_LAST: + break; + } + return str ? _(str) : _("unknown"); +} + +VIR_ENUM_DECL(virshDomainEventWatchdog); +VIR_ENUM_IMPL(virshDomainEventWatchdog, + VIR_DOMAIN_EVENT_WATCHDOG_LAST, + N_("none"), + N_("pause"), + N_("reset"), + N_("poweroff"), + N_("shutdown"), + N_("debug"), + N_("inject-nmi")); + +static const char * +virshDomainEventWatchdogToString(int action) +{ + const char *str =3D virshDomainEventWatchdogTypeToString(action); + return str ? _(str) : _("unknown"); +} + +VIR_ENUM_DECL(virshDomainEventIOError); +VIR_ENUM_IMPL(virshDomainEventIOError, + VIR_DOMAIN_EVENT_IO_ERROR_LAST, + N_("none"), + N_("pause"), + N_("report")); + +static const char * +virshDomainEventIOErrorToString(int action) +{ + const char *str =3D virshDomainEventIOErrorTypeToString(action); + return str ? _(str) : _("unknown"); +} + +VIR_ENUM_DECL(virshGraphicsPhase); +VIR_ENUM_IMPL(virshGraphicsPhase, + VIR_DOMAIN_EVENT_GRAPHICS_LAST, + N_("connect"), + N_("initialize"), + N_("disconnect")); + +static const char * +virshGraphicsPhaseToString(int phase) +{ + const char *str =3D virshGraphicsPhaseTypeToString(phase); + return str ? _(str) : _("unknown"); +} + +VIR_ENUM_DECL(virshGraphicsAddress); +VIR_ENUM_IMPL(virshGraphicsAddress, + VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_LAST, + N_("IPv4"), + N_("IPv6"), + N_("unix")); + +static const char * +virshGraphicsAddressToString(int family) +{ + const char *str =3D virshGraphicsAddressTypeToString(family); + return str ? _(str) : _("unknown"); +} + +VIR_ENUM_DECL(virshDomainBlockJobStatus); +VIR_ENUM_IMPL(virshDomainBlockJobStatus, + VIR_DOMAIN_BLOCK_JOB_LAST, + N_("completed"), + N_("failed"), + N_("canceled"), + N_("ready")); + +static const char * +virshDomainBlockJobStatusToString(int status) +{ + const char *str =3D virshDomainBlockJobStatusTypeToString(status); + return str ? _(str) : _("unknown"); +} + +VIR_ENUM_DECL(virshDomainEventDiskChange); +VIR_ENUM_IMPL(virshDomainEventDiskChange, + VIR_DOMAIN_EVENT_DISK_CHANGE_LAST, + N_("changed"), + N_("dropped")); + +static const char * +virshDomainEventDiskChangeToString(int reason) +{ + const char *str =3D virshDomainEventDiskChangeTypeToString(reason); + return str ? _(str) : _("unknown"); +} + +VIR_ENUM_DECL(virshDomainEventTrayChange); +VIR_ENUM_IMPL(virshDomainEventTrayChange, + VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST, + N_("opened"), + N_("closed")); + +static const char * +virshDomainEventTrayChangeToString(int reason) +{ + const char *str =3D virshDomainEventTrayChangeTypeToString(reason); + return str ? _(str) : _("unknown"); +} + + +struct virshDomainEventCallback { + const char *name; + virConnectDomainEventGenericCallback cb; +}; +typedef struct virshDomainEventCallback virshDomainEventCallback; + + +struct virshDomEventData { + vshControl *ctl; + bool loop; + int *count; + bool timestamp; + virshDomainEventCallback *cb; + int id; +}; +typedef struct virshDomEventData virshDomEventData; + +/** + * virshEventPrint: + * + * @data: opaque data passed to all event callbacks + * @buf: string buffer describing the event + * + * Print the event description found in @buf and update virshDomEventData. + * + * This function resets @buf and frees all memory consumed by its content. + */ +static void +virshEventPrint(virshDomEventData *data, + virBuffer *buf) +{ + g_autofree char *msg =3D NULL; + + if (!(msg =3D virBufferContentAndReset(buf))) + return; + + if (!data->loop && *data->count) + return; + + if (data->timestamp) { + char timestamp[VIR_TIME_STRING_BUFLEN]; + + if (virTimeStringNowRaw(timestamp) < 0) + timestamp[0] =3D '\0'; + + vshPrint(data->ctl, "%s: %s", timestamp, msg); + } else { + vshPrint(data->ctl, "%s", msg); + } + + (*data->count)++; + if (!data->loop) + vshEventDone(data->ctl); +} + +static void +virshEventGenericPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event '%s' for domain '%s'\n"), + ((virshDomEventData *) opaque)->cb->name, + virDomainGetName(dom)); + virshEventPrint(opaque, &buf); +} + +static void +virshEventLifecyclePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + int event, + int detail, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'lifecycle' for domain '%s': %s %s\n"= ), + virDomainGetName(dom), + virshDomainEventToString(event), + virshDomainEventDetailToString(event, detail)); + virshEventPrint(opaque, &buf); +} + +static void +virshEventRTCChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + long long utcoffset, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'rtc-change' for domain '%s': %lld\n"= ), + virDomainGetName(dom), + utcoffset); + virshEventPrint(opaque, &buf); +} + +static void +virshEventWatchdogPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + int action, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'watchdog' for domain '%s': %s\n"), + virDomainGetName(dom), + virshDomainEventWatchdogToString(action)); + virshEventPrint(opaque, &buf); +} + +static void +virshEventIOErrorPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *srcPath, + const char *devAlias, + int action, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'io-error' for domain '%s': %s (%s) %= s\n"), + virDomainGetName(dom), + srcPath, + devAlias, + virshDomainEventIOErrorToString(action)); + virshEventPrint(opaque, &buf); +} + +static void +virshEventGraphicsPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + int phase, + const virDomainEventGraphicsAddress *local, + const virDomainEventGraphicsAddress *remote, + const char *authScheme, + const virDomainEventGraphicsSubject *subject, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + size_t i; + + virBufferAsprintf(&buf, _("event 'graphics' for domain '%s': " + "%s local[%s %s %s] remote[%s %s %s] %s\n"), + virDomainGetName(dom), + virshGraphicsPhaseToString(phase), + virshGraphicsAddressToString(local->family), + local->node, + local->service, + virshGraphicsAddressToString(remote->family), + remote->node, + remote->service, + authScheme); + for (i =3D 0; i < subject->nidentity; i++) { + virBufferAsprintf(&buf, "\t%s=3D%s\n", + subject->identities[i].type, + subject->identities[i].name); + } + virshEventPrint(opaque, &buf); +} + +static void +virshEventIOErrorReasonPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *srcPath, + const char *devAlias, + int action, + const char *reason, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'io-error-reason' for domain '%s': " + "%s (%s) %s due to %s\n"), + virDomainGetName(dom), + srcPath, + devAlias, + virshDomainEventIOErrorToString(action), + reason); + virshEventPrint(opaque, &buf); +} + +static void +virshEventBlockJobPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *disk, + int type, + int status, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event '%s' for domain '%s': %s for %s %s\n"= ), + ((virshDomEventData *) opaque)->cb->name, + virDomainGetName(dom), + virshDomainBlockJobToString(type), + disk, + virshDomainBlockJobStatusToString(status)); + virshEventPrint(opaque, &buf); +} + +static void +virshEventDiskChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *oldSrc, + const char *newSrc, + const char *alias, + int reason, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'disk-change' for domain '%s' disk %s= : " + "%s -> %s: %s\n"), + virDomainGetName(dom), + alias, + NULLSTR(oldSrc), + NULLSTR(newSrc), + virshDomainEventDiskChangeToString(reason)); + virshEventPrint(opaque, &buf); +} + +static void +virshEventTrayChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *alias, + int reason, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'tray-change' for domain '%s' disk %s= : %s\n"), + virDomainGetName(dom), + alias, + virshDomainEventTrayChangeToString(reason)); + virshEventPrint(opaque, &buf); +} + +static void +virshEventPMChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + int reason G_GNUC_UNUSED, + void *opaque) +{ + /* As long as libvirt.h doesn't define any reasons, we might as + * well treat all PM state changes as generic events. */ + virshEventGenericPrint(conn, dom, opaque); +} + +static void +virshEventBalloonChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + unsigned long long actual, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'balloon-change' for domain '%s': %ll= uKiB\n"), + virDomainGetName(dom), + actual); + virshEventPrint(opaque, &buf); +} + +static void +virshEventDeviceRemovedPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *alias, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'device-removed' for domain '%s': %s\= n"), + virDomainGetName(dom), + alias); + virshEventPrint(opaque, &buf); +} + +static void +virshEventDeviceAddedPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *alias, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'device-added' for domain '%s': %s\n"= ), + virDomainGetName(dom), + alias); + virshEventPrint(opaque, &buf); +} + +static void +virshEventTunablePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + virTypedParameterPtr params, + int nparams, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + size_t i; + char *value; + + virBufferAsprintf(&buf, _("event 'tunable' for domain '%s':\n"), + virDomainGetName(dom)); + for (i =3D 0; i < nparams; i++) { + value =3D virTypedParameterToString(¶ms[i]); + if (value) { + virBufferAsprintf(&buf, "\t%s: %s\n", params[i].field, value); + VIR_FREE(value); + } + } + virshEventPrint(opaque, &buf); +} + +VIR_ENUM_DECL(virshEventAgentLifecycleState); +VIR_ENUM_IMPL(virshEventAgentLifecycleState, + VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_LAST, + N_("unknown"), + N_("connected"), + N_("disconnected")); + +VIR_ENUM_DECL(virshEventAgentLifecycleReason); +VIR_ENUM_IMPL(virshEventAgentLifecycleReason, + VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_LAST, + N_("unknown"), + N_("domain started"), + N_("channel event")); + +#define UNKNOWNSTR(str) (str ? str : N_("unsupported value")) +static void +virshEventAgentLifecyclePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + int state, + int reason, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'agent-lifecycle' for domain '%s': st= ate: " + "'%s' reason: '%s'\n"), + virDomainGetName(dom), + UNKNOWNSTR(virshEventAgentLifecycleStateTypeToString= (state)), + UNKNOWNSTR(virshEventAgentLifecycleReasonTypeToStrin= g(reason))); + virshEventPrint(opaque, &buf); +} + +static void +virshEventMigrationIterationPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + int iteration, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'migration-iteration' for domain '%s'= : " + "iteration: '%d'\n"), + virDomainGetName(dom), + iteration); + + virshEventPrint(opaque, &buf); +} + +static void +virshEventJobCompletedPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + virTypedParameterPtr params, + int nparams, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + size_t i; + + virBufferAsprintf(&buf, _("event 'job-completed' for domain '%s':\n"), + virDomainGetName(dom)); + for (i =3D 0; i < nparams; i++) { + g_autofree char *value =3D virTypedParameterToString(¶ms[i]); + if (value) + virBufferAsprintf(&buf, "\t%s: %s\n", params[i].field, value); + } + virshEventPrint(opaque, &buf); +} + + +static void +virshEventDeviceRemovalFailedPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *alias, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'device-removal-failed' for domain '%= s': %s\n"), + virDomainGetName(dom), + alias); + virshEventPrint(opaque, &buf); +} + +VIR_ENUM_DECL(virshEventMetadataChangeType); +VIR_ENUM_IMPL(virshEventMetadataChangeType, + VIR_DOMAIN_METADATA_LAST, + N_("description"), + N_("title"), + N_("element")); + +static void +virshEventMetadataChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + int type, + const char *nsuri, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'metadata-change' for domain '%s': ty= pe %s, uri %s\n"), + virDomainGetName(dom), + UNKNOWNSTR(virshEventMetadataChangeTypeTypeToString(= type)), + NULLSTR(nsuri)); + virshEventPrint(opaque, &buf); +} + + +static void +virshEventBlockThresholdPrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *dev, + const char *path, + unsigned long long threshold, + unsigned long long excess, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'block-threshold' for domain '%s': " + "dev: %s(%s) %llu %llu\n"), + virDomainGetName(dom), + dev, NULLSTR(path), threshold, excess); + virshEventPrint(opaque, &buf); +} + + +VIR_ENUM_DECL(virshEventMemoryFailureRecipientType); +VIR_ENUM_IMPL(virshEventMemoryFailureRecipientType, + VIR_DOMAIN_EVENT_MEMORY_FAILURE_RECIPIENT_LAST, + N_("hypervisor"), + N_("guest")); + +VIR_ENUM_DECL(virshEventMemoryFailureActionType); +VIR_ENUM_IMPL(virshEventMemoryFailureActionType, + VIR_DOMAIN_EVENT_MEMORY_FAILURE_ACTION_LAST, + N_("ignore"), + N_("inject"), + N_("fatal"), + N_("reset")); + +static void +virshEventMemoryFailurePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + int recipient, + int action, + unsigned int flags, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, _("event 'memory-failure' for domain '%s':\n" + "recipient: %s\naction: %s\n"), + virDomainGetName(dom), + UNKNOWNSTR(virshEventMemoryFailureRecipientTypeTypeT= oString(recipient)), + UNKNOWNSTR(virshEventMemoryFailureActionTypeTypeToSt= ring(action))); + virBufferAsprintf(&buf, _("flags:\n" + "\taction required: %d\n\trecursive: %d\n"), + !!(flags & VIR_DOMAIN_MEMORY_FAILURE_ACTION_REQUIRED= ), + !!(flags & VIR_DOMAIN_MEMORY_FAILURE_RECURSIVE)); + + virshEventPrint(opaque, &buf); +} + + +static void +virshEventMemoryDeviceSizeChangePrint(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom, + const char *alias, + unsigned long long size, + void *opaque) +{ + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, + _("event 'memory-device-size-change' for domain '%s'= :\n" + "alias: %s\nsize: %llu\n"), + virDomainGetName(dom), alias, size); + + virshEventPrint(opaque, &buf); +} + + +virshDomainEventCallback virshDomainEventCallbacks[] =3D { + { "lifecycle", + VIR_DOMAIN_EVENT_CALLBACK(virshEventLifecyclePrint), }, + { "reboot", virshEventGenericPrint, }, + { "rtc-change", + VIR_DOMAIN_EVENT_CALLBACK(virshEventRTCChangePrint), }, + { "watchdog", + VIR_DOMAIN_EVENT_CALLBACK(virshEventWatchdogPrint), }, + { "io-error", + VIR_DOMAIN_EVENT_CALLBACK(virshEventIOErrorPrint), }, + { "graphics", + VIR_DOMAIN_EVENT_CALLBACK(virshEventGraphicsPrint), }, + { "io-error-reason", + VIR_DOMAIN_EVENT_CALLBACK(virshEventIOErrorReasonPrint), }, + { "control-error", virshEventGenericPrint, }, + { "block-job", + VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockJobPrint), }, + { "disk-change", + VIR_DOMAIN_EVENT_CALLBACK(virshEventDiskChangePrint), }, + { "tray-change", + VIR_DOMAIN_EVENT_CALLBACK(virshEventTrayChangePrint), }, + { "pm-wakeup", + VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), }, + { "pm-suspend", + VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), }, + { "balloon-change", + VIR_DOMAIN_EVENT_CALLBACK(virshEventBalloonChangePrint), }, + { "pm-suspend-disk", + VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), }, + { "device-removed", + VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceRemovedPrint), }, + { "block-job-2", + VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockJobPrint), }, + { "tunable", + VIR_DOMAIN_EVENT_CALLBACK(virshEventTunablePrint), }, + { "agent-lifecycle", + VIR_DOMAIN_EVENT_CALLBACK(virshEventAgentLifecyclePrint), }, + { "device-added", + VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceAddedPrint), }, + { "migration-iteration", + VIR_DOMAIN_EVENT_CALLBACK(virshEventMigrationIterationPrint), }, + { "job-completed", + VIR_DOMAIN_EVENT_CALLBACK(virshEventJobCompletedPrint), }, + { "device-removal-failed", + VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceRemovalFailedPrint), }, + { "metadata-change", + VIR_DOMAIN_EVENT_CALLBACK(virshEventMetadataChangePrint), }, + { "block-threshold", + VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockThresholdPrint), }, + { "memory-failure", + VIR_DOMAIN_EVENT_CALLBACK(virshEventMemoryFailurePrint), }, + { "memory-device-size-change", + VIR_DOMAIN_EVENT_CALLBACK(virshEventMemoryDeviceSizeChangePrint), }, +}; +G_STATIC_ASSERT(VIR_DOMAIN_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshDomainEv= entCallbacks)); + + +static char ** +virshDomainEventNameCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + size_t i =3D 0; + g_auto(GStrv) tmp =3D NULL; + + virCheckFlags(0, NULL); + + tmp =3D g_new0(char *, VIR_DOMAIN_EVENT_ID_LAST + 1); + + for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) + tmp[i] =3D g_strdup(virshDomainEventCallbacks[i].name); + + return g_steal_pointer(&tmp); +} + + +static const vshCmdInfo info_event[] =3D { + {.name =3D "help", + .data =3D N_("Domain Events") + }, + {.name =3D "desc", + .data =3D N_("List event types, or wait for domain events to occur") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_event[] =3D { + VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("filter by domain name, id or uui= d"), + 0, 0), + {.name =3D "event", + .type =3D VSH_OT_STRING, + .completer =3D virshDomainEventNameCompleter, + .help =3D N_("which event type to wait for") + }, + {.name =3D "all", + .type =3D VSH_OT_BOOL, + .help =3D N_("wait for all events instead of just one type") + }, + {.name =3D "loop", + .type =3D VSH_OT_BOOL, + .help =3D N_("loop until timeout or interrupt, rather than one-shot") + }, + {.name =3D "timeout", + .type =3D VSH_OT_INT, + .help =3D N_("timeout seconds") + }, + {.name =3D "list", + .type =3D VSH_OT_BOOL, + .help =3D N_("list valid event types") + }, + {.name =3D "timestamp", + .type =3D VSH_OT_BOOL, + .help =3D N_("show timestamp for each printed event") + }, + {.name =3D NULL} +}; + +static bool +cmdEvent(vshControl *ctl, const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + bool ret =3D false; + int timeout =3D 0; + virshDomEventData *data =3D NULL; + size_t i; + const char *eventName =3D NULL; + int event =3D -1; + bool all =3D vshCommandOptBool(cmd, "all"); + bool loop =3D vshCommandOptBool(cmd, "loop"); + bool timestamp =3D vshCommandOptBool(cmd, "timestamp"); + int count =3D 0; + virshControl *priv =3D ctl->privData; + + VSH_EXCLUSIVE_OPTIONS("all", "event"); + VSH_EXCLUSIVE_OPTIONS("list", "all"); + VSH_EXCLUSIVE_OPTIONS("list", "event"); + + if (vshCommandOptBool(cmd, "list")) { + for (event =3D 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) + vshPrint(ctl, "%s\n", virshDomainEventCallbacks[event].name); + return true; + } + + if (vshCommandOptStringReq(ctl, cmd, "event", &eventName) < 0) + return false; + if (eventName) { + for (event =3D 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) + if (STREQ(eventName, virshDomainEventCallbacks[event].name)) + break; + if (event =3D=3D VIR_DOMAIN_EVENT_ID_LAST) { + vshError(ctl, _("unknown event type %s"), eventName); + return false; + } + } else if (!all) { + vshError(ctl, "%s", + _("one of --list, --all, or --event is required")); + return false; + } + + if (all) { + data =3D g_new0(virshDomEventData, VIR_DOMAIN_EVENT_ID_LAST); + for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { + data[i].ctl =3D ctl; + data[i].loop =3D loop; + data[i].count =3D &count; + data[i].timestamp =3D timestamp; + data[i].cb =3D &virshDomainEventCallbacks[i]; + data[i].id =3D -1; + } + } else { + data =3D g_new0(virshDomEventData, 1); + data[0].ctl =3D ctl; + data[0].loop =3D vshCommandOptBool(cmd, "loop"); + data[0].count =3D &count; + data[0].timestamp =3D timestamp; + data[0].cb =3D &virshDomainEventCallbacks[event]; + data[0].id =3D -1; + } + if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) + goto cleanup; + + if (vshCommandOptBool(cmd, "domain")) + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + if (vshEventStart(ctl, timeout) < 0) + goto cleanup; + + for (i =3D 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) { + if ((data[i].id =3D virConnectDomainEventRegisterAny(priv->conn, d= om, + all ? i : event, + data[i].cb->cb, + &data[i], + NULL)) < 0) { + /* When registering for all events: if the first + * registration succeeds, silently ignore failures on all + * later registrations on the assumption that the server + * is older and didn't know quite as many events. */ + if (i) + vshResetLibvirtError(); + else + goto cleanup; + } + } + switch (vshEventWait(ctl)) { + case VSH_EVENT_INTERRUPT: + vshPrint(ctl, "%s", _("event loop interrupted\n")); + break; + case VSH_EVENT_TIMEOUT: + vshPrint(ctl, "%s", _("event loop timed out\n")); + break; + case VSH_EVENT_DONE: + break; + default: + goto cleanup; + } + vshPrint(ctl, _("events received: %d\n"), count); + if (count) + ret =3D true; + + cleanup: + vshEventCleanup(ctl); + if (data) { + for (i =3D 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) { + if (data[i].id >=3D 0 && + virConnectDomainEventDeregisterAny(priv->conn, data[i].id)= < 0) + ret =3D false; + } + VIR_FREE(data); + } + return ret; +} + + +const vshCmdDef domEventCmds[] =3D { + {.name =3D "event", + .handler =3D cmdEvent, + .opts =3D opts_event, + .info =3D info_event, + .flags =3D 0 + }, + {.name =3D NULL} +}; diff --git a/tools/virsh-domain-event.h b/tools/virsh-domain-event.h new file mode 100644 index 0000000000..dd96ef21ac --- /dev/null +++ b/tools/virsh-domain-event.h @@ -0,0 +1,23 @@ +/* + * virsh-domain-event.h: Commands for domain events + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "virsh.h" + +extern const vshCmdDef domEventCmds[]; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 9c304dbf78..dc6e3b5020 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12887,946 +12887,6 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd) } -/* - * "event" command - */ -VIR_ENUM_DECL(virshDomainEvent); -VIR_ENUM_IMPL(virshDomainEvent, - VIR_DOMAIN_EVENT_LAST, - N_("Defined"), - N_("Undefined"), - N_("Started"), - N_("Suspended"), - N_("Resumed"), - N_("Stopped"), - N_("Shutdown"), - N_("PMSuspended"), - N_("Crashed")); - -static const char * -virshDomainEventToString(int event) -{ - const char *str =3D virshDomainEventTypeToString(event); - return str ? _(str) : _("unknown"); -} - -VIR_ENUM_DECL(virshDomainEventDefined); -VIR_ENUM_IMPL(virshDomainEventDefined, - VIR_DOMAIN_EVENT_DEFINED_LAST, - N_("Added"), - N_("Updated"), - N_("Renamed"), - N_("Snapshot")); - -VIR_ENUM_DECL(virshDomainEventUndefined); -VIR_ENUM_IMPL(virshDomainEventUndefined, - VIR_DOMAIN_EVENT_UNDEFINED_LAST, - N_("Removed"), - N_("Renamed")); - -VIR_ENUM_DECL(virshDomainEventStarted); -VIR_ENUM_IMPL(virshDomainEventStarted, - VIR_DOMAIN_EVENT_STARTED_LAST, - N_("Booted"), - N_("Migrated"), - N_("Restored"), - N_("Snapshot"), - N_("Event wakeup")); - -VIR_ENUM_DECL(virshDomainEventSuspended); -VIR_ENUM_IMPL(virshDomainEventSuspended, - VIR_DOMAIN_EVENT_SUSPENDED_LAST, - N_("Paused"), - N_("Migrated"), - N_("I/O Error"), - N_("Watchdog"), - N_("Restored"), - N_("Snapshot"), - N_("API error"), - N_("Post-copy"), - N_("Post-copy Error")); - -VIR_ENUM_DECL(virshDomainEventResumed); -VIR_ENUM_IMPL(virshDomainEventResumed, - VIR_DOMAIN_EVENT_RESUMED_LAST, - N_("Unpaused"), - N_("Migrated"), - N_("Snapshot"), - N_("Post-copy")); - -VIR_ENUM_DECL(virshDomainEventStopped); -VIR_ENUM_IMPL(virshDomainEventStopped, - VIR_DOMAIN_EVENT_STOPPED_LAST, - N_("Shutdown"), - N_("Destroyed"), - N_("Crashed"), - N_("Migrated"), - N_("Saved"), - N_("Failed"), - N_("Snapshot")); - -VIR_ENUM_DECL(virshDomainEventShutdown); -VIR_ENUM_IMPL(virshDomainEventShutdown, - VIR_DOMAIN_EVENT_SHUTDOWN_LAST, - N_("Finished"), - N_("Finished after guest request"), - N_("Finished after host request")); - -VIR_ENUM_DECL(virshDomainEventPMSuspended); -VIR_ENUM_IMPL(virshDomainEventPMSuspended, - VIR_DOMAIN_EVENT_PMSUSPENDED_LAST, - N_("Memory"), - N_("Disk")); - -VIR_ENUM_DECL(virshDomainEventCrashed); -VIR_ENUM_IMPL(virshDomainEventCrashed, - VIR_DOMAIN_EVENT_CRASHED_LAST, - N_("Panicked"), - N_("Crashloaded")); - -static const char * -virshDomainEventDetailToString(int event, int detail) -{ - const char *str =3D NULL; - switch ((virDomainEventType) event) { - case VIR_DOMAIN_EVENT_DEFINED: - str =3D virshDomainEventDefinedTypeToString(detail); - break; - case VIR_DOMAIN_EVENT_UNDEFINED: - str =3D virshDomainEventUndefinedTypeToString(detail); - break; - case VIR_DOMAIN_EVENT_STARTED: - str =3D virshDomainEventStartedTypeToString(detail); - break; - case VIR_DOMAIN_EVENT_SUSPENDED: - str =3D virshDomainEventSuspendedTypeToString(detail); - break; - case VIR_DOMAIN_EVENT_RESUMED: - str =3D virshDomainEventResumedTypeToString(detail); - break; - case VIR_DOMAIN_EVENT_STOPPED: - str =3D virshDomainEventStoppedTypeToString(detail); - break; - case VIR_DOMAIN_EVENT_SHUTDOWN: - str =3D virshDomainEventShutdownTypeToString(detail); - break; - case VIR_DOMAIN_EVENT_PMSUSPENDED: - str =3D virshDomainEventPMSuspendedTypeToString(detail); - break; - case VIR_DOMAIN_EVENT_CRASHED: - str =3D virshDomainEventCrashedTypeToString(detail); - break; - case VIR_DOMAIN_EVENT_LAST: - break; - } - return str ? _(str) : _("unknown"); -} - -VIR_ENUM_DECL(virshDomainEventWatchdog); -VIR_ENUM_IMPL(virshDomainEventWatchdog, - VIR_DOMAIN_EVENT_WATCHDOG_LAST, - N_("none"), - N_("pause"), - N_("reset"), - N_("poweroff"), - N_("shutdown"), - N_("debug"), - N_("inject-nmi")); - -static const char * -virshDomainEventWatchdogToString(int action) -{ - const char *str =3D virshDomainEventWatchdogTypeToString(action); - return str ? _(str) : _("unknown"); -} - -VIR_ENUM_DECL(virshDomainEventIOError); -VIR_ENUM_IMPL(virshDomainEventIOError, - VIR_DOMAIN_EVENT_IO_ERROR_LAST, - N_("none"), - N_("pause"), - N_("report")); - -static const char * -virshDomainEventIOErrorToString(int action) -{ - const char *str =3D virshDomainEventIOErrorTypeToString(action); - return str ? _(str) : _("unknown"); -} - -VIR_ENUM_DECL(virshGraphicsPhase); -VIR_ENUM_IMPL(virshGraphicsPhase, - VIR_DOMAIN_EVENT_GRAPHICS_LAST, - N_("connect"), - N_("initialize"), - N_("disconnect")); - -static const char * -virshGraphicsPhaseToString(int phase) -{ - const char *str =3D virshGraphicsPhaseTypeToString(phase); - return str ? _(str) : _("unknown"); -} - -VIR_ENUM_DECL(virshGraphicsAddress); -VIR_ENUM_IMPL(virshGraphicsAddress, - VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_LAST, - N_("IPv4"), - N_("IPv6"), - N_("unix")); - -static const char * -virshGraphicsAddressToString(int family) -{ - const char *str =3D virshGraphicsAddressTypeToString(family); - return str ? _(str) : _("unknown"); -} - -VIR_ENUM_DECL(virshDomainBlockJobStatus); -VIR_ENUM_IMPL(virshDomainBlockJobStatus, - VIR_DOMAIN_BLOCK_JOB_LAST, - N_("completed"), - N_("failed"), - N_("canceled"), - N_("ready")); - -static const char * -virshDomainBlockJobStatusToString(int status) -{ - const char *str =3D virshDomainBlockJobStatusTypeToString(status); - return str ? _(str) : _("unknown"); -} - -VIR_ENUM_DECL(virshDomainEventDiskChange); -VIR_ENUM_IMPL(virshDomainEventDiskChange, - VIR_DOMAIN_EVENT_DISK_CHANGE_LAST, - N_("changed"), - N_("dropped")); - -static const char * -virshDomainEventDiskChangeToString(int reason) -{ - const char *str =3D virshDomainEventDiskChangeTypeToString(reason); - return str ? _(str) : _("unknown"); -} - -VIR_ENUM_DECL(virshDomainEventTrayChange); -VIR_ENUM_IMPL(virshDomainEventTrayChange, - VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST, - N_("opened"), - N_("closed")); - -static const char * -virshDomainEventTrayChangeToString(int reason) -{ - const char *str =3D virshDomainEventTrayChangeTypeToString(reason); - return str ? _(str) : _("unknown"); -} - -struct virshDomEventData { - vshControl *ctl; - bool loop; - int *count; - bool timestamp; - virshDomainEventCallback *cb; - int id; -}; -typedef struct virshDomEventData virshDomEventData; - -/** - * virshEventPrint: - * - * @data: opaque data passed to all event callbacks - * @buf: string buffer describing the event - * - * Print the event description found in @buf and update virshDomEventData. - * - * This function resets @buf and frees all memory consumed by its content. - */ -static void -virshEventPrint(virshDomEventData *data, - virBuffer *buf) -{ - g_autofree char *msg =3D NULL; - - if (!(msg =3D virBufferContentAndReset(buf))) - return; - - if (!data->loop && *data->count) - return; - - if (data->timestamp) { - char timestamp[VIR_TIME_STRING_BUFLEN]; - - if (virTimeStringNowRaw(timestamp) < 0) - timestamp[0] =3D '\0'; - - vshPrint(data->ctl, "%s: %s", timestamp, msg); - } else { - vshPrint(data->ctl, "%s", msg); - } - - (*data->count)++; - if (!data->loop) - vshEventDone(data->ctl); -} - -static void -virshEventGenericPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event '%s' for domain '%s'\n"), - ((virshDomEventData *) opaque)->cb->name, - virDomainGetName(dom)); - virshEventPrint(opaque, &buf); -} - -static void -virshEventLifecyclePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - int event, - int detail, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'lifecycle' for domain '%s': %s %s\n"= ), - virDomainGetName(dom), - virshDomainEventToString(event), - virshDomainEventDetailToString(event, detail)); - virshEventPrint(opaque, &buf); -} - -static void -virshEventRTCChangePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - long long utcoffset, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'rtc-change' for domain '%s': %lld\n"= ), - virDomainGetName(dom), - utcoffset); - virshEventPrint(opaque, &buf); -} - -static void -virshEventWatchdogPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - int action, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'watchdog' for domain '%s': %s\n"), - virDomainGetName(dom), - virshDomainEventWatchdogToString(action)); - virshEventPrint(opaque, &buf); -} - -static void -virshEventIOErrorPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - const char *srcPath, - const char *devAlias, - int action, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'io-error' for domain '%s': %s (%s) %= s\n"), - virDomainGetName(dom), - srcPath, - devAlias, - virshDomainEventIOErrorToString(action)); - virshEventPrint(opaque, &buf); -} - -static void -virshEventGraphicsPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - int phase, - const virDomainEventGraphicsAddress *local, - const virDomainEventGraphicsAddress *remote, - const char *authScheme, - const virDomainEventGraphicsSubject *subject, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - size_t i; - - virBufferAsprintf(&buf, _("event 'graphics' for domain '%s': " - "%s local[%s %s %s] remote[%s %s %s] %s\n"), - virDomainGetName(dom), - virshGraphicsPhaseToString(phase), - virshGraphicsAddressToString(local->family), - local->node, - local->service, - virshGraphicsAddressToString(remote->family), - remote->node, - remote->service, - authScheme); - for (i =3D 0; i < subject->nidentity; i++) { - virBufferAsprintf(&buf, "\t%s=3D%s\n", - subject->identities[i].type, - subject->identities[i].name); - } - virshEventPrint(opaque, &buf); -} - -static void -virshEventIOErrorReasonPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - const char *srcPath, - const char *devAlias, - int action, - const char *reason, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'io-error-reason' for domain '%s': " - "%s (%s) %s due to %s\n"), - virDomainGetName(dom), - srcPath, - devAlias, - virshDomainEventIOErrorToString(action), - reason); - virshEventPrint(opaque, &buf); -} - -static void -virshEventBlockJobPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - const char *disk, - int type, - int status, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event '%s' for domain '%s': %s for %s %s\n"= ), - ((virshDomEventData *) opaque)->cb->name, - virDomainGetName(dom), - virshDomainBlockJobToString(type), - disk, - virshDomainBlockJobStatusToString(status)); - virshEventPrint(opaque, &buf); -} - -static void -virshEventDiskChangePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - const char *oldSrc, - const char *newSrc, - const char *alias, - int reason, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'disk-change' for domain '%s' disk %s= : " - "%s -> %s: %s\n"), - virDomainGetName(dom), - alias, - NULLSTR(oldSrc), - NULLSTR(newSrc), - virshDomainEventDiskChangeToString(reason)); - virshEventPrint(opaque, &buf); -} - -static void -virshEventTrayChangePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - const char *alias, - int reason, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'tray-change' for domain '%s' disk %s= : %s\n"), - virDomainGetName(dom), - alias, - virshDomainEventTrayChangeToString(reason)); - virshEventPrint(opaque, &buf); -} - -static void -virshEventPMChangePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - int reason G_GNUC_UNUSED, - void *opaque) -{ - /* As long as libvirt.h doesn't define any reasons, we might as - * well treat all PM state changes as generic events. */ - virshEventGenericPrint(conn, dom, opaque); -} - -static void -virshEventBalloonChangePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - unsigned long long actual, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'balloon-change' for domain '%s': %ll= uKiB\n"), - virDomainGetName(dom), - actual); - virshEventPrint(opaque, &buf); -} - -static void -virshEventDeviceRemovedPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - const char *alias, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'device-removed' for domain '%s': %s\= n"), - virDomainGetName(dom), - alias); - virshEventPrint(opaque, &buf); -} - -static void -virshEventDeviceAddedPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - const char *alias, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'device-added' for domain '%s': %s\n"= ), - virDomainGetName(dom), - alias); - virshEventPrint(opaque, &buf); -} - -static void -virshEventTunablePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - virTypedParameterPtr params, - int nparams, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - size_t i; - char *value; - - virBufferAsprintf(&buf, _("event 'tunable' for domain '%s':\n"), - virDomainGetName(dom)); - for (i =3D 0; i < nparams; i++) { - value =3D virTypedParameterToString(¶ms[i]); - if (value) { - virBufferAsprintf(&buf, "\t%s: %s\n", params[i].field, value); - VIR_FREE(value); - } - } - virshEventPrint(opaque, &buf); -} - -VIR_ENUM_DECL(virshEventAgentLifecycleState); -VIR_ENUM_IMPL(virshEventAgentLifecycleState, - VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_LAST, - N_("unknown"), - N_("connected"), - N_("disconnected")); - -VIR_ENUM_DECL(virshEventAgentLifecycleReason); -VIR_ENUM_IMPL(virshEventAgentLifecycleReason, - VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_LAST, - N_("unknown"), - N_("domain started"), - N_("channel event")); - -#define UNKNOWNSTR(str) (str ? str : N_("unsupported value")) -static void -virshEventAgentLifecyclePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - int state, - int reason, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'agent-lifecycle' for domain '%s': st= ate: " - "'%s' reason: '%s'\n"), - virDomainGetName(dom), - UNKNOWNSTR(virshEventAgentLifecycleStateTypeToString= (state)), - UNKNOWNSTR(virshEventAgentLifecycleReasonTypeToStrin= g(reason))); - virshEventPrint(opaque, &buf); -} - -static void -virshEventMigrationIterationPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - int iteration, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'migration-iteration' for domain '%s'= : " - "iteration: '%d'\n"), - virDomainGetName(dom), - iteration); - - virshEventPrint(opaque, &buf); -} - -static void -virshEventJobCompletedPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - virTypedParameterPtr params, - int nparams, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - size_t i; - - virBufferAsprintf(&buf, _("event 'job-completed' for domain '%s':\n"), - virDomainGetName(dom)); - for (i =3D 0; i < nparams; i++) { - g_autofree char *value =3D virTypedParameterToString(¶ms[i]); - if (value) - virBufferAsprintf(&buf, "\t%s: %s\n", params[i].field, value); - } - virshEventPrint(opaque, &buf); -} - - -static void -virshEventDeviceRemovalFailedPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - const char *alias, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'device-removal-failed' for domain '%= s': %s\n"), - virDomainGetName(dom), - alias); - virshEventPrint(opaque, &buf); -} - -VIR_ENUM_DECL(virshEventMetadataChangeType); -VIR_ENUM_IMPL(virshEventMetadataChangeType, - VIR_DOMAIN_METADATA_LAST, - N_("description"), - N_("title"), - N_("element")); - -static void -virshEventMetadataChangePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - int type, - const char *nsuri, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'metadata-change' for domain '%s': ty= pe %s, uri %s\n"), - virDomainGetName(dom), - UNKNOWNSTR(virshEventMetadataChangeTypeTypeToString(= type)), - NULLSTR(nsuri)); - virshEventPrint(opaque, &buf); -} - - -static void -virshEventBlockThresholdPrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - const char *dev, - const char *path, - unsigned long long threshold, - unsigned long long excess, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'block-threshold' for domain '%s': " - "dev: %s(%s) %llu %llu\n"), - virDomainGetName(dom), - dev, NULLSTR(path), threshold, excess); - virshEventPrint(opaque, &buf); -} - - -VIR_ENUM_DECL(virshEventMemoryFailureRecipientType); -VIR_ENUM_IMPL(virshEventMemoryFailureRecipientType, - VIR_DOMAIN_EVENT_MEMORY_FAILURE_RECIPIENT_LAST, - N_("hypervisor"), - N_("guest")); - -VIR_ENUM_DECL(virshEventMemoryFailureActionType); -VIR_ENUM_IMPL(virshEventMemoryFailureActionType, - VIR_DOMAIN_EVENT_MEMORY_FAILURE_ACTION_LAST, - N_("ignore"), - N_("inject"), - N_("fatal"), - N_("reset")); - -static void -virshEventMemoryFailurePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - int recipient, - int action, - unsigned int flags, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, _("event 'memory-failure' for domain '%s':\n" - "recipient: %s\naction: %s\n"), - virDomainGetName(dom), - UNKNOWNSTR(virshEventMemoryFailureRecipientTypeTypeT= oString(recipient)), - UNKNOWNSTR(virshEventMemoryFailureActionTypeTypeToSt= ring(action))); - virBufferAsprintf(&buf, _("flags:\n" - "\taction required: %d\n\trecursive: %d\n"), - !!(flags & VIR_DOMAIN_MEMORY_FAILURE_ACTION_REQUIRED= ), - !!(flags & VIR_DOMAIN_MEMORY_FAILURE_RECURSIVE)); - - virshEventPrint(opaque, &buf); -} - - -static void -virshEventMemoryDeviceSizeChangePrint(virConnectPtr conn G_GNUC_UNUSED, - virDomainPtr dom, - const char *alias, - unsigned long long size, - void *opaque) -{ - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, - _("event 'memory-device-size-change' for domain '%s'= :\n" - "alias: %s\nsize: %llu\n"), - virDomainGetName(dom), alias, size); - - virshEventPrint(opaque, &buf); -} - - -virshDomainEventCallback virshDomainEventCallbacks[] =3D { - { "lifecycle", - VIR_DOMAIN_EVENT_CALLBACK(virshEventLifecyclePrint), }, - { "reboot", virshEventGenericPrint, }, - { "rtc-change", - VIR_DOMAIN_EVENT_CALLBACK(virshEventRTCChangePrint), }, - { "watchdog", - VIR_DOMAIN_EVENT_CALLBACK(virshEventWatchdogPrint), }, - { "io-error", - VIR_DOMAIN_EVENT_CALLBACK(virshEventIOErrorPrint), }, - { "graphics", - VIR_DOMAIN_EVENT_CALLBACK(virshEventGraphicsPrint), }, - { "io-error-reason", - VIR_DOMAIN_EVENT_CALLBACK(virshEventIOErrorReasonPrint), }, - { "control-error", virshEventGenericPrint, }, - { "block-job", - VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockJobPrint), }, - { "disk-change", - VIR_DOMAIN_EVENT_CALLBACK(virshEventDiskChangePrint), }, - { "tray-change", - VIR_DOMAIN_EVENT_CALLBACK(virshEventTrayChangePrint), }, - { "pm-wakeup", - VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), }, - { "pm-suspend", - VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), }, - { "balloon-change", - VIR_DOMAIN_EVENT_CALLBACK(virshEventBalloonChangePrint), }, - { "pm-suspend-disk", - VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), }, - { "device-removed", - VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceRemovedPrint), }, - { "block-job-2", - VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockJobPrint), }, - { "tunable", - VIR_DOMAIN_EVENT_CALLBACK(virshEventTunablePrint), }, - { "agent-lifecycle", - VIR_DOMAIN_EVENT_CALLBACK(virshEventAgentLifecyclePrint), }, - { "device-added", - VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceAddedPrint), }, - { "migration-iteration", - VIR_DOMAIN_EVENT_CALLBACK(virshEventMigrationIterationPrint), }, - { "job-completed", - VIR_DOMAIN_EVENT_CALLBACK(virshEventJobCompletedPrint), }, - { "device-removal-failed", - VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceRemovalFailedPrint), }, - { "metadata-change", - VIR_DOMAIN_EVENT_CALLBACK(virshEventMetadataChangePrint), }, - { "block-threshold", - VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockThresholdPrint), }, - { "memory-failure", - VIR_DOMAIN_EVENT_CALLBACK(virshEventMemoryFailurePrint), }, - { "memory-device-size-change", - VIR_DOMAIN_EVENT_CALLBACK(virshEventMemoryDeviceSizeChangePrint), }, -}; -G_STATIC_ASSERT(VIR_DOMAIN_EVENT_ID_LAST =3D=3D G_N_ELEMENTS(virshDomainEv= entCallbacks)); - -static const vshCmdInfo info_event[] =3D { - {.name =3D "help", - .data =3D N_("Domain Events") - }, - {.name =3D "desc", - .data =3D N_("List event types, or wait for domain events to occur") - }, - {.name =3D NULL} -}; - -static const vshCmdOptDef opts_event[] =3D { - VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("filter by domain name, id or uui= d"), - 0, 0), - {.name =3D "event", - .type =3D VSH_OT_STRING, - .completer =3D virshDomainEventNameCompleter, - .help =3D N_("which event type to wait for") - }, - {.name =3D "all", - .type =3D VSH_OT_BOOL, - .help =3D N_("wait for all events instead of just one type") - }, - {.name =3D "loop", - .type =3D VSH_OT_BOOL, - .help =3D N_("loop until timeout or interrupt, rather than one-shot") - }, - {.name =3D "timeout", - .type =3D VSH_OT_INT, - .help =3D N_("timeout seconds") - }, - {.name =3D "list", - .type =3D VSH_OT_BOOL, - .help =3D N_("list valid event types") - }, - {.name =3D "timestamp", - .type =3D VSH_OT_BOOL, - .help =3D N_("show timestamp for each printed event") - }, - {.name =3D NULL} -}; - -static bool -cmdEvent(vshControl *ctl, const vshCmd *cmd) -{ - g_autoptr(virshDomain) dom =3D NULL; - bool ret =3D false; - int timeout =3D 0; - virshDomEventData *data =3D NULL; - size_t i; - const char *eventName =3D NULL; - int event =3D -1; - bool all =3D vshCommandOptBool(cmd, "all"); - bool loop =3D vshCommandOptBool(cmd, "loop"); - bool timestamp =3D vshCommandOptBool(cmd, "timestamp"); - int count =3D 0; - virshControl *priv =3D ctl->privData; - - VSH_EXCLUSIVE_OPTIONS("all", "event"); - VSH_EXCLUSIVE_OPTIONS("list", "all"); - VSH_EXCLUSIVE_OPTIONS("list", "event"); - - if (vshCommandOptBool(cmd, "list")) { - for (event =3D 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) - vshPrint(ctl, "%s\n", virshDomainEventCallbacks[event].name); - return true; - } - - if (vshCommandOptStringReq(ctl, cmd, "event", &eventName) < 0) - return false; - if (eventName) { - for (event =3D 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) - if (STREQ(eventName, virshDomainEventCallbacks[event].name)) - break; - if (event =3D=3D VIR_DOMAIN_EVENT_ID_LAST) { - vshError(ctl, _("unknown event type %s"), eventName); - return false; - } - } else if (!all) { - vshError(ctl, "%s", - _("one of --list, --all, or --event is required")); - return false; - } - - if (all) { - data =3D g_new0(virshDomEventData, VIR_DOMAIN_EVENT_ID_LAST); - for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { - data[i].ctl =3D ctl; - data[i].loop =3D loop; - data[i].count =3D &count; - data[i].timestamp =3D timestamp; - data[i].cb =3D &virshDomainEventCallbacks[i]; - data[i].id =3D -1; - } - } else { - data =3D g_new0(virshDomEventData, 1); - data[0].ctl =3D ctl; - data[0].loop =3D vshCommandOptBool(cmd, "loop"); - data[0].count =3D &count; - data[0].timestamp =3D timestamp; - data[0].cb =3D &virshDomainEventCallbacks[event]; - data[0].id =3D -1; - } - if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) - goto cleanup; - - if (vshCommandOptBool(cmd, "domain")) - if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; - - if (vshEventStart(ctl, timeout) < 0) - goto cleanup; - - for (i =3D 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) { - if ((data[i].id =3D virConnectDomainEventRegisterAny(priv->conn, d= om, - all ? i : event, - data[i].cb->cb, - &data[i], - NULL)) < 0) { - /* When registering for all events: if the first - * registration succeeds, silently ignore failures on all - * later registrations on the assumption that the server - * is older and didn't know quite as many events. */ - if (i) - vshResetLibvirtError(); - else - goto cleanup; - } - } - switch (vshEventWait(ctl)) { - case VSH_EVENT_INTERRUPT: - vshPrint(ctl, "%s", _("event loop interrupted\n")); - break; - case VSH_EVENT_TIMEOUT: - vshPrint(ctl, "%s", _("event loop timed out\n")); - break; - case VSH_EVENT_DONE: - break; - default: - goto cleanup; - } - vshPrint(ctl, _("events received: %d\n"), count); - if (count) - ret =3D true; - - cleanup: - vshEventCleanup(ctl); - if (data) { - for (i =3D 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) { - if (data[i].id >=3D 0 && - virConnectDomainEventDeregisterAny(priv->conn, data[i].id)= < 0) - ret =3D false; - } - VIR_FREE(data); - } - return ret; -} - - /* * "change-media" command */ @@ -14851,12 +13911,6 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_edit, .flags =3D 0 }, - {.name =3D "event", - .handler =3D cmdEvent, - .opts =3D opts_event, - .info =3D info_event, - .flags =3D 0 - }, {.name =3D "get-user-sshkeys", .handler =3D cmdGetUserSSHKeys, .opts =3D opts_get_user_sshkeys, diff --git a/tools/virsh.c b/tools/virsh.c index 64e0700fcd..f7adb90be8 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -45,6 +45,7 @@ #include "virsh-checkpoint.h" #include "virsh-console.h" #include "virsh-domain.h" +#include "virsh-domain-event.h" #include "virsh-domain-monitor.h" #include "virsh-host.h" #include "virsh-interface.h" @@ -814,6 +815,7 @@ static const vshCmdDef virshCmds[] =3D { static const vshCmdGrp cmdGroups[] =3D { {VIRSH_CMD_GRP_DOM_MANAGEMENT, "domain", domManagementCmds}, {VIRSH_CMD_GRP_DOM_MONITORING, "monitor", domMonitoringCmds}, + {VIRSH_CMD_GRP_DOM_EVENTS, "events", domEventCmds}, {VIRSH_CMD_GRP_HOST_AND_HV, "host", hostAndHypervisorCmds}, {VIRSH_CMD_GRP_CHECKPOINT, "checkpoint", checkpointCmds}, {VIRSH_CMD_GRP_IFACE, "interface", ifaceCmds}, diff --git a/tools/virsh.h b/tools/virsh.h index cacd54db57..d7a60b135d 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -41,6 +41,7 @@ #define VIRSH_CMD_GRP_CHECKPOINT "Checkpoint" #define VIRSH_CMD_GRP_DOM_MANAGEMENT "Domain Management" #define VIRSH_CMD_GRP_DOM_MONITORING "Domain Monitoring" +#define VIRSH_CMD_GRP_DOM_EVENTS "Domain Events" #define VIRSH_CMD_GRP_STORAGE_POOL "Storage Pool" #define VIRSH_CMD_GRP_STORAGE_VOL "Storage Volume" #define VIRSH_CMD_GRP_NETWORK "Networking" --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229362; cv=none; d=zohomail.com; s=zohoarc; b=Ow82pgQznzW5U2jDS7X/Lp9XuQ4XQ00lHABxjp8zK7df3WModojCf02/Sse/761mQq0zZUOh+fUeGFuRfgEM5e/u/0Qs+lSiPprRKJa4GFfbZDAXWUrsDYD9j1kR0ZWxe5t2K2lmsTLdsHXDBkhzmckfs7U+KmOWpbB/byq4v0U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229362; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=udRnoCzaKGXqpPOzec3c76egN7oqSzP3Y3XQyxX6W+A=; b=kzXnuDkH8XPXe7xgzoMecwJ3zgjSPsyerpu45ixoY1ic88/f6/zvJGDGR0kH5t96YIrBFTYr5HZU8MDabo3e2yXJADE4JqQKK62tZ4WBSfA9MpQOKKrf7eT1S188Bwo5FumeqKmWqueyvFrqf8tuIH5U2j5NNJXAGFJMHcnJWfU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1646229362142272.22411407145546; Wed, 2 Mar 2022 05:56:02 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-320-4YAMuehEP1eZVSJC6aewdA-1; Wed, 02 Mar 2022 08:55:58 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A9F0521C; Wed, 2 Mar 2022 13:55:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BE4583782; Wed, 2 Mar 2022 13:55:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E2CAA1808800; Wed, 2 Mar 2022 13:55:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222Dtkqf017486 for ; Wed, 2 Mar 2022 08:55:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6B41D17B7D; Wed, 2 Mar 2022 13:55:46 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2C2783780 for ; Wed, 2 Mar 2022 13:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229361; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=udRnoCzaKGXqpPOzec3c76egN7oqSzP3Y3XQyxX6W+A=; b=CAuJBtwpF4xL3VSp8qHQUCLddUMpmvjyKditQfJICAtToQs3lRct097U0phpDv67VTiLm/ 0nmbDzc/w1KbELJ6jRQLIJEJr22eqJPH0rfI5bv8cpKb8sIWPf+gXJbJskZ3wHt+Pzw3qJ Scfl9MI9DDLZHE3jaOqbk/ydWBnGI24= X-MC-Unique: 4YAMuehEP1eZVSJC6aewdA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/23] virsh: cmdEvent: Rewrite questionable event registration Date: Wed, 2 Mar 2022 14:55:09 +0100 Message-Id: <22e85eb216bb78599f1436e8e7ecc7471f877b03.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229364519100008 Content-Type: text/plain; charset="utf-8" The code registering the event handlers in 'cmdEvent' had too many blocks of code conditional on whether just one event is being listened to or all events. The code can be greatly simplified by uniting the code paths and having only one branch when filling the list of events we want to listen for. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain-event.c | 70 +++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/tools/virsh-domain-event.c b/tools/virsh-domain-event.c index 51571dffad..1a2f1cb6e0 100644 --- a/tools/virsh-domain-event.c +++ b/tools/virsh-domain-event.c @@ -274,6 +274,7 @@ typedef struct virshDomainEventCallback virshDomainEven= tCallback; struct virshDomEventData { vshControl *ctl; + int event; bool loop; int *count; bool timestamp; @@ -885,10 +886,10 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshDomain) dom =3D NULL; bool ret =3D false; int timeout =3D 0; - virshDomEventData *data =3D NULL; + g_autofree virshDomEventData *data =3D NULL; + size_t ndata =3D 0; size_t i; const char *eventName =3D NULL; - int event =3D -1; bool all =3D vshCommandOptBool(cmd, "all"); bool loop =3D vshCommandOptBool(cmd, "loop"); bool timestamp =3D vshCommandOptBool(cmd, "timestamp"); @@ -900,59 +901,59 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS("list", "event"); if (vshCommandOptBool(cmd, "list")) { - for (event =3D 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) - vshPrint(ctl, "%s\n", virshDomainEventCallbacks[event].name); + for (i =3D 0; i < G_N_ELEMENTS(virshDomainEventCallbacks); i++) + vshPrint(ctl, "%s\n", virshDomainEventCallbacks[i].name); return true; } if (vshCommandOptStringReq(ctl, cmd, "event", &eventName) < 0) return false; - if (eventName) { - for (event =3D 0; event < VIR_DOMAIN_EVENT_ID_LAST; event++) - if (STREQ(eventName, virshDomainEventCallbacks[event].name)) - break; - if (event =3D=3D VIR_DOMAIN_EVENT_ID_LAST) { - vshError(ctl, _("unknown event type %s"), eventName); - return false; - } - } else if (!all) { + + if (!eventName && !all) { vshError(ctl, "%s", _("one of --list, --all, or --event is required")); return false; } - if (all) { - data =3D g_new0(virshDomEventData, VIR_DOMAIN_EVENT_ID_LAST); - for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { - data[i].ctl =3D ctl; - data[i].loop =3D loop; - data[i].count =3D &count; - data[i].timestamp =3D timestamp; - data[i].cb =3D &virshDomainEventCallbacks[i]; - data[i].id =3D -1; - } - } else { + if (eventName) data =3D g_new0(virshDomEventData, 1); - data[0].ctl =3D ctl; - data[0].loop =3D vshCommandOptBool(cmd, "loop"); - data[0].count =3D &count; - data[0].timestamp =3D timestamp; - data[0].cb =3D &virshDomainEventCallbacks[event]; - data[0].id =3D -1; + else + data =3D g_new0(virshDomEventData, G_N_ELEMENTS(virshDomainEventCa= llbacks)); + + for (i =3D 0; i < G_N_ELEMENTS(virshDomainEventCallbacks); i++) { + if (eventName && + STRNEQ(eventName, virshDomainEventCallbacks[i].name)) + continue; + + data[i].event =3D i; + data[i].ctl =3D ctl; + data[i].loop =3D loop; + data[i].count =3D &count; + data[i].timestamp =3D timestamp; + data[i].cb =3D &virshDomainEventCallbacks[i]; + data[i].id =3D -1; + ndata++; } + + if (ndata =3D=3D 0) { + vshError(ctl, _("unknown event type %s"), eventName); + return false; + } + if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) goto cleanup; - if (vshCommandOptBool(cmd, "domain")) + if (vshCommandOptBool(cmd, "domain")) { if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) goto cleanup; + } if (vshEventStart(ctl, timeout) < 0) goto cleanup; - for (i =3D 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) { + for (i =3D 0; i < ndata; i++) { if ((data[i].id =3D virConnectDomainEventRegisterAny(priv->conn, d= om, - all ? i : event, + data[i].event, data[i].cb->cb, &data[i], NULL)) < 0) { @@ -985,12 +986,11 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) cleanup: vshEventCleanup(ctl); if (data) { - for (i =3D 0; i < (all ? VIR_DOMAIN_EVENT_ID_LAST : 1); i++) { + for (i =3D 0; i < ndata; i++) { if (data[i].id >=3D 0 && virConnectDomainEventDeregisterAny(priv->conn, data[i].id)= < 0) ret =3D false; } - VIR_FREE(data); } return ret; } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229382; cv=none; d=zohomail.com; s=zohoarc; b=TOfMwmGQBzortApdPIy4BeqPfLbYwaS3hXjMnCCmqM0kVp2kpMEgzuuLMQ9EQP8Ar6+WXzmzWb+gq6xdZQq22DN/HnlupDZioa9gLHZ4t6PCI/OzhTW8eMTd/DTeUicjG0nY/I/f4vwAu2n8HnLT9e8H3jNzOZ7PNI4OfHrVwGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229382; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J1bYDDQM7Il0DkL2CZshm8D3MMqF45gp5Ens5IyDIaQ=; b=FHVbGLVNpCHm9CFpD/Dm5iMgpi1myQjstBlqOn0ZkIWn/MqLQqwidbqQ/6MxYebBGkLlf797NXO9g+VqAS0t7TXOw5xr8qbVpHmWj7k1em+FF9aO7TI0qxid46efVlKrO006HHNEuFz/qXGtJ0moKHKs/lBTSqk/HUr3nyvLQ5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1646229382676470.06124954752977; Wed, 2 Mar 2022 05:56:22 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-672-v7LduyUJPRyPg1D3bnSRpw-1; Wed, 02 Mar 2022 08:56:18 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D57BE824FAC; Wed, 2 Mar 2022 13:56:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2CF6838DA; Wed, 2 Mar 2022 13:56:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 81F221809CB4; Wed, 2 Mar 2022 13:56:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DuCob017733 for ; Wed, 2 Mar 2022 08:56:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5657383780; Wed, 2 Mar 2022 13:56:12 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99E4B83783 for ; Wed, 2 Mar 2022 13:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229382; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=J1bYDDQM7Il0DkL2CZshm8D3MMqF45gp5Ens5IyDIaQ=; b=VBQZFnotNWvclz22lDtqG74APClDsdjkTJNUUXNiwFDmSPNtNqr5Htr5YbOFczSUSeS/P7 F3pefxqeVHyss4YjFJUskfqCKRmB4CH8/H8xBml5SirTMU2wtqvm+G1c/JOjuTdc1kXwLo 1xiue68+laUKRmys6VckxPChIYbYRNk= X-MC-Unique: v7LduyUJPRyPg1D3bnSRpw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/23] virsh: cmdDomDisplay: Extract loop body fetching display URIs into 'virshGetOneDisplay' Date: Wed, 2 Mar 2022 14:55:10 +0100 Message-Id: <7fd02940e2e7cfd9d98d2a780cc4b4f71f0d88d0.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229391586100003 Content-Type: text/plain; charset="utf-8" Separate the code so that the function is not as massive. Note that this is a minimal extraction which does not clean up the code meant for looping. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 352 ++++++++++++++++++++++--------------------- 1 file changed, 183 insertions(+), 169 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index dc6e3b5020..f82aa49745 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11659,215 +11659,235 @@ static const vshCmdOptDef opts_domdisplay[] =3D= { {.name =3D NULL} }; -static bool -cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) + +static char * +virshGetOneDisplay(vshControl *ctl, + const char *scheme, + xmlXPathContext *ctxt) { - g_autoptr(xmlDoc) xml =3D NULL; - g_autoptr(xmlXPathContext) ctxt =3D NULL; - g_autoptr(virshDomain) dom =3D NULL; + const char *xpath_fmt =3D "string(/domain/devices/graphics[@type=3D'%s= ']/%s)"; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - bool ret =3D false; char *xpath =3D NULL; char *listen_addr =3D NULL; - int port, tls_port =3D 0; + int port =3D 0; + int tls_port =3D 0; char *type_conn =3D NULL; char *sockpath =3D NULL; char *passwd =3D NULL; - char *output =3D NULL; - const char *scheme[] =3D { "vnc", "spice", "rdp", NULL }; - const char *type =3D NULL; - int iter =3D 0; int tmp; - int flags =3D 0; bool params =3D false; - bool all =3D vshCommandOptBool(cmd, "all"); - const char *xpath_fmt =3D "string(/domain/devices/graphics[@type=3D'%s= ']/%s)"; virSocketAddr addr; - VSH_EXCLUSIVE_OPTIONS("all", "type"); + /* Create our XPATH lookup for the current display's port */ + VIR_FREE(xpath); + xpath =3D g_strdup_printf(xpath_fmt, scheme, "@port"); - if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - return false; + /* Attempt to get the port number for the current graphics scheme */ + tmp =3D virXPathInt(xpath, ctxt, &port); + VIR_FREE(xpath); - if (!virDomainIsActive(dom)) { - vshError(ctl, _("Domain is not running")); - goto cleanup; - } + /* If there is no port number for this type, then jump to the next + * scheme */ + if (tmp) + port =3D 0; - if (vshCommandOptBool(cmd, "include-password")) - flags |=3D VIR_DOMAIN_XML_SECURE; + /* Create our XPATH lookup for TLS Port (automatically skipped + * for unsupported schemes */ + xpath =3D g_strdup_printf(xpath_fmt, scheme, "@tlsPort"); - if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) - goto cleanup; + /* Attempt to get the TLS port number */ + tmp =3D virXPathInt(xpath, ctxt, &tls_port); + VIR_FREE(xpath); + if (tmp) + tls_port =3D 0; - if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0) - goto cleanup; + /* Create our XPATH lookup for the current display's address */ + xpath =3D g_strdup_printf(xpath_fmt, scheme, "@listen"); - /* Attempt to grab our display info */ - for (iter =3D 0; scheme[iter] !=3D NULL; iter++) { - /* Particular scheme requested */ - if (!all && type && STRNEQ(type, scheme[iter])) - continue; + /* Attempt to get the listening addr if set for the current + * graphics scheme */ + VIR_FREE(listen_addr); + listen_addr =3D virXPathString(xpath, ctxt); + VIR_FREE(xpath); - /* Create our XPATH lookup for the current display's port */ - VIR_FREE(xpath); - xpath =3D g_strdup_printf(xpath_fmt, scheme[iter], "@port"); + /* Create our XPATH lookup for the current spice type. */ + xpath =3D g_strdup_printf(xpath_fmt, scheme, "listen/@type"); - /* Attempt to get the port number for the current graphics scheme = */ - tmp =3D virXPathInt(xpath, ctxt, &port); - VIR_FREE(xpath); + /* Attempt to get the type of spice connection */ + VIR_FREE(type_conn); + type_conn =3D virXPathString(xpath, ctxt); + VIR_FREE(xpath); - /* If there is no port number for this type, then jump to the next - * scheme */ - if (tmp) - port =3D 0; + if (STREQ_NULLABLE(type_conn, "socket")) { + if (!sockpath) { + xpath =3D g_strdup_printf(xpath_fmt, scheme, "listen/@socket"); - /* Create our XPATH lookup for TLS Port (automatically skipped - * for unsupported schemes */ - xpath =3D g_strdup_printf(xpath_fmt, scheme[iter], "@tlsPort"); + sockpath =3D virXPathString(xpath, ctxt); - /* Attempt to get the TLS port number */ - tmp =3D virXPathInt(xpath, ctxt, &tls_port); - VIR_FREE(xpath); - if (tmp) - tls_port =3D 0; + VIR_FREE(xpath); + } + } + + if (!port && !tls_port && !sockpath) + goto cleanup; - /* Create our XPATH lookup for the current display's address */ - xpath =3D g_strdup_printf(xpath_fmt, scheme[iter], "@listen"); + if (!listen_addr) { + /* The subelement address - - + * *should* have been automatically backfilled into its + * parent (which we just tried to + * retrieve into listen_addr above) but in some cases it + * isn't, so we also do an explicit check for the + * subelement (which, by the way, doesn't exist on libvirt + * < 0.9.4, so we really do need to check both places) + */ + xpath =3D g_strdup_printf(xpath_fmt, scheme, "listen/@address"); - /* Attempt to get the listening addr if set for the current - * graphics scheme */ - VIR_FREE(listen_addr); listen_addr =3D virXPathString(xpath, ctxt); VIR_FREE(xpath); + } else { + /* If listen_addr is 0.0.0.0 or [::] we should try to parse URI an= d set + * listen_addr based on current URI. */ + if (virSocketAddrParse(&addr, listen_addr, AF_UNSPEC) > 0 && + virSocketAddrIsWildcard(&addr)) { + + virConnectPtr conn =3D ((virshControl *)(ctl->privData))->conn; + char *uriStr =3D virConnectGetURI(conn); + virURI *uri =3D NULL; + + if (uriStr) { + uri =3D virURIParse(uriStr); + VIR_FREE(uriStr); + } - /* Create our XPATH lookup for the current spice type. */ - xpath =3D g_strdup_printf(xpath_fmt, scheme[iter], "listen/@type"); + /* It's safe to free the listen_addr even if parsing of URI + * fails, if there is no listen_addr we will print "localhost"= . */ + VIR_FREE(listen_addr); - /* Attempt to get the type of spice connection */ - VIR_FREE(type_conn); - type_conn =3D virXPathString(xpath, ctxt); - VIR_FREE(xpath); + if (uri) { + listen_addr =3D g_strdup(uri->server); + virURIFree(uri); + } + } + } - if (STREQ_NULLABLE(type_conn, "socket")) { - if (!sockpath) { - xpath =3D g_strdup_printf(xpath_fmt, scheme[iter], "listen= /@socket"); + /* We can query this info for all the graphics types since we'll + * get nothing for the unsupported ones (just rdp for now). + * Also the parameter '--include-password' was already taken + * care of when getting the XML */ - sockpath =3D virXPathString(xpath, ctxt); + /* Create our XPATH lookup for the password */ + xpath =3D g_strdup_printf(xpath_fmt, scheme, "@passwd"); - VIR_FREE(xpath); - } + /* Attempt to get the password */ + VIR_FREE(passwd); + passwd =3D virXPathString(xpath, ctxt); + VIR_FREE(xpath); + + /* Build up the full URI, starting with the scheme */ + if (sockpath) + virBufferAsprintf(&buf, "%s+unix://", scheme); + else + virBufferAsprintf(&buf, "%s://", scheme); + + /* There is no user, so just append password if there's any */ + if (STREQ(scheme, "vnc") && passwd) + virBufferAsprintf(&buf, ":%s@", passwd); + + /* Then host name or IP */ + if (!listen_addr && !sockpath) + virBufferAddLit(&buf, "localhost"); + else if (!sockpath && strchr(listen_addr, ':')) + virBufferAsprintf(&buf, "[%s]", listen_addr); + else if (sockpath) + virBufferAsprintf(&buf, "%s", sockpath); + else + virBufferAsprintf(&buf, "%s", listen_addr); + + /* Free socket to prepare the pointer for the next iteration */ + VIR_FREE(sockpath); + + /* Add the port */ + if (port) { + if (STREQ(scheme, "vnc")) { + /* VNC protocol handlers take their port number as + * 'port' - 5900 */ + port -=3D 5900; } - if (!port && !tls_port && !sockpath) - continue; + virBufferAsprintf(&buf, ":%d", port); + } - if (!listen_addr) { - /* The subelement address - - - * *should* have been automatically backfilled into its - * parent (which we just tried to - * retrieve into listen_addr above) but in some cases it - * isn't, so we also do an explicit check for the - * subelement (which, by the way, doesn't exist on libvirt - * < 0.9.4, so we really do need to check both places) - */ - xpath =3D g_strdup_printf(xpath_fmt, scheme[iter], "listen/@ad= dress"); - - listen_addr =3D virXPathString(xpath, ctxt); - VIR_FREE(xpath); - } else { - /* If listen_addr is 0.0.0.0 or [::] we should try to parse UR= I and set - * listen_addr based on current URI. */ - if (virSocketAddrParse(&addr, listen_addr, AF_UNSPEC) > 0 && - virSocketAddrIsWildcard(&addr)) { - - virConnectPtr conn =3D ((virshControl *)(ctl->privData))->= conn; - char *uriStr =3D virConnectGetURI(conn); - virURI *uri =3D NULL; - - if (uriStr) { - uri =3D virURIParse(uriStr); - VIR_FREE(uriStr); - } + /* TLS Port */ + if (tls_port) { + virBufferAsprintf(&buf, + "?tls-port=3D%d", + tls_port); + params =3D true; + } - /* It's safe to free the listen_addr even if parsing of URI - * fails, if there is no listen_addr we will print "localh= ost". */ - VIR_FREE(listen_addr); + if (STREQ(scheme, "spice") && passwd) { + virBufferAsprintf(&buf, + "%spassword=3D%s", + params ? "&" : "?", + passwd); + params =3D true; + } - if (uri) { - listen_addr =3D g_strdup(uri->server); - virURIFree(uri); - } - } - } + cleanup: + VIR_FREE(xpath); + VIR_FREE(type_conn); + VIR_FREE(sockpath); + VIR_FREE(passwd); + VIR_FREE(listen_addr); - /* We can query this info for all the graphics types since we'll - * get nothing for the unsupported ones (just rdp for now). - * Also the parameter '--include-password' was already taken - * care of when getting the XML */ + return virBufferContentAndReset(&buf); +} - /* Create our XPATH lookup for the password */ - xpath =3D g_strdup_printf(xpath_fmt, scheme[iter], "@passwd"); - /* Attempt to get the password */ - VIR_FREE(passwd); - passwd =3D virXPathString(xpath, ctxt); - VIR_FREE(xpath); +static bool +cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) +{ + g_autoptr(xmlDoc) xml =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autoptr(virshDomain) dom =3D NULL; + bool ret =3D false; + const char *scheme[] =3D { "vnc", "spice", "rdp", NULL }; + const char *type =3D NULL; + int iter =3D 0; + int flags =3D 0; + bool all =3D vshCommandOptBool(cmd, "all"); - /* Build up the full URI, starting with the scheme */ - if (sockpath) - virBufferAsprintf(&buf, "%s+unix://", scheme[iter]); - else - virBufferAsprintf(&buf, "%s://", scheme[iter]); - - /* There is no user, so just append password if there's any */ - if (STREQ(scheme[iter], "vnc") && passwd) - virBufferAsprintf(&buf, ":%s@", passwd); - - /* Then host name or IP */ - if (!listen_addr && !sockpath) - virBufferAddLit(&buf, "localhost"); - else if (!sockpath && strchr(listen_addr, ':')) - virBufferAsprintf(&buf, "[%s]", listen_addr); - else if (sockpath) - virBufferAsprintf(&buf, "%s", sockpath); - else - virBufferAsprintf(&buf, "%s", listen_addr); + VSH_EXCLUSIVE_OPTIONS("all", "type"); - /* Free socket to prepare the pointer for the next iteration */ - VIR_FREE(sockpath); + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; - /* Add the port */ - if (port) { - if (STREQ(scheme[iter], "vnc")) { - /* VNC protocol handlers take their port number as - * 'port' - 5900 */ - port -=3D 5900; - } + if (!virDomainIsActive(dom)) { + vshError(ctl, _("Domain is not running")); + goto cleanup; + } - virBufferAsprintf(&buf, ":%d", port); - } + if (vshCommandOptBool(cmd, "include-password")) + flags |=3D VIR_DOMAIN_XML_SECURE; - /* TLS Port */ - if (tls_port) { - virBufferAsprintf(&buf, - "?tls-port=3D%d", - tls_port); - params =3D true; - } + if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) + goto cleanup; - if (STREQ(scheme[iter], "spice") && passwd) { - virBufferAsprintf(&buf, - "%spassword=3D%s", - params ? "&" : "?", - passwd); - params =3D true; - } + if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0) + goto cleanup; - /* Print out our full URI */ - VIR_FREE(output); - output =3D virBufferContentAndReset(&buf); - vshPrint(ctl, "%s", output); + /* Attempt to grab our display info */ + for (iter =3D 0; scheme[iter] !=3D NULL; iter++) { + g_autofree char *display =3D NULL; + + /* Particular scheme requested */ + if (!all && type && STRNEQ(type, scheme[iter])) + continue; + + if (!(display =3D virshGetOneDisplay(ctl, scheme[iter], ctxt))) + continue; + + vshPrint(ctl, "%s", display); /* We got what we came for so return successfully */ ret =3D true; @@ -11884,12 +11904,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) } cleanup: - VIR_FREE(xpath); - VIR_FREE(type_conn); - VIR_FREE(sockpath); - VIR_FREE(passwd); - VIR_FREE(listen_addr); - VIR_FREE(output); return ret; } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229384; cv=none; d=zohomail.com; s=zohoarc; b=F8vdkKlBFSk9hli82fYXpCHka3v4SwKUBuIlBP8q7FxbRqtO/6vEhkJdAqPgf8WLI6I5ZGbexK6c2m+4SlII4c+66i3Hki3CJgyGxGYj9/7RPlur6tJUFalEqQKACKj7YKun/TlJxy3mBMdqmARTeoq0gFmkrlqMVX0+/sBDdsM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229384; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/ojsv+PmaQAiIvHkjRldTuO5myp+RWYOu5Zu1RBRTrc=; b=KeNbY06dXVW1JNtXMOnEGCVtMQa6MQkc6wKwb3R1LJKbmEzcvKyzCREdCyFXDOzoCL1mvAybdQCm3Wn2IcUToLwHvl4oUfvDhX1T1kZMeXXCwd3plYIjhXnYEgvtAsyYTMCU6+UZbN+WqmLu4xWxbCrWXN9319xKUGtRC6x/bng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229384126571.8228399318043; Wed, 2 Mar 2022 05:56:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-7fzFdk-eN5Knq3QXCCmfVg-1; Wed, 02 Mar 2022 08:56:19 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 12E695200; Wed, 2 Mar 2022 13:56:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8EF07B8D8; Wed, 2 Mar 2022 13:56:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BBEAF1807D69; Wed, 2 Mar 2022 13:56:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DuDCZ017765 for ; Wed, 2 Mar 2022 08:56:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5AB8083783; Wed, 2 Mar 2022 13:56:13 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4F4C83780 for ; Wed, 2 Mar 2022 13:56:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229383; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/ojsv+PmaQAiIvHkjRldTuO5myp+RWYOu5Zu1RBRTrc=; b=IIaNFPiLfFOrzFYCVXKcEZgxnzAFZwXt7BcgSH7Bbftc8QMR4Q/wGmMB+bBei0/Pt6h29f 9LMgTZlKJrh8iS5bQ6rJOVVjQwfcKc59j26DLs4Kl2EKtzviOGBnKeZUqfrGfZSBd8q2nh nTbm42wCXG0xpjAROMIZj7fCvLcp0Os= X-MC-Unique: 7fzFdk-eN5Knq3QXCCmfVg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/23] virsh: cmdDomDisplay: Remove unneeded 'cleanup' label Date: Wed, 2 Mar 2022 14:55:11 +0100 Message-Id: <50d3b06d1269d7fac207ed9506f42343e9ff8cfe.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229385253100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f82aa49745..7c06c3f80d 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11864,17 +11864,17 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) if (!virDomainIsActive(dom)) { vshError(ctl, _("Domain is not running")); - goto cleanup; + return false; } if (vshCommandOptBool(cmd, "include-password")) flags |=3D VIR_DOMAIN_XML_SECURE; if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) - goto cleanup; + return false; if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0) - goto cleanup; + return false; /* Attempt to grab our display info */ for (iter =3D 0; scheme[iter] !=3D NULL; iter++) { @@ -11903,7 +11903,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("No graphical display found")); } - cleanup: return ret; } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229383; cv=none; d=zohomail.com; s=zohoarc; b=gR11QH7aUpCvXYFXW7/3eAAOfj9KyMxQyD3i0KLvJZZ/ZorVa+xcnMZuumQa8mT1GVpJPsly2IYFsD9MHo6a1KqQ9iiwodTJcs3w6yIFLECVt+6uvKsUNDQiHfCTMyIZ90UZRV5tlowACEmAJG7UVzC/xkw6gnWFIifktAMWtK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229383; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iqitK4rYzFW60Z8IrpDlsEB7vlV4uQmnUj+OxfdzpnE=; b=jvrIbeRWPg5+Ue0USf7t5fqpNympL+DoAV27PMjVk/yIEf0hKeNJLeetK4E+zedq1U6nQS+WPMz4CQDRXQig/Dd0in+uVRevDMkxLHaDy/SytmojEUveN/EBoBQmpN24x4Qhxo0EYHVAQg+Tkttcf+YszTyRlidu7EO/DKDWv+U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1646229383772569.5135902536366; Wed, 2 Mar 2022 05:56:23 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-192-FgFnKUE8Mr6Wp7BPeFCvVQ-1; Wed, 02 Mar 2022 08:56:21 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AA4B61091DA3; Wed, 2 Mar 2022 13:56:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F80F8494E; Wed, 2 Mar 2022 13:56:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 347DB1807D6D; Wed, 2 Mar 2022 13:56:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DuEtX017810 for ; Wed, 2 Mar 2022 08:56:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 622CC83783; Wed, 2 Mar 2022 13:56:14 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C316A83780 for ; Wed, 2 Mar 2022 13:56:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229383; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iqitK4rYzFW60Z8IrpDlsEB7vlV4uQmnUj+OxfdzpnE=; b=KbpahIyRT3hYM1yZp2nRQqM6sJBegYTkL7WjgksQx3eE+Rbv3b4nW01+PbEMJyHZs/88qF vzfayNcDHtVLz5msYYDwREPbyYQr+ZSowmSdpw6xkZvHVlfj9wLrEUxGnzuiLB85wk0oGh c3Y/nCGUhp35akluQcYLAp1FUYr2ctw= X-MC-Unique: FgFnKUE8Mr6Wp7BPeFCvVQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/23] virshGetOneDisplay: Automaticaly free extracted data Date: Wed, 2 Mar 2022 14:55:12 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229385286100002 Content-Type: text/plain; charset="utf-8" Use automatic memory freeing for the temporary variables hodling the data extracted from the XML. The code in this function was originally extracted from a loop so we can also drop pre-clearing of the pointers. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 49 ++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7c06c3f80d..d5157e4a63 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11668,15 +11668,14 @@ virshGetOneDisplay(vshControl *ctl, const char *xpath_fmt =3D "string(/domain/devices/graphics[@type=3D'%s= ']/%s)"; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; char *xpath =3D NULL; - char *listen_addr =3D NULL; + g_autofree char *listen_addr =3D NULL; int port =3D 0; int tls_port =3D 0; - char *type_conn =3D NULL; - char *sockpath =3D NULL; - char *passwd =3D NULL; + g_autofree char *type_conn =3D NULL; + g_autofree char *sockpath =3D NULL; + g_autofree char *passwd =3D NULL; int tmp; bool params =3D false; - virSocketAddr addr; /* Create our XPATH lookup for the current display's port */ VIR_FREE(xpath); @@ -11706,7 +11705,6 @@ virshGetOneDisplay(vshControl *ctl, /* Attempt to get the listening addr if set for the current * graphics scheme */ - VIR_FREE(listen_addr); listen_addr =3D virXPathString(xpath, ctxt); VIR_FREE(xpath); @@ -11714,18 +11712,15 @@ virshGetOneDisplay(vshControl *ctl, xpath =3D g_strdup_printf(xpath_fmt, scheme, "listen/@type"); /* Attempt to get the type of spice connection */ - VIR_FREE(type_conn); type_conn =3D virXPathString(xpath, ctxt); VIR_FREE(xpath); if (STREQ_NULLABLE(type_conn, "socket")) { - if (!sockpath) { - xpath =3D g_strdup_printf(xpath_fmt, scheme, "listen/@socket"); + xpath =3D g_strdup_printf(xpath_fmt, scheme, "listen/@socket"); - sockpath =3D virXPathString(xpath, ctxt); + sockpath =3D virXPathString(xpath, ctxt); - VIR_FREE(xpath); - } + VIR_FREE(xpath); } if (!port && !tls_port && !sockpath) @@ -11745,28 +11740,22 @@ virshGetOneDisplay(vshControl *ctl, listen_addr =3D virXPathString(xpath, ctxt); VIR_FREE(xpath); } else { + virSocketAddr addr; + /* If listen_addr is 0.0.0.0 or [::] we should try to parse URI an= d set - * listen_addr based on current URI. */ + * listen_addr based on current URI. If that fails we'll print + * 'localhost' as the address as INADDR_ANY won't help the user. */ if (virSocketAddrParse(&addr, listen_addr, AF_UNSPEC) > 0 && virSocketAddrIsWildcard(&addr)) { virConnectPtr conn =3D ((virshControl *)(ctl->privData))->conn; - char *uriStr =3D virConnectGetURI(conn); - virURI *uri =3D NULL; + g_autofree char *uriStr =3D virConnectGetURI(conn); + g_autoptr(virURI) uri =3D NULL; - if (uriStr) { - uri =3D virURIParse(uriStr); - VIR_FREE(uriStr); - } - - /* It's safe to free the listen_addr even if parsing of URI - * fails, if there is no listen_addr we will print "localhost"= . */ - VIR_FREE(listen_addr); + g_clear_pointer(&listen_addr, g_free); - if (uri) { + if (uriStr && (uri =3D virURIParse(uriStr))) listen_addr =3D g_strdup(uri->server); - virURIFree(uri); - } } } @@ -11779,7 +11768,6 @@ virshGetOneDisplay(vshControl *ctl, xpath =3D g_strdup_printf(xpath_fmt, scheme, "@passwd"); /* Attempt to get the password */ - VIR_FREE(passwd); passwd =3D virXPathString(xpath, ctxt); VIR_FREE(xpath); @@ -11803,9 +11791,6 @@ virshGetOneDisplay(vshControl *ctl, else virBufferAsprintf(&buf, "%s", listen_addr); - /* Free socket to prepare the pointer for the next iteration */ - VIR_FREE(sockpath); - /* Add the port */ if (port) { if (STREQ(scheme, "vnc")) { @@ -11835,10 +11820,6 @@ virshGetOneDisplay(vshControl *ctl, cleanup: VIR_FREE(xpath); - VIR_FREE(type_conn); - VIR_FREE(sockpath); - VIR_FREE(passwd); - VIR_FREE(listen_addr); return virBufferContentAndReset(&buf); } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229441; cv=none; d=zohomail.com; s=zohoarc; b=Hqgtriolr0WFGK8HOco9SEdu9KbZ3YgE2Dp3UfTMCvitB4/EpFWZ4UCctCetQO5iNxc0mIuVMlnROgeGw8aSacZF9A5xY9I6LjqIBlTll2PTqek279VEQsvTYnLbbB+C97ZEgFweMR1HRn5YPblXBN2PWD9ymswJ6aQ3SwlFRRQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229441; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HdFy6ptjlvc2yKkjLyP9WH11ypGmfQESl9o1IO4d0vY=; b=nIM8GEWkPFxqLKsdAhPOP86on1z4whS/VpwHW+Osu5xXSP9wxj66SovCPChhPh+M3P/7SfdwKFhEwcixqWE5UJWCUfF8Qrv9RH99lCulPcRZjUcWUMJ2Ufxjrd8zecNZEPrXYiyOV7TA5+KgtFcK5PgwM1ihlBiOd9hQ9bb5eQU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1646229441393493.07595039106104; Wed, 2 Mar 2022 05:57:21 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-312-m2h3fe74OBSP3bjnbZYgeg-1; Wed, 02 Mar 2022 08:57:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 859D0824FAC; Wed, 2 Mar 2022 13:56:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4027284954; Wed, 2 Mar 2022 13:56:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 116C04ED79; Wed, 2 Mar 2022 13:56:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DuFl5017859 for ; Wed, 2 Mar 2022 08:56:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6BBFC83783; Wed, 2 Mar 2022 13:56:15 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id C003A83780 for ; Wed, 2 Mar 2022 13:56:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229440; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=HdFy6ptjlvc2yKkjLyP9WH11ypGmfQESl9o1IO4d0vY=; b=D8Qbiw1ChtMyA9Q3YSEgRHU/nFMJYy2US0gbC0p2VwcEMNFt/NKYJLDGoiA/4a6K9weHCK /uXBr2eTvZpfwygGv1HebaREdPRDfV61C8Xrto4ASnsIWDwzKRWr7tSXxJdJDj5ez8H0NA UeWwkDe6zQtb6HNOmTb7kvLgGVXMJFQ= X-MC-Unique: m2h3fe74OBSP3bjnbZYgeg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/23] virshGetOneDisplay: Don't reuse 'xpath' variable Date: Wed, 2 Mar 2022 14:55:13 +0100 Message-Id: <7527cad12253d664a62bcb13cc0740f8ffc7b002.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229443751100003 Content-Type: text/plain; charset="utf-8" Add autofreed per-xpath variables to simplify the code. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 74 +++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 49 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index d5157e4a63..d0f78798b5 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11667,66 +11667,50 @@ virshGetOneDisplay(vshControl *ctl, { const char *xpath_fmt =3D "string(/domain/devices/graphics[@type=3D'%s= ']/%s)"; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - char *xpath =3D NULL; + g_autofree char *xpathPort =3D NULL; + g_autofree char *xpathPortTLS =3D NULL; + g_autofree char *xpathListen =3D NULL; + g_autofree char *xpathType =3D NULL; + g_autofree char *xpathPasswd =3D NULL; g_autofree char *listen_addr =3D NULL; int port =3D 0; int tls_port =3D 0; g_autofree char *type_conn =3D NULL; g_autofree char *sockpath =3D NULL; g_autofree char *passwd =3D NULL; - int tmp; bool params =3D false; - /* Create our XPATH lookup for the current display's port */ - VIR_FREE(xpath); - xpath =3D g_strdup_printf(xpath_fmt, scheme, "@port"); - /* Attempt to get the port number for the current graphics scheme */ - tmp =3D virXPathInt(xpath, ctxt, &port); - VIR_FREE(xpath); + xpathPort =3D g_strdup_printf(xpath_fmt, scheme, "@port"); - /* If there is no port number for this type, then jump to the next - * scheme */ - if (tmp) + if (virXPathInt(xpathPort, ctxt, &port) < 0) port =3D 0; - /* Create our XPATH lookup for TLS Port (automatically skipped - * for unsupported schemes */ - xpath =3D g_strdup_printf(xpath_fmt, scheme, "@tlsPort"); - /* Attempt to get the TLS port number */ - tmp =3D virXPathInt(xpath, ctxt, &tls_port); - VIR_FREE(xpath); - if (tmp) - tls_port =3D 0; + xpathPortTLS =3D g_strdup_printf(xpath_fmt, scheme, "@tlsPort"); - /* Create our XPATH lookup for the current display's address */ - xpath =3D g_strdup_printf(xpath_fmt, scheme, "@listen"); - - /* Attempt to get the listening addr if set for the current - * graphics scheme */ - listen_addr =3D virXPathString(xpath, ctxt); - VIR_FREE(xpath); + if (virXPathInt(xpathPortTLS, ctxt, &tls_port) < 0) + tls_port =3D 0; - /* Create our XPATH lookup for the current spice type. */ - xpath =3D g_strdup_printf(xpath_fmt, scheme, "listen/@type"); + /* Attempt to get the listening addr if set for the current graphics s= cheme */ + xpathListen =3D g_strdup_printf(xpath_fmt, scheme, "@listen"); + listen_addr =3D virXPathString(xpathListen, ctxt); /* Attempt to get the type of spice connection */ - type_conn =3D virXPathString(xpath, ctxt); - VIR_FREE(xpath); + xpathType =3D g_strdup_printf(xpath_fmt, scheme, "listen/@type"); + type_conn =3D virXPathString(xpathType, ctxt); if (STREQ_NULLABLE(type_conn, "socket")) { - xpath =3D g_strdup_printf(xpath_fmt, scheme, "listen/@socket"); - - sockpath =3D virXPathString(xpath, ctxt); + g_autofree char *xpathSockpath =3D g_strdup_printf(xpath_fmt, sche= me, "listen/@socket"); - VIR_FREE(xpath); + sockpath =3D virXPathString(xpathSockpath, ctxt); } if (!port && !tls_port && !sockpath) - goto cleanup; + return NULL; if (!listen_addr) { + g_autofree char *xpathListenAddress =3D NULL; /* The subelement address - - * *should* have been automatically backfilled into its * parent (which we just tried to @@ -11735,10 +11719,9 @@ virshGetOneDisplay(vshControl *ctl, * subelement (which, by the way, doesn't exist on libvirt * < 0.9.4, so we really do need to check both places) */ - xpath =3D g_strdup_printf(xpath_fmt, scheme, "listen/@address"); + xpathListenAddress =3D g_strdup_printf(xpath_fmt, scheme, "listen/= @address"); - listen_addr =3D virXPathString(xpath, ctxt); - VIR_FREE(xpath); + listen_addr =3D virXPathString(xpathListenAddress, ctxt); } else { virSocketAddr addr; @@ -11759,17 +11742,13 @@ virshGetOneDisplay(vshControl *ctl, } } - /* We can query this info for all the graphics types since we'll + /* Attempt to get the password. + * We can query this info for all the graphics types since we'll * get nothing for the unsupported ones (just rdp for now). * Also the parameter '--include-password' was already taken * care of when getting the XML */ - - /* Create our XPATH lookup for the password */ - xpath =3D g_strdup_printf(xpath_fmt, scheme, "@passwd"); - - /* Attempt to get the password */ - passwd =3D virXPathString(xpath, ctxt); - VIR_FREE(xpath); + xpathPasswd =3D g_strdup_printf(xpath_fmt, scheme, "@passwd"); + passwd =3D virXPathString(xpathPasswd, ctxt); /* Build up the full URI, starting with the scheme */ if (sockpath) @@ -11818,9 +11797,6 @@ virshGetOneDisplay(vshControl *ctl, params =3D true; } - cleanup: - VIR_FREE(xpath); - return virBufferContentAndReset(&buf); } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229424; cv=none; d=zohomail.com; s=zohoarc; b=EUtCJ0F3uGYH4Zd3WoVMGrtlcOwV0HpdIBtO/Ku38/GRs0N+l7uNscNVFzHdOsLv5SP83EximD2mxeLdLbXn7dSKvrrVzszSZ0nR6eNbQUUN+YJDlVwRe9qD5z7IQttiSZ1q0OKGrBQe7SR4DnBAp/6c2Y+FT3F9JpMvFLAUU0o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229424; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YcHq2ELIQgKOzHlxn65D6/PHqY6cSJbpCfmcJYrrXB0=; b=fX+1eXJHUyJXxFjSFuXwDYv1WRtDbAQIaT01kaIUCMWpnUcejSnW6ooXholqOMSZ6CgiGrvuLwvV3MLWNyUubx/HmMX/DGVmve9dj9wY+J+44W9jm9Kte8rNxAKzxggw2W4qYXPjrm9MzNJg5o7PTxK9fU0pxvZCtgNBxQxjDp0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1646229424618121.90972948943875; Wed, 2 Mar 2022 05:57:04 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-315-a7dDujICNSy51JVo8CcjRw-1; Wed, 02 Mar 2022 08:56:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E3C5D1091DA2; Wed, 2 Mar 2022 13:56:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB19B7B8D8; Wed, 2 Mar 2022 13:56:21 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A05841807D70; Wed, 2 Mar 2022 13:56:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DuGUM017901 for ; Wed, 2 Mar 2022 08:56:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7B3AD83780; Wed, 2 Mar 2022 13:56:16 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id D52F883788 for ; Wed, 2 Mar 2022 13:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229423; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YcHq2ELIQgKOzHlxn65D6/PHqY6cSJbpCfmcJYrrXB0=; b=TCdAVZJ+1mkItBEHO5ib/vYMCOUdGer1XXnBAztOdhelvTh5/H87kDx9uvi5r4H3bFCspD w6jJPbphAfLAM2JvheCR5MfAVaTyq7CYH9DKsUax18CcdyBHkQcv0HS+sbthl0rCJavYAs vXyymGIJIp0N3AP03M120SOm7RbxGEs= X-MC-Unique: a7dDujICNSy51JVo8CcjRw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 15/23] virshGetOneDisplay: Refactor formatting of URI params Date: Wed, 2 Mar 2022 14:55:14 +0100 Message-Id: <2daf0816e5879bc8c664629314327e1fb0b7563b.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229425618100001 Content-Type: text/plain; charset="utf-8" Unconditionally format the start of the query ('?') and make delimiters ('&') part of the arguments. At the end we can trim off 1 char from the end of the buffer unconditionally. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index d0f78798b5..ca1145428f 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11678,7 +11678,6 @@ virshGetOneDisplay(vshControl *ctl, g_autofree char *type_conn =3D NULL; g_autofree char *sockpath =3D NULL; g_autofree char *passwd =3D NULL; - bool params =3D false; /* Attempt to get the port number for the current graphics scheme */ xpathPort =3D g_strdup_printf(xpath_fmt, scheme, "@port"); @@ -11781,22 +11780,20 @@ virshGetOneDisplay(vshControl *ctl, virBufferAsprintf(&buf, ":%d", port); } + /* format the parameters part of the uri */ + virBufferAddLit(&buf, "?"); + /* TLS Port */ if (tls_port) { - virBufferAsprintf(&buf, - "?tls-port=3D%d", - tls_port); - params =3D true; + virBufferAsprintf(&buf, "tls-port=3D%d&", tls_port); } if (STREQ(scheme, "spice") && passwd) { - virBufferAsprintf(&buf, - "%spassword=3D%s", - params ? "&" : "?", - passwd); - params =3D true; + virBufferAsprintf(&buf, "password=3D%s&", passwd); } + virBufferTrimLen(&buf, 1); + return virBufferContentAndReset(&buf); } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229391; cv=none; d=zohomail.com; s=zohoarc; b=ceoZeYs2XbVXo7xav6FFfNAJxVxpXqf1uCAYgIKRbeWVcrSCdjc+VTlLgRb3NFrK+9fpe4NOZ33nKJmBsAe03596uGTRL2NQyRSO/TEfL85HFNjVMunkcj0E619P8zVJe3AlZpbByEe6CI/A5YPSgf8XQRKe8cDzsP9XBkVuLow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229391; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/6bBSNWw5GGM8MjSoZjDy9sogYCKIdUMWejOBCRON3s=; b=RJKf6lNuCsXrKOohvDJJ9KdGS8iifN9Y3E0slOZbupzrVkafST/A/qryqLbMJrzUEnQdoWOU+mbkWsThz7Q8v83kP7O4T66YFJ0UvnYiYLaekP1645DJAspWyg7nkbaNnAefbEgDkRHBAHc3w/tKwpsQ755EOu8nNyayzSzFRsc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 16462293912744.24294205978515; Wed, 2 Mar 2022 05:56:31 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-191-UAHs2XveN8CXekZ6uNpLTA-1; Wed, 02 Mar 2022 08:56:25 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B3D71006AA5; Wed, 2 Mar 2022 13:56:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E04927B8D5; Wed, 2 Mar 2022 13:56:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B3E3C1CBF; Wed, 2 Mar 2022 13:56:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DuHII017927 for ; Wed, 2 Mar 2022 08:56:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8081783787; Wed, 2 Mar 2022 13:56:17 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4A2683780 for ; Wed, 2 Mar 2022 13:56:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229390; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/6bBSNWw5GGM8MjSoZjDy9sogYCKIdUMWejOBCRON3s=; b=Me8qQ5FcUw1ikVL7q2ee+AECOu6yXjfpZjXCea+PL+R7LSMKL6W+YTWHtBKSxRlz9mh169 vTm+F/Ty+2pW77nuj3VOtmHbyuoyr1S2354wTNyDiwI8qBkv2MpsNurxHTc/vXuiQGFh/o 4bBixuHJgKug/5UelYSnxP/oKqkVeLo= X-MC-Unique: UAHs2XveN8CXekZ6uNpLTA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/23] virsh: cmdSchedinfo: Add separate variable for holding flags used for query Date: Wed, 2 Mar 2022 14:55:15 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229393361100005 Content-Type: text/plain; charset="utf-8" Instead of having two ad-hoc places which decide whether the original flags can be used add another variable specifically for flags used for query. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ca1145428f..2d1889c71e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5158,6 +5158,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) size_t i; bool ret_val =3D false; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + unsigned int queryflags =3D VIR_DOMAIN_AFFECT_CURRENT; bool current =3D vshCommandOptBool(cmd, "current"); bool config =3D vshCommandOptBool(cmd, "config"); bool live =3D vshCommandOptBool(cmd, "live"); @@ -5170,6 +5171,14 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) if (live) flags |=3D VIR_DOMAIN_AFFECT_LIVE; + /* We cannot query both live and config at once, so settle + on current in that case. If we are setting, then the two values sh= ould + match when we re-query; otherwise, we report the error later. */ + if (config && live) + queryflags =3D VIR_DOMAIN_AFFECT_CURRENT; + else + queryflags =3D flags; + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -5188,12 +5197,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) memset(params, 0, sizeof(*params) * nparams); if (flags || current) { - /* We cannot query both live and config at once, so settle - on current in that case. If we are setting, then the - two values should match when we re-query; otherwise, we - report the error later. */ - if (virDomainGetSchedulerParametersFlags(dom, params, &nparams, - ((live && config) ? 0 : f= lags)) =3D=3D -1) + if (virDomainGetSchedulerParametersFlags(dom, params, &nparams, qu= eryflags) =3D=3D -1) goto cleanup; } else { if (virDomainGetSchedulerParameters(dom, params, &nparams) =3D=3D = -1) @@ -5212,8 +5216,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd) nupdates, flags) =3D= =3D -1) goto cleanup; - if (virDomainGetSchedulerParametersFlags(dom, params, &nparams, - ((live && config) ? 0= : flags)) =3D=3D -1) + if (virDomainGetSchedulerParametersFlags(dom, params, &nparams= , queryflags) =3D=3D -1) goto cleanup; } else { if (virDomainSetSchedulerParameters(dom, updates, nupdates) = =3D=3D -1) --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229471; cv=none; d=zohomail.com; s=zohoarc; b=NYB5UoVKa3IHpWK07ZwArFCXDlhcCMTLIwdHJs72cjEroZKdhXKu+Vsj5gMuGqbvOFbcqWT9NB4CtUtZ58Sk0GV5A/CJ1Bnj28ABAK8g/neK+RPdxZcywMBu3dsMRZnVdLiPNTw2OFLj0i82k0My1tcIT4NwdjG3goX/UFI8oG4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229471; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UCd3vk7lGbP8Yq2nEAw9Mj1D8sucxGljg3h7Yfluy9g=; b=k5vUcBBQCa3gCCfwPyg4ke9TGCQk3YqlqyUhgvgD1mI9umqxf3yMneF/mFBVPrVz/NDogY3tTofOOmu4LCcnElU17IBtQ8h6+Ii6aAodfbolfRFE5D2TGd7c0fIduRlAO3ff6k0Tw91kmhKun1mLWo+bV1sLoQK6jlMD/tPg+RA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229471817238.9931882832492; Wed, 2 Mar 2022 05:57:51 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-637-GFtBVEgAMKOO-7hHwcXJpQ-1; Wed, 02 Mar 2022 08:56:46 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50D421856A77; Wed, 2 Mar 2022 13:56:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61DF183BF0; Wed, 2 Mar 2022 13:56:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2C7FD1807D73; Wed, 2 Mar 2022 13:56:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DudY4018214 for ; Wed, 2 Mar 2022 08:56:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3B6C183788; Wed, 2 Mar 2022 13:56:39 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93CAC83783 for ; Wed, 2 Mar 2022 13:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229471; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UCd3vk7lGbP8Yq2nEAw9Mj1D8sucxGljg3h7Yfluy9g=; b=A4gUwLO93oP5jOFwRRoUvxlfI//y/Gfh1Ad+rEZnbTE6g9xHAlxk3c6NExs9M4/siYsvgW v5PTpv/DvVotgZwa6gTnyT4MNUCD+OzhVgkp1oAlQpCAfR2+lFABG8ykHIRRxoRvP8tTM+ QEfK9Hm21LrL+3t2bU4Dmo1YwBaJ+wY= X-MC-Unique: GFtBVEgAMKOO-7hHwcXJpQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 17/23] virsh: cmdDesc: Use separate flags variable for getters Date: Wed, 2 Mar 2022 14:55:16 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229474011100001 Content-Type: text/plain; charset="utf-8" The getters have a different set of flags. Add a variable for the getter to avoid having to construct flags when calling the getter. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 2d1889c71e..cac50dba51 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8341,12 +8341,15 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; bool ret =3D false; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; + unsigned int queryflags =3D 0; VSH_EXCLUSIVE_OPTIONS_VAR(current, live); VSH_EXCLUSIVE_OPTIONS_VAR(current, config); - if (config) + if (config) { flags |=3D VIR_DOMAIN_AFFECT_CONFIG; + queryflags |=3D VIR_DOMAIN_XML_INACTIVE; + } if (live) flags |=3D VIR_DOMAIN_AFFECT_LIVE; @@ -8370,8 +8373,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) if (edit || desc) { if (!desc) { - desc =3D virshGetDomainDescription(ctl, dom, title, - config?VIR_DOMAIN_XML_INACTIVE:= 0); + desc =3D virshGetDomainDescription(ctl, dom, title, queryf= lags); if (!desc) goto cleanup; } @@ -8420,8 +8422,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) title ? _("Domain title updated successfully") : _("Domain description updated successfully")= ); } else { - desc =3D virshGetDomainDescription(ctl, dom, title, - config?VIR_DOMAIN_XML_INACTIVE:0); + desc =3D virshGetDomainDescription(ctl, dom, title, queryflags); if (!desc) goto cleanup; --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229425; cv=none; d=zohomail.com; s=zohoarc; b=WlOtJnoteQ8jfgwKvgcXnVnII0Y6rVCsu011N5WWta/d0Y4rZyVCD5rw7lJwZXyNe80kVaKsftfZufKvzOn+QU0XDX6nAk0N6H/2yJtdLbyEg166tDXi6LRkMD9K6Yl68sjSRpjoJgcMRD39i9hAeuYWPHrKS3eiJWWVvqywUYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229425; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v5Oj9wRZv7AWzZHHBlPldovdANkFs1zTn2ycWuM3K+0=; b=nVSFGfkn6BKSKjHu39iY+GpBtPhQC5pxbo87lKFlW2qF50GlgVEQhto7yKLDGu/pQDDy4DiS0oxH5iDhDZdtz9YxJOQrO83FPax7USZBQBlhZy5Dim2Jcg/axGTpU9U5GkSX19nBB4pM6vwyGebzjXNG/YD0JgSnbmbWMTvu2Ng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229425502780.9320156315391; Wed, 2 Mar 2022 05:57:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-77-B9qE4SURPqO80_qWaNmK3w-1; Wed, 02 Mar 2022 08:56:51 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87E93100CCC6; Wed, 2 Mar 2022 13:56:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FFFC26E41; Wed, 2 Mar 2022 13:56:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2ED6F4ED28; Wed, 2 Mar 2022 13:56:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222Due5v018222 for ; Wed, 2 Mar 2022 08:56:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3F77083788; Wed, 2 Mar 2022 13:56:40 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A463E83783 for ; Wed, 2 Mar 2022 13:56:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229424; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=v5Oj9wRZv7AWzZHHBlPldovdANkFs1zTn2ycWuM3K+0=; b=iYeUxH7ZZ1H+n6pMlVvTA5FLjqkWlz8NonwF246fdPotSw9Iwg2cygX+5z78A74iO1+oC5 JQ+Kepw8qo9pFGE3/LWQFX5Uok7r16TddAqF8Iryxf46p0v7Fxrzip9/vFbxJ7NDd6yu4k fX3g/UguzD1WJ9JwrzXNmzae/CK9SPk= X-MC-Unique: B9qE4SURPqO80_qWaNmK3w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 18/23] vsh: Add helper for auto-removing temporary file Date: Wed, 2 Mar 2022 14:55:17 +0100 Message-Id: <812b148f13c63b7d64be375c401a38b7c8831e6d.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229427644100004 Content-Type: text/plain; charset="utf-8" The vsh helpers for user-editing of contents use temporary files. Introduce 'vshTempFile' type which automatically removes the file. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 25 +++++++++++++++++++------ tools/vsh.h | 3 +++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 4ec5e54b5d..bbde594967 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2378,34 +2378,47 @@ vshAskReedit(vshControl *ctl, #endif /* WIN32 */ +void +vshEditUnlinkTempfile(char *file) +{ + if (!file) + return; + + ignore_value(unlink(file)); + g_free(file); +} + + /* Common code for the edit / net-edit / pool-edit functions which follow.= */ char * vshEditWriteToTempFile(vshControl *ctl, const char *doc) { - g_autofree char *ret =3D NULL; + g_autofree char *filename =3D NULL; + g_autoptr(vshTempFile) ret =3D NULL; const char *tmpdir; VIR_AUTOCLOSE fd =3D -1; tmpdir =3D getenv("TMPDIR"); - if (!tmpdir) tmpdir =3D "/tmp"; - ret =3D g_strdup_printf("%s/virshXXXXXX.xml", tmpdir); - fd =3D g_mkstemp_full(ret, O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR); + if (!tmpdir) + tmpdir =3D "/tmp"; + filename =3D g_strdup_printf("%s/virshXXXXXX.xml", tmpdir); + fd =3D g_mkstemp_full(filename, O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR); if (fd =3D=3D -1) { vshError(ctl, _("g_mkstemp_full: failed to create temporary file: = %s"), g_strerror(errno)); return NULL; } + ret =3D g_steal_pointer(&filename); + if (safewrite(fd, doc, strlen(doc)) =3D=3D -1) { vshError(ctl, _("write: %s: failed to write to temporary file: %s"= ), ret, g_strerror(errno)); - unlink(ret); return NULL; } if (VIR_CLOSE(fd) < 0) { vshError(ctl, _("close: %s: failed to write or close temporary fil= e: %s"), ret, g_strerror(errno)); - unlink(ret); return NULL; } diff --git a/tools/vsh.h b/tools/vsh.h index e208d957bb..663dc1ffce 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -341,6 +341,9 @@ void vshSaveLibvirtError(void); void vshSaveLibvirtHelperError(void); /* file handling */ +void vshEditUnlinkTempfile(char *file); +typedef char vshTempFile; +G_DEFINE_AUTOPTR_CLEANUP_FUNC(vshTempFile, vshEditUnlinkTempfile); char *vshEditWriteToTempFile(vshControl *ctl, const char *doc); int vshEditFile(vshControl *ctl, const char *filename); char *vshEditReadBackFile(vshControl *ctl, const char *filename); --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229412; cv=none; d=zohomail.com; s=zohoarc; b=Omw7B7Bufp2BWI+N6/cMcNoIwN23epn1ns/opdmv6FtwdfqXJO9di87Kqwk5Oa1dkRNgBodSln7Yf1x9xgJabb+NwRjLthapCEJ1NgpgGxb876JWGRVQv8p47R5zk5+DKZRk0zwH/d6WugJLQt4qKzhNauVHYVoYAk0IWCTRbt4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229412; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kAtxBHEmah4lwYdtGahbNLXWvadb1MD9LwLlzYHpJUs=; b=hj8elVYkl7qHpBRmpHEmPh+I/rQw6a6He8/0Kxrdd8UWVbXu71Ez06jeg8Mi+WN7Ir/yAZwSIVw8zUuELyR6rOAAX4AzX8ZuofoYNEFQJt83WJtB+HVxNVw/BraSMHMuw4BCvrV5vK3xNQQw72IdqCQgSa68KFpG13Abi+RnfqQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229412161371.1156303871411; Wed, 2 Mar 2022 05:56:52 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-217-WSf_R0tuPhuhBUFCOwyZIg-1; Wed, 02 Mar 2022 08:56:49 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C93AE8DCC44; Wed, 2 Mar 2022 13:56:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A4F227BCC; Wed, 2 Mar 2022 13:56:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 154B14EA37; Wed, 2 Mar 2022 13:56:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222Duf8K018242 for ; Wed, 2 Mar 2022 08:56:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 44A9C83788; Wed, 2 Mar 2022 13:56:41 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FD9383783 for ; Wed, 2 Mar 2022 13:56:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229411; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kAtxBHEmah4lwYdtGahbNLXWvadb1MD9LwLlzYHpJUs=; b=Fm2PfHXrX019zJFtMhK+K6Vf7uuyiDDPKgBOFmEf9jzoMT/z1CpfMQBd1fs9XS0B9rMD61 14qlktcXgqeYthWiwXV73o13A4k+9UQUaabYJnJR0u4lhclGfhmrW5sAjLPtoDI2mR4u1A /deQuaS/bDqiffQpGoJz19ZtNjUlpeI= X-MC-Unique: WSf_R0tuPhuhBUFCOwyZIg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 19/23] virsh: cmdDesc: Use 'vshTempFile' type to simplify cleanup Date: Wed, 2 Mar 2022 14:55:18 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229413471100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index cac50dba51..dcf0f712f6 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8335,7 +8335,6 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) int type; char *desc =3D NULL; char *desc_edited =3D NULL; - char *tmp =3D NULL; char *tmpstr; const vshCmdOpt *opt =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; @@ -8379,6 +8378,8 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) } if (edit) { + g_autoptr(vshTempFile) tmp =3D NULL; + /* Create and open the temporary file. */ if (!(tmp =3D vshEditWriteToTempFile(ctl, desc))) goto cleanup; @@ -8439,10 +8440,6 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(desc_edited); VIR_FREE(desc); - if (tmp) { - unlink(tmp); - VIR_FREE(tmp); - } return ret; } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229416; cv=none; d=zohomail.com; s=zohoarc; b=fWeU+aJ3fVUBRzy2brDVM3RUDrF1nHjVUmoQOFwIs6JlzWryudZeIaV620fDD/+K26Qfyaa3N06W+BEumlXruMfOrgAS3yaRhfkT221jpFwhgN8Zs+aAWFR22qdCAO4DR47cLm2ZKrH5CRCEGiMoqadKvxK2SkTXzp8tjpFIBNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229416; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=p6ZEWYxkgSFpyviWtH08fDLJjzg2mBf2cxvV2bwZwqw=; b=Vr6prH0J+IigdzLlE4GtEAVI3rJlEMyXDixShnQqcvonWAcsfGvgB7bpuO+FNONsPNZtVmeDCluNN2rCc8ahAZ4UpYdmJPodBRFBzo3fM7QDriPdT+jX7TsMBO/LJ36LiD6jkg8RxEm98qyTWMer71yQUKzN+VN0VZvLg9VOe+8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229416777420.0595908232542; Wed, 2 Mar 2022 05:56:56 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-qP9AZMwTNOeVR2feaZuBMg-1; Wed, 02 Mar 2022 08:56:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3EAE6188E3FD; Wed, 2 Mar 2022 13:56:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DAACE26DFE; Wed, 2 Mar 2022 13:56:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A64C54EA37; Wed, 2 Mar 2022 13:56:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DugX5018260 for ; Wed, 2 Mar 2022 08:56:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 52A0D83788; Wed, 2 Mar 2022 13:56:42 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B446D83783 for ; Wed, 2 Mar 2022 13:56:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229416; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=p6ZEWYxkgSFpyviWtH08fDLJjzg2mBf2cxvV2bwZwqw=; b=WbW8w5t8vXr56NnVETs+g7GZDl5XE06sXK3BxutdMPlOfyhegWJYG6WIQ0ja0sVKkkBDUO pAu3Li61sDPv9Qmd/q+NgLADua1zBan6WzD5+Pb+aEjnDjI8nzxc9V/yoDYJN2jHVBDLph c76IGzftcwVX33gQ9scr+pGJR3e70j8= X-MC-Unique: qP9AZMwTNOeVR2feaZuBMg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 20/23] virsh: cmdDesc: Automatically free memory Date: Wed, 2 Mar 2022 14:55:19 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229421619100003 Content-Type: text/plain; charset="utf-8" Decrease scope of variables and use automatic freeing. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index dcf0f712f6..4d9722f400 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8333,9 +8333,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) int state; int type; - char *desc =3D NULL; - char *desc_edited =3D NULL; - char *tmpstr; + g_autofree char *desc =3D NULL; const vshCmdOpt *opt =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; bool ret =3D false; @@ -8379,6 +8377,8 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) if (edit) { g_autoptr(vshTempFile) tmp =3D NULL; + g_autofree char *desc_edited =3D NULL; + char *tmpstr; /* Create and open the temporary file. */ if (!(tmp =3D vshEditWriteToTempFile(ctl, desc))) @@ -8438,8 +8438,6 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - VIR_FREE(desc_edited); - VIR_FREE(desc); return ret; } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229420; cv=none; d=zohomail.com; s=zohoarc; b=Ot924vDEYr/qwlX1E1J0Kauw7ZjzkWTh5Bmpl9QHjWSqCjDh0AIy7XO3OMXDV84t8NUk7+DPXdAjFneZtGM3zGOzsfi7DNnMKt0TkIRf+zX6QcjJt5DUmTtodrhB7L//f1espfdFjLUIp9ni9IwEPiOZKWL3CKHMe3UxoxpiPko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229420; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XMykoCqsIj+3F79+UO2dMZ7dsUaDmmkqlUso5pYGR0s=; b=Q9yzbFzbi2Zhw+PLiCEbi+Yiyx7F6r/UU0nbdwqvcQd9lyK6laPl3a9zhZGtEd1OnADuGRAAYR+7JeOky43i5df6NElC7YLlcmfn+vnGkYanMxjaxIKhY0VnaKm/F4LZn6zCG/gUJ9Q7wxAPvffUNQ6qn2j7U3pS2qMjrrs1jeY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1646229420648161.6563487217869; Wed, 2 Mar 2022 05:57:00 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-298-JVlXi8etPNOu9eyky5sbRg-1; Wed, 02 Mar 2022 08:56:55 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 361C110199BF; Wed, 2 Mar 2022 13:56:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 12A977D879; Wed, 2 Mar 2022 13:56:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D9AEA4ED79; Wed, 2 Mar 2022 13:56:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DuhU6018268 for ; Wed, 2 Mar 2022 08:56:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6441783788; Wed, 2 Mar 2022 13:56:43 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAF2483783 for ; Wed, 2 Mar 2022 13:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229419; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=XMykoCqsIj+3F79+UO2dMZ7dsUaDmmkqlUso5pYGR0s=; b=IhEIRXL48/0uReym/ttEsY3B5rV1aNL3x9f50w91cpJlUc3X2R4HPfGvQwaHKkpR6gvO0B 0vaHZVUfDZIrWcXHpJhcpEPxfbeMVYizuSX6irVfMrPmkNxwROGBcYpVhXim7laichoWb4 zG5gU9MrcASluQ4abesSxD73BGKx1pg= X-MC-Unique: JVlXi8etPNOu9eyky5sbRg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 21/23] virsh: cmdDesc: Remove unneeded 'cleanup' Date: Wed, 2 Mar 2022 14:55:20 +0100 Message-Id: <7ee425ed968bfa35e86e00a7191d6e2d391d6022.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229421565100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 4d9722f400..7b4f8638a9 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8336,7 +8336,6 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) g_autofree char *desc =3D NULL; const vshCmdOpt *opt =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - bool ret =3D false; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; unsigned int queryflags =3D 0; @@ -8354,7 +8353,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) return false; if ((state =3D virshDomainState(ctl, dom, NULL)) < 0) - goto cleanup; + return false; if (title) type =3D VIR_DOMAIN_METADATA_TITLE; @@ -8372,7 +8371,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) if (!desc) { desc =3D virshGetDomainDescription(ctl, dom, title, queryf= lags); if (!desc) - goto cleanup; + return false; } if (edit) { @@ -8382,15 +8381,15 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) /* Create and open the temporary file. */ if (!(tmp =3D vshEditWriteToTempFile(ctl, desc))) - goto cleanup; + return false; /* Start the editor. */ if (vshEditFile(ctl, tmp) =3D=3D -1) - goto cleanup; + return false; /* Read back the edited file. */ if (!(desc_edited =3D vshEditReadBackFile(ctl, tmp))) - goto cleanup; + return false; /* strip a possible newline at the end of file; some * editors enforce a newline, this makes editing the title @@ -8405,8 +8404,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, "%s", title ? _("Domain title not changed\n") : _("Domain description not changed\n"= )); - ret =3D true; - goto cleanup; + return true; } VIR_FREE(desc); @@ -8417,7 +8415,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) vshError(ctl, "%s", title ? _("Failed to set new domain title") : _("Failed to set new domain description")); - goto cleanup; + return false; } vshPrintExtra(ctl, "%s", title ? _("Domain title updated successfully") : @@ -8425,7 +8423,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) } else { desc =3D virshGetDomainDescription(ctl, dom, title, queryflags); if (!desc) - goto cleanup; + return false; if (strlen(desc) > 0) vshPrint(ctl, "%s", desc); @@ -8436,9 +8434,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) virDomainGetName(dom)); } - ret =3D true; - cleanup: - return ret; + return true; } --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229427; cv=none; d=zohomail.com; s=zohoarc; b=S5riIGiHZdRO7c1olBu9IxUmAqcU9bz3OaLWT9An6j3Fge5V2xdu+2ueUd7RM5O3X/QR8VUMWmmc+PBb7eyX9OoXl2FUK+B6V+ITGKQS/qLRMHtskFVbT2vPKWyTvy8Iu30ELKx1ynl1Ab2h7FUwmUkC9QobdJrJSWfi96Mlzgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229427; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cnMeOd9vzWockSceljymyjg5o9zs2n8FfhztgJbvp1Y=; b=V3N1azbCVGNyBQNnX2rqH3YJjAGunOjFroIj7PMS/Uz5fu7CBDJ15uT+qy5t21ISvELny+fDHV2W7LJjbWfmW+ShcaFvlukOPT4Cf3AVJzp3QZTxy4eyKD5ljh0Qe0VCN8uXZQ53ONC8AX/RjiuokP6Ds+QUTU8vuQv/l12sPIY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229427129320.66085772962697; Wed, 2 Mar 2022 05:57:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-25-dhFA01qdN42niVrvaIdAxQ-1; Wed, 02 Mar 2022 08:56:54 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A662218B9FB6; Wed, 2 Mar 2022 13:56:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8114E7D879; Wed, 2 Mar 2022 13:56:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5287C4ED28; Wed, 2 Mar 2022 13:56:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222Duim1018282 for ; Wed, 2 Mar 2022 08:56:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id 814BD83788; Wed, 2 Mar 2022 13:56:44 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E35AB83783 for ; Wed, 2 Mar 2022 13:56:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229426; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=cnMeOd9vzWockSceljymyjg5o9zs2n8FfhztgJbvp1Y=; b=goDVKCcKXbTL6Qz//TG36UREDT/7YmMR+sF+ydVfkZ1n1yRxfcGf37Imc0LKIui/n/k0GX zHZsOtLv8iQY0O0vei/rgGzCpPw8HzR3N9EOxKTPQsIVmAnJHH6U6cYfwdsZDOGUDqkk8R +IkdtN3BkI7udg/DLsSm2+ocNThUqSY= X-MC-Unique: dhFA01qdN42niVrvaIdAxQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 22/23] virsh: domain: Don't use ternaries inside vshPrint/vshError functions Date: Wed, 2 Mar 2022 14:55:21 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229427651100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 50 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7b4f8638a9..89ad45dbf0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3929,11 +3929,13 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) /* No way to emulate deletion of just snapshot metadata * without support for the newer flags. Oh well. */ if (has_snapshots_metadata) { - vshError(ctl, - snapshots_metadata ? - _("Unable to remove metadata of %d snapshots") : - _("Refusing to undefine while %d snapshots exist"), - has_snapshots_metadata); + if (snapshots_metadata) + vshError(ctl, _("Unable to remove metadata of %d snapshots"), + has_snapshots_metadata); + else + vshError(ctl, _("Refusing to undefine while %d snapshots exist= "), + has_snapshots_metadata); + goto cleanup; } @@ -8401,9 +8403,11 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) /* Compare original XML with edited. Has it changed at all? */ if (STREQ(desc, desc_edited)) { - vshPrintExtra(ctl, "%s", - title ? _("Domain title not changed\n") : - _("Domain description not changed\n"= )); + if (title) + vshPrintExtra(ctl, "%s", _("Domain title not changed\n= ")); + else + vshPrintExtra(ctl, "%s", _("Domain description not cha= nged\n")); + return true; } @@ -8412,26 +8416,32 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) } if (virDomainSetMetadata(dom, type, desc, NULL, NULL, flags) < 0) { - vshError(ctl, "%s", - title ? _("Failed to set new domain title") : - _("Failed to set new domain description")); + if (title) + vshError(ctl, "%s", _("Failed to set new domain title")); + else + vshError(ctl, "%s", _("Failed to set new domain descriptio= n")); + return false; } - vshPrintExtra(ctl, "%s", - title ? _("Domain title updated successfully") : - _("Domain description updated successfully")= ); + + if (title) + vshPrintExtra(ctl, "%s", _("Domain title updated successfully"= )); + else + vshPrintExtra(ctl, "%s", _("Domain description updated success= fully")); + } else { desc =3D virshGetDomainDescription(ctl, dom, title, queryflags); if (!desc) return false; - if (strlen(desc) > 0) + if (strlen(desc) > 0) { vshPrint(ctl, "%s", desc); - else - vshPrintExtra(ctl, - title ? _("No title for domain: %s") : - _("No description for domain: %s"), - virDomainGetName(dom)); + } else { + if (title) + vshPrintExtra(ctl, _("No title for domain: %s"), virDomain= GetName(dom)); + else + vshPrintExtra(ctl, _("No description for domain: %s"), vir= DomainGetName(dom)); + } } return true; --=20 2.35.1 From nobody Sun May 12 05:54:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646229419; cv=none; d=zohomail.com; s=zohoarc; b=SFixrmCGDG55n/VqTs1idldtM2ADh4RQi/N4d62xmUjnQwdEzSFgCr6z8iE6HomxvdWfkVsppO5NPtly0EK0MRSwbUs3LD8J1+50JpOU4asYHNLSIPBGgS8MDG/4cSh4XpPbnFNyeADq4V2PI5zTFgGPS1WKIzVCHsaOvWTPESM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229419; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=K6QEawQ69s92MFGSZqy/L4y91DAdlLeaWYnSblzUO8Y=; b=J8tH4aZvuLFPRWk9fkrwQfAFG9i3iJEIANrHAulKcdRIB+aoZSfUi47PkBYTdD5aDeHUQlTUDSYjqnc5u8jdK9TZ+PhAUMgOi5L664VUvBRrH0ko0gZArUNpclRjWziT6VZc5eIREj01hzP0WUkHdGr+zHs/6DXt95Vqgc0sGe0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646229419373645.7528939000008; Wed, 2 Mar 2022 05:56:59 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-25-lIkJD39qM8yzCEeC-Ss2ow-1; Wed, 02 Mar 2022 08:56:54 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2D5C18BA283; Wed, 2 Mar 2022 13:56:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B78361042A66; Wed, 2 Mar 2022 13:56:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 866D91809CB4; Wed, 2 Mar 2022 13:56:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DujkL018304 for ; Wed, 2 Mar 2022 08:56:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8775783581; Wed, 2 Mar 2022 13:56:45 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E37F383577 for ; Wed, 2 Mar 2022 13:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229418; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=K6QEawQ69s92MFGSZqy/L4y91DAdlLeaWYnSblzUO8Y=; b=YnNMMKpguJqL6g/XJYvZ2MuBSJgnbHjUJlkXo3YgYSqDplNB0x4eFkcZzvU/9WTL4GnguW IPlCj8We3pqKjAS46Drh5p0hh5Diz8Mo+i+983DSHV0oaxnBNYIZfcvFXtQoTpF0ZS+k02 9OEPIHRlzETHDbnZHuDP/tUIDSWwrIY= X-MC-Unique: lIkJD39qM8yzCEeC-Ss2ow-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 23/23] virsh: cmdDesc: Fix logic when '-edit' is used along with 'desc' argument Date: Wed, 2 Mar 2022 14:55:22 +0100 Message-Id: <4fe3f3d7063a3f78a3dd892361245e5f912bc117.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646229421602100002 Content-Type: text/plain; charset="utf-8" Historically the use of the '-desc' multiple argument parameter was not forbidden toghether with '-edit', but use of both together has some unexpected behaviour. Specifically the editor is filled with the contents passed via '-desc' but if the user doesn't change the text in any way virsh will claim that the description was not chaged even if it differs from the currently set description. Similarly, when the user would edit the description provided via 'desc' so that it's identical with the one configured for the domain, virsh would claim that it was updated: # virsh desc cd No description for domain: cd # EDITOR=3Dtrue virsh desc cd --edit "test desc" Domain description not changed After the fix: # virsh desc cd No description for domain: cd # EDITOR=3Dtrue virsh desc cd --edit "test desc" Domain description updated successfully # EDITOR=3Dtrue virsh desc cd --edit "test desc" Domain description not changed Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 89ad45dbf0..d5fd8be7c3 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8335,7 +8335,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) int state; int type; - g_autofree char *desc =3D NULL; + g_autofree char *descArg =3D NULL; const vshCmdOpt *opt =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; @@ -8367,14 +8367,17 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) virBufferTrim(&buf, " "); - desc =3D virBufferContentAndReset(&buf); + descArg =3D virBufferContentAndReset(&buf); - if (edit || desc) { - if (!desc) { - desc =3D virshGetDomainDescription(ctl, dom, title, queryf= lags); - if (!desc) - return false; - } + if (edit || descArg) { + g_autofree char *descDom =3D NULL; + g_autofree char *descNew =3D NULL; + + if (!(descDom =3D virshGetDomainDescription(ctl, dom, title, query= flags))) + return false; + + if (!descArg) + descArg =3D g_strdup(descDom); if (edit) { g_autoptr(vshTempFile) tmp =3D NULL; @@ -8382,7 +8385,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) char *tmpstr; /* Create and open the temporary file. */ - if (!(tmp =3D vshEditWriteToTempFile(ctl, desc))) + if (!(tmp =3D vshEditWriteToTempFile(ctl, descArg))) return false; /* Start the editor. */ @@ -8402,7 +8405,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) *tmpstr =3D '\0'; /* Compare original XML with edited. Has it changed at all? */ - if (STREQ(desc, desc_edited)) { + if (STREQ(descDom, desc_edited)) { if (title) vshPrintExtra(ctl, "%s", _("Domain title not changed\n= ")); else @@ -8411,11 +8414,12 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) return true; } - VIR_FREE(desc); - desc =3D g_steal_pointer(&desc_edited); + descNew =3D g_steal_pointer(&desc_edited); + } else { + descNew =3D g_steal_pointer(&descArg); } - if (virDomainSetMetadata(dom, type, desc, NULL, NULL, flags) < 0) { + if (virDomainSetMetadata(dom, type, descNew, NULL, NULL, flags) < = 0) { if (title) vshError(ctl, "%s", _("Failed to set new domain title")); else @@ -8430,7 +8434,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, "%s", _("Domain description updated success= fully")); } else { - desc =3D virshGetDomainDescription(ctl, dom, title, queryflags); + g_autofree char *desc =3D virshGetDomainDescription(ctl, dom, titl= e, queryflags); if (!desc) return false; --=20 2.35.1