[PATCH]Support virtio-scsi disk XML with tag 'model'

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

 



From: ChenHanxiao <chenhanxiao@xxxxxxxxxxxxxx>

If we add a virtio-disk, we need to add a SCSI controller with
model 'virtio-scsi'.
This patch allows libvirt to analyze disks XML with tag 'model':

<disk type='block' device='disk'>
    <driver name='qemu' type='raw'/>
    <source dev='/dev/sdb'/>
    <target dev='sda' bus='scsi' model = 'virtio-scsi'/>
</disk>

If we got a disks XML with bus='scsi' model = 'virtio-scsi',
we'll add a SCSI controller with model 'virtio-scsi' automatically.

Signed-off-by: ChenHanxiao <chenhanxiao@xxxxxxxxxxxxxx>
---
 src/conf/domain_conf.c |   29 ++++++++++++++++++++++++-----
 src/conf/domain_conf.h |    2 ++
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 99f03a9..0032df4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3528,6 +3528,7 @@ virDomainDiskDefParseXML(virCapsPtr caps,
     virDomainDiskHostDefPtr hosts = NULL;
     int nhosts = 0;
     char *bus = NULL;
+    char *model = NULL;
     char *cachetag = NULL;
     char *error_policy = NULL;
     char *rerror_policy = NULL;
@@ -3667,6 +3668,7 @@ virDomainDiskDefParseXML(virCapsPtr caps,
                 target = virXMLPropString(cur, "dev");
                 bus = virXMLPropString(cur, "bus");
                 tray = virXMLPropString(cur, "tray");
+                model = virXMLPropString(cur, "model");
 
                 /* HACK: Work around for compat with Xen
                  * driver in previous libvirt releases */
@@ -4015,6 +4017,14 @@ virDomainDiskDefParseXML(virCapsPtr caps,
         }
     }
 
+    if (model) {
+        if ((def->model = virDomainControllerModelSCSITypeFromString(model)) < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                            _("unknown disk bus model type '%s'"), bus);
+            goto error;
+        }
+    }
+
     if (tray) {
         if ((def->tray_status = virDomainDiskTrayTypeFromString(tray)) < 0) {
             virReportError(VIR_ERR_XML_ERROR,
@@ -4221,6 +4231,7 @@ virDomainDiskDefParseXML(virCapsPtr caps,
 
 cleanup:
     VIR_FREE(bus);
+    VIR_FREE(model);
     VIR_FREE(type);
     VIR_FREE(snapshot);
     VIR_FREE(rawio);
@@ -8499,6 +8510,7 @@ virDomainLookupVcpuPin(virDomainDefPtr def,
 
 static int virDomainDefMaybeAddController(virDomainDefPtr def,
                                           int type,
+                                          int model,
                                           int idx)
 {
     int found = 0;
@@ -8521,7 +8533,7 @@ static int virDomainDefMaybeAddController(virDomainDefPtr def,
 
     cont->type = type;
     cont->idx = idx;
-    cont->model = -1;
+    cont->model = model;
 
     if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL) {
         cont->opts.vioserial.ports = -1;
@@ -9508,7 +9520,8 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     if (def->virtType == VIR_DOMAIN_VIRT_QEMU ||
         def->virtType == VIR_DOMAIN_VIRT_KQEMU ||
         def->virtType == VIR_DOMAIN_VIRT_KVM)
-        if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_USB, 0) < 0)
+        if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_USB, 
+                VIR_DOMAIN_CONTROLLER_MODEL_UNDEF, 0) < 0)
             goto error;
 
     /* analysis of the resource leases */
@@ -11390,6 +11403,7 @@ static int virDomainDefAddDiskControllersForType(virDomainDefPtr def,
 {
     int i;
     int maxController = -1;
+    int model = VIR_DOMAIN_CONTROLLER_MODEL_UNDEF;
 
     for (i = 0 ; i < def->ndisks ; i++) {
         if (def->disks[i]->bus != diskBus)
@@ -11400,10 +11414,12 @@ static int virDomainDefAddDiskControllersForType(virDomainDefPtr def,
 
         if ((int)def->disks[i]->info.addr.drive.controller > maxController)
             maxController = def->disks[i]->info.addr.drive.controller;
+
+        model = def->disks[i]->model;
     }
 
     for (i = 0 ; i <= maxController ; i++) {
-        if (virDomainDefMaybeAddController(def, controllerType, i) < 0)
+        if (virDomainDefMaybeAddController(def, controllerType, model, i) < 0)
             return -1;
     }
 
@@ -11425,7 +11441,8 @@ static int virDomainDefMaybeAddVirtioSerialController(virDomainDefPtr def)
                 idx = channel->info.addr.vioserial.controller;
 
             if (virDomainDefMaybeAddController(def,
-                VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, idx) < 0)
+                    VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, 
+                    VIR_DOMAIN_CONTROLLER_MODEL_UNDEF, idx) < 0)
                 return -1;
         }
     }
@@ -11440,7 +11457,8 @@ static int virDomainDefMaybeAddVirtioSerialController(virDomainDefPtr def)
                 idx = console->info.addr.vioserial.controller;
 
             if (virDomainDefMaybeAddController(def,
-                VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, idx) < 0)
+                    VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, 
+                    VIR_DOMAIN_CONTROLLER_MODEL_UNDEF, idx) < 0)
                 return -1;
         }
     }
@@ -11480,6 +11498,7 @@ virDomainDefMaybeAddSmartcardController(virDomainDefPtr def)
 
         if (virDomainDefMaybeAddController(def,
                                            VIR_DOMAIN_CONTROLLER_TYPE_CCID,
+                                           VIR_DOMAIN_CONTROLLER_MODEL_UNDEF,
                                            idx) < 0)
             return -1;
     }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6539281..ba7accf 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -553,6 +553,7 @@ struct _virDomainDiskDef {
     int type;
     int device;
     int bus;
+    int model;
     char *src;
     char *dst;
     int tray_status;
@@ -672,6 +673,7 @@ struct _virDomainControllerDef {
     virDomainDeviceInfo info;
 };
 
+#define VIR_DOMAIN_CONTROLLER_MODEL_UNDEF -1
 
 /* Two types of disk backends */
 enum virDomainFSType {
-- 
1.7.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]