Just like for domain starting, this checks if the shared disk's conf
conflicts with others which are in use. Currently it only checks
the setting of cdbfilter.
* src/qemu/qemu_process.h (Abstract a helper function qemuCheckSharedDisk)
* src/qemu/qemu_process.c (Implement the helper)
* src/qemu/qemu_driver.c (Check the shared disk's conf)
---
src/qemu/qemu_driver.c | 4 ++
src/qemu/qemu_process.c | 105 +++++++++++++++++++++++++++++------------------
src/qemu/qemu_process.h | 4 ++
3 files changed, 73 insertions(+), 40 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index cedf636..7288ad6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5991,6 +5991,10 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
goto end;
}
+ if (disk->shared &&
+ (qemuCheckSharedDisk(driver, disk, vm) < 0))
+ goto end;
+
if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
goto end;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 2938a65..b38fc7b 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3380,6 +3380,68 @@ qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr
driver)
virHashForEach(driver->domains.objs, qemuProcessReconnectHelper, &data);
}
+/*
+ * Check if the shared disk's configraution conflicts with others.
+ *
+ * Return 0 if there is no conflict, otherwise return -1.
+ */
+int
+qemuCheckSharedDisk(virQEMUDriverPtr driver,
+ virDomainDiskDefPtr disk,
+ virDomainObjPtr vm)
+{
+ qemuSharedDiskPtr entry = NULL;
+ int i;
+
+ if ((entry = qemuSharedDiskListFind(driver->sharedDisks,
+ disk->src,
+ NULL,
+ NULL))) {
+ virDomainObjUnlock(vm);
+ for (i = 0; i < entry->ndomains; i++) {
+ virDomainObjPtr domobj = NULL;
+ virDomainDiskDefPtr diskdef = NULL;
+
+ if (!(domobj = virDomainFindByName(&driver->domains,
+ entry->domains[i]))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to look up domain '%s'"),
+ entry->domains[i]);
+ virDomainObjLock(vm);
+ return -1;
+ }
+
+ if (!(diskdef = virDomainDiskFindByPath(domobj->def,
+ disk->src))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to find disk '%s' of domain
'%s'"),
+ disk->src, domobj->def->name);
+ virDomainObjUnlock(domobj);
+ virDomainObjLock(vm);
+ return -1;
+ }
+
+ /* XXX: Can be abstracted into a function when there
+ * are more stuffs to check in future.
+ */
+ if (diskdef->cdbfilter != disk->cdbfilter) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cdbfilter of shared disk '%s' "
+ "conflicts with other active "
+ "domains"), disk->src);
+ virDomainObjUnlock(domobj);
+ virDomainObjLock(vm);
+ return -1;
+ }
+ virDomainObjUnlock(domobj);
+ }
+ virDomainObjLock(vm);
+ }
+
+ return 0;
+}
+
+
int qemuProcessStart(virConnectPtr conn,
virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -3716,46 +3778,9 @@ int qemuProcessStart(virConnectPtr conn,
/* Error out if the cdbfilter setting is different with what
* other domain(s) uses.
*/
- qemuSharedDiskPtr entry = NULL;
-
- if ((entry = qemuSharedDiskListFind(driver->sharedDisks,
- disk->src,
- NULL,
- NULL))) {
- virDomainObjUnlock(vm);
- for (i = 0; i < entry->ndomains; i++) {
- virDomainObjPtr domobj = NULL;
- virDomainDiskDefPtr diskdef = NULL;
-
- if (!(domobj = virDomainFindByName(&driver->domains,
- entry->domains[i]))) {
- virDomainObjLock(vm);
- goto cleanup;
- }
-
- if (!(diskdef = virDomainDiskFindByPath(domobj->def,
- disk->src))) {
- virDomainObjUnlock(domobj);
- virDomainObjLock(vm);
- goto cleanup;
- }
-
- /* XXX: Can be abstracted into a function when there
- * are more stuffs to check in future.
- */
- if (diskdef->cdbfilter != disk->cdbfilter) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cdbfilter of shared disk '%s'
"
- "conflicts with other active "
- "domains"), disk->src);
- virDomainObjUnlock(domobj);
- virDomainObjLock(vm);
- goto cleanup;
- }
- virDomainObjUnlock(domobj);
- }
- virDomainObjLock(vm);
- }
+
+ if (qemuCheckSharedDisk(driver, disk, vm) < 0)
+ goto cleanup;
/* Add to qemud_driver->sharedDisks list if the disk is shared */
if (qemuSharedDiskListAdd(driver->sharedDisks,
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index c12df32..501f206 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -99,4 +99,8 @@ bool qemuProcessAutoDestroyActive(virQEMUDriverPtr driver,
virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver,
virBitmapPtr nodemask);
+int qemuCheckSharedDisk(virQEMUDriverPtr driver,
+ virDomainDiskDefPtr disk,
+ virDomainObjPtr vm);
+
#endif /* __QEMU_PROCESS_H__ */
--
1.7.7.6