提交 bed681d7 编写于 作者: P Peter Krempa

qemu: block: Create helper for creating data for legacy snapshots

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 faf769d8
......@@ -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"
......@@ -1707,3 +1709,37 @@ 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;
}
......@@ -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__ */
......@@ -14935,23 +14935,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;
......@@ -14965,14 +14958,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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册