nodedev: add ability to specify UUID for new mdevs

Use the new <uuid> element in the mdev caps to define and start devices
with a specific UUID.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Jonathon Jongsma 2021-01-29 16:24:50 -06:00
parent 07666e292e
commit 62a73c525c
4 changed files with 21 additions and 5 deletions

View File

@ -729,6 +729,10 @@ nodeDeviceGetMdevctlDefineStartCommand(virNodeDeviceDef *def,
NULL);
virCommandSetInputBuffer(cmd, json);
if (def->caps->data.mdev.uuid)
virCommandAddArgPair(cmd, "--uuid", def->caps->data.mdev.uuid);
virCommandSetOutputBuffer(cmd, uuid_out);
virCommandSetErrorBuffer(cmd, errmsg);
@ -818,7 +822,12 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn,
return NULL;
}
return nodeDeviceFindNewMediatedDevice(conn, uuid);
if (uuid && uuid[0]) {
g_free(def->caps->data.mdev.uuid);
def->caps->data.mdev.uuid = g_steal_pointer(&uuid);
}
return nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.uuid);
}
@ -1235,9 +1244,13 @@ nodeDeviceDefineXML(virConnect *conn,
return NULL;
}
def->caps->data.mdev.uuid = g_strdup(uuid);
if (uuid && uuid[0]) {
g_free(def->caps->data.mdev.uuid);
def->caps->data.mdev.uuid = g_steal_pointer(&uuid);
}
mdevGenerateDeviceName(def);
device = nodeDeviceFindNewMediatedDevice(conn, uuid);
device = nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.uuid);
return device;
}

View File

@ -1 +1,2 @@
$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin
$MDEVCTL_BINARY$ define -p 0000:00:02.0 --jsonfile /dev/stdin \
--uuid=d069d019-36ea-4111-8f0a-8c9a70e21366

View File

@ -1 +1,2 @@
$MDEVCTL_BINARY$ start -p 0000:00:02.0 --jsonfile /dev/stdin
$MDEVCTL_BINARY$ start -p 0000:00:02.0 --jsonfile /dev/stdin \
--uuid=d069d019-36ea-4111-8f0a-8c9a70e21366

View File

@ -3,5 +3,6 @@
<parent>pci_0000_00_02_0</parent>
<capability type='mdev'>
<type id='i915-GVTg_V5_8'/>
<uuid>d069d019-36ea-4111-8f0a-8c9a70e21366</uuid>
</capability>
</device>