mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
qemu: Refactor qemuDomainPrepareDiskChainElement
Now that there are only two elements in the enum, let's change it to a bool and rename the function similarly to the one added in previous commit.
This commit is contained in:
parent
5126174357
commit
358c18c391
@ -13503,12 +13503,6 @@ qemuDomainMigrateStartPostCopy(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
VIR_DISK_CHAIN_READ_ONLY,
|
|
||||||
VIR_DISK_CHAIN_READ_WRITE,
|
|
||||||
} qemuDomainDiskChainMode;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qemuDomainDiskChainElementRevoke:
|
* qemuDomainDiskChainElementRevoke:
|
||||||
*
|
*
|
||||||
@ -13533,23 +13527,25 @@ qemuDomainDiskChainElementRevoke(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Several operations end up adding a single element of a disk
|
/**
|
||||||
* backing file chain; this helper function ensures that the lock manager,
|
* qemuDomainDiskChainElementPrepare:
|
||||||
* cgroup device controller, and security manager labelling are all aware of
|
*
|
||||||
* each new file before it is added to a chain */
|
* Allow a VM access to a single element of a disk backing chain; this helper
|
||||||
|
* ensures that the lock manager, cgroup device controller, and security manager
|
||||||
|
* labelling are all aware of each new file before it is added to a chain */
|
||||||
static int
|
static int
|
||||||
qemuDomainPrepareDiskChainElement(virQEMUDriverPtr driver,
|
qemuDomainDiskChainElementPrepare(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virStorageSourcePtr elem,
|
virStorageSourcePtr elem,
|
||||||
qemuDomainDiskChainMode mode)
|
bool readonly)
|
||||||
{
|
{
|
||||||
bool readonly = elem->readonly;
|
bool was_readonly = elem->readonly;
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
virQEMUDriverConfigPtr cfg = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
cfg = virQEMUDriverGetConfig(driver);
|
cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
|
||||||
elem->readonly = mode == VIR_DISK_CHAIN_READ_ONLY;
|
elem->readonly = readonly;
|
||||||
|
|
||||||
if (virDomainLockImageAttach(driver->lockManager, cfg->uri, vm, elem) < 0)
|
if (virDomainLockImageAttach(driver->lockManager, cfg->uri, vm, elem) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -13564,7 +13560,7 @@ qemuDomainPrepareDiskChainElement(virQEMUDriverPtr driver,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
elem->readonly = readonly;
|
elem->readonly = was_readonly;
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -14289,8 +14285,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set correct security, cgroup and locking options on the new image */
|
/* set correct security, cgroup and locking options on the new image */
|
||||||
if (qemuDomainPrepareDiskChainElement(driver, vm, newDiskSrc,
|
if (qemuDomainDiskChainElementPrepare(driver, vm, newDiskSrc, false) < 0) {
|
||||||
VIR_DISK_CHAIN_READ_WRITE) < 0) {
|
|
||||||
qemuDomainDiskChainElementRevoke(driver, vm, newDiskSrc);
|
qemuDomainDiskChainElementRevoke(driver, vm, newDiskSrc);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -16846,8 +16841,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
keepParentLabel) < 0)
|
keepParentLabel) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (qemuDomainPrepareDiskChainElement(driver, vm, mirror,
|
if (qemuDomainDiskChainElementPrepare(driver, vm, mirror, false) < 0) {
|
||||||
VIR_DISK_CHAIN_READ_WRITE) < 0) {
|
|
||||||
qemuDomainDiskChainElementRevoke(driver, vm, mirror);
|
qemuDomainDiskChainElementRevoke(driver, vm, mirror);
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
@ -17211,11 +17205,9 @@ qemuDomainBlockCommit(virDomainPtr dom,
|
|||||||
* operation succeeds, but doing that requires tracking the
|
* operation succeeds, but doing that requires tracking the
|
||||||
* operation in XML across libvirtd restarts. */
|
* operation in XML across libvirtd restarts. */
|
||||||
clean_access = true;
|
clean_access = true;
|
||||||
if (qemuDomainPrepareDiskChainElement(driver, vm, baseSource,
|
if (qemuDomainDiskChainElementPrepare(driver, vm, baseSource, false) < 0 ||
|
||||||
VIR_DISK_CHAIN_READ_WRITE) < 0 ||
|
|
||||||
(top_parent && top_parent != disk->src &&
|
(top_parent && top_parent != disk->src &&
|
||||||
qemuDomainPrepareDiskChainElement(driver, vm, top_parent,
|
qemuDomainDiskChainElementPrepare(driver, vm, top_parent, false) < 0))
|
||||||
VIR_DISK_CHAIN_READ_WRITE) < 0))
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_BLOCK_COMMIT_RELATIVE &&
|
if (flags & VIR_DOMAIN_BLOCK_COMMIT_RELATIVE &&
|
||||||
@ -17283,11 +17275,9 @@ qemuDomainBlockCommit(virDomainPtr dom,
|
|||||||
endjob:
|
endjob:
|
||||||
if (ret < 0 && clean_access) {
|
if (ret < 0 && clean_access) {
|
||||||
/* Revert access to read-only, if possible. */
|
/* Revert access to read-only, if possible. */
|
||||||
qemuDomainPrepareDiskChainElement(driver, vm, baseSource,
|
qemuDomainDiskChainElementPrepare(driver, vm, baseSource, true);
|
||||||
VIR_DISK_CHAIN_READ_ONLY);
|
|
||||||
if (top_parent && top_parent != disk->src)
|
if (top_parent && top_parent != disk->src)
|
||||||
qemuDomainPrepareDiskChainElement(driver, vm, top_parent,
|
qemuDomainDiskChainElementPrepare(driver, vm, top_parent, true);
|
||||||
VIR_DISK_CHAIN_READ_ONLY);
|
|
||||||
}
|
}
|
||||||
virStorageSourceFree(mirror);
|
virStorageSourceFree(mirror);
|
||||||
qemuDomainObjEndJob(driver, vm);
|
qemuDomainObjEndJob(driver, vm);
|
||||||
|
Loading…
Reference in New Issue
Block a user