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

qemu_block: change qemuBlockCommit to return job pointer

The created job will be needed by external snapshot delete code so
rework qemuBlockCommit to return that pointer.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Pavel Hrdina 2022-12-13 16:46:59 +01:00
parent 47cc6470f2
commit 2686738b6c
3 changed files with 35 additions and 29 deletions

View File

@ -3218,9 +3218,10 @@ qemuBlockExportAddNBD(virDomainObj *vm,
* disable automatic finalization for some use-case. The default value passed * disable automatic finalization for some use-case. The default value passed
* to this argument should be VIR_TRISTATE_BOOL_YES. * to this argument should be VIR_TRISTATE_BOOL_YES.
* *
* Returns -1 on error, 0 on success. * Returns qemuBlockJobData pointer on success, NULL on error. Caller is responsible
* to call virObjectUnref on the pointer.
*/ */
int qemuBlockJobData *
qemuBlockCommit(virDomainObj *vm, qemuBlockCommit(virDomainObj *vm,
virDomainDiskDef *disk, virDomainDiskDef *disk,
virStorageSource *baseSource, virStorageSource *baseSource,
@ -3233,14 +3234,15 @@ qemuBlockCommit(virDomainObj *vm,
{ {
qemuDomainObjPrivate *priv = vm->privateData; qemuDomainObjPrivate *priv = vm->privateData;
virQEMUDriver *driver = priv->driver; virQEMUDriver *driver = priv->driver;
int ret = -1; int rc = -1;
bool clean_access = false; bool clean_access = false;
g_autofree char *backingPath = NULL; g_autofree char *backingPath = NULL;
qemuBlockJobData *job = NULL; qemuBlockJobData *job = NULL;
qemuBlockJobData *ret = NULL;
g_autoptr(virStorageSource) mirror = NULL; g_autoptr(virStorageSource) mirror = NULL;
if (virDomainObjCheckActive(vm) < 0) if (virDomainObjCheckActive(vm) < 0)
return -1; return NULL;
/* Convert bandwidth MiB to bytes, if necessary */ /* Convert bandwidth MiB to bytes, if necessary */
if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)) { if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)) {
@ -3248,26 +3250,26 @@ qemuBlockCommit(virDomainObj *vm,
virReportError(VIR_ERR_OVERFLOW, virReportError(VIR_ERR_OVERFLOW,
_("bandwidth must be less than %llu"), _("bandwidth must be less than %llu"),
LLONG_MAX >> 20); LLONG_MAX >> 20);
return -1; return NULL;
} }
bandwidth <<= 20; bandwidth <<= 20;
} }
if (!qemuDomainDiskBlockJobIsSupported(disk)) if (!qemuDomainDiskBlockJobIsSupported(disk))
return -1; return NULL;
if (virStorageSourceIsEmpty(disk->src)) { if (virStorageSourceIsEmpty(disk->src)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk %s has no source file to be committed"), _("disk %s has no source file to be committed"),
disk->dst); disk->dst);
return -1; return NULL;
} }
if (qemuDomainDiskBlockJobIsActive(disk)) if (qemuDomainDiskBlockJobIsActive(disk))
return -1; return NULL;
if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0) if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0)
return -1; return NULL;
if (topSource == disk->src) { if (topSource == disk->src) {
/* XXX Should we auto-pivot when COMMIT_ACTIVE is not specified? */ /* XXX Should we auto-pivot when COMMIT_ACTIVE is not specified? */
@ -3275,20 +3277,20 @@ qemuBlockCommit(virDomainObj *vm,
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("commit of '%s' active layer requires active flag"), _("commit of '%s' active layer requires active flag"),
disk->dst); disk->dst);
return -1; return NULL;
} }
} else if (flags & VIR_DOMAIN_BLOCK_COMMIT_ACTIVE) { } else if (flags & VIR_DOMAIN_BLOCK_COMMIT_ACTIVE) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("active commit requested but '%s' is not active"), _("active commit requested but '%s' is not active"),
topSource->path); topSource->path);
return -1; return NULL;
} }
if (!virStorageSourceHasBacking(topSource)) { if (!virStorageSourceHasBacking(topSource)) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("top '%s' in chain for '%s' has no backing file"), _("top '%s' in chain for '%s' has no backing file"),
topSource->path, disk->src->path); topSource->path, disk->src->path);
return -1; return NULL;
} }
if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) && if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) &&
@ -3297,33 +3299,33 @@ qemuBlockCommit(virDomainObj *vm,
_("base '%s' is not immediately below '%s' in chain " _("base '%s' is not immediately below '%s' in chain "
"for '%s'"), "for '%s'"),
baseSource->path, topSource->path, disk->src->path); baseSource->path, topSource->path, disk->src->path);
return -1; return NULL;
} }
/* For an active commit, clone enough of the base to act as the mirror */ /* For an active commit, clone enough of the base to act as the mirror */
if (topSource == disk->src) { if (topSource == disk->src) {
if (!(mirror = virStorageSourceCopy(baseSource, false))) if (!(mirror = virStorageSourceCopy(baseSource, false)))
return -1; return NULL;
if (virStorageSourceInitChainElement(mirror, if (virStorageSourceInitChainElement(mirror,
disk->src, disk->src,
true) < 0) true) < 0)
return -1; return NULL;
} }
if (flags & VIR_DOMAIN_BLOCK_COMMIT_RELATIVE && if (flags & VIR_DOMAIN_BLOCK_COMMIT_RELATIVE &&
topSource != disk->src) { topSource != disk->src) {
if (top_parent && if (top_parent &&
qemuBlockUpdateRelativeBacking(vm, top_parent, disk->src) < 0) qemuBlockUpdateRelativeBacking(vm, top_parent, disk->src) < 0)
return -1; return NULL;
if (virStorageSourceGetRelativeBackingPath(topSource, baseSource, if (virStorageSourceGetRelativeBackingPath(topSource, baseSource,
&backingPath) < 0) &backingPath) < 0)
return -1; return NULL;
if (!backingPath) { if (!backingPath) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("can't keep relative backing relationship")); _("can't keep relative backing relationship"));
return -1; return NULL;
} }
} }
@ -3366,7 +3368,7 @@ qemuBlockCommit(virDomainObj *vm,
if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0)
goto cleanup; goto cleanup;
ret = qemuMonitorBlockCommit(priv->mon, rc = qemuMonitorBlockCommit(priv->mon,
qemuDomainDiskGetTopNodename(disk), qemuDomainDiskGetTopNodename(disk),
job->name, job->name,
topSource->nodeformat, topSource->nodeformat,
@ -3376,7 +3378,7 @@ qemuBlockCommit(virDomainObj *vm,
qemuDomainObjExitMonitor(vm); qemuDomainObjExitMonitor(vm);
if (ret < 0) if (rc < 0)
goto cleanup; goto cleanup;
if (mirror) { if (mirror) {
@ -3384,9 +3386,10 @@ qemuBlockCommit(virDomainObj *vm,
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT; disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT;
} }
qemuBlockJobStarted(job, vm); qemuBlockJobStarted(job, vm);
ret = virObjectRef(job);
cleanup: cleanup:
if (ret < 0 && clean_access) { if (rc < 0 && clean_access) {
virErrorPtr orig_err; virErrorPtr orig_err;
virErrorPreserveLast(&orig_err); virErrorPreserveLast(&orig_err);
/* Revert access to read-only, if possible. */ /* Revert access to read-only, if possible. */

View File

@ -277,7 +277,7 @@ qemuBlockExportAddNBD(virDomainObj *vm,
bool writable, bool writable,
const char *bitmap); const char *bitmap);
int qemuBlockJobData *
qemuBlockCommit(virDomainObj *vm, qemuBlockCommit(virDomainObj *vm,
virDomainDiskDef *disk, virDomainDiskDef *disk,
virStorageSource *baseSource, virStorageSource *baseSource,

View File

@ -14994,6 +14994,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
virStorageSource *topSource; virStorageSource *topSource;
virStorageSource *baseSource = NULL; virStorageSource *baseSource = NULL;
virStorageSource *top_parent = NULL; virStorageSource *top_parent = NULL;
g_autoptr(qemuBlockJobData) job = NULL;
virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW | virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW |
VIR_DOMAIN_BLOCK_COMMIT_ACTIVE | VIR_DOMAIN_BLOCK_COMMIT_ACTIVE |
@ -15025,9 +15026,11 @@ qemuDomainBlockCommit(virDomainPtr dom,
base, disk->dst, NULL))) base, disk->dst, NULL)))
goto endjob; goto endjob;
ret = qemuBlockCommit(vm, disk, baseSource, topSource, top_parent, job = qemuBlockCommit(vm, disk, baseSource, topSource, top_parent,
bandwidth, VIR_ASYNC_JOB_NONE, VIR_TRISTATE_BOOL_YES, bandwidth, VIR_ASYNC_JOB_NONE, VIR_TRISTATE_BOOL_YES,
flags); flags);
if (job)
ret = 0;
endjob: endjob:
virDomainObjEndJob(vm); virDomainObjEndJob(vm);