[libvirt] [PATCH 2/9] Extend <disk> element with controller information

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

 



This allows us to connect a disk with a specific controller,
which is required for disk hotadd/remove. A new XML child
element is added to the <disk> container:

<disk>
...
	<controller pci_addr="<addr>" id="<identifier>" bus="<number>" unit="<number>"/>
</disk>

Either id _or_ pci_addr can be specified. When the controller
has been brought into the system via tghe hotplug mechanism also
included in this patch series, it will typically have an ID.
In other cases, the controller can also be specified with
the PCI address.

Wrt. the data structures touched in this commit, notice
that while "bus" as subelement of target specifies
the type of bus (e.g., scsi, ide,...), it is used
to enumerate the buses on the controller here.

Signed-off-by: Wolfgang Mauerer <wolfgang.mauerer@xxxxxxxxxxx>
Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
 src/domain_conf.c |   29 +++++++++++++++++++++++++++++
 src/domain_conf.h |    5 ++++-
 2 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/src/domain_conf.c b/src/domain_conf.c
index 5ae0775..a6120c8 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -650,7 +650,12 @@ virDomainDiskDefParseXML(virConnectPtr conn,
     char *driverType = NULL;
     char *source = NULL;
     char *target = NULL;
+    char *controller = NULL;
+    char *bus_id = NULL;
+    char *unit_id = NULL;
+    char *controller_id = NULL;
     char *bus = NULL;
+    char *unit = NULL;
     char *cachetag = NULL;
     char *devaddr = NULL;
     virStorageEncryptionPtr encryption = NULL;
@@ -694,12 +699,18 @@ virDomainDiskDefParseXML(virConnectPtr conn,
                        (xmlStrEqual(cur->name, BAD_CAST "target"))) {
                 target = virXMLPropString(cur, "dev");
                 bus = virXMLPropString(cur, "bus");
+                unit = virXMLPropString(cur, "unit");
 
                 /* HACK: Work around for compat with Xen
                  * driver in previous libvirt releases */
                 if (target &&
                     STRPREFIX(target, "ioemu:"))
                     memmove(target, target+6, strlen(target)-5);
+            } else if ((controller == NULL) &&
+                       (xmlStrEqual(cur->name, BAD_CAST "controller"))) {
+	      controller_id = virXMLPropString(cur, "id");
+	      bus_id = virXMLPropString(cur, "bus");
+	      unit_id = virXMLPropString(cur, "unit");
             } else if ((driverName == NULL) &&
                        (xmlStrEqual(cur->name, BAD_CAST "driver"))) {
                 driverName = virXMLPropString(cur, "name");
@@ -800,6 +811,24 @@ virDomainDiskDefParseXML(virConnectPtr conn,
         }
     }
 
+    if (controller) {
+        def->controller_id = controller_id;
+
+	def->bus_id = -1;
+	if (bus_id && virStrToLong_i(bus_id, NULL, 10, &def->bus_id) < 0) {
+	    virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
+			 _("Cannot parse <controller> 'bus' attribute"));
+	    goto error;
+      } 
+
+	def->unit_id = -1;
+	if (unit_id && virStrToLong_i(unit_id, NULL, 10, &def->unit_id) < 0) {
+	    virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
+			 _("Cannot parse <controller> 'unit' attribute"));
+	    goto error;
+	} 
+    }
+
     if (def->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
         def->bus != VIR_DOMAIN_DISK_BUS_FDC) {
         virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
diff --git a/src/domain_conf.h b/src/domain_conf.h
index 09368d9..898f6c9 100644
--- a/src/domain_conf.h
+++ b/src/domain_conf.h
@@ -105,9 +105,12 @@ typedef virDomainDiskDef *virDomainDiskDefPtr;
 struct _virDomainDiskDef {
     int type;
     int device;
-    int bus;
+    int bus;          /* Bus type, e.g. scsi or ide */
+    int bus_id;       /* Bus number on the controller */
+    int unit_id;      /* Unit on the controller */
     char *src;
     char *dst;
+    char *controller_id;
     char *driverName;
     char *driverType;
     char *serial;
-- 
1.6.4

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