[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v3 02/13] vbox: Process <controller> element in domain XML



With this patch, the vbox driver will no longer attach all supported
storage controllers by default even if no disk devices are associated
with them. Instead, it will attach only those that are implicitly added
by virDomainDefAddImplicitController based on <disk> element or if
explicitly specified via the <controller> element.
---
 src/vbox/vbox_common.c | 199 ++++++++++++++++++++++++++++++++++++++-----------
 src/vbox/vbox_common.h |   7 ++
 2 files changed, 161 insertions(+), 45 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index d93b0855f..49df52c12 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -406,6 +406,154 @@ static char *vboxGenerateMediumName(PRUint32 storageBus,
     return name;
 }
 
+
+static int
+vboxSetStorageController(virDomainControllerDefPtr controller,
+                         vboxDriverPtr data,
+                         IMachine *machine)
+{
+    PRUnichar *controllerName = NULL;
+    PRInt32 vboxModel = StorageControllerType_Null;
+    PRInt32 vboxBusType = StorageBus_Null;
+    IStorageController *vboxController = NULL;
+    nsresult rc = 0;
+    char *debugName = NULL;
+    int ret = -1;
+
+    /* libvirt controller type => vbox bus type */
+    switch ((virDomainControllerType) controller->type) {
+    case VIR_DOMAIN_CONTROLLER_TYPE_FDC:
+        VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_FLOPPY_NAME, &controllerName);
+        vboxBusType = StorageBus_Floppy;
+
+        break;
+    case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
+        VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_IDE_NAME, &controllerName);
+        vboxBusType = StorageBus_IDE;
+
+        break;
+    case VIR_DOMAIN_CONTROLLER_TYPE_SCSI:
+        VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_SCSI_NAME, &controllerName);
+        vboxBusType = StorageBus_SCSI;
+
+        break;
+    case VIR_DOMAIN_CONTROLLER_TYPE_SATA:
+        VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_SATA_NAME, &controllerName);
+        vboxBusType = StorageBus_SATA;
+
+        break;
+    case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL:
+    case VIR_DOMAIN_CONTROLLER_TYPE_CCID:
+    case VIR_DOMAIN_CONTROLLER_TYPE_USB:
+    case VIR_DOMAIN_CONTROLLER_TYPE_PCI:
+    case VIR_DOMAIN_CONTROLLER_TYPE_LAST:
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("The vbox driver does not support %s controller type"),
+                       virDomainControllerTypeToString(controller->type));
+        return -1;
+    }
+
+    /* libvirt scsi model => vbox scsi model */
+    if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_SCSI) {
+        switch ((virDomainControllerModelSCSI) controller->model) {
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC:
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_AUTO:
+            vboxModel = StorageControllerType_LsiLogic;
+
+            break;
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_BUSLOGIC:
+            vboxModel = StorageControllerType_BusLogic;
+
+            break;
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VMPVSCSI:
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_IBMVSCSI:
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI:
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSISAS1068:
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSISAS1078:
+        case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LAST:
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("The vbox driver does not support %s SCSI "
+                             "controller model"),
+                           virDomainControllerModelSCSITypeToString(controller->model));
+            goto cleanup;
+        }
+    /* libvirt ide model => vbox ide model */
+    } else if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE) {
+        switch ((virDomainControllerModelIDE) controller->model) {
+        case VIR_DOMAIN_CONTROLLER_MODEL_IDE_PIIX3:
+            vboxModel = StorageControllerType_PIIX3;
+
+            break;
+        case VIR_DOMAIN_CONTROLLER_MODEL_IDE_PIIX4:
+            vboxModel = StorageControllerType_PIIX4;
+
+            break;
+        case VIR_DOMAIN_CONTROLLER_MODEL_IDE_ICH6:
+            vboxModel = StorageControllerType_ICH6;
+
+            break;
+        case VIR_DOMAIN_CONTROLLER_MODEL_IDE_LAST:
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("The vbox driver does not support %s IDE "
+                             "controller model"),
+                             virDomainControllerModelIDETypeToString(controller->model));
+            goto cleanup;
+        }
+    }
+
+    VBOX_UTF16_TO_UTF8(controllerName, &debugName);
+    VIR_DEBUG("Adding VBOX storage controller (name: %s, busType: %d)",
+               debugName, vboxBusType);
+
+    rc = gVBoxAPI.UIMachine.AddStorageController(machine, controllerName,
+                                                 vboxBusType, &vboxController);
+
+    if (NS_FAILED(rc)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to add storage controller "
+                         "(name: %s, busType: %d), rc=%08x"),
+                       debugName, vboxBusType, rc);
+        goto cleanup;
+    }
+
+    /* only IDE or SCSI controller have model choices */
+    if (vboxModel != StorageControllerType_Null) {
+        rc = gVBoxAPI.UIStorageController.SetControllerType(vboxController,
+                                                            vboxModel);
+        if (NS_FAILED(rc)) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                            _("Failed to change storage controller model, "
+                              "rc=%08x"), rc);
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+ cleanup:
+    VBOX_UTF16_FREE(controllerName);
+    VBOX_UTF8_FREE(debugName);
+    VBOX_RELEASE(vboxController);
+
+    return ret;
+}
+
+
+static int
+vboxAttachStorageControllers(virDomainDefPtr def,
+                             vboxDriverPtr data,
+                             IMachine *machine)
+{
+    size_t i;
+    for (i = 0; i < def->ncontrollers; i++) {
+        if (vboxSetStorageController(def->controllers[i], data, machine) < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
+
 static virDrvOpenStatus
 vboxConnectOpen(virConnectPtr conn,
                 virConnectAuthPtr auth ATTRIBUTE_UNUSED,
@@ -972,46 +1120,6 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
 
     VBOX_IID_INITIALIZE(&mediumUUID);
 
-    /* add a storage controller for the mediums to be attached */
-    /* this needs to change when multiple controller are supported for
-     * ver > 3.1 */
-    {
-        IStorageController *storageCtl = NULL;
-        PRUnichar *sName = NULL;
-
-        VBOX_UTF8_TO_UTF16("IDE Controller", &sName);
-        gVBoxAPI.UIMachine.AddStorageController(machine,
-                                                sName,
-                                                StorageBus_IDE,
-                                                &storageCtl);
-        VBOX_UTF16_FREE(sName);
-        VBOX_RELEASE(storageCtl);
-
-        VBOX_UTF8_TO_UTF16("SATA Controller", &sName);
-        gVBoxAPI.UIMachine.AddStorageController(machine,
-                                                sName,
-                                                StorageBus_SATA,
-                                                &storageCtl);
-        VBOX_UTF16_FREE(sName);
-        VBOX_RELEASE(storageCtl);
-
-        VBOX_UTF8_TO_UTF16("SCSI Controller", &sName);
-        gVBoxAPI.UIMachine.AddStorageController(machine,
-                                                sName,
-                                                StorageBus_SCSI,
-                                                &storageCtl);
-        VBOX_UTF16_FREE(sName);
-        VBOX_RELEASE(storageCtl);
-
-        VBOX_UTF8_TO_UTF16("Floppy Controller", &sName);
-        gVBoxAPI.UIMachine.AddStorageController(machine,
-                                                sName,
-                                                StorageBus_Floppy,
-                                                &storageCtl);
-        VBOX_UTF16_FREE(sName);
-        VBOX_RELEASE(storageCtl);
-    }
-
     for (i = 0; i < def->ndisks; i++) {
         disk = def->disks[i];
         src = virDomainDiskGetSource(disk);
@@ -1066,21 +1174,21 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
 
         switch ((virDomainDiskBus) disk->bus) {
         case VIR_DOMAIN_DISK_BUS_IDE:
-            VBOX_UTF8_TO_UTF16("IDE Controller", &storageCtlName);
+            VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_IDE_NAME, &storageCtlName);
             devicePort = def->disks[i]->info.addr.drive.bus;
             deviceSlot = def->disks[i]->info.addr.drive.unit;
 
             break;
         case VIR_DOMAIN_DISK_BUS_SATA:
-            VBOX_UTF8_TO_UTF16("SATA Controller", &storageCtlName);
+            VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_SATA_NAME, &storageCtlName);
 
             break;
         case VIR_DOMAIN_DISK_BUS_SCSI:
-            VBOX_UTF8_TO_UTF16("SCSI Controller", &storageCtlName);
+            VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_SCSI_NAME, &storageCtlName);
 
             break;
         case VIR_DOMAIN_DISK_BUS_FDC:
-            VBOX_UTF8_TO_UTF16("Floppy Controller", &storageCtlName);
+            VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_FLOPPY_NAME, &storageCtlName);
             devicePort = 0;
             deviceSlot = disk->info.addr.drive.unit;
 
@@ -1148,7 +1256,6 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
                 gVBoxAPI.UIMedium.SetType(medium, MediumType_Normal);
                 VIR_DEBUG("Setting hard disk type to normal");
             }
-
         }
 
         VBOX_UTF16_TO_UTF8(storageCtlName, &controllerName);
@@ -1917,6 +2024,8 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags
     gVBoxAPI.UISession.GetMachine(data->vboxSession, &machine);
 
     vboxSetBootDeviceOrder(def, data, machine);
+    if (vboxAttachStorageControllers(def, data, machine) < 0)
+        goto cleanup;
     if (vboxAttachDrives(def, data, machine) < 0)
         goto cleanup;
     vboxAttachSound(def, machine);
diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h
index f28f2e03f..5dc87239d 100644
--- a/src/vbox/vbox_common.h
+++ b/src/vbox/vbox_common.h
@@ -326,6 +326,13 @@ enum HardDiskVariant
 # define VBOX_E_INVALID_SESSION_STATE 0x80BB000B
 # define VBOX_E_OBJECT_IN_USE 0x80BB000C
 
+/* VBOX storage controller name definitions */
+
+# define VBOX_CONTROLLER_IDE_NAME "IDE Controller"
+# define VBOX_CONTROLLER_FLOPPY_NAME "Floppy Controller"
+# define VBOX_CONTROLLER_SATA_NAME "SATA Controller"
+# define VBOX_CONTROLLER_SCSI_NAME "SCSI Controller"
+
 /* Simplied definitions in vbox_CAPI_*.h */
 
 typedef void const *PCVBOXXPCOM;
-- 
2.14.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]