From aa6aa624adb0dda920be1a1868f32cb421962931 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Sat, 18 Feb 2017 08:25:07 -0500 Subject: [PATCH] nodedev: Introduce virNodeDeviceGetParentName Create a function which takes a node device "name" entry to lookup and returns a string containing the parent name for the node device. --- src/conf/node_device_conf.c | 30 ++++++++++++++++++++++++++++++ src/conf/node_device_conf.h | 3 +++ src/libvirt_private.syms | 1 + 3 files changed, 34 insertions(+) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index c15c917a24..bc976d0e47 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2288,3 +2288,33 @@ virNodeDeviceObjListExport(virConnectPtr conn, VIR_FREE(tmp_devices); return ret; } + + +/* virNodeDeviceGetParentName + * @conn: Connection pointer + * @nodedev_name: Node device to lookup + * + * Lookup the node device by name and return the parent name + * + * Returns parent name on success, caller is responsible for freeing; + * otherwise, returns NULL on failure + */ +char * +virNodeDeviceGetParentName(virConnectPtr conn, + const char *nodedev_name) +{ + virNodeDevicePtr device = NULL; + char *parent; + + if (!(device = virNodeDeviceLookupByName(conn, nodedev_name))) { + virReportError(VIR_ERR_XML_ERROR, + _("Cannot find '%s' in node device database"), + nodedev_name); + return NULL; + } + + ignore_value(VIR_STRDUP(parent, virNodeDeviceGetParent(device))); + virObjectUnref(device); + + return parent; +} diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 40e930a280..6c43546926 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -352,4 +352,7 @@ int virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjListFilter filter, unsigned int flags); +char *virNodeDeviceGetParentName(virConnectPtr conn, + const char *nodedev_name); + #endif /* __VIR_NODE_DEVICE_CONF_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d721c12d3c..9ad0b0a68e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -706,6 +706,7 @@ virNodeDeviceFindVportParentHost; virNodeDeviceGetParentHost; virNodeDeviceGetParentHostByFabricWWN; virNodeDeviceGetParentHostByWWNs; +virNodeDeviceGetParentName; virNodeDeviceGetWWNs; virNodeDeviceHasCap; virNodeDeviceObjListExport; -- GitLab