Re: [libvirt PATCH v2 10/16] api: add virNodeDeviceDefineXML()

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

 



On Tue, Aug 18, 2020 at 09:48:00AM -0500, Jonathon Jongsma wrote:
> With mediated devices, we can now define persistent node devices that
> can be started and stopped. In order to take advantage of this, we need
> an API to define new node devices.
>
> Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
> ---
...

> +virNodeDevicePtr
> +nodeDeviceDefineXML(virConnectPtr conn,
> +                    const char *xmlDesc,
> +                    unsigned int flags)
> +{
> +    g_autoptr(virNodeDeviceDef) def = NULL;
> +    virNodeDevicePtr device = NULL;
> +    const char *virt_type = NULL;
> +
> +    virCheckFlags(0, NULL);
> +
> +    if (nodeDeviceWaitInit() < 0)
> +        return NULL;
> +
> +    virt_type  = virConnectGetType(conn);
> +
> +    if (!(def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt_type)))
> +        return NULL;
> +
> +    if (virNodeDeviceDefineXMLEnsureACL(conn, def) < 0)
> +        return NULL;
> +
> +    if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) {
> +        g_autofree char *uuid = NULL;
> +
> +        if (!def->parent) {
> +            virReportError(VIR_ERR_XML_ERROR, "%s",
> +                           _("cannot define a mediated device without a parent"));
> +            return NULL;
> +        }
> +
> +        if (virMdevctlDefine(def, &uuid) < 0) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                           _("Unable to define mediated device"));
> +            return NULL;
> +        }
> +
> +        def->caps->data.mdev.uuid = g_strdup(uuid);
> +        mdevGenerateDeviceName(def);
> +        device = nodeDeviceFindNewMediatedDevice(conn, uuid);
> +    } else {
> +        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> +                       _("Unsupported device type"));

Per our coding style guideline, can we flip this condition and keep the shorter
block first?

Erik




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

  Powered by Linux