]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Merge qemuCheckSharedDisk into qemuAddSharedDisk
authorOsier Yang <jyang@redhat.com>
Tue, 19 Feb 2013 12:27:41 +0000 (20:27 +0800)
committerOsier Yang <jyang@redhat.com>
Wed, 20 Feb 2013 16:31:24 +0000 (00:31 +0800)
Based on moving various checking into qemuAddSharedDisk, this
avoids the caller using it in wrong ways. Also this adds two
new checking for qemuCheckSharedDisk (disk device not 'lun'
and kernel doesn't support unpriv_sgio simply returns 0).

src/qemu/qemu_conf.c
src/qemu/qemu_driver.c
src/qemu/qemu_process.c
src/qemu/qemu_process.h

index da1d1d40803a1de2cfdf78e4e2a78f2c9d43d6d4..e54227f9206ec79d1c9794eeeb578eef1685fe3b 100644 (file)
@@ -847,6 +847,75 @@ qemuGetSharedDiskKey(const char *disk_path)
     return key;
 }
 
+/* Check if a shared disk's setting conflicts with the conf
+ * used by other domain(s). Currently only checks the sgio
+ * setting. Note that this should only be called for disk with
+ * block source.
+ *
+ * Returns 0 if no conflicts, otherwise returns -1.
+ */
+static int
+qemuCheckSharedDisk(virHashTablePtr sharedDisks,
+                    virDomainDiskDefPtr disk)
+{
+    int val;
+    size_t *ref = NULL;
+    char *sysfs_path = NULL;
+    char *key = NULL;
+    int ret = 0;
+
+    /* The only conflicts between shared disk we care about now
+     * is sgio setting, which is only valid for device='lun'.
+     */
+    if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
+        return 0;
+
+    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(disk->src, NULL))) {
+        ret = -1;
+        goto cleanup;
+    }
+
+    /* It can't be conflict if unpriv_sgio is not supported
+     * by kernel.
+     */
+    if (!virFileExists(sysfs_path))
+        goto cleanup;
+
+
+    if (!(key = qemuGetSharedDiskKey(disk->src))) {
+        ret = -1;
+        goto cleanup;
+    }
+
+    /* It can't be conflict if no other domain is
+     * is sharing it.
+     */
+    if (!(ref = virHashLookup(sharedDisks, key)))
+        goto cleanup;
+
+    if (virGetDeviceUnprivSGIO(disk->src, NULL, &val) < 0) {
+        ret = -1;
+        goto cleanup;
+    }
+
+    if ((val == 0 &&
+         (disk->sgio == VIR_DOMAIN_DISK_SGIO_FILTERED ||
+          disk->sgio == VIR_DOMAIN_DISK_SGIO_DEFAULT)) ||
+        (val == 1 &&
+         disk->sgio == VIR_DOMAIN_DISK_SGIO_UNFILTERED))
+        goto cleanup;
+
+    virReportError(VIR_ERR_OPERATION_INVALID,
+                   _("sgio of shared disk '%s' conflicts with other "
+                     "active domains"), disk->src);
+    ret = -1;
+
+cleanup:
+    VIR_FREE(sysfs_path);
+    VIR_FREE(key);
+    return ret;
+}
+
 /* Increase ref count if the entry already exists, otherwise
  * add a new entry.
  */
@@ -867,6 +936,9 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
         return 0;
 
     qemuDriverLock(driver);
+    if (qemuCheckSharedDisk(driver->sharedDisks, disk) < 0)
+        goto cleanup;
+
     if (!(key = qemuGetSharedDiskKey(disk->src)))
         goto cleanup;
 
index 65ab81f75ed65a4f78ae4038a98b141fc2387bd9..813411db2f1538167263c02dd459ab4a0f69b8ce 100644 (file)
@@ -5714,11 +5714,6 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
         goto end;
     }
 
-    if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK &&
-        disk->shared &&
-        (qemuCheckSharedDisk(driver, disk) < 0))
-        goto end;
-
     if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
         goto end;
 
index f80fe677035baf82fcfe975938da2ff78a8f4385..a925d61d97c5e634a15652ff39e33dab1f40dfcc 100644 (file)
@@ -3477,56 +3477,6 @@ qemuSetUnprivSGIO(virDomainDiskDefPtr disk)
     return 0;
 }
 
-/* Check if a shared disk's setting conflicts with the conf
- * used by other domain(s). Currently only checks the sgio
- * setting. Note that this should only be called for disk with
- * block source.
- *
- * Returns 0 if no conflicts, otherwise returns -1.
- */
-int
-qemuCheckSharedDisk(virQEMUDriverPtr driver,
-                    virDomainDiskDefPtr disk)
-{
-    int val;
-    size_t *ref = NULL;
-    char *key = NULL;
-    int ret = 0;
-
-    if (!(key = qemuGetSharedDiskKey(disk->src)))
-        return -1;
-
-    /* It can't be conflict if no other domain is
-     * is sharing it.
-     */
-    if (!(ref = virHashLookup(driver->sharedDisks, key)))
-        goto cleanup;
-
-    if (ref == (void *)0x1)
-        goto cleanup;
-
-    if (virGetDeviceUnprivSGIO(disk->src, NULL, &val) < 0) {
-        ret = -1;
-        goto cleanup;
-    }
-
-    if ((val == 0 &&
-         (disk->sgio == VIR_DOMAIN_DISK_SGIO_FILTERED ||
-          disk->sgio == VIR_DOMAIN_DISK_SGIO_DEFAULT)) ||
-        (val == 1 &&
-         disk->sgio == VIR_DOMAIN_DISK_SGIO_UNFILTERED))
-        goto cleanup;
-
-    virReportError(VIR_ERR_OPERATION_INVALID,
-                   _("sgio of shared disk '%s' conflicts with other "
-                     "active domains"), disk->src);
-    ret = -1;
-
-cleanup:
-    VIR_FREE(key);
-    return ret;
-}
-
 int qemuProcessStart(virConnectPtr conn,
                      virQEMUDriverPtr driver,
                      virDomainObjPtr vm,
@@ -3883,9 +3833,6 @@ int qemuProcessStart(virConnectPtr conn,
         if (qemuAddSharedDisk(driver, disk) < 0)
             goto cleanup;
 
-        if (qemuCheckSharedDisk(driver, disk) < 0)
-            goto cleanup;
-
         if (qemuSetUnprivSGIO(disk) < 0)
             goto cleanup;
     }
index ce44fe5a3722e9b105cdc0de74767995f45b2535..bc4d54db42c1b47e583906cc36c6cb23b352ea9c 100644 (file)
@@ -99,7 +99,4 @@ virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver,
                                virBitmapPtr nodemask);
 int qemuSetUnprivSGIO(virDomainDiskDefPtr disk);
 
-int qemuCheckSharedDisk(virQEMUDriverPtr driver,
-                        virDomainDiskDefPtr disk);
-
 #endif /* __QEMU_PROCESS_H__ */