From nobody Sat Feb 7 10:44:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550678007783711.3125691002892; Wed, 20 Feb 2019 07:53:27 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id DFABFA327A; Wed, 20 Feb 2019 15:53:25 +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 9F96C607CB; Wed, 20 Feb 2019 15:53:25 +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 42A623F5CC; Wed, 20 Feb 2019 15:53:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1KFrKhN031740 for ; Wed, 20 Feb 2019 10:53:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id BC0AA60C67; Wed, 20 Feb 2019 15:53:20 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-222.phx2.redhat.com [10.3.116.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72D1260BF6; Wed, 20 Feb 2019 15:53:20 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 20 Feb 2019 09:53:12 -0600 Message-Id: <20190220155316.6329-4-eblake@redhat.com> In-Reply-To: <20190220155316.6329-1-eblake@redhat.com> References: <20190220155316.6329-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com Subject: [libvirt] [PATCH 3/7] snapshot: Refactor virDomainSnapshotDefFormat 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 20 Feb 2019 15:53:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Split out an internal helper that produces format into a virBuffer, similar to what domain_conf.c does, and making the next patch easier to write. Signed-off-by: Eric Blake --- src/conf/snapshot_conf.c | 103 ++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 44 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index b8012cb111..b7b5873cbe 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -700,92 +700,107 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, } -char * -virDomainSnapshotDefFormat(const char *domain_uuid, - virDomainSnapshotDefPtr def, - virCapsPtr caps, - virDomainXMLOptionPtr xmlopt, - unsigned int flags) +static int +virDomainSnapshotDefFormatInternal(virBufferPtr buf, + const char *domain_uuid, + virDomainSnapshotDefPtr def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) { - virBuffer buf =3D VIR_BUFFER_INITIALIZER; size_t i; int domainflags =3D VIR_DOMAIN_DEF_FORMAT_INACTIVE; - virCheckFlags(VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE | - VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL, NULL); - if (flags & VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE) domainflags |=3D VIR_DOMAIN_DEF_FORMAT_SECURE; - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); - virBufferEscapeString(&buf, "%s\n", def->name); + virBufferEscapeString(buf, "%s\n", def->name); if (def->description) - virBufferEscapeString(&buf, "%s\n", + virBufferEscapeString(buf, "%s\n", def->description); - virBufferAsprintf(&buf, "%s\n", + virBufferAsprintf(buf, "%s\n", virDomainSnapshotStateTypeToString(def->state)); if (def->parent) { - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); - virBufferEscapeString(&buf, "%s\n", def->parent); - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferEscapeString(buf, "%s\n", def->parent); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } - virBufferAsprintf(&buf, "%lld\n", + virBufferAsprintf(buf, "%lld\n", def->creationTime); if (def->memory) { - virBufferAsprintf(&buf, "memor= y)); - virBufferEscapeString(&buf, " file=3D'%s'", def->file); - virBufferAddLit(&buf, "/>\n"); + virBufferEscapeString(buf, " file=3D'%s'", def->file); + virBufferAddLit(buf, "/>\n"); } if (def->ndisks) { - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); for (i =3D 0; i < def->ndisks; i++) { - if (virDomainSnapshotDiskDefFormat(&buf, &def->disks[i], xmlop= t) < 0) + if (virDomainSnapshotDiskDefFormat(buf, &def->disks[i], xmlopt= ) < 0) goto error; } - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } if (def->dom) { - if (virDomainDefFormatInternal(def->dom, caps, domainflags, &buf, + if (virDomainDefFormatInternal(def->dom, caps, domainflags, buf, xmlopt) < 0) goto error; } else if (domain_uuid) { - virBufferAddLit(&buf, "\n"); - virBufferAdjustIndent(&buf, 2); - virBufferAsprintf(&buf, "%s\n", domain_uuid); - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferAsprintf(buf, "%s\n", domain_uuid); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } - if (virSaveCookieFormatBuf(&buf, def->cookie, + if (virSaveCookieFormatBuf(buf, def->cookie, virDomainXMLOptionGetSaveCookie(xmlopt)) < = 0) goto error; if (flags & VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL) - virBufferAsprintf(&buf, "%d\n", def->current); + virBufferAsprintf(buf, "%d\n", def->current); - virBufferAdjustIndent(&buf, -2); - virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); - if (virBufferCheckError(&buf) < 0) - return NULL; + if (virBufferCheckError(buf) < 0) + goto error; - return virBufferContentAndReset(&buf); + return 0; error: - virBufferFreeAndReset(&buf); - return NULL; + virBufferFreeAndReset(buf); + return -1; +} + +char * +virDomainSnapshotDefFormat(const char *domain_uuid, + virDomainSnapshotDefPtr def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + virCheckFlags(VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE | + VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL, NULL); + if (virDomainSnapshotDefFormatInternal(&buf, domain_uuid, def, caps, + xmlopt, flags) < 0) + return NULL; + + return virBufferContentAndReset(&buf); } /* Snapshot Obj functions */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list