From nobody Tue May 13 20:34:03 2025 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 1530620743551981.6024478835212; Tue, 3 Jul 2018 05:25:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5082A30832E9; Tue, 3 Jul 2018 12:25: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 19839655C8; Tue, 3 Jul 2018 12:25: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 BCDD218363F6; Tue, 3 Jul 2018 12:25:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w63CPJOh007914 for ; Tue, 3 Jul 2018 08:25:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 78DC22027047; Tue, 3 Jul 2018 12:25:19 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DEA22026D76 for ; Tue, 3 Jul 2018 12:25:18 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 3 Jul 2018 14:33:04 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/8] qemu: block: Create helper for creating data for legacy snapshots 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 03 Jul 2018 12:25:42 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" With 'transaction' support we don't need to keep around the multipurpose code which would create the snapshot if 'transaction' is not supported. To simplify this add a new helper that just wraps the arguments for 'blockdev-snapshot-sync' operation in 'transaction' and use it instead of qemuBlockSnapshotAddLegacy. Additionally this allows to format the arguments prior to creating the file for simpler cleanup. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/qemu/qemu_block.c | 37 +++++++++++++++++++++++++++++++++++++ src/qemu/qemu_block.h | 6 ++++++ src/qemu/qemu_driver.c | 18 +++--------------- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 0ebf2d2aff..db1579ca20 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -19,8 +19,10 @@ #include #include "qemu_block.h" +#include "qemu_command.h" #include "qemu_domain.h" #include "qemu_alias.h" +#include "qemu_monitor_json.h" #include "viralloc.h" #include "virstring.h" @@ -1683,3 +1685,38 @@ qemuBlockStorageSourceDetachOneBlockdev(virQEMUDrive= rPtr driver, return ret; } + + +int +qemuBlockSnapshotAddLegacy(virJSONValuePtr actions, + virDomainDiskDefPtr disk, + virStorageSourcePtr newsrc, + bool reuse) +{ + const char *format =3D virStorageFileFormatTypeToString(newsrc->format= ); + char *device =3D NULL; + char *source =3D NULL; + int ret =3D -1; + + if (!(device =3D qemuAliasDiskDriveFromDisk(disk))) + goto cleanup; + + if (qemuGetDriveSourceString(newsrc, NULL, &source) < 0) + goto cleanup; + + if (qemuMonitorJSONTransactionAdd(actions, "blockdev-snapshot-sync", + "s:device", device, + "s:snapshot-file", source, + "s:format", format, + "S:mode", reuse ? "existing" : NULL, + NULL) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(device); + VIR_FREE(source); + + return ret; +} diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 418b5064b5..fd8984e60b 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -117,4 +117,10 @@ qemuBlockStorageSourceDetachOneBlockdev(virQEMUDriverP= tr driver, qemuDomainAsyncJob asyncJob, virStorageSourcePtr src); +int +qemuBlockSnapshotAddLegacy(virJSONValuePtr actions, + virDomainDiskDefPtr disk, + virStorageSourcePtr newsrc, + bool reuse); + #endif /* __QEMU_BLOCK_H__ */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ea06e23ff1..2d8af5daaa 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14932,23 +14932,16 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUD= riverPtr driver, virJSONValuePtr actions, bool reuse) { - qemuDomainObjPrivatePtr priv =3D vm->privateData; - char *device =3D NULL; - char *source =3D NULL; - const char *formatStr =3D NULL; int ret =3D -1; - if (!(device =3D qemuAliasDiskDriveFromDisk(dd->disk))) - goto cleanup; - - if (qemuGetDriveSourceString(dd->src, NULL, &source) < 0) + if (qemuBlockSnapshotAddLegacy(actions, dd->disk, dd->src, reuse) < 0) goto cleanup; /* pre-create the image file so that we can label it before handing it= to qemu */ if (!reuse && dd->src->type !=3D VIR_STORAGE_TYPE_BLOCK) { if (virStorageFileCreate(dd->src) < 0) { virReportSystemError(errno, _("failed to create image file '%s= '"), - source); + NULLSTR(dd->src->path)); goto cleanup; } dd->created =3D true; @@ -14962,14 +14955,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDr= iverPtr driver, dd->prepared =3D true; - formatStr =3D virStorageFileFormatTypeToString(dd->src->format); - - ret =3D qemuMonitorDiskSnapshot(priv->mon, actions, device, source, - formatStr, reuse); + ret =3D 0; cleanup: - VIR_FREE(device); - VIR_FREE(source); return ret; } --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list