1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

nodedev: look up mdevs by UUID and parent

Since UUID is not guaranteed to be unique by mdevctl, we may have more
than one nodedev with the same UUID. Therefore, we need to disambiguate
when looking up mdevs by specifying the UUID and parent address, which
mdevctl guarantees to be a unique combination.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jonathon Jongsma 2021-07-16 14:33:50 -05:00
parent 3bd8181bc5
commit fcae7a44c3
3 changed files with 33 additions and 13 deletions

View File

@ -401,13 +401,21 @@ virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjList *devs,
&data);
}
typedef struct _FindMediatedDeviceData FindMediatedDeviceData;
struct _FindMediatedDeviceData {
const char *uuid;
const char *parent_addr;
};
static int
virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(const void *payload,
const char *name G_GNUC_UNUSED,
const void *opaque)
{
virNodeDeviceObj *obj = (virNodeDeviceObj *) payload;
const char *uuid = (const char *) opaque;
const FindMediatedDeviceData* data = opaque;
virNodeDevCapsDef *cap;
int want = 0;
@ -415,7 +423,8 @@ virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(const void *payload,
for (cap = obj->def->caps; cap != NULL; cap = cap->next) {
if (cap->data.type == VIR_NODE_DEV_CAP_MDEV) {
if (STREQ(cap->data.mdev.uuid, uuid)) {
if (STREQ(cap->data.mdev.uuid, data->uuid) &&
STREQ(cap->data.mdev.parent_addr, data->parent_addr)) {
want = 1;
break;
}
@ -429,11 +438,13 @@ virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(const void *payload,
virNodeDeviceObj *
virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjList *devs,
const char *uuid)
const char *uuid,
const char *parent_addr)
{
const FindMediatedDeviceData data = {uuid, parent_addr};
return virNodeDeviceObjListSearch(devs,
virNodeDeviceObjListFindMediatedDeviceByUUIDCallback,
uuid);
&data);
}
static void

View File

@ -122,7 +122,8 @@ virNodeDeviceObjSetSkipUpdateCaps(virNodeDeviceObj *obj,
bool skipUpdateCaps);
virNodeDeviceObj *
virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjList *devs,
const char *uuid);
const char *uuid,
const char *parent_addr);
bool
virNodeDeviceObjIsActive(virNodeDeviceObj *obj);

View File

@ -321,6 +321,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
static virNodeDevicePtr
nodeDeviceLookupMediatedDeviceByUUID(virConnectPtr conn,
const char *uuid,
const char *parent_addr,
unsigned int flags)
{
virNodeDeviceObj *obj = NULL;
@ -330,7 +331,7 @@ nodeDeviceLookupMediatedDeviceByUUID(virConnectPtr conn,
virCheckFlags(0, NULL);
if (!(obj = virNodeDeviceObjListFindMediatedDeviceByUUID(driver->devs,
uuid)))
uuid, parent_addr)))
return NULL;
def = virNodeDeviceObjGetDef(obj);
@ -542,23 +543,29 @@ nodeDeviceFindNewDevice(virConnectPtr conn,
}
typedef struct {
const char *uuid;
const char *parent_addr;
} NewMediatedDeviceData;
static virNodeDevicePtr
nodeDeviceFindNewMediatedDeviceFunc(virConnectPtr conn,
const void *opaque)
{
const char *uuid = opaque;
const NewMediatedDeviceData *data = opaque;
return nodeDeviceLookupMediatedDeviceByUUID(conn, uuid, 0);
return nodeDeviceLookupMediatedDeviceByUUID(conn, data->uuid, data->parent_addr, 0);
}
static virNodeDevicePtr
nodeDeviceFindNewMediatedDevice(virConnectPtr conn,
const char *mdev_uuid)
const char *mdev_uuid,
const char *parent_addr)
{
return nodeDeviceFindNewDevice(conn,
nodeDeviceFindNewMediatedDeviceFunc,
mdev_uuid);
NewMediatedDeviceData data = {mdev_uuid, parent_addr};
return nodeDeviceFindNewDevice(conn, nodeDeviceFindNewMediatedDeviceFunc,
&data);
}
@ -867,7 +874,8 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn,
def->caps->data.mdev.uuid = g_steal_pointer(&uuid);
}
return nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.uuid);
return nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.uuid,
def->caps->data.mdev.parent_addr);
}