[PATCH libvirt v2 03/11] nodedev: detect AP queues

Jonathon Jongsma jjongsma at redhat.com
Thu Nov 12 17:01:06 UTC 2020


On Thu, 12 Nov 2020 13:15:11 +0100
Shalini Chellathurai Saroja <shalini at linux.ibm.com> wrote:

> Each AP card device can support upto 256 AP queues.  AP queues are
> also detected by udev, so add support for libvirt nodedev driver.
> 
> Signed-off-by: Farhan Ali <alifm at linux.ibm.com>
> Signed-off-by: Shalini Chellathurai Saroja <shalini at linux.ibm.com>
> Reviewed-by: Bjoern Walk <bwalk at linux.ibm.com>
> Reviewed-by: Boris Fiuczynski <fiuczy at linux.ibm.com>
> ---
>  docs/formatnode.html.in            | 11 ++++++
>  docs/schemas/nodedev.rng           | 25 +++++++++++++
>  src/conf/node_device_conf.c        | 59
> ++++++++++++++++++++++++++++++ src/conf/node_device_conf.h        |
> 9 +++++ src/conf/virnodedeviceobj.c        |  1 +
>  src/node_device/node_device_udev.c | 27 ++++++++++++++
>  tools/virsh-nodedev.c              |  1 +
>  7 files changed, 133 insertions(+)
> 
> diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in
> index d10a79e3..45281363 100644
> --- a/docs/formatnode.html.in
> +++ b/docs/formatnode.html.in
> @@ -439,6 +439,17 @@
>                <dd>AP Card identifier.</dd>
>              </dl>
>            </dd>
> +          <dt><code>ap_queue</code></dt>
> +          <dd>Describes the AP Queue on a S390 host. An AP Queue is
> +              identified by it's ap-adapter and ap-domain id.

"it's" should be "its". Is it worth a very brief description of what an
AP queue actually is?

> Sub-elements include:
> +            <dl>
> +              <dt><code>ap-adapter</code></dt>
> +              <dd>The ap-adapter of an AP Queue identifies AP Card
> to which
> +                  this queue belongs.</dd>
> +              <dt><code>ap-domain</code></dt>
> +              <dd>AP Queue identifier.</dd>
> +            </dl>
> +          </dd>
>          </dl>
>        </dd>
>      </dl>
> diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng
> index d02e5377..51cb8854 100644
> --- a/docs/schemas/nodedev.rng
> +++ b/docs/schemas/nodedev.rng
> @@ -88,6 +88,7 @@
>          <ref name="capcssdev"/>
>          <ref name="capvdpa"/>
>          <ref name="capapcard"/>
> +        <ref name="capapqueue"/>
>        </choice>
>      </element>
>    </define>
> @@ -678,6 +679,18 @@
>      </element>
>    </define>
>  
> +  <define name='capapqueue'>
> +    <attribute name='type'>
> +      <value>ap_queue</value>
> +    </attribute>
> +    <element name='ap-adapter'>
> +      <ref name='apAdapterRange'/>
> +    </element>
> +    <element name='ap-domain'>
> +      <ref name='apDomainRange'/>
> +    </element>
> +  </define>

Let's use double quotes to keep the file consistent.

> +
>    <define name='address'>
>      <element name='address'>
>        <attribute name='domain'><ref name='hexuint'/></attribute>
> @@ -738,4 +751,16 @@
>      </choice>
>    </define>
>  
> +  <define name="apDomainRange">
> +    <choice>
> +      <data type="string">
> +        <param name="pattern">(0x)?[0-9a-fA-F]{1,4}</param>
> +      </data>
> +      <data type="int">
> +        <param name="minInclusive">0</param>
> +        <param name="maxInclusive">255</param>

Is 255 correct here? the hex pattern above implies that it is a 16
bit value, but here you're limiting it to 255. If it is a 16 bit value,
can we just use the already-defined 'uint16' type from basictypes.rng?

> +      </data>
> +    </choice>
> +  </define>
> +
>  </grammar>
> diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
> index 5d7a23cb..fa3b823f 100644
> --- a/src/conf/node_device_conf.c
> +++ b/src/conf/node_device_conf.c
> @@ -68,6 +68,7 @@ VIR_ENUM_IMPL(virNodeDevCap,
>                "css",
>                "vdpa",
>                "ap_card",
> +              "ap_queue",
>  );
>  
>  VIR_ENUM_IMPL(virNodeDevNetCap,
> @@ -655,6 +656,12 @@ virNodeDeviceDefFormat(const virNodeDeviceDef
> *def) virBufferAsprintf(&buf, "<ap-adapter>0x%02x</ap-adapter>\n",
>                                data->ap_card.ap_adapter);
>              break;
> +        case VIR_NODE_DEV_CAP_AP_QUEUE:
> +            virBufferAsprintf(&buf,
> "<ap-adapter>0x%02x</ap-adapter>\n",
> +                              data->ap_queue.ap_adapter);
> +            virBufferAsprintf(&buf,
> "<ap-domain>0x%04x</ap-domain>\n",
> +                              data->ap_queue.ap_domain);
> +            break;
>          case VIR_NODE_DEV_CAP_MDEV_TYPES:
>          case VIR_NODE_DEV_CAP_FC_HOST:
>          case VIR_NODE_DEV_CAP_VPORTS:
> @@ -976,6 +983,52 @@ virNodeDevCapAPCardParseXML(xmlXPathContextPtr
> ctxt, }
>  
>  
> +static int
> +virNodeDevCapAPQueueParseXML(xmlXPathContextPtr ctxt,
> +                            virNodeDeviceDefPtr def,
> +                            xmlNodePtr node,
> +                            virNodeDevCapAPQueuePtr ap_queue)
> +{
> +    xmlNodePtr orig;
> +    int ret = -1;
> +    g_autofree char *adapter = NULL, *dom = NULL;
> +
> +    orig = ctxt->node;
> +    ctxt->node = node;
> +
> +   if (!(adapter = virXPathString("string(./ap-adapter[1])", ctxt)))
> {
> +        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                       _("missing ap-adapter value for '%s'"),
> def->name);
> +        return -1;
> +    }
> +
> +    if (virStrToLong_uip(adapter, NULL, 0, &ap_queue->ap_adapter) <
> 0) {
> +        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                       _("invalid ap-adapter value '%s' for '%s'"),
> +                       adapter, def->name);
> +        goto out;
> +    }
> +
> +    if (!(dom = virXPathString("string(./ap-domain[1])", ctxt))) {
> +        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                       _("missing ap-domain value for '%s'"),
> def->name);
> +        goto out;
> +    }
> +
> +    if (virStrToLong_uip(dom, NULL, 0, &ap_queue->ap_domain) < 0) {
> +        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                       _("invalid ap-domain value '%s' for '%s'"),
> +                       dom, def->name);
> +        goto out;
> +    }
> +
> +    ret = 0;
> + out:
> +    ctxt->node = orig;
> +    return ret;
> +}
> +
> +
>  static int
>  virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
>                               virNodeDeviceDefPtr def,
> @@ -2018,6 +2071,10 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr
> ctxt, ret = virNodeDevCapAPCardParseXML(ctxt, def, node,
>                                            &caps->data.ap_card);
>          break;
> +    case VIR_NODE_DEV_CAP_AP_QUEUE:
> +        ret = virNodeDevCapAPQueueParseXML(ctxt, def, node,
> +                                           &caps->data.ap_queue);
> +        break;
>      case VIR_NODE_DEV_CAP_MDEV_TYPES:
>      case VIR_NODE_DEV_CAP_FC_HOST:
>      case VIR_NODE_DEV_CAP_VPORTS:
> @@ -2346,6 +2403,7 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
>      case VIR_NODE_DEV_CAP_CCW_DEV:
>      case VIR_NODE_DEV_CAP_VDPA:
>      case VIR_NODE_DEV_CAP_AP_CARD:
> +    case VIR_NODE_DEV_CAP_AP_QUEUE:
>      case VIR_NODE_DEV_CAP_LAST:
>          /* This case is here to shutup the compiler */
>          break;
> @@ -2406,6 +2464,7 @@ virNodeDeviceUpdateCaps(virNodeDeviceDefPtr def)
>          case VIR_NODE_DEV_CAP_CCW_DEV:
>          case VIR_NODE_DEV_CAP_VDPA:
>          case VIR_NODE_DEV_CAP_AP_CARD:
> +        case VIR_NODE_DEV_CAP_AP_QUEUE:
>          case VIR_NODE_DEV_CAP_LAST:
>              break;
>          }
> diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
> index f86f880c..27cb0004 100644
> --- a/src/conf/node_device_conf.h
> +++ b/src/conf/node_device_conf.h
> @@ -67,6 +67,7 @@ typedef enum {
>      VIR_NODE_DEV_CAP_CSS_DEV,           /* s390 channel subsystem
> device */ VIR_NODE_DEV_CAP_VDPA,              /* vDPA device */
>      VIR_NODE_DEV_CAP_AP_CARD,           /* s390 AP Card device */
> +    VIR_NODE_DEV_CAP_AP_QUEUE,          /* s390 AP Queue */
>  
>      VIR_NODE_DEV_CAP_LAST
>  } virNodeDevCapType;
> @@ -296,6 +297,13 @@ struct _virNodeDevCapAPCard {
>      unsigned int ap_adapter;
>  };
>  
> +typedef struct _virNodeDevCapAPQueue virNodeDevCapAPQueue;
> +typedef virNodeDevCapAPQueue *virNodeDevCapAPQueuePtr;
> +struct _virNodeDevCapAPQueue {
> +    unsigned int ap_adapter;
> +    unsigned int ap_domain;
> +};
> +
>  typedef struct _virNodeDevCapData virNodeDevCapData;
>  typedef virNodeDevCapData *virNodeDevCapDataPtr;
>  struct _virNodeDevCapData {
> @@ -316,6 +324,7 @@ struct _virNodeDevCapData {
>          virNodeDevCapCCW ccw_dev;
>          virNodeDevCapVDPA vdpa;
>          virNodeDevCapAPCard ap_card;
> +        virNodeDevCapAPQueue ap_queue;
>      };
>  };
>  
> diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
> index 0aa59289..8b4302d7 100644
> --- a/src/conf/virnodedeviceobj.c
> +++ b/src/conf/virnodedeviceobj.c
> @@ -718,6 +718,7 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj
> *obj, case VIR_NODE_DEV_CAP_CCW_DEV:
>          case VIR_NODE_DEV_CAP_VDPA:
>          case VIR_NODE_DEV_CAP_AP_CARD:
> +        case VIR_NODE_DEV_CAP_AP_QUEUE:
>          case VIR_NODE_DEV_CAP_LAST:
>              break;
>          }
> diff --git a/src/node_device/node_device_udev.c
> b/src/node_device/node_device_udev.c index b4eb4553..6bbff571 100644
> --- a/src/node_device/node_device_udev.c
> +++ b/src/node_device/node_device_udev.c
> @@ -1218,6 +1218,29 @@ udevProcessAPCard(struct udev_device *device,
>  }
>  
>  
> +static int
> +udevProcessAPQueue(struct udev_device *device,
> +                   virNodeDeviceDefPtr def)
> +{
> +    char *c;
> +    virNodeDevCapDataPtr data = &def->caps->data;
> +


In the previous patch, you added a comment explaining the format of the
sysfs path. I found that helpful. Without knowing the format, it's
a bit difficult to judge whether this code below is correct. 

> +    if ((c = strrchr(def->sysfs_path, '/')) == NULL ||
> +        virStrToLong_ui(c + 1, &c, 16, &data->ap_queue.ap_adapter) <
> 0 ||
> +        virStrToLong_ui(c + 1, &c, 16, &data->ap_queue.ap_domain) <
> 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("failed to parse the AP Queue from sysfs
> path: '%s'"),
> +                       def->sysfs_path);
> +        return -1;
> +    }
> +
> +    if (udevGenerateDeviceName(device, def, NULL) != 0)
> +        return -1;
> +
> +    return 0;
> +}
> +
> +
>  static int
>  udevGetDeviceNodes(struct udev_device *device,
>                     virNodeDeviceDefPtr def)
> @@ -1274,6 +1297,8 @@ udevGetDeviceType(struct udev_device *device,
>              *type = VIR_NODE_DEV_CAP_DRM;
>          else if (STREQ(devtype, "ap_card"))
>              *type = VIR_NODE_DEV_CAP_AP_CARD;
> +        else if (STREQ(devtype, "ap_queue"))
> +            *type = VIR_NODE_DEV_CAP_AP_QUEUE;
>      } else {
>          /* PCI devices don't set the DEVTYPE property. */
>          if (udevHasDeviceProperty(device, "PCI_CLASS"))
> @@ -1351,6 +1376,8 @@ udevGetDeviceDetails(struct udev_device *device,
>          return udevProcessVDPA(device, def);
>      case VIR_NODE_DEV_CAP_AP_CARD:
>          return udevProcessAPCard(device, def);
> +    case VIR_NODE_DEV_CAP_AP_QUEUE:
> +        return udevProcessAPQueue(device, def);
>      case VIR_NODE_DEV_CAP_MDEV_TYPES:
>      case VIR_NODE_DEV_CAP_SYSTEM:
>      case VIR_NODE_DEV_CAP_FC_HOST:
> diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
> index 32c12553..81752e85 100644
> --- a/tools/virsh-nodedev.c
> +++ b/tools/virsh-nodedev.c
> @@ -468,6 +468,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd
> *cmd G_GNUC_UNUSED) flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_VDPA;
>              break;
>          case VIR_NODE_DEV_CAP_AP_CARD:
> +        case VIR_NODE_DEV_CAP_AP_QUEUE:
>          case VIR_NODE_DEV_CAP_LAST:
>              break;
>          }




More information about the libvir-list mailing list