From: Boris Fiuczynski Date: Fri, 14 May 2021 21:28:59 +0000 (-0500) Subject: nodedev: support auto-start property for mdevs X-Git-Tag: v7.4.0-rc1~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42a558549935336cbdb7cbfe8b239ffb0e3442e3;p=thirdparty%2Flibvirt.git nodedev: support auto-start property for mdevs 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 Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index 3b3c3105d4..9a505f0fe9 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -388,6 +388,16 @@
This element represents the UUID of the mediated device.
+
start
+
+ This element represents the start policy for the device. It + has a required attribute type, which can have a + value of auto or manual. Mediated + devices with an auto 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. +
ccw
diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 777227c38a..660cbda3be 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -622,6 +622,17 @@ + + + + + manual + auto + + + + + diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 332b12f997..4e2b37c612 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -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, "\n", data->mdev.type); virBufferEscapeString(buf, "%s\n", data->mdev.uuid); + virBufferEscapeString(buf, "\n", + virNodeDevMdevStartTypeToString(data->mdev.start)); virBufferAsprintf(buf, "\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)", diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index a60562e4fe..1a31133c4c 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -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; }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b7bbe46dc7..6fbdee4124 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -846,6 +846,8 @@ virNodeDeviceGetSCSIHostCaps; virNodeDeviceGetSCSITargetCaps; virNodeDeviceGetWWNs; virNodeDeviceUpdateCaps; +virNodeDevMdevStartTypeFromString; +virNodeDevMdevStartTypeToString; # conf/node_device_event.h diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 8a0a2c3847..a9f605715b 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -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; diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml b/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml index cf7e966256..83a3010455 100644 --- a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml @@ -4,6 +4,7 @@ 200f228a-c80a-4d50-bfb7-f5a0e4e34045 + @@ -13,6 +14,7 @@ de807ffc-1923-4d5f-b6c9-b20ecebc6d4b + @@ -22,6 +24,7 @@ 435722ea-5f43-468a-874f-da34f1217f13 + @@ -32,6 +35,7 @@ 783e6dbb-ea0e-411f-94e2-717eaad438bf + diff --git a/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml b/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml deleted file mode 120000 index cbc883e48c..0000000000 --- a/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml +++ /dev/null @@ -1 +0,0 @@ -../nodedevschemadata/mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml \ No newline at end of file diff --git a/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml b/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml new file mode 100644 index 0000000000..30dda60e87 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_3627463d_b7f0_4fea_b468_f1da537d301b.xml @@ -0,0 +1,9 @@ + + mdev_3627463d_b7f0_4fea_b468_f1da537d301b + computer + + + + + + diff --git a/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad.xml b/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad.xml deleted file mode 120000 index 238bfb4dfd..0000000000 --- a/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad.xml +++ /dev/null @@ -1 +0,0 @@ -../nodedevschemadata/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad.xml \ No newline at end of file diff --git a/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad.xml b/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad.xml new file mode 100644 index 0000000000..1988ffa679 --- /dev/null +++ b/tests/nodedevxml2xmlout/mdev_ee0b88c4_f554_4dc1_809d_b2a01e8e48ad.xml @@ -0,0 +1,10 @@ + + mdev_ee0b88c4-f554-4dc1-809d-b2a01e8e48ad + /sys/devices/vfio_ap/matrix/mdev_ee0b88c4-f554-4dc1-809d-b2a01e8e48ad + ap_matrix + + + + + +