[libvirt] [PATCH 05/10] conf: Introduce new attribute for device address format

Osier Yang jyang at redhat.com
Fri Feb 17 17:18:02 UTC 2012


* src/conf/domain_conf.h: Add new member "target" to struct
  _virDomainDeviceDriveAddress.

* src/conf/domain_conf.c:
  - virDomainDeviceDriveAddressParseXML: Parse "target".
  - virDomainDeviceInfoFormat: new parameter "controllerType"
    (disk controller type) and "bus" (disk bus type)" to
    distiguish the lsilogic model and other models of disk
    controller, if the model is lsilogic, then old address
    format (without "target") is printed, otherwise new address
    format (with "target") is printed.
  - virDomainDiskDefFormat: New parameter "vmdef", to pass to
    virDomainDiskFindControllerModel as an argument.
  - New helper function virDomainDeviceInfoFormatCommon, which
    is an simple wrapper of virDomainDeviceInfoFormat.
  - Replace virDomainDeviceInfoFormat with
    virDomainDeviceInfoFormatCommon accross the file, except
    the one used for disk def formating.

* docs/schemas/domaincommon.rng: Define the rng schema for
  "target".

* docs/formatdomain.html.in: Document "target".
---
 docs/formatdomain.html.in     |   13 +++++-
 docs/schemas/domaincommon.rng |   10 +++++
 src/conf/domain_conf.c        |   87 ++++++++++++++++++++++++++++------------
 src/conf/domain_conf.h        |    1 +
 4 files changed, 83 insertions(+), 28 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 29497a0..f923c75 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1094,7 +1094,14 @@
       <target dev='hdc' bus='ide'/>
       <readonly/>
     </disk>
+    <disk type='block' device='lun'>
+      <driver name='qemu' type='raw'/>
+      <source dev='/dev/sda'/<
+      <target dev='sda' bus='scsi'/<
+      <address type='drive' controller='0' bus='0' target='3' unit='0'/<
+    </disk>
   </devices>
+
   ...</pre>
 
     <dl>
@@ -1401,8 +1408,9 @@
         Multifunction defaults to 'off'; any other value requires
         QEMU 0.1.3 and <span class="since">libvirt 0.9.7</span>.  For a
         "drive" controller, additional attributes
-        <code>controller</code>, <code>bus</code>,
-        and <code>unit</code> are available, each defaulting to 0.
+        <code>controller</code>, <code>bus</code>, <code>target</code>
+        (<span class="since">libvirt 0.9.11</span>), and <code>unit</code>
+        are available, each defaulting to 0.
       </dd>
       <dt><code>auth</code></dt>
       <dd>If present, the <code>auth</code> element provides the
@@ -1592,6 +1600,7 @@
       <dd>Drive addresses have the following additional
         attributes: <code>controller</code> (a 2-digit controller
         number), <code>bus</code> (a 2-digit bus number),
+        <code>target</code> (a 2-digit bus number),
         and <code>unit</code> (a 2-digit unit number on the bus).
       </dd>
       <dt><code>type='virtio-serial'</code></dt>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 724d7d0..3908733 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2460,6 +2460,11 @@
       </attribute>
     </optional>
     <optional>
+      <attribute name="target">
+        <ref name="driveTarget"/>
+      </attribute>
+    </optional>
+    <optional>
       <attribute name="unit">
         <ref name="driveUnit"/>
       </attribute>
@@ -3147,6 +3152,11 @@
       <param name="pattern">[0-9]{1,2}</param>
     </data>
   </define>
+  <define name="driveTarget">
+    <data type="string">
+      <param name="pattern">[0-9]{1,2}</param>
+    </data>
+  </define>
   <define name="driveUnit">
     <data type="string">
       <param name="pattern">[0-9]{1,2}</param>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c36ac18..b8e5a78 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -240,7 +240,7 @@ VIR_ENUM_IMPL(virDomainControllerModelSCSI, VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LAS
               "lsisas1068",
               "vmpvscsi",
               "ibmvscsi",
-              "virtio-scsi")
+              "virtio-scsi");
 
 VIR_ENUM_IMPL(virDomainControllerModelUSB, VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST,
               "piix3-uhci",
@@ -1913,11 +1913,13 @@ void virDomainDefClearDeviceAliases(virDomainDefPtr def)
 
 
 /* Generate a string representation of a device address
- * @param address Device address to stringify
+ * @info address Device address to stringify
  */
 static int ATTRIBUTE_NONNULL(2)
 virDomainDeviceInfoFormat(virBufferPtr buf,
                           virDomainDeviceInfoPtr info,
+                          int controllerModel,
+                          int bus,
                           unsigned int flags)
 {
     if ((flags & VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) && info->bootIndex)
@@ -1975,10 +1977,19 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
-        virBufferAsprintf(buf, " controller='%d' bus='%d' unit='%d'",
-                          info->addr.drive.controller,
-                          info->addr.drive.bus,
-                          info->addr.drive.unit);
+        if ((bus == VIR_DOMAIN_DISK_BUS_SCSI) &&
+            (controllerModel != VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC)) {
+            virBufferAsprintf(buf, " controller='%d' bus='%d' target='%d' unit='%d'",
+                              info->addr.drive.controller,
+                              info->addr.drive.bus,
+                              info->addr.drive.target,
+                              info->addr.drive.unit);
+        } else {
+            virBufferAsprintf(buf, " controller='%d' bus='%d' unit='%d'",
+                              info->addr.drive.controller,
+                              info->addr.drive.bus,
+                              info->addr.drive.unit);
+        }
         break;
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
@@ -2016,6 +2027,12 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
     return 0;
 }
 
+static int ATTRIBUTE_NONNULL(2)
+virDomainDeviceInfoFormatCommon(virBufferPtr buf,
+                                virDomainDeviceInfoPtr info,
+                                unsigned int flags) {
+    return virDomainDeviceInfoFormat(buf, info, -1, -1, flags);
+}
 
 static int
 virDomainDevicePCIAddressParseXML(xmlNodePtr node,
@@ -2090,13 +2107,14 @@ static int
 virDomainDeviceDriveAddressParseXML(xmlNodePtr node,
                                     virDomainDeviceDriveAddressPtr addr)
 {
-    char *bus, *unit, *controller;
+    char *bus, *unit, *controller, *target;
     int ret = -1;
 
     memset(addr, 0, sizeof(*addr));
 
     controller = virXMLPropString(node, "controller");
     bus = virXMLPropString(node, "bus");
+    target = virXMLPropString(node, "target");
     unit = virXMLPropString(node, "unit");
 
     if (controller &&
@@ -2113,6 +2131,13 @@ virDomainDeviceDriveAddressParseXML(xmlNodePtr node,
         goto cleanup;
     }
 
+    if (target &&
+        virStrToLong_ui(target, NULL, 10, &addr->target) < 0) {
+        virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                             _("Cannot parse <address> 'target' attribute"));
+        goto cleanup;
+    }
+
     if (unit &&
         virStrToLong_ui(unit, NULL, 10, &addr->unit) < 0) {
         virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2125,6 +2150,7 @@ virDomainDeviceDriveAddressParseXML(xmlNodePtr node,
 cleanup:
     VIR_FREE(controller);
     VIR_FREE(bus);
+    VIR_FREE(target);
     VIR_FREE(unit);
     return ret;
 }
@@ -3550,6 +3576,7 @@ virDomainControllerDefParseXML(xmlNodePtr node,
         def->model = -1;
     }
 
+    /* ESX detects the model itself if model is "auto". */
     if (def->model == -1 ||
         def->model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_AUTO)
         def->model = virDomainControllerDefaultModel(dom, def->type);
@@ -10072,6 +10099,7 @@ virDomainLeaseDefFormat(virBufferPtr buf,
 
 static int
 virDomainDiskDefFormat(virBufferPtr buf,
+                       virDomainDefPtr vmdef,
                        virDomainDiskDefPtr def,
                        unsigned int flags)
 {
@@ -10088,6 +10116,7 @@ virDomainDiskDefFormat(virBufferPtr buf,
     const char *startupPolicy = virDomainStartupPolicyTypeToString(def->startupPolicy);
 
     char uuidstr[VIR_UUID_STRING_BUFLEN];
+    int controllerModel = -1;
 
     if (!type) {
         virDomainReportError(VIR_ERR_INTERNAL_ERROR,
@@ -10297,7 +10326,13 @@ virDomainDiskDefFormat(virBufferPtr buf,
         virBufferAdjustIndent(buf, -6);
     }
 
-    if (virDomainDeviceInfoFormat(buf, &def->info,
+    if (def->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
+        controllerModel =
+            virDomainDiskFindControllerModel(vmdef, def,
+                                             VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
+    }
+
+    if (virDomainDeviceInfoFormat(buf, &def->info, controllerModel, def->bus,
                                   flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0)
         return -1;
 
@@ -10368,7 +10403,7 @@ virDomainControllerDefFormat(virBufferPtr buf,
 
     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
             return -1;
         virBufferAddLit(buf, "    </controller>\n");
     } else {
@@ -10445,7 +10480,7 @@ virDomainFSDefFormat(virBufferPtr buf,
     if (def->readonly)
         virBufferAddLit(buf, "      <readonly/>\n");
 
-    if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+    if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
         return -1;
 
     virBufferAddLit(buf, "    </filesystem>\n");
@@ -10676,9 +10711,9 @@ virDomainNetDefFormat(virBufferPtr buf,
         return -1;
     virBufferAdjustIndent(buf, -6);
 
-    if (virDomainDeviceInfoFormat(buf, &def->info,
-                                  flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT
-                                  | VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0)
+    if (virDomainDeviceInfoFormatCommon(buf, &def->info,
+                                        flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT
+                                        | VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0)
         return -1;
 
     virBufferAddLit(buf, "    </interface>\n");
@@ -10870,7 +10905,7 @@ virDomainChrDefFormat(virBufferPtr buf,
     }
 
     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
-        if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
             return -1;
     }
 
@@ -10923,7 +10958,7 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
                              _("unexpected smartcard type %d"), def->type);
         return -1;
     }
-    if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+    if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
         return -1;
     virBufferAddLit(buf, "    </smartcard>\n");
     return 0;
@@ -10946,7 +10981,7 @@ virDomainSoundDefFormat(virBufferPtr buf,
 
     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
             return -1;
         virBufferAddLit(buf, "    </sound>\n");
     } else {
@@ -10974,7 +11009,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
 
     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
             return -1;
         virBufferAddLit(buf, "    </memballoon>\n");
     } else {
@@ -11021,7 +11056,7 @@ virDomainWatchdogDefFormat(virBufferPtr buf,
 
     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
             return -1;
         virBufferAddLit(buf, "    </watchdog>\n");
     } else {
@@ -11072,7 +11107,7 @@ virDomainVideoDefFormat(virBufferPtr buf,
         virBufferAddLit(buf, "/>\n");
     }
 
-    if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+    if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
         return -1;
 
     virBufferAddLit(buf, "    </video>\n");
@@ -11104,7 +11139,7 @@ virDomainInputDefFormat(virBufferPtr buf,
 
     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
             return -1;
         virBufferAddLit(buf, "    </input>\n");
     } else {
@@ -11510,9 +11545,9 @@ virDomainHostdevDefFormat(virBufferPtr buf,
 
     virBufferAddLit(buf, "      </source>\n");
 
-    if (virDomainDeviceInfoFormat(buf, &def->info,
-                                  flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT
-                                  | VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0)
+    if (virDomainDeviceInfoFormatCommon(buf, &def->info,
+                                        flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT
+                                        | VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM) < 0)
         return -1;
 
     virBufferAddLit(buf, "    </hostdev>\n");
@@ -11532,7 +11567,7 @@ virDomainRedirdevDefFormat(virBufferPtr buf,
     virBufferAsprintf(buf, "    <redirdev bus='%s'", bus);
     if (virDomainChrSourceDefFormat(buf, &def->source.chr, false, flags) < 0)
         return -1;
-    if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+    if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
         return -1;
     virBufferAddLit(buf, "    </redirdev>\n");
 
@@ -11556,7 +11591,7 @@ virDomainHubDefFormat(virBufferPtr buf,
 
     if (virDomainDeviceInfoIsSet(&def->info, flags)) {
         virBufferAddLit(buf, ">\n");
-        if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        if (virDomainDeviceInfoFormatCommon(buf, &def->info, flags) < 0)
             return -1;
         virBufferAddLit(buf, "    </hub>\n");
     } else {
@@ -11937,7 +11972,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                           def->emulator);
 
     for (n = 0 ; n < def->ndisks ; n++)
-        if (virDomainDiskDefFormat(buf, def->disks[n], flags) < 0)
+        if (virDomainDiskDefFormat(buf, def, def->disks[n], flags) < 0)
             goto cleanup;
 
     for (n = 0 ; n < def->ncontrollers ; n++)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fed7cc3..596be4d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -106,6 +106,7 @@ typedef virDomainDeviceDriveAddress *virDomainDeviceDriveAddressPtr;
 struct _virDomainDeviceDriveAddress {
     unsigned int controller;
     unsigned int bus;
+    unsigned int target;
     unsigned int unit;
 };
 
-- 
1.7.7.3




More information about the libvir-list mailing list