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 <pkrempa@redhat.com>
---
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 <config.h>
#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(virQEMUDriverPtr driver,
return ret;
}
+
+
+int
+qemuBlockSnapshotAddLegacy(virJSONValuePtr actions,
+ virDomainDiskDefPtr disk,
+ virStorageSourcePtr newsrc,
+ bool reuse)
+{
+ const char *format = virStorageFileFormatTypeToString(newsrc->format);
+ char *device = NULL;
+ char *source = NULL;
+ int ret = -1;
+
+ if (!(device = 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 = 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(virQEMUDriverPtr 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(virQEMUDriverPtr driver,
virJSONValuePtr actions,
bool reuse)
{
- qemuDomainObjPrivatePtr priv = vm->privateData;
- char *device = NULL;
- char *source = NULL;
- const char *formatStr = NULL;
int ret = -1;
- if (!(device = 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 != 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 = true;
@@ -14962,14 +14955,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
dd->prepared = true;
- formatStr = virStorageFileFormatTypeToString(dd->src->format);
-
- ret = qemuMonitorDiskSnapshot(priv->mon, actions, device, source,
- formatStr, reuse);
+ ret = 0;
cleanup:
- VIR_FREE(device);
- VIR_FREE(source);
return ret;
}
--
2.16.2
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Tue, Jul 03, 2018 at 02:33:04PM +0200, Peter Krempa wrote: >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 <pkrempa@redhat.com> >--- > 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 <config.h> > > #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(virQEMUDriverPtr driver, > > return ret; > } >+ >+ >+int >+qemuBlockSnapshotAddLegacy(virJSONValuePtr actions, >+ virDomainDiskDefPtr disk, >+ virStorageSourcePtr newsrc, >+ bool reuse) >+{ >+ const char *format = virStorageFileFormatTypeToString(newsrc->format); >+ char *device = NULL; >+ char *source = NULL; >+ int ret = -1; >+ >+ if (!(device = 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) Indentation is off. >+ goto cleanup; >+ >+ ret = 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(virQEMUDriverPtr 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(virQEMUDriverPtr driver, > virJSONValuePtr actions, > bool reuse) > { >- qemuDomainObjPrivatePtr priv = vm->privateData; >- char *device = NULL; >- char *source = NULL; >- const char *formatStr = NULL; > int ret = -1; > >- if (!(device = 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 != VIR_STORAGE_TYPE_BLOCK) { > if (virStorageFileCreate(dd->src) < 0) { > virReportSystemError(errno, _("failed to create image file '%s'"), >- source); >+ NULLSTR(dd->src->path)); Doesn't this make the error message less usable? > goto cleanup; > } > dd->created = true; Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2025 Red Hat, Inc.