]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: Translate the pool disk source earlier
authorOsier Yang <jyang@redhat.com>
Thu, 4 Apr 2013 19:38:00 +0000 (03:38 +0800)
committerOsier Yang <jyang@redhat.com>
Mon, 8 Apr 2013 11:02:34 +0000 (19:02 +0800)
To support "shareable" for volume type disk, we have to translate
the source before trying to add the shared disk entry. To achieve
the goal, this moves the helper qemuTranslateDiskSourcePool into
src/qemu/qemu_conf.c, and introduce an internal only member (voltype)
for struct _virDomainDiskSourcePoolDef, to record the underlying
volume type for use when building the drive string.

Later patch will support "shareable" volume type disk.

src/conf/domain_conf.h
src/qemu/qemu_command.c
src/qemu/qemu_command.h
src/qemu/qemu_conf.c
src/qemu/qemu_conf.h
src/qemu/qemu_driver.c
src/qemu/qemu_process.c

index 230f0a5e27e518a425d695080aa2c6ec6697f050..a24ebc70960b15c35a6d309ab5ccb020996899f5 100644 (file)
@@ -611,6 +611,7 @@ typedef struct _virDomainDiskSourcePoolDef virDomainDiskSourcePoolDef;
 struct _virDomainDiskSourcePoolDef {
     char *pool; /* pool name */
     char *volume; /* volume name */
+    int voltype; /* enum virStorageVolType, internal only */
 };
 typedef virDomainDiskSourcePoolDef *virDomainDiskSourcePoolDefPtr;
 
index a98d21c60da967dca6e5bdb947a18f343c036fde..84f87565295827cbd665042b3cf57ea00bbb1263 100644 (file)
@@ -2681,56 +2681,6 @@ qemuBuildNBDString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPtr op
     return 0;
 }
 
-static int
-qemuTranslateDiskSourcePool(virConnectPtr conn,
-                            virDomainDiskDefPtr def,
-                            int *voltype)
-{
-    virStoragePoolPtr pool = NULL;
-    virStorageVolPtr vol = NULL;
-    virStorageVolInfo info;
-    int ret = -1;
-
-    if (def->type != VIR_DOMAIN_DISK_TYPE_VOLUME)
-        return 0;
-
-    if (!(pool = virStoragePoolLookupByName(conn, def->srcpool->pool)))
-        return -1;
-
-    if (!(vol = virStorageVolLookupByName(pool, def->srcpool->volume)))
-        goto cleanup;
-
-    if (virStorageVolGetInfo(vol, &info) < 0)
-        goto cleanup;
-
-    if (def->startupPolicy &&
-        info.type != VIR_STORAGE_VOL_FILE) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("'startupPolicy' is only valid for 'file' type volume"));
-        goto cleanup;
-    }
-
-    switch (info.type) {
-    case VIR_STORAGE_VOL_FILE:
-    case VIR_STORAGE_VOL_BLOCK:
-    case VIR_STORAGE_VOL_DIR:
-        if (!(def->src = virStorageVolGetPath(vol)))
-            goto cleanup;
-        break;
-    case VIR_STORAGE_VOL_NETWORK:
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Using network volume as disk source is not supported"));
-        goto cleanup;
-    }
-
-    *voltype = info.type;
-    ret = 0;
-cleanup:
-    virStoragePoolFree(pool);
-    virStorageVolFree(vol);
-    return ret;
-}
-
 char *
 qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
                   virDomainDiskDefPtr disk,
@@ -2743,7 +2693,6 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
         virDomainDiskGeometryTransTypeToString(disk->geometry.trans);
     int idx = virDiskNameToIndex(disk->dst);
     int busid = -1, unitid = -1;
-    int voltype = -1;
 
     if (idx < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2751,9 +2700,6 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
         goto error;
     }
 
-    if (qemuTranslateDiskSourcePool(conn, disk, &voltype) < 0)
-        goto error;
-
     switch (disk->bus) {
     case VIR_DOMAIN_DISK_BUS_SCSI:
         if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
@@ -2889,7 +2835,7 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
                 break;
             }
         } else if (disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME) {
-            switch (voltype) {
+            switch (disk->srcpool->voltype) {
             case VIR_STORAGE_VOL_DIR:
                 if (!disk->readonly) {
                     virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
index 2db1551632a7fc7d9c1aeea9c986c88060b9a4a9..1789c20f334d26c229775518c38bedabefafdf0b 100644 (file)
@@ -237,5 +237,4 @@ qemuParseKeywords(const char *str,
                   char ***retvalues,
                   int allowEmptyValue);
 
-
 #endif /* __QEMU_COMMAND_H__*/
index 7da1c53b8967ecc6fe896d75ccc22a0cc1ac4335..3b881b1f7f4a878cd3943193b0fd024c442baf9d 100644 (file)
@@ -1222,3 +1222,55 @@ int qemuDriverAllocateID(virQEMUDriverPtr driver)
 {
     return virAtomicIntInc(&driver->nextvmid);
 }
+
+int
+qemuTranslateDiskSourcePool(virConnectPtr conn,
+                            virDomainDiskDefPtr def)
+{
+    virStoragePoolPtr pool = NULL;
+    virStorageVolPtr vol = NULL;
+    virStorageVolInfo info;
+    int ret = -1;
+
+    if (def->type != VIR_DOMAIN_DISK_TYPE_VOLUME)
+        return 0;
+
+    if (!def->srcpool)
+        return 0;
+
+    if (!(pool = virStoragePoolLookupByName(conn, def->srcpool->pool)))
+        return -1;
+
+    if (!(vol = virStorageVolLookupByName(pool, def->srcpool->volume)))
+        goto cleanup;
+
+    if (virStorageVolGetInfo(vol, &info) < 0)
+        goto cleanup;
+
+    if (def->startupPolicy &&
+        info.type != VIR_STORAGE_VOL_FILE) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("'startupPolicy' is only valid for 'file' type volume"));
+        goto cleanup;
+    }
+
+    switch (info.type) {
+    case VIR_STORAGE_VOL_FILE:
+    case VIR_STORAGE_VOL_BLOCK:
+    case VIR_STORAGE_VOL_DIR:
+        if (!(def->src = virStorageVolGetPath(vol)))
+            goto cleanup;
+        break;
+    case VIR_STORAGE_VOL_NETWORK:
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Using network volume as disk source is not supported"));
+        goto cleanup;
+    }
+
+    def->srcpool->voltype = info.type;
+    ret = 0;
+cleanup:
+    virStoragePoolFree(pool);
+    virStorageVolFree(vol);
+    return ret;
+}
index 52999200c4c99ccdcab5ebd85bafd0ff8ab470a3..9ec993f90b4b3c0881ac1550c551059ca10c2eb5 100644 (file)
@@ -303,5 +303,7 @@ void qemuSharedDiskEntryFree(void *payload, const void *name)
 int qemuDriverAllocateID(virQEMUDriverPtr driver);
 virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);
 
+int qemuTranslateDiskSourcePool(virConnectPtr conn,
+                                virDomainDiskDefPtr def);
 
 #endif /* __QEMUD_CONF_H */
index 997d7c3162ace142969f9be38508af71b96fe6fb..2c0d7d1135f04acead5044f98f1c7a7c7baba857 100644 (file)
@@ -5738,6 +5738,9 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
         goto end;
     }
 
+    if (qemuTranslateDiskSourcePool(conn, disk) < 0)
+        goto end;
+
     if (qemuAddSharedDisk(driver, disk, vm->def->name) < 0)
         goto end;
 
@@ -6007,7 +6010,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
 }
 
 static int
-qemuDomainChangeDiskMediaLive(virDomainObjPtr vm,
+qemuDomainChangeDiskMediaLive(virConnectPtr conn,
+                              virDomainObjPtr vm,
                               virDomainDeviceDefPtr dev,
                               virQEMUDriverPtr driver,
                               bool force)
@@ -6020,6 +6024,9 @@ qemuDomainChangeDiskMediaLive(virDomainObjPtr vm,
     virCapsPtr caps = NULL;
     int ret = -1;
 
+    if (qemuTranslateDiskSourcePool(conn, disk) < 0)
+        goto end;
+
     if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
         goto end;
 
@@ -6099,7 +6106,8 @@ end:
 }
 
 static int
-qemuDomainUpdateDeviceLive(virDomainObjPtr vm,
+qemuDomainUpdateDeviceLive(virConnectPtr conn,
+                           virDomainObjPtr vm,
                            virDomainDeviceDefPtr dev,
                            virDomainPtr dom,
                            bool force)
@@ -6109,7 +6117,7 @@ qemuDomainUpdateDeviceLive(virDomainObjPtr vm,
 
     switch (dev->type) {
     case VIR_DOMAIN_DEVICE_DISK:
-        ret = qemuDomainChangeDiskMediaLive(vm, dev, driver, force);
+        ret = qemuDomainChangeDiskMediaLive(conn, vm, dev, driver, force);
         break;
     case VIR_DOMAIN_DEVICE_GRAPHICS:
         ret = qemuDomainChangeGraphics(driver, vm, dev->data.graphics);
@@ -6522,7 +6530,7 @@ qemuDomainModifyDeviceFlags(virDomainPtr dom, const char *xml,
             ret = qemuDomainDetachDeviceLive(vm, dev_copy, dom);
             break;
         case QEMU_DEVICE_UPDATE:
-            ret = qemuDomainUpdateDeviceLive(vm, dev_copy, dom, force);
+            ret = qemuDomainUpdateDeviceLive(dom->conn, vm, dev_copy, dom, force);
             break;
         default:
             virReportError(VIR_ERR_INTERNAL_ERROR,
index 9f7c087c20857a2c17c99088c2abb084a42763f8..31427edb5c938d0488d7e81c4c891f7ea3896f5f 100644 (file)
@@ -3008,6 +3008,8 @@ qemuProcessReconnect(void *opaque)
      * qemu_driver->sharedDisks.
      */
     for (i = 0; i < obj->def->ndisks; i++) {
+        if (qemuTranslateDiskSourcePool(conn, obj->def->disks[i]) < 0)
+            goto error;
         if (qemuAddSharedDisk(driver, obj->def->disks[i],
                               obj->def->name) < 0)
             goto error;
@@ -3556,6 +3558,11 @@ int qemuProcessStart(virConnectPtr conn,
             goto cleanup;
     }
 
+    for (i = 0; i < vm->def->ndisks; i++) {
+        if (qemuTranslateDiskSourcePool(conn, vm->def->disks[i]) < 0)
+            goto cleanup;
+    }
+
     VIR_DEBUG("Building emulator command line");
     if (!(cmd = qemuBuildCommandLine(conn, driver, vm->def, priv->monConfig,
                                      priv->monJSON != 0, priv->qemuCaps,