From nobody Mon Feb 9 18:17:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1594006917; cv=none; d=zohomail.com; s=zohoarc; b=X3V/di2ziRwsWGoixw1Nf9W5lTw6S54iZkz3FtNIjE84qZYrjrAjCvJqkDRnQKrId0NFIBb+f7lnj4BHTcallLnTckzOZ0zS/J3LfbPo941I5FE1GTQpR69y7qz+MurKwANUlDKhxVmO8GHUq+/PjytNmjs6UM1az5zckCVK6Sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594006917; 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=3bZjdob8ooINa6E1k82G83aprH5EGhB2oWubro24PG4=; b=HWMD7Y3aBPVzxKDtO2bltEBv1vpfdR9WDr66sIlQrHLVZPzZkF+jeC/wNli8S+RG12gvZREDMu7+WAYl5ltm+jt4c8hWM8lKVPA60XxBtA6PzP5AgA/ds0YT9XItxi7lbJ7fkkbOFCdfmIVC1vD9vu/heAff18u5oXH1k6B7AF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1594006917293120.19241581825872; Sun, 5 Jul 2020 20:41:57 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-HF3FzgbKMYqFaY8_J6MQ0Q-1; Sun, 05 Jul 2020 23:41:53 -0400 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 A3B3580040D; Mon, 6 Jul 2020 03:41:48 +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 5A5895BAD5; Mon, 6 Jul 2020 03:41:48 +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 7D4B81809547; Mon, 6 Jul 2020 03:41:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0663fe0l004395 for ; Sun, 5 Jul 2020 23:41:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB4537AC9F; Mon, 6 Jul 2020 03:41:40 +0000 (UTC) Received: from vhost2.laine.org (ovpn-112-194.phx2.redhat.com [10.3.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7078571678 for ; Mon, 6 Jul 2020 03:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594006916; 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=3bZjdob8ooINa6E1k82G83aprH5EGhB2oWubro24PG4=; b=CKs/q/te7qxB6AqJv1ntovxuMhAvgWScf4tU4XaRJLNvOenJNNhQNDUgTEmewRk1+nW4Ae ial1sBsPGiqLvV4FGBTbiuyilX+gDzQIWdv08YjMq8W1ni9mYmNKnzQReH1Mio7+pX365t xOmKArvhwntXvsYlTJBnzX+sX/cGknQ= X-MC-Unique: HF3FzgbKMYqFaY8_J6MQ0Q-1 From: Laine Stump To: libvir-list@redhat.com Subject: [PATCH 01/32] bhyve: use g_auto() for all virBuffers Date: Sun, 5 Jul 2020 23:40:56 -0400 Message-Id: <20200706034127.1117504-2-laine@redhat.com> In-Reply-To: <20200706034127.1117504-1-laine@redhat.com> References: <20200706034127.1117504-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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) Content-Type: text/plain; charset="utf-8" In most cases this eliminates one or more calls to virBufferClearAndReset(), but even when it doesn't it's better because: 1) it makes the code more consistent, making it more likely that new contri= butors who are "learning by example" will to the right thing. 2) it protects against future modifications that might have otherwise needed to add a virBufferClearAndReset() 3) Currently some functions don't call virBufferClearAndReset() only because they're relying on some subordinate function to call it for them (e.g. bhyveConnectGetSysinfo() in this patch relies on virSysinfoFormat() to clear out the buffer when there is an error). I think this is sloppy behavior, and that the toplevel function that defines and initializes the buffer should be the function clearing it at the end. Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- src/bhyve/bhyve_command.c | 15 ++++++--------- src/bhyve/bhyve_driver.c | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 5b1d80083a..9649c2d2a2 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -166,14 +166,15 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *de= f, bhyveConnPtr driver, virCommandPtr cmd) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; - virBuffer device =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; const char *disk_source; size_t i; int ret =3D -1; =20 for (i =3D 0; i < def->ndisks; i++) { + g_auto(virBuffer) device =3D VIR_BUFFER_INITIALIZER; virDomainDiskDefPtr disk =3D def->disks[i]; + if (disk->bus !=3D VIR_DOMAIN_DISK_BUS_SATA) continue; =20 @@ -221,7 +222,6 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def, goto error; } virBufferAddBuffer(&buf, &device); - virBufferFreeAndReset(&device); } =20 virCommandAddArg(cmd, "-s"); @@ -231,7 +231,6 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def, =20 ret =3D 0; error: - virBufferFreeAndReset(&buf); return ret; } =20 @@ -378,7 +377,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def, virCommandPtr cmd, bool dryRun) { - virBuffer opt =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) opt =3D VIR_BUFFER_INITIALIZER; virDomainGraphicsListenDefPtr glisten =3D NULL; bool escapeAddr; unsigned short port; @@ -478,7 +477,6 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def, return 0; =20 error: - virBufferFreeAndReset(&opt); return -1; } =20 @@ -765,7 +763,6 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def, char **devicesmap_out) { virDomainDiskDefPtr hdd, cd, userdef, diskdef; - virBuffer devicemap; virCommandPtr cmd; unsigned int best_idx =3D UINT_MAX; size_t i; @@ -773,8 +770,6 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def, if (def->os.bootloaderArgs !=3D NULL) return virBhyveProcessBuildCustomLoaderCmd(def); =20 - devicemap =3D (virBuffer)VIR_BUFFER_INITIALIZER; - /* Search disk list for CD or HDD device. We'll respect if * present and otherwise pick the first CD or failing that HDD we come * across. */ @@ -809,6 +804,8 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def, VIR_DEBUG("grub-bhyve with default arguments"); =20 if (devicesmap_out !=3D NULL) { + g_auto(virBuffer) devicemap =3D VIR_BUFFER_INITIALIZER; + /* Grub device.map (just for boot) */ if (userdef !=3D NULL) { virBhyveFormatGrubDevice(&devicemap, userdef); diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index b6204c7fb9..daa20bad40 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -244,7 +244,7 @@ static char * bhyveConnectGetSysinfo(virConnectPtr conn, unsigned int flags) { bhyveConnPtr privconn =3D conn->privateData; - virBuffer buf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; =20 virCheckFlags(0, NULL); =20 @@ -678,7 +678,7 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn, const char *xmlData, unsigned int flags) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; bhyveConnPtr privconn =3D conn->privateData; virDomainDefPtr def =3D NULL; virCommandPtr cmd =3D NULL, loadcmd =3D NULL; --=20 2.25.4