1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemu: Escape external snapshot names containing comma

The code for creating external snapshots for an offline domain
called out to qemu-img without escaping commas in the manner
that qemu-img expects. This also fixes a typo in the comment.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Eric Blake 2019-02-12 22:18:15 -06:00
parent 2c48e84b75
commit 174309a1f8

View File

@ -100,6 +100,7 @@
#include "virnuma.h" #include "virnuma.h"
#include "dirname.h" #include "dirname.h"
#include "netdev_bandwidth_conf.h" #include "netdev_bandwidth_conf.h"
#include "virqemu.h"
#define VIR_FROM_THIS VIR_FROM_QEMU #define VIR_FROM_THIS VIR_FROM_QEMU
@ -14561,6 +14562,7 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
virBitmapPtr created = NULL; virBitmapPtr created = NULL;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
int ret = -1; int ret = -1;
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (!(qemuImgPath = qemuFindQemuImgBinary(driver))) if (!(qemuImgPath = qemuFindQemuImgBinary(driver)))
goto cleanup; goto cleanup;
@ -14589,13 +14591,15 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
NULL))) NULL)))
goto cleanup; goto cleanup;
/* adds cmd line arg: backing_file=/path/to/backing/file,backing_fmd=format */ /* adds cmd line arg: backing_fmt=format,backing_file=/path/to/backing/file */
virCommandAddArgFormat(cmd, "backing_file=%s,backing_fmt=%s", virBufferAsprintf(&buf, "backing_fmt=%s,backing_file=",
defdisk->src->path,
virStorageFileFormatTypeToString(defdisk->src->format)); virStorageFileFormatTypeToString(defdisk->src->format));
virQEMUBuildBufferEscapeComma(&buf, defdisk->src->path);
virCommandAddArgBuffer(cmd, &buf);
/* adds cmd line args: /path/to/target/file */ /* adds cmd line args: /path/to/target/file */
virCommandAddArg(cmd, snapdisk->src->path); virQEMUBuildBufferEscapeComma(&buf, snapdisk->src->path);
virCommandAddArgBuffer(cmd, &buf);
/* If the target does not exist, we're going to create it possibly */ /* If the target does not exist, we're going to create it possibly */
if (!virFileExists(snapdisk->src->path)) if (!virFileExists(snapdisk->src->path))
@ -14629,6 +14633,7 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver,
ret = 0; ret = 0;
cleanup: cleanup:
virBufferFreeAndReset(&buf);
virCommandFree(cmd); virCommandFree(cmd);
/* unlink images if creation has failed */ /* unlink images if creation has failed */