]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodedev: support auto-start property for mdevs
authorBoris Fiuczynski <fiuczy@linux.ibm.com>
Fri, 14 May 2021 21:28:59 +0000 (16:28 -0500)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 20 May 2021 09:10:08 +0000 (11:10 +0200)
This adds a new element to the mdev capabilities xml schema that
represents the start policy for a defined mediated device. The actual
auto-start functionality is handled behind the scenes by mdevctl, but it
wasn't yet hooked up in libvirt.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
docs/formatnode.html.in
docs/schemas/nodedev.rng
src/conf/node_device_conf.c
src/conf/node_device_conf.h
src/libvirt_private.syms
src/node_device/node_device_driver.c
tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml
tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml [changed from symlink to file mode: 0644]
tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad.xml [changed from symlink to file mode: 0644]

index 3b3c3105d4fc6e058add3a8ffbde4030e97a1412..9a505f0fe92dbafc6da36b7e5cab2c8f44d4b5a6 100644 (file)
               <dd>
                 This element represents the UUID of the mediated device.
               </dd>
+              <dt><code>start</code></dt>
+              <dd>
+                This element represents the start policy for the device.  It
+                has a required attribute <code>type</code>, which can have a
+                value of <code>auto</code> or <code>manual</code>. Mediated
+                devices with an <code>auto</code> start type will be started
+                automatically by the host when the parent device becomes
+                available (either on boot, or when the parent device is
+                attached). Otherwise the device must be started manually.
+              </dd>
             </dl>
           </dd>
           <dt><code>ccw</code></dt>
index 777227c38ab6ed2cdd762d47a7894bbbec5b2780..660cbda3be17ab76fb1644bf60d4022673d1ecce 100644 (file)
           </attribute>
         </element>
       </optional>
+      <optional>
+        <element name="start">
+          <attribute name="type">
+            <choice>
+              <value>manual</value>
+              <value>auto</value>
+            </choice>
+          </attribute>
+          <empty/>
+        </element>
+      </optional>
       <optional>
         <element name="uuid">
           <ref name="UUID"/>
index 332b12f9971c999dc8c70b90b941a35405c8592e..4e2b37c61238bf8fae2e4b078f58a06516c83661 100644 (file)
@@ -85,6 +85,12 @@ VIR_ENUM_IMPL(virNodeDevDRM,
               "render",
 );
 
+VIR_ENUM_IMPL(virNodeDevMdevStart,
+              VIR_NODE_DEV_MDEV_START_LAST,
+              "manual",
+              "auto",
+);
+
 static int
 virNodeDevCapsDefParseString(const char *xpath,
                              xmlXPathContextPtr ctxt,
@@ -528,6 +534,8 @@ virNodeDeviceCapMdevDefFormat(virBuffer *buf,
 
     virBufferEscapeString(buf, "<type id='%s'/>\n", data->mdev.type);
     virBufferEscapeString(buf, "<uuid>%s</uuid>\n", data->mdev.uuid);
+    virBufferEscapeString(buf, "<start type='%s'/>\n",
+                          virNodeDevMdevStartTypeToString(data->mdev.start));
     virBufferAsprintf(buf, "<iommuGroup number='%u'/>\n",
                       data->mdev.iommuGroupNumber);
 
@@ -1149,7 +1157,6 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
                 return -1;
             }
             storage->removable_media_size = val;
-
             ctxt->node = orignode2;
         } else {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1912,6 +1919,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
     g_autofree xmlNodePtr *attrs = NULL;
     size_t i;
     g_autofree char *uuidstr = NULL;
+    g_autofree char *starttype = NULL;
 
     ctxt->node = node;
 
@@ -1933,6 +1941,16 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
         virUUIDFormat(uuidbuf, mdev->uuid);
     }
 
+    if ((starttype = virXPathString("string(./start[1]/@type)", ctxt))) {
+        if ((mdev->start = virNodeDevMdevStartTypeFromString(starttype)) < 0) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("unknown mdev start type '%s' for '%s'"), starttype, def->name);
+            return -1;
+        }
+    } else {
+        mdev->start = VIR_NODE_DEV_MDEV_START_MANUAL;
+    }
+
     /* 'iommuGroup' is optional, only report an error if the supplied value is
      * invalid (-2), not if it's missing (-1) */
     if (virXPathUInt("number(./iommuGroup[1]/@number)",
index a60562e4fe63cb0c12a6c349eb4f94f909b07217..1a31133c4c17866be477575681c464952e95cb6a 100644 (file)
@@ -124,6 +124,17 @@ typedef enum {
 
 VIR_ENUM_DECL(virNodeDevDRM);
 
+typedef enum {
+    /* Keep in sync with VIR_ENUM_IMPL in node_device_conf.c */
+    VIR_NODE_DEV_MDEV_START_MANUAL,
+    VIR_NODE_DEV_MDEV_START_AUTO,
+
+    VIR_NODE_DEV_MDEV_START_LAST
+} virNodeDevMdevStartType;
+
+VIR_ENUM_DECL(virNodeDevMdevStart);
+
+
 typedef struct _virNodeDevCapSystemHardware virNodeDevCapSystemHardware;
 struct _virNodeDevCapSystemHardware {
     char *vendor_name;
@@ -151,6 +162,7 @@ struct _virNodeDevCapMdev {
     char *type;
     unsigned int iommuGroupNumber;
     char *uuid;
+    virNodeDevMdevStartType start;
     virMediatedDeviceAttr **attributes;
     size_t nattributes;
 };
index b7bbe46dc7c363a18325ac9831a4bd34849cd7e5..6fbdee41243b6e4cf0d4d692f734c4afe95117a1 100644 (file)
@@ -846,6 +846,8 @@ virNodeDeviceGetSCSIHostCaps;
 virNodeDeviceGetSCSITargetCaps;
 virNodeDeviceGetWWNs;
 virNodeDeviceUpdateCaps;
+virNodeDevMdevStartTypeFromString;
+virNodeDevMdevStartTypeToString;
 
 
 # conf/node_device_event.h
index 8a0a2c3847caa486ab061e43c5cc1ca771f5fdd4..a9f605715b79022c7ed247edda46df75bf197ce0 100644 (file)
@@ -615,7 +615,8 @@ nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, char **buf)
     if (virJSONValueObjectAppendString(json, "mdev_type", mdev->type) < 0)
         return -1;
 
-    if (virJSONValueObjectAppendString(json, "start", "manual") < 0)
+    if (virJSONValueObjectAppendString(json, "start",
+                                       virNodeDevMdevStartTypeToString(mdev->start)) < 0)
         return -1;
 
     if (mdev->attributes) {
@@ -1014,6 +1015,8 @@ nodeDeviceParseMdevctlChildDevice(const char *parent,
     mdev->uuid = g_strdup(uuid);
     mdev->type =
         g_strdup(virJSONValueObjectGetString(props, "mdev_type"));
+    mdev->start =
+        virNodeDevMdevStartTypeFromString(virJSONValueObjectGetString(props, "start"));
 
     attrs = virJSONValueObjectGet(props, "attrs");
 
@@ -1683,6 +1686,8 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst,
         dstmdev->uuid = g_strdup(srcmdev->uuid);
     }
 
+    dstmdev->start = srcmdev->start;
+
     if (virMediatedDeviceAttrsCopy(dstmdev, srcmdev))
         ret = true;
 
index cf7e96625605f88b6d2fe0fd1086e92c553a7988..83a3010455633a5dd52cf2b229e9719e9666efc1 100644 (file)
@@ -4,6 +4,7 @@
   <capability type='mdev'>
     <type id='i915-GVTg_V5_4'/>
     <uuid>200f228a-c80a-4d50-bfb7-f5a0e4e34045</uuid>
+    <start type='manual'/>
     <iommuGroup number='0'/>
   </capability>
 </device>
@@ -13,6 +14,7 @@
   <capability type='mdev'>
     <type id='i915-GVTg_V5_4'/>
     <uuid>de807ffc-1923-4d5f-b6c9-b20ecebc6d4b</uuid>
+    <start type='auto'/>
     <iommuGroup number='0'/>
   </capability>
 </device>
@@ -22,6 +24,7 @@
   <capability type='mdev'>
     <type id='i915-GVTg_V5_8'/>
     <uuid>435722ea-5f43-468a-874f-da34f1217f13</uuid>
+    <start type='manual'/>
     <iommuGroup number='0'/>
     <attr name='testattr' value='42'/>
   </capability>
@@ -32,6 +35,7 @@
   <capability type='mdev'>
     <type id='vfio_ap-passthrough'/>
     <uuid>783e6dbb-ea0e-411f-94e2-717eaad438bf</uuid>
+    <start type='manual'/>
     <iommuGroup number='0'/>
     <attr name='assign_adapter' value='5'/>
     <attr name='assign_adapter' value='6'/>
deleted file mode 120000 (symlink)
index cbc883e48cab1110a92d8e8255656aa46aa9febd..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1 +0,0 @@
-../nodedevschemadata/mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml
\ No newline at end of file
new file mode 100644 (file)
index 0000000000000000000000000000000000000000..30dda60e875d11aeba584c225c9c4adba1ffe54d
--- /dev/null
@@ -0,0 +1,9 @@
+<device>
+  <name>mdev_3627463d_b7f0_4fea_b468_f1da537d301b</name>
+  <parent>computer</parent>
+  <capability type='mdev'>
+    <type id='mtty-1'/>
+    <start type='manual'/>
+    <iommuGroup number='12'/>
+  </capability>
+</device>
deleted file mode 120000 (symlink)
index 238bfb4dfd747e1d9d0a0bcd5e63ee958eb28f78..0000000000000000000000000000000000000000
+++ /dev/null
@@ -1 +0,0 @@
-../nodedevschemadata/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad.xml
\ No newline at end of file
new file mode 100644 (file)
index 0000000000000000000000000000000000000000..1988ffa679d11de76ae21478fb9a78009e1ac9a9
--- /dev/null
@@ -0,0 +1,10 @@
+<device>
+  <name>mdev_ee0b88c4-f554-4dc1-809d-b2a01e8e48ad</name>
+  <path>/sys/devices/vfio_ap/matrix/mdev_ee0b88c4-f554-4dc1-809d-b2a01e8e48ad</path>
+  <parent>ap_matrix</parent>
+  <capability type='mdev'>
+    <type id='vfio_ap-passthrough'/>
+    <start type='manual'/>
+    <iommuGroup number='0'/>
+  </capability>
+</device>