Move it to qemu_domain.c and call it
qemuDomainStorageSourceChainAccessPrepare.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_domain.c | 68 +++++++++++++++++++++++++++++++++++
src/qemu/qemu_domain.h | 5 +++
src/qemu/qemu_hotplug.c | 80 ++++-------------------------------------
3 files changed, 79 insertions(+), 74 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index ce8f4a0dca..ab96688a65 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9211,6 +9211,74 @@ qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
}
+/**
+ * qemuDomainStorageSourceChainAccessPrepare:
+ * @driver: qemu driver struct
+ * @vm: domain object
+ * @src: Source to prepare
+ * @teardown: Teardown the access to @src instead of adding it to a vm
+ *
+ * Setup the locks, cgroups and security permissions on a disk source and its
+ * backing chain. If @teardown is true, then the labels and cgroups are removed
+ * instead.
+ *
+ * Returns 0 on success and -1 on error. Reports libvirt error.
+ */
+int
+qemuDomainStorageSourceChainAccessPrepare(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virStorageSourcePtr src,
+ bool teardown)
+{
+ VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
+ const char *srcstr = NULLSTR(src->path);
+ int ret = -1;
+ virErrorPtr orig_err = NULL;
+
+ /* just tear down the disk access */
+ if (teardown) {
+ virErrorPreserveLast(&orig_err);
+ ret = 0;
+ goto rollback_cgroup;
+ }
+
+ if (virDomainLockImageAttach(driver->lockManager, cfg->uri, vm, src) < 0)
+ goto cleanup;
+
+ if (qemuDomainNamespaceSetupDisk(vm, src) < 0)
+ goto rollback_lock;
+
+ if (qemuSecuritySetImageLabel(driver, vm, src, true) < 0)
+ goto rollback_namespace;
+
+ if (qemuSetupImageChainCgroup(vm, src) < 0)
+ goto rollback_label;
+
+ ret = 0;
+ goto cleanup;
+
+ rollback_cgroup:
+ if (qemuTeardownImageChainCgroup(vm, src) < 0)
+ VIR_WARN("Unable to tear down cgroup access on %s", srcstr);
+ rollback_label:
+ if (qemuSecurityRestoreImageLabel(driver, vm, src, true) < 0)
+ VIR_WARN("Unable to restore security label on %s", srcstr);
+
+ rollback_namespace:
+ if (qemuDomainNamespaceTeardownDisk(vm, src) < 0)
+ VIR_WARN("Unable to remove /dev entry for %s", srcstr);
+
+ rollback_lock:
+ if (virDomainLockImageDetach(driver->lockManager, vm, src) < 0)
+ VIR_WARN("Unable to release lock on %s", srcstr);
+
+ cleanup:
+ virErrorRestore(&orig_err);
+
+ return ret;
+}
+
+
/**
* qemuDomainStorageSourceAccessRevoke:
*
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 9a48b5b69d..65b0e8c39d 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -770,6 +770,11 @@ int qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
+int qemuDomainStorageSourceChainAccessPrepare(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virStorageSourcePtr src,
+ bool teardown);
+
void qemuDomainStorageSourceAccessRevoke(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virStorageSourcePtr elem);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index a4f7d111b1..dd5571aea3 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -132,74 +132,6 @@ qemuDomainDeleteDevice(virDomainObjPtr vm,
}
-/**
- * qemuHotplugPrepareDiskSourceAccess:
- * @driver: qemu driver struct
- * @vm: domain object
- * @src: Source to prepare
- * @teardown: Teardown the access to @src instead of adding it to a vm
- *
- * Setup the locks, cgroups and security permissions on a disk source and its
- * backing chain. If @teardown is true, then the labels and cgroups are removed
- * instead.
- *
- * Returns 0 on success and -1 on error. Reports libvirt error.
- */
-static int
-qemuHotplugPrepareDiskSourceAccess(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virStorageSourcePtr src,
- bool teardown)
-{
- VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
- const char *srcstr = NULLSTR(src->path);
- int ret = -1;
- virErrorPtr orig_err = NULL;
-
- /* just tear down the disk access */
- if (teardown) {
- virErrorPreserveLast(&orig_err);
- ret = 0;
- goto rollback_cgroup;
- }
-
- if (virDomainLockImageAttach(driver->lockManager, cfg->uri, vm, src) < 0)
- goto cleanup;
-
- if (qemuDomainNamespaceSetupDisk(vm, src) < 0)
- goto rollback_lock;
-
- if (qemuSecuritySetImageLabel(driver, vm, src, true) < 0)
- goto rollback_namespace;
-
- if (qemuSetupImageChainCgroup(vm, src) < 0)
- goto rollback_label;
-
- ret = 0;
- goto cleanup;
-
- rollback_cgroup:
- if (qemuTeardownImageChainCgroup(vm, src) < 0)
- VIR_WARN("Unable to tear down cgroup access on %s", srcstr);
- rollback_label:
- if (qemuSecurityRestoreImageLabel(driver, vm, src, true) < 0)
- VIR_WARN("Unable to restore security label on %s", srcstr);
-
- rollback_namespace:
- if (qemuDomainNamespaceTeardownDisk(vm, src) < 0)
- VIR_WARN("Unable to remove /dev entry for %s", srcstr);
-
- rollback_lock:
- if (virDomainLockImageDetach(driver->lockManager, vm, src) < 0)
- VIR_WARN("Unable to release lock on %s", srcstr);
-
- cleanup:
- virErrorRestore(&orig_err);
-
- return ret;
-}
-
-
static int
qemuDomainAttachZPCIDevice(qemuMonitorPtr mon,
virDomainDeviceInfoPtr info)
@@ -877,7 +809,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0)
goto cleanup;
- if (qemuHotplugPrepareDiskSourceAccess(driver, vm, newsrc, false) < 0)
+ if (qemuDomainStorageSourceChainAccessPrepare(driver, vm, newsrc, false) < 0)
goto cleanup;
if (qemuHotplugAttachManagedPR(driver, vm, newsrc, QEMU_ASYNC_JOB_NONE) < 0)
@@ -896,7 +828,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
/* remove the old source from shared device list */
disk->src = oldsrc;
ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
- ignore_value(qemuHotplugPrepareDiskSourceAccess(driver, vm, oldsrc, true));
+ ignore_value(qemuDomainStorageSourceChainAccessPrepare(driver, vm, oldsrc, true));
/* media was changed, so we can remove the old media definition now */
virObjectUnref(oldsrc);
@@ -911,7 +843,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
if (sharedAdded)
ignore_value(qemuRemoveSharedDisk(driver, disk, vm->def->name));
- ignore_value(qemuHotplugPrepareDiskSourceAccess(driver, vm, newsrc, true));
+ ignore_value(qemuDomainStorageSourceChainAccessPrepare(driver, vm, newsrc,
true));
}
/* remove PR manager object if unneeded */
@@ -941,7 +873,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
char *devstr = NULL;
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
- if (qemuHotplugPrepareDiskSourceAccess(driver, vm, disk->src, false) < 0)
+ if (qemuDomainStorageSourceChainAccessPrepare(driver, vm, disk->src, false) <
0)
goto cleanup;
if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
@@ -1003,7 +935,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
error:
- ignore_value(qemuHotplugPrepareDiskSourceAccess(driver, vm, disk->src, true));
+ ignore_value(qemuDomainStorageSourceChainAccessPrepare(driver, vm, disk->src,
true));
goto cleanup;
}
@@ -4532,7 +4464,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
qemuDomainReleaseDeviceAddress(vm, &disk->info);
/* tear down disk security access */
- qemuHotplugPrepareDiskSourceAccess(driver, vm, disk->src, true);
+ qemuDomainStorageSourceChainAccessPrepare(driver, vm, disk->src, true);
dev.type = VIR_DOMAIN_DEVICE_DISK;
dev.data.disk = disk;
--
2.20.1