[PATCH v2 05/10] hyperv: create SCSI controllers when defining domains

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

 



Co-authored-by: Sri Ramanujam <sramanujam@xxxxxxxxx>
Signed-off-by: Matt Coleman <matt@xxxxxxxxx>
---
 src/hyperv/hyperv_driver.c | 64 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 65eb3c9ad6..ba39870b10 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -327,6 +327,66 @@ hypervGetDeviceParentRasdFromDeviceId(const char *parentDeviceId,
 }
 
 
+static int
+hypervDomainCreateSCSIController(virDomainPtr domain, virDomainControllerDefPtr def)
+{
+    g_autoptr(GHashTable) scsiResource = NULL;
+    g_autofree char *resourceType = NULL;
+
+    if (def->model != VIR_DOMAIN_CONTROLLER_MODEL_SCSI_DEFAULT &&
+        def->model != VIR_DOMAIN_CONTROLLER_MODEL_SCSI_AUTO) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Unsupported SCSI controller model '%d'"), def->model);
+        return -1;
+    }
+
+    if (def->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Unsupported SCSI controller address type '%d'"), def->info.type);
+        return -1;
+    }
+
+    resourceType = g_strdup_printf("%d", MSVM_RASD_RESOURCETYPE_PARALLEL_SCSI_HBA);
+
+    VIR_DEBUG("Attaching SCSI Controller");
+
+    /* prepare embedded param */
+    scsiResource = hypervCreateEmbeddedParam(Msvm_ResourceAllocationSettingData_WmiInfo);
+    if (!scsiResource)
+        return -1;
+
+    if (hypervSetEmbeddedProperty(scsiResource, "ResourceType", resourceType) < 0)
+        return -1;
+
+    if (hypervSetEmbeddedProperty(scsiResource, "ResourceSubType",
+                                  "Microsoft:Hyper-V:Synthetic SCSI Controller") < 0)
+        return -1;
+
+    /* perform the settings change */
+    if (hypervMsvmVSMSAddResourceSettings(domain, &scsiResource,
+                                          Msvm_ResourceAllocationSettingData_WmiInfo, NULL) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+static int
+hypervDomainAttachStorage(virDomainPtr domain, virDomainDefPtr def)
+{
+    size_t i = 0;
+
+    for (i = 0; i < def->ncontrollers; i++) {
+        if (def->controllers[i]->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI)
+            continue;
+
+        if (hypervDomainCreateSCSIController(domain, def->controllers[i]) < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
 
 /*
  * Functions for deserializing device entries
@@ -1982,6 +2042,10 @@ hypervDomainDefineXML(virConnectPtr conn, const char *xml)
     if (def->mem.cur_balloon > 0 && hypervDomainSetMemory(domain, def->mem.cur_balloon) < 0)
         goto error;
 
+    /* attach all storage */
+    if (hypervDomainAttachStorage(domain, def) < 0)
+        goto error;
+
     return domain;
 
  error:
-- 
2.27.0





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux