[libvirt PATCH v2 10/16] api: add virNodeDeviceDefineXML()
Erik Skultety
eskultet at redhat.com
Tue Aug 25 11:39:20 UTC 2020
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 at redhat.com>
> ---
...
> +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
More information about the libvir-list
mailing list