[libvirt] [PATCH 0/3] Split out node device object into its own module

Feedback from the initial pass at RFC for making a common pool object was that it got really confusing trying to manage the multitude of changes. See patch 3 of the series: http://www.redhat.com/archives/libvir-list/2017-February/msg00519.html So while I figure out what it'll take to make a better object framework, I figure I could start splitting out things a bit to make future work a bit easier to understand. Also rather than trying to do them all in one massive series, I can do shorter series contained to each of the driver conf's. Besides let's figure out whether all the thoughts and ideas are good. I would think moving to virnodedeviceobj wouldn't be an issue (other than needing to deal with backports). However, I'm sure there could be some "alternate opinions" over whether to make static functions not start with vir[DriverSubsystem] and rather go with driverSubsystem. Changing the API's to use the Obj is mainly a consistency thing. Let's see what falls out of this before I start queuing up other ones as it's a lot of rote work! John Ferlan (3): conf: Introduce virnodedeviceobj conf: Clean up nodedev code conf: Use consistent function name prefixes for virnodedeviceobj po/POTFILES.in | 1 + src/Makefile.am | 3 +- src/conf/node_device_conf.c | 981 +++++++++-------------------------- src/conf/node_device_conf.h | 50 -- src/conf/virnodedeviceobj.c | 558 ++++++++++++++++++++ src/conf/virnodedeviceobj.h | 78 +++ src/libvirt_private.syms | 23 +- src/node_device/node_device_driver.c | 24 +- src/node_device/node_device_driver.h | 2 +- src/node_device/node_device_hal.c | 10 +- src/node_device/node_device_udev.c | 12 +- src/test/test_driver.c | 29 +- 12 files changed, 940 insertions(+), 831 deletions(-) create mode 100644 src/conf/virnodedeviceobj.c create mode 100644 src/conf/virnodedeviceobj.h -- 2.9.3

Move all the NodeDeviceObj API's into their own module virnodedeviceobj from the node_device_conf Purely code motion at this point, plus adjustments to cleanly build. Signed-off-by: John Ferlan <jferlan@redhat.com> --- po/POTFILES.in | 1 + src/Makefile.am | 3 +- src/conf/node_device_conf.c | 505 -------------------------------- src/conf/node_device_conf.h | 50 ---- src/conf/virnodedeviceobj.c | 542 +++++++++++++++++++++++++++++++++++ src/conf/virnodedeviceobj.h | 78 +++++ src/libvirt_private.syms | 23 +- src/node_device/node_device_driver.h | 2 +- src/test/test_driver.c | 1 + 9 files changed, 638 insertions(+), 567 deletions(-) create mode 100644 src/conf/virnodedeviceobj.c create mode 100644 src/conf/virnodedeviceobj.h diff --git a/po/POTFILES.in b/po/POTFILES.in index 9f66697..7c7f530 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -42,6 +42,7 @@ src/conf/snapshot_conf.c src/conf/storage_conf.c src/conf/virchrdev.c src/conf/virdomainobjlist.c +src/conf/virnodedeviceobj.c src/conf/virsecretobj.c src/cpu/cpu.c src/cpu/cpu_arm.c diff --git a/src/Makefile.am b/src/Makefile.am index a85cd0d..7d42eac 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -390,7 +390,8 @@ SECRET_CONF_SOURCES = \ # Network driver generic impl APIs NODE_DEVICE_CONF_SOURCES = \ - conf/node_device_conf.c conf/node_device_conf.h + conf/node_device_conf.c conf/node_device_conf.h \ + conf/virnodedeviceobj.c conf/virnodedeviceobj.h CPU_CONF_SOURCES = \ conf/cpu_conf.c conf/cpu_conf.h diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 43e23fc..bc36527 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -85,170 +85,6 @@ virNodeDevCapsDefParseString(const char *xpath, return 0; } -int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) -{ - virNodeDevCapsDefPtr caps = dev->def->caps; - const char *fc_host_cap = - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_FC_HOST); - const char *vports_cap = - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); - - while (caps) { - if (STREQ(cap, virNodeDevCapTypeToString(caps->data.type))) - return 1; - else if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) - if ((STREQ(cap, fc_host_cap) && - (caps->data.scsi_host.flags & - VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) || - (STREQ(cap, vports_cap) && - (caps->data.scsi_host.flags & - VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS))) - return 1; - caps = caps->next; - } - return 0; -} - - -/* virNodeDeviceFindFCCapDef: - * @dev: Pointer to current device - * - * Search the device object 'caps' array for fc_host capability. - * - * Returns: - * Pointer to the caps or NULL if not found - */ -static virNodeDevCapsDefPtr -virNodeDeviceFindFCCapDef(const virNodeDeviceObj *dev) -{ - virNodeDevCapsDefPtr caps = dev->def->caps; - - while (caps) { - if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST && - (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) - break; - - caps = caps->next; - } - return caps; -} - - -/* virNodeDeviceFindVPORTCapDef: - * @dev: Pointer to current device - * - * Search the device object 'caps' array for vport_ops capability. - * - * Returns: - * Pointer to the caps or NULL if not found - */ -static virNodeDevCapsDefPtr -virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *dev) -{ - virNodeDevCapsDefPtr caps = dev->def->caps; - - while (caps) { - if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST && - (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)) - break; - - caps = caps->next; - } - return caps; -} - - -virNodeDeviceObjPtr -virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) -{ - size_t i; - - for (i = 0; i < devs->count; i++) { - virNodeDeviceObjLock(devs->objs[i]); - if ((devs->objs[i]->def->sysfs_path != NULL) && - (STREQ(devs->objs[i]->def->sysfs_path, sysfs_path))) { - return devs->objs[i]; - } - virNodeDeviceObjUnlock(devs->objs[i]); - } - - return NULL; -} - - -virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, - const char *name) -{ - size_t i; - - for (i = 0; i < devs->count; i++) { - virNodeDeviceObjLock(devs->objs[i]); - if (STREQ(devs->objs[i]->def->name, name)) - return devs->objs[i]; - virNodeDeviceObjUnlock(devs->objs[i]); - } - - return NULL; -} - - -static virNodeDeviceObjPtr -virNodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, - const char *parent_wwnn, - const char *parent_wwpn) -{ - size_t i; - - for (i = 0; i < devs->count; i++) { - virNodeDevCapsDefPtr cap; - virNodeDeviceObjLock(devs->objs[i]); - if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) && - STREQ_NULLABLE(cap->data.scsi_host.wwnn, parent_wwnn) && - STREQ_NULLABLE(cap->data.scsi_host.wwpn, parent_wwpn)) - return devs->objs[i]; - virNodeDeviceObjUnlock(devs->objs[i]); - } - - return NULL; -} - - -static virNodeDeviceObjPtr -virNodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs, - const char *parent_fabric_wwn) -{ - size_t i; - - for (i = 0; i < devs->count; i++) { - virNodeDevCapsDefPtr cap; - virNodeDeviceObjLock(devs->objs[i]); - if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) && - STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_wwn)) - return devs->objs[i]; - virNodeDeviceObjUnlock(devs->objs[i]); - } - - return NULL; -} - - -static virNodeDeviceObjPtr -virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, - const char *cap) -{ - size_t i; - - for (i = 0; i < devs->count; i++) { - virNodeDeviceObjLock(devs->objs[i]); - if (virNodeDeviceHasCap(devs->objs[i], cap)) - return devs->objs[i]; - virNodeDeviceObjUnlock(devs->objs[i]); - } - - return NULL; -} - void virNodeDeviceDefFree(virNodeDeviceDefPtr def) { @@ -278,82 +114,6 @@ void virNodeDeviceDefFree(virNodeDeviceDefPtr def) VIR_FREE(def); } -void virNodeDeviceObjFree(virNodeDeviceObjPtr dev) -{ - if (!dev) - return; - - virNodeDeviceDefFree(dev->def); - if (dev->privateFree) - (*dev->privateFree)(dev->privateData); - - virMutexDestroy(&dev->lock); - - VIR_FREE(dev); -} - -void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) -{ - size_t i; - for (i = 0; i < devs->count; i++) - virNodeDeviceObjFree(devs->objs[i]); - VIR_FREE(devs->objs); - devs->count = 0; -} - -virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def) -{ - virNodeDeviceObjPtr device; - - if ((device = virNodeDeviceFindByName(devs, def->name))) { - virNodeDeviceDefFree(device->def); - device->def = def; - return device; - } - - if (VIR_ALLOC(device) < 0) - return NULL; - - if (virMutexInit(&device->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); - VIR_FREE(device); - return NULL; - } - virNodeDeviceObjLock(device); - - if (VIR_APPEND_ELEMENT_COPY(devs->objs, devs->count, device) < 0) { - virNodeDeviceObjUnlock(device); - virNodeDeviceObjFree(device); - return NULL; - } - device->def = def; - - return device; - -} - -void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr *dev) -{ - size_t i; - - virNodeDeviceObjUnlock(*dev); - - for (i = 0; i < devs->count; i++) { - virNodeDeviceObjLock(*dev); - if (devs->objs[i] == *dev) { - virNodeDeviceObjUnlock(*dev); - virNodeDeviceObjFree(devs->objs[i]); - *dev = NULL; - - VIR_DELETE_ELEMENT(devs->objs, i, devs->count); - break; - } - virNodeDeviceObjUnlock(*dev); - } -} static void virPCIELinkFormat(virBufferPtr buf, @@ -1976,152 +1736,6 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, return ret; } -/* - * Return the NPIV dev's parent device name - */ -/* virNodeDeviceFindFCParentHost: - * @parent: Pointer to node device object - * - * Search the capabilities for the device to find the FC capabilities - * in order to set the parent_host value. - * - * Returns: - * parent_host value on success (>= 0), -1 otherwise. - */ -static int -virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) -{ - virNodeDevCapsDefPtr cap = virNodeDeviceFindVPORTCapDef(parent); - - if (!cap) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Parent device %s is not capable " - "of vport operations"), - parent->def->name); - return -1; - } - - return cap->data.scsi_host.host; -} - - -static int -virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_name) -{ - virNodeDeviceObjPtr parent = NULL; - int ret; - - if (!(parent = virNodeDeviceFindByName(devs, parent_name))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find parent device for '%s'"), - dev_name); - return -1; - } - - ret = virNodeDeviceFindFCParentHost(parent); - - virNodeDeviceObjUnlock(parent); - - return ret; -} - - -static int -virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_wwnn, - const char *parent_wwpn) -{ - virNodeDeviceObjPtr parent = NULL; - int ret; - - if (!(parent = virNodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwpn))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find parent device for '%s'"), - dev_name); - return -1; - } - - ret = virNodeDeviceFindFCParentHost(parent); - - virNodeDeviceObjUnlock(parent); - - return ret; -} - - -static int -virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_fabric_wwn) -{ - virNodeDeviceObjPtr parent = NULL; - int ret; - - if (!(parent = virNodeDeviceFindByFabricWWN(devs, parent_fabric_wwn))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find parent device for '%s'"), - dev_name); - return -1; - } - - ret = virNodeDeviceFindFCParentHost(parent); - - virNodeDeviceObjUnlock(parent); - - return ret; -} - - -static int -virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) -{ - virNodeDeviceObjPtr parent = NULL; - const char *cap = virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); - int ret; - - if (!(parent = virNodeDeviceFindByCap(devs, cap))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not find any vport capable device")); - return -1; - } - - ret = virNodeDeviceFindFCParentHost(parent); - - virNodeDeviceObjUnlock(parent); - - return ret; -} - - -int -virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create) -{ - int parent_host = -1; - - if (def->parent) { - parent_host = virNodeDeviceGetParentHostByParent(devs, def->name, - def->parent); - } else if (def->parent_wwnn && def->parent_wwpn) { - parent_host = virNodeDeviceGetParentHostByWWNs(devs, def->name, - def->parent_wwnn, - def->parent_wwpn); - } else if (def->parent_fabric_wwn) { - parent_host = - virNodeDeviceGetParentHostByFabricWWN(devs, def->name, - def->parent_fabric_wwn); - } else if (create == CREATE_DEVICE) { - /* Try to find a vport capable scsi_host when no parent supplied */ - parent_host = virNodeDeviceFindVportParentHost(devs); - } - - return parent_host; -} - void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) { @@ -2198,125 +1812,6 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) } -void virNodeDeviceObjLock(virNodeDeviceObjPtr obj) -{ - virMutexLock(&obj->lock); -} - -void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) -{ - virMutexUnlock(&obj->lock); -} - -static bool -virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, - int type) -{ - virNodeDevCapsDefPtr cap = NULL; - - for (cap = devobj->def->caps; cap; cap = cap->next) { - if (type == cap->data.type) - return true; - - if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) { - if (type == VIR_NODE_DEV_CAP_FC_HOST && - (cap->data.scsi_host.flags & - VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) - return true; - - if (type == VIR_NODE_DEV_CAP_VPORTS && - (cap->data.scsi_host.flags & - VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)) - return true; - } - } - - return false; -} - -#define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \ - virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG)) -static bool -virNodeDeviceMatch(virNodeDeviceObjPtr devobj, - unsigned int flags) -{ - /* filter by cap type */ - if (flags & VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP) { - if (!(MATCH(SYSTEM) || - MATCH(PCI_DEV) || - MATCH(USB_DEV) || - MATCH(USB_INTERFACE) || - MATCH(NET) || - MATCH(SCSI_HOST) || - MATCH(SCSI_TARGET) || - MATCH(SCSI) || - MATCH(STORAGE) || - MATCH(FC_HOST) || - MATCH(VPORTS) || - MATCH(SCSI_GENERIC) || - MATCH(DRM))) - return false; - } - - return true; -} -#undef MATCH - -int -virNodeDeviceObjListExport(virConnectPtr conn, - virNodeDeviceObjList devobjs, - virNodeDevicePtr **devices, - virNodeDeviceObjListFilter filter, - unsigned int flags) -{ - virNodeDevicePtr *tmp_devices = NULL; - virNodeDevicePtr device = NULL; - int ndevices = 0; - int ret = -1; - size_t i; - - if (devices && VIR_ALLOC_N(tmp_devices, devobjs.count + 1) < 0) - goto cleanup; - - for (i = 0; i < devobjs.count; i++) { - virNodeDeviceObjPtr devobj = devobjs.objs[i]; - virNodeDeviceObjLock(devobj); - if ((!filter || filter(conn, devobj->def)) && - virNodeDeviceMatch(devobj, flags)) { - if (devices) { - if (!(device = virGetNodeDevice(conn, devobj->def->name)) || - VIR_STRDUP(device->parent, devobj->def->parent) < 0) { - virObjectUnref(device); - virNodeDeviceObjUnlock(devobj); - goto cleanup; - } - tmp_devices[ndevices] = device; - } - ndevices++; - } - virNodeDeviceObjUnlock(devobj); - } - - if (tmp_devices) { - /* trim the array to the final size */ - ignore_value(VIR_REALLOC_N(tmp_devices, ndevices + 1)); - *devices = tmp_devices; - tmp_devices = NULL; - } - - ret = ndevices; - - cleanup: - if (tmp_devices) { - for (i = 0; i < ndevices; i++) - virObjectUnref(tmp_devices[i]); - } - - VIR_FREE(tmp_devices); - return ret; -} - - /* virNodeDeviceGetParentName * @conn: Connection pointer * @nodedev_name: Node device to lookup diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 8213c27..6c94262 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -28,10 +28,8 @@ # include "internal.h" # include "virbitmap.h" # include "virutil.h" -# include "virthread.h" # include "virpci.h" # include "device_conf.h" -# include "object_event.h" # include <libxml/tree.h> @@ -253,34 +251,6 @@ struct _virNodeDeviceObjList { virNodeDeviceObjPtr *objs; }; -typedef struct _virNodeDeviceDriverState virNodeDeviceDriverState; -typedef virNodeDeviceDriverState *virNodeDeviceDriverStatePtr; -struct _virNodeDeviceDriverState { - virMutex lock; - - virNodeDeviceObjList devs; /* currently-known devices */ - void *privateData; /* driver-specific private data */ - - /* Immutable pointer, self-locking APIs */ - virObjectEventStatePtr nodeDeviceEventState; -}; - - -int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap); - -virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, - const char *name); -virNodeDeviceObjPtr -virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) - ATTRIBUTE_NONNULL(2); - -virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def); - -void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr *dev); - char *virNodeDeviceDefFormat(const virNodeDeviceDef *def); virNodeDeviceDefPtr virNodeDeviceDefParseString(const char *str, @@ -298,21 +268,10 @@ int virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, char **wwnn, char **wwpn); -int virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create); - void virNodeDeviceDefFree(virNodeDeviceDefPtr def); -void virNodeDeviceObjFree(virNodeDeviceObjPtr dev); - -void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs); - void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); -void virNodeDeviceObjLock(virNodeDeviceObjPtr obj); -void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj); - # define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP \ (VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV | \ @@ -328,15 +287,6 @@ void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj); VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM) -typedef bool (*virNodeDeviceObjListFilter)(virConnectPtr conn, - virNodeDeviceDefPtr def); - -int virNodeDeviceObjListExport(virConnectPtr conn, - virNodeDeviceObjList devobjs, - virNodeDevicePtr **devices, - virNodeDeviceObjListFilter filter, - unsigned int flags); - char *virNodeDeviceGetParentName(virConnectPtr conn, const char *nodedev_name); diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c new file mode 100644 index 0000000..83f7217 --- /dev/null +++ b/src/conf/virnodedeviceobj.c @@ -0,0 +1,542 @@ +/* + * virnodedeviceobj.c: node device object handling + * (derived from node_device_conf.c) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#include <config.h> + +#include "datatypes.h" +#include "node_device_conf.h" + +#include "viralloc.h" +#include "virnodedeviceobj.h" +#include "virerror.h" +#include "virlog.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NODEDEV + +VIR_LOG_INIT("conf.virnodedeviceobj"); + + +int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) +{ + virNodeDevCapsDefPtr caps = dev->def->caps; + const char *fc_host_cap = + virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_FC_HOST); + const char *vports_cap = + virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); + + while (caps) { + if (STREQ(cap, virNodeDevCapTypeToString(caps->data.type))) + return 1; + else if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) + if ((STREQ(cap, fc_host_cap) && + (caps->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) || + (STREQ(cap, vports_cap) && + (caps->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS))) + return 1; + caps = caps->next; + } + return 0; +} + + +/* virNodeDeviceFindFCCapDef: + * @dev: Pointer to current device + * + * Search the device object 'caps' array for fc_host capability. + * + * Returns: + * Pointer to the caps or NULL if not found + */ +static virNodeDevCapsDefPtr +virNodeDeviceFindFCCapDef(const virNodeDeviceObj *dev) +{ + virNodeDevCapsDefPtr caps = dev->def->caps; + + while (caps) { + if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST && + (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) + break; + + caps = caps->next; + } + return caps; +} + + +/* virNodeDeviceFindVPORTCapDef: + * @dev: Pointer to current device + * + * Search the device object 'caps' array for vport_ops capability. + * + * Returns: + * Pointer to the caps or NULL if not found + */ +static virNodeDevCapsDefPtr +virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *dev) +{ + virNodeDevCapsDefPtr caps = dev->def->caps; + + while (caps) { + if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST && + (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)) + break; + + caps = caps->next; + } + return caps; +} + + +virNodeDeviceObjPtr +virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) +{ + size_t i; + + for (i = 0; i < devs->count; i++) { + virNodeDeviceObjLock(devs->objs[i]); + if ((devs->objs[i]->def->sysfs_path != NULL) && + (STREQ(devs->objs[i]->def->sysfs_path, sysfs_path))) { + return devs->objs[i]; + } + virNodeDeviceObjUnlock(devs->objs[i]); + } + + return NULL; +} + + +virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, + const char *name) +{ + size_t i; + + for (i = 0; i < devs->count; i++) { + virNodeDeviceObjLock(devs->objs[i]); + if (STREQ(devs->objs[i]->def->name, name)) + return devs->objs[i]; + virNodeDeviceObjUnlock(devs->objs[i]); + } + + return NULL; +} + + +static virNodeDeviceObjPtr +virNodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, + const char *parent_wwnn, + const char *parent_wwpn) +{ + size_t i; + + for (i = 0; i < devs->count; i++) { + virNodeDevCapsDefPtr cap; + virNodeDeviceObjLock(devs->objs[i]); + if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) && + STREQ_NULLABLE(cap->data.scsi_host.wwnn, parent_wwnn) && + STREQ_NULLABLE(cap->data.scsi_host.wwpn, parent_wwpn)) + return devs->objs[i]; + virNodeDeviceObjUnlock(devs->objs[i]); + } + + return NULL; +} + + +static virNodeDeviceObjPtr +virNodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs, + const char *parent_fabric_wwn) +{ + size_t i; + + for (i = 0; i < devs->count; i++) { + virNodeDevCapsDefPtr cap; + virNodeDeviceObjLock(devs->objs[i]); + if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) && + STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_wwn)) + return devs->objs[i]; + virNodeDeviceObjUnlock(devs->objs[i]); + } + + return NULL; +} + + +static virNodeDeviceObjPtr +virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, + const char *cap) +{ + size_t i; + + for (i = 0; i < devs->count; i++) { + virNodeDeviceObjLock(devs->objs[i]); + if (virNodeDeviceHasCap(devs->objs[i], cap)) + return devs->objs[i]; + virNodeDeviceObjUnlock(devs->objs[i]); + } + + return NULL; +} + + +void virNodeDeviceObjFree(virNodeDeviceObjPtr dev) +{ + if (!dev) + return; + + virNodeDeviceDefFree(dev->def); + if (dev->privateFree) + (*dev->privateFree)(dev->privateData); + + virMutexDestroy(&dev->lock); + + VIR_FREE(dev); +} + +void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) +{ + size_t i; + for (i = 0; i < devs->count; i++) + virNodeDeviceObjFree(devs->objs[i]); + VIR_FREE(devs->objs); + devs->count = 0; +} + +virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def) +{ + virNodeDeviceObjPtr device; + + if ((device = virNodeDeviceFindByName(devs, def->name))) { + virNodeDeviceDefFree(device->def); + device->def = def; + return device; + } + + if (VIR_ALLOC(device) < 0) + return NULL; + + if (virMutexInit(&device->lock) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot initialize mutex")); + VIR_FREE(device); + return NULL; + } + virNodeDeviceObjLock(device); + + if (VIR_APPEND_ELEMENT_COPY(devs->objs, devs->count, device) < 0) { + virNodeDeviceObjUnlock(device); + virNodeDeviceObjFree(device); + return NULL; + } + device->def = def; + + return device; + +} + +void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr *dev) +{ + size_t i; + + virNodeDeviceObjUnlock(*dev); + + for (i = 0; i < devs->count; i++) { + virNodeDeviceObjLock(*dev); + if (devs->objs[i] == *dev) { + virNodeDeviceObjUnlock(*dev); + virNodeDeviceObjFree(devs->objs[i]); + *dev = NULL; + + VIR_DELETE_ELEMENT(devs->objs, i, devs->count); + break; + } + virNodeDeviceObjUnlock(*dev); + } +} + + +/* + * Return the NPIV dev's parent device name + */ +/* virNodeDeviceFindFCParentHost: + * @parent: Pointer to node device object + * + * Search the capabilities for the device to find the FC capabilities + * in order to set the parent_host value. + * + * Returns: + * parent_host value on success (>= 0), -1 otherwise. + */ +static int +virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) +{ + virNodeDevCapsDefPtr cap = virNodeDeviceFindVPORTCapDef(parent); + + if (!cap) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Parent device %s is not capable " + "of vport operations"), + parent->def->name); + return -1; + } + + return cap->data.scsi_host.host; +} + + +static int +virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_name) +{ + virNodeDeviceObjPtr parent = NULL; + int ret; + + if (!(parent = virNodeDeviceFindByName(devs, parent_name))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find parent device for '%s'"), + dev_name); + return -1; + } + + ret = virNodeDeviceFindFCParentHost(parent); + + virNodeDeviceObjUnlock(parent); + + return ret; +} + + +static int +virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_wwnn, + const char *parent_wwpn) +{ + virNodeDeviceObjPtr parent = NULL; + int ret; + + if (!(parent = virNodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwpn))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find parent device for '%s'"), + dev_name); + return -1; + } + + ret = virNodeDeviceFindFCParentHost(parent); + + virNodeDeviceObjUnlock(parent); + + return ret; +} + + +static int +virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_fabric_wwn) +{ + virNodeDeviceObjPtr parent = NULL; + int ret; + + if (!(parent = virNodeDeviceFindByFabricWWN(devs, parent_fabric_wwn))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find parent device for '%s'"), + dev_name); + return -1; + } + + ret = virNodeDeviceFindFCParentHost(parent); + + virNodeDeviceObjUnlock(parent); + + return ret; +} + + +static int +virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) +{ + virNodeDeviceObjPtr parent = NULL; + const char *cap = virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); + int ret; + + if (!(parent = virNodeDeviceFindByCap(devs, cap))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not find any vport capable device")); + return -1; + } + + ret = virNodeDeviceFindFCParentHost(parent); + + virNodeDeviceObjUnlock(parent); + + return ret; +} + + +int +virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create) +{ + int parent_host = -1; + + if (def->parent) { + parent_host = virNodeDeviceGetParentHostByParent(devs, def->name, + def->parent); + } else if (def->parent_wwnn && def->parent_wwpn) { + parent_host = virNodeDeviceGetParentHostByWWNs(devs, def->name, + def->parent_wwnn, + def->parent_wwpn); + } else if (def->parent_fabric_wwn) { + parent_host = + virNodeDeviceGetParentHostByFabricWWN(devs, def->name, + def->parent_fabric_wwn); + } else if (create == CREATE_DEVICE) { + /* Try to find a vport capable scsi_host when no parent supplied */ + parent_host = virNodeDeviceFindVportParentHost(devs); + } + + return parent_host; +} + + +void virNodeDeviceObjLock(virNodeDeviceObjPtr obj) +{ + virMutexLock(&obj->lock); +} + +void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) +{ + virMutexUnlock(&obj->lock); +} + +static bool +virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, + int type) +{ + virNodeDevCapsDefPtr cap = NULL; + + for (cap = devobj->def->caps; cap; cap = cap->next) { + if (type == cap->data.type) + return true; + + if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) { + if (type == VIR_NODE_DEV_CAP_FC_HOST && + (cap->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) + return true; + + if (type == VIR_NODE_DEV_CAP_VPORTS && + (cap->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)) + return true; + } + } + + return false; +} + +#define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \ + virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG)) +static bool +virNodeDeviceMatch(virNodeDeviceObjPtr devobj, + unsigned int flags) +{ + /* filter by cap type */ + if (flags & VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP) { + if (!(MATCH(SYSTEM) || + MATCH(PCI_DEV) || + MATCH(USB_DEV) || + MATCH(USB_INTERFACE) || + MATCH(NET) || + MATCH(SCSI_HOST) || + MATCH(SCSI_TARGET) || + MATCH(SCSI) || + MATCH(STORAGE) || + MATCH(FC_HOST) || + MATCH(VPORTS) || + MATCH(SCSI_GENERIC) || + MATCH(DRM))) + return false; + } + + return true; +} +#undef MATCH + +int +virNodeDeviceObjListExport(virConnectPtr conn, + virNodeDeviceObjList devobjs, + virNodeDevicePtr **devices, + virNodeDeviceObjListFilter filter, + unsigned int flags) +{ + virNodeDevicePtr *tmp_devices = NULL; + virNodeDevicePtr device = NULL; + int ndevices = 0; + int ret = -1; + size_t i; + + if (devices && VIR_ALLOC_N(tmp_devices, devobjs.count + 1) < 0) + goto cleanup; + + for (i = 0; i < devobjs.count; i++) { + virNodeDeviceObjPtr devobj = devobjs.objs[i]; + virNodeDeviceObjLock(devobj); + if ((!filter || filter(conn, devobj->def)) && + virNodeDeviceMatch(devobj, flags)) { + if (devices) { + if (!(device = virGetNodeDevice(conn, devobj->def->name)) || + VIR_STRDUP(device->parent, devobj->def->parent) < 0) { + virObjectUnref(device); + virNodeDeviceObjUnlock(devobj); + goto cleanup; + } + tmp_devices[ndevices] = device; + } + ndevices++; + } + virNodeDeviceObjUnlock(devobj); + } + + if (tmp_devices) { + /* trim the array to the final size */ + ignore_value(VIR_REALLOC_N(tmp_devices, ndevices + 1)); + *devices = tmp_devices; + tmp_devices = NULL; + } + + ret = ndevices; + + cleanup: + if (tmp_devices) { + for (i = 0; i < ndevices; i++) + virObjectUnref(tmp_devices[i]); + } + + VIR_FREE(tmp_devices); + return ret; +} diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h new file mode 100644 index 0000000..6ad7fb1 --- /dev/null +++ b/src/conf/virnodedeviceobj.h @@ -0,0 +1,78 @@ +/* + * virnodedeviceobj.h: node device object handling for node devices + * (derived from node_device_conf.h) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#ifndef __VIRNODEDEVICEOBJ_H__ +# define __VIRNODEDEVICEOBJ_H__ + +# include "internal.h" +# include "virthread.h" + +# include "node_device_conf.h" +# include "object_event.h" + + +typedef struct _virNodeDeviceDriverState virNodeDeviceDriverState; +typedef virNodeDeviceDriverState *virNodeDeviceDriverStatePtr; +struct _virNodeDeviceDriverState { + virMutex lock; + + virNodeDeviceObjList devs; /* currently-known devices */ + void *privateData; /* driver-specific private data */ + + /* Immutable pointer, self-locking APIs */ + virObjectEventStatePtr nodeDeviceEventState; +}; + + +int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap); + +virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, + const char *name); +virNodeDeviceObjPtr +virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) + ATTRIBUTE_NONNULL(2); + +virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def); + +void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr *dev); + +int virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create); + +void virNodeDeviceObjFree(virNodeDeviceObjPtr dev); + +void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs); + +void virNodeDeviceObjLock(virNodeDeviceObjPtr obj); +void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj); + +typedef bool (*virNodeDeviceObjListFilter)(virConnectPtr conn, + virNodeDeviceDefPtr def); + +int virNodeDeviceObjListExport(virConnectPtr conn, + virNodeDeviceObjList devobjs, + virNodeDevicePtr **devices, + virNodeDeviceObjListFilter filter, + unsigned int flags); + +#endif /* __VIRNODEDEVICEOBJ_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bce0487..8639979 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -694,23 +694,13 @@ virNetDevIPRouteParseXML; virNodeDevCapsDefFree; virNodeDevCapTypeFromString; virNodeDevCapTypeToString; -virNodeDeviceAssignDef; virNodeDeviceDefFormat; virNodeDeviceDefFree; virNodeDeviceDefParseFile; virNodeDeviceDefParseNode; virNodeDeviceDefParseString; -virNodeDeviceFindByName; -virNodeDeviceFindBySysfsPath; -virNodeDeviceGetParentHost; virNodeDeviceGetParentName; virNodeDeviceGetWWNs; -virNodeDeviceHasCap; -virNodeDeviceObjListExport; -virNodeDeviceObjListFree; -virNodeDeviceObjLock; -virNodeDeviceObjRemove; -virNodeDeviceObjUnlock; # conf/node_device_event.h @@ -958,6 +948,19 @@ virDomainObjListRemoveLocked; virDomainObjListRename; +# conf/virnodedeviceobj.h +virNodeDeviceAssignDef; +virNodeDeviceFindByName; +virNodeDeviceFindBySysfsPath; +virNodeDeviceGetParentHost; +virNodeDeviceHasCap; +virNodeDeviceObjListExport; +virNodeDeviceObjListFree; +virNodeDeviceObjLock; +virNodeDeviceObjRemove; +virNodeDeviceObjUnlock; + + # conf/virsecretobj.h virSecretLoadAllConfigs; virSecretObjDeleteConfig; diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h index 56f89ab..bc8af8a 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -26,7 +26,7 @@ # include "internal.h" # include "driver.h" -# include "node_device_conf.h" +# include "virnodedeviceobj.h" # define LINUX_NEW_DEVICE_WAIT_TIME 60 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 314f08c..c6214c6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -51,6 +51,7 @@ #include "storage_conf.h" #include "storage_event.h" #include "node_device_conf.h" +#include "virnodedeviceobj.h" #include "node_device_event.h" #include "virxml.h" #include "virthread.h" -- 2.9.3

On Wed, Mar 01, 2017 at 07:27:14PM -0500, John Ferlan wrote:
Move all the NodeDeviceObj API's into their own module virnodedeviceobj from the node_device_conf
Purely code motion at this point, plus adjustments to cleanly build.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- po/POTFILES.in | 1 + src/Makefile.am | 3 +- src/conf/node_device_conf.c | 505 -------------------------------- src/conf/node_device_conf.h | 50 ---- src/conf/virnodedeviceobj.c | 542 +++++++++++++++++++++++++++++++++++ src/conf/virnodedeviceobj.h | 78 +++++ src/libvirt_private.syms | 23 +- src/node_device/node_device_driver.h | 2 +- src/test/test_driver.c | 1 + 9 files changed, 638 insertions(+), 567 deletions(-) create mode 100644 src/conf/virnodedeviceobj.c create mode 100644 src/conf/virnodedeviceobj.h
[...]
diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h new file mode 100644 index 0000000..6ad7fb1 --- /dev/null +++ b/src/conf/virnodedeviceobj.h @@ -0,0 +1,78 @@ +/* + * virnodedeviceobj.h: node device object handling for node devices + * (derived from node_device_conf.h) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#ifndef __VIRNODEDEVICEOBJ_H__ +# define __VIRNODEDEVICEOBJ_H__ + +# include "internal.h" +# include "virthread.h" + +# include "node_device_conf.h" +# include "object_event.h" + + +typedef struct _virNodeDeviceDriverState virNodeDeviceDriverState; +typedef virNodeDeviceDriverState *virNodeDeviceDriverStatePtr; +struct _virNodeDeviceDriverState { + virMutex lock; + + virNodeDeviceObjList devs; /* currently-known devices */ + void *privateData; /* driver-specific private data */ + + /* Immutable pointer, self-locking APIs */ + virObjectEventStatePtr nodeDeviceEventState; +}; + +
Since I'm the only one that tries to change the different coding style between header and source files this is a kind reminder that it would be nice to use the same coding style, placing the return value on separate line. Thanks, Pavel
+int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap); + +virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, + const char *name); +virNodeDeviceObjPtr +virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) + ATTRIBUTE_NONNULL(2); + +virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def); + +void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr *dev); + +int virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create); + +void virNodeDeviceObjFree(virNodeDeviceObjPtr dev); + +void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs); + +void virNodeDeviceObjLock(virNodeDeviceObjPtr obj); +void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj); + +typedef bool (*virNodeDeviceObjListFilter)(virConnectPtr conn, + virNodeDeviceDefPtr def); + +int virNodeDeviceObjListExport(virConnectPtr conn, + virNodeDeviceObjList devobjs, + virNodeDevicePtr **devices, + virNodeDeviceObjListFilter filter, + unsigned int flags); + +#endif /* __VIRNODEDEVICEOBJ_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index bce0487..8639979 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -694,23 +694,13 @@ virNetDevIPRouteParseXML; virNodeDevCapsDefFree; virNodeDevCapTypeFromString; virNodeDevCapTypeToString; -virNodeDeviceAssignDef; virNodeDeviceDefFormat; virNodeDeviceDefFree; virNodeDeviceDefParseFile; virNodeDeviceDefParseNode; virNodeDeviceDefParseString; -virNodeDeviceFindByName; -virNodeDeviceFindBySysfsPath; -virNodeDeviceGetParentHost; virNodeDeviceGetParentName; virNodeDeviceGetWWNs; -virNodeDeviceHasCap; -virNodeDeviceObjListExport; -virNodeDeviceObjListFree; -virNodeDeviceObjLock; -virNodeDeviceObjRemove; -virNodeDeviceObjUnlock;
# conf/node_device_event.h @@ -958,6 +948,19 @@ virDomainObjListRemoveLocked; virDomainObjListRename;
+# conf/virnodedeviceobj.h +virNodeDeviceAssignDef; +virNodeDeviceFindByName; +virNodeDeviceFindBySysfsPath; +virNodeDeviceGetParentHost; +virNodeDeviceHasCap; +virNodeDeviceObjListExport; +virNodeDeviceObjListFree; +virNodeDeviceObjLock; +virNodeDeviceObjRemove; +virNodeDeviceObjUnlock; + + # conf/virsecretobj.h virSecretLoadAllConfigs; virSecretObjDeleteConfig; diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_device_driver.h index 56f89ab..bc8af8a 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -26,7 +26,7 @@
# include "internal.h" # include "driver.h" -# include "node_device_conf.h" +# include "virnodedeviceobj.h"
# define LINUX_NEW_DEVICE_WAIT_TIME 60
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 314f08c..c6214c6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -51,6 +51,7 @@ #include "storage_conf.h" #include "storage_event.h" #include "node_device_conf.h" +#include "virnodedeviceobj.h" #include "node_device_event.h" #include "virxml.h" #include "virthread.h" -- 2.9.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 03/02/2017 04:03 AM, Pavel Hrdina wrote:
On Wed, Mar 01, 2017 at 07:27:14PM -0500, John Ferlan wrote:
Move all the NodeDeviceObj API's into their own module virnodedeviceobj from the node_device_conf
Purely code motion at this point, plus adjustments to cleanly build.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- po/POTFILES.in | 1 + src/Makefile.am | 3 +- src/conf/node_device_conf.c | 505 -------------------------------- src/conf/node_device_conf.h | 50 ---- src/conf/virnodedeviceobj.c | 542 +++++++++++++++++++++++++++++++++++ src/conf/virnodedeviceobj.h | 78 +++++ src/libvirt_private.syms | 23 +- src/node_device/node_device_driver.h | 2 +- src/test/test_driver.c | 1 + 9 files changed, 638 insertions(+), 567 deletions(-) create mode 100644 src/conf/virnodedeviceobj.c create mode 100644 src/conf/virnodedeviceobj.h
[...]
diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h new file mode 100644 index 0000000..6ad7fb1 --- /dev/null +++ b/src/conf/virnodedeviceobj.h @@ -0,0 +1,78 @@ +/* + * virnodedeviceobj.h: node device object handling for node devices + * (derived from node_device_conf.h) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#ifndef __VIRNODEDEVICEOBJ_H__ +# define __VIRNODEDEVICEOBJ_H__ + +# include "internal.h" +# include "virthread.h" + +# include "node_device_conf.h" +# include "object_event.h" + + +typedef struct _virNodeDeviceDriverState virNodeDeviceDriverState; +typedef virNodeDeviceDriverState *virNodeDeviceDriverStatePtr; +struct _virNodeDeviceDriverState { + virMutex lock; + + virNodeDeviceObjList devs; /* currently-known devices */ + void *privateData; /* driver-specific private data */ + + /* Immutable pointer, self-locking APIs */ + virObjectEventStatePtr nodeDeviceEventState; +}; + +
Since I'm the only one that tries to change the different coding style between header and source files this is a kind reminder that it would be nice to use the same coding style, placing the return value on separate line.
Thanks,
Pavel
Sure I can add that to the list of things to do for each of these in "followup" patches... So that I don't break the unwritten? policy that thou shalt not make formatting or style changes for code motion because it's "difficult" to review ;-) John [...]

Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code. Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..09e815a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -72,9 +72,9 @@ VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, "render") static int -virNodeDevCapsDefParseString(const char *xpath, - xmlXPathContextPtr ctxt, - char **string) +nodeDevCapsDefParseString(const char *xpath, + xmlXPathContextPtr ctxt, + char **string) { char *s; @@ -86,7 +86,8 @@ virNodeDevCapsDefParseString(const char *xpath, } -void virNodeDeviceDefFree(virNodeDeviceDefPtr def) +void +virNodeDeviceDefFree(virNodeDeviceDefPtr def) { virNodeDevCapsDefPtr caps; @@ -116,9 +117,9 @@ void virNodeDeviceDefFree(virNodeDeviceDefPtr def) static void -virPCIELinkFormat(virBufferPtr buf, - virPCIELinkPtr lnk, - const char *attrib) +nodeDevPCIELinkFormat(virBufferPtr buf, + virPCIELinkPtr lnk, + const char *attrib) { if (!lnk) return; @@ -133,9 +134,10 @@ virPCIELinkFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } + static void -virPCIEDeviceInfoFormat(virBufferPtr buf, - virPCIEDeviceInfoPtr info) +nodeDevPCIEDeviceInfoFormat(virBufferPtr buf, + virPCIEDeviceInfoPtr info) { if (!info->link_cap && !info->link_sta) { virBufferAddLit(buf, "<pci-express/>\n"); @@ -145,14 +147,16 @@ virPCIEDeviceInfoFormat(virBufferPtr buf, virBufferAddLit(buf, "<pci-express>\n"); virBufferAdjustIndent(buf, 2); - virPCIELinkFormat(buf, info->link_cap, "cap"); - virPCIELinkFormat(buf, info->link_sta, "sta"); + nodeDevPCIELinkFormat(buf, info->link_cap, "cap"); + nodeDevPCIELinkFormat(buf, info->link_sta, "sta"); virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</pci-express>\n"); } -char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) + +char * +virNodeDeviceDefFormat(const virNodeDeviceDef *def) { virBuffer buf = VIR_BUFFER_INITIALIZER; virNodeDevCapsDefPtr caps; @@ -305,7 +309,7 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) data->pci_dev.numa_node); if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCIE) - virPCIEDeviceInfoFormat(&buf, data->pci_dev.pci_express); + nodeDevPCIEDeviceInfoFormat(&buf, data->pci_dev.pci_express); break; case VIR_NODE_DEV_CAP_USB_DEV: virBufferAsprintf(&buf, "<bus>%d</bus>\n", data->usb_dev.bus); @@ -489,8 +493,9 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) return virBufferContentAndReset(&buf); } + /** - * virNodeDevCapsDefParseIntOptional: + * nodeDevCapsDefParseIntOptional: * @xpath: XPath to evaluate * @ctxt: Context * @value: Where to store parsed value @@ -502,11 +507,11 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) * 1 on success */ static int -virNodeDevCapsDefParseIntOptional(const char *xpath, - xmlXPathContextPtr ctxt, - int *value, - virNodeDeviceDefPtr def, - const char *invalid_error_fmt) +nodeDevCapsDefParseIntOptional(const char *xpath, + xmlXPathContextPtr ctxt, + int *value, + virNodeDeviceDefPtr def, + const char *invalid_error_fmt) { int ret; int val; @@ -524,13 +529,14 @@ virNodeDevCapsDefParseIntOptional(const char *xpath, return 1; } + static int -virNodeDevCapsDefParseULong(const char *xpath, - xmlXPathContextPtr ctxt, - unsigned *value, - virNodeDeviceDefPtr def, - const char *missing_error_fmt, - const char *invalid_error_fmt) +nodeDevCapsDefParseULong(const char *xpath, + xmlXPathContextPtr ctxt, + unsigned *value, + virNodeDeviceDefPtr def, + const char *missing_error_fmt, + const char *invalid_error_fmt) { int ret; unsigned long val; @@ -547,13 +553,14 @@ virNodeDevCapsDefParseULong(const char *xpath, return 0; } + static int -virNodeDevCapsDefParseULongLong(const char *xpath, - xmlXPathContextPtr ctxt, - unsigned long long *value, - virNodeDeviceDefPtr def, - const char *missing_error_fmt, - const char *invalid_error_fmt) +nodeDevCapsDefParseULongLong(const char *xpath, + xmlXPathContextPtr ctxt, + unsigned long long *value, + virNodeDeviceDefPtr def, + const char *missing_error_fmt, + const char *invalid_error_fmt) { int ret; unsigned long long val; @@ -570,11 +577,12 @@ virNodeDevCapsDefParseULongLong(const char *xpath, return 0; } + static int -virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1, val; @@ -600,11 +608,12 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, return ret; } + static int -virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode, *nodes = NULL; size_t i; @@ -657,9 +666,9 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, data->storage.media_label = virXPathString("string(./media_label[1])", ctxt); val = 0; - if (virNodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def, - _("no removable media size supplied for '%s'"), - _("invalid removable media size supplied for '%s'")) < 0) { + if (nodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def, + _("no removable media size supplied for '%s'"), + _("invalid removable media size supplied for '%s'")) < 0) { ctxt->node = orignode2; VIR_FREE(type); goto out; @@ -680,9 +689,9 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, if (!(data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) { val = 0; - if (virNodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def, - _("no size supplied for '%s'"), - _("invalid size supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def, + _("no size supplied for '%s'"), + _("invalid size supplied for '%s'")) < 0) goto out; data->storage.size = val; } @@ -694,11 +703,12 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, return ret; } + static int -virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -706,28 +716,28 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node; - if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, - &data->scsi.host, def, - _("no SCSI host ID supplied for '%s'"), - _("invalid SCSI host ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./host[1])", ctxt, + &data->scsi.host, def, + _("no SCSI host ID supplied for '%s'"), + _("invalid SCSI host ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->scsi.bus, def, - _("no SCSI bus ID supplied for '%s'"), - _("invalid SCSI bus ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./bus[1])", ctxt, + &data->scsi.bus, def, + _("no SCSI bus ID supplied for '%s'"), + _("invalid SCSI bus ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong("number(./target[1])", ctxt, - &data->scsi.target, def, - _("no SCSI target ID supplied for '%s'"), + if (nodeDevCapsDefParseULong("number(./target[1])", ctxt, + &data->scsi.target, def, + _("no SCSI target ID supplied for '%s'"), _("invalid SCSI target ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong("number(./lun[1])", ctxt, - &data->scsi.lun, def, - _("no SCSI LUN ID supplied for '%s'"), - _("invalid SCSI LUN ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./lun[1])", ctxt, + &data->scsi.lun, def, + _("no SCSI LUN ID supplied for '%s'"), + _("invalid SCSI LUN ID supplied for '%s'")) < 0) goto out; data->scsi.type = virXPathString("string(./type[1])", ctxt); @@ -740,10 +750,10 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, static int -virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -768,12 +778,12 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, static int -virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data, - int create, - const char *virt_type) +nodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data, + int create, + const char *virt_type) { xmlNodePtr orignode, *nodes = NULL; int ret = -1, n = 0; @@ -784,17 +794,17 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, ctxt->node = node; if (create == EXISTING_DEVICE) { - if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, - &data->scsi_host.host, def, - _("no SCSI host ID supplied for '%s'"), - _("invalid SCSI host ID supplied for '%s'")) < 0) { + if (nodeDevCapsDefParseULong("number(./host[1])", ctxt, + &data->scsi_host.host, def, + _("no SCSI host ID supplied for '%s'"), + _("invalid SCSI host ID supplied for '%s'")) < 0) { goto out; } /* Optional unique_id value */ data->scsi_host.unique_id = -1; - if (virNodeDevCapsDefParseIntOptional("number(./unique_id[1])", ctxt, - &data->scsi_host.unique_id, def, - _("invalid unique_id supplied for '%s'")) < 0) { + if (nodeDevCapsDefParseIntOptional("number(./unique_id[1])", ctxt, + &data->scsi_host.unique_id, def, + _("invalid unique_id supplied for '%s'")) < 0) { goto out; } } @@ -825,9 +835,9 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, orignode2 = ctxt->node; ctxt->node = nodes[i]; - if (virNodeDevCapsDefParseString("string(./wwnn[1])", - ctxt, - &data->scsi_host.wwnn) < 0) { + if (nodeDevCapsDefParseString("string(./wwnn[1])", + ctxt, + &data->scsi_host.wwnn) < 0) { if (virRandomGenerateWWN(&data->scsi_host.wwnn, virt_type) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("no WWNN supplied for '%s', and " @@ -837,9 +847,9 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, } } - if (virNodeDevCapsDefParseString("string(./wwpn[1])", - ctxt, - &data->scsi_host.wwpn) < 0) { + if (nodeDevCapsDefParseString("string(./wwpn[1])", + ctxt, + &data->scsi_host.wwpn) < 0) { if (virRandomGenerateWWN(&data->scsi_host.wwpn, virt_type) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("no WWPN supplied for '%s', and " @@ -849,9 +859,9 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, } } - if (virNodeDevCapsDefParseString("string(./fabric_wwn[1])", - ctxt, - &data->scsi_host.fabric_wwn) < 0) + if (nodeDevCapsDefParseString("string(./fabric_wwn[1])", + ctxt, + &data->scsi_host.fabric_wwn) < 0) VIR_DEBUG("No fabric_wwn defined for '%s'", def->name); ctxt->node = orignode2; @@ -877,10 +887,10 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, static int -virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapNetParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode, lnk; size_t i = -1; @@ -954,11 +964,12 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, return ret; } + static int -virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -966,27 +977,27 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node; - if (virNodeDevCapsDefParseULong("number(./number[1])", ctxt, - &data->usb_if.number, def, - _("no USB interface number supplied for '%s'"), - _("invalid USB interface number supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./number[1])", ctxt, + &data->usb_if.number, def, + _("no USB interface number supplied for '%s'"), + _("invalid USB interface number supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong("number(./class[1])", ctxt, - &data->usb_if._class, def, - _("no USB interface class supplied for '%s'"), - _("invalid USB interface class supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./class[1])", ctxt, + &data->usb_if._class, def, + _("no USB interface class supplied for '%s'"), + _("invalid USB interface class supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong("number(./subclass[1])", ctxt, - &data->usb_if.subclass, def, - _("no USB interface subclass supplied for '%s'"), - _("invalid USB interface subclass supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./subclass[1])", ctxt, + &data->usb_if.subclass, def, + _("no USB interface subclass supplied for '%s'"), + _("invalid USB interface subclass supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong("number(./protocol[1])", ctxt, - &data->usb_if.protocol, def, - _("no USB interface protocol supplied for '%s'"), + if (nodeDevCapsDefParseULong("number(./protocol[1])", ctxt, + &data->usb_if.protocol, def, + _("no USB interface protocol supplied for '%s'"), _("invalid USB interface protocol supplied for '%s'")) < 0) goto out; @@ -998,13 +1009,14 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, return ret; } + static int -virNodeDevCapsDefParseHexId(const char *xpath, - xmlXPathContextPtr ctxt, - unsigned *value, - virNodeDeviceDefPtr def, - const char *missing_error_fmt, - const char *invalid_error_fmt) +nodeDevCapsDefParseHexId(const char *xpath, + xmlXPathContextPtr ctxt, + unsigned *value, + virNodeDeviceDefPtr def, + const char *missing_error_fmt, + const char *invalid_error_fmt) { int ret; unsigned long val; @@ -1021,11 +1033,12 @@ virNodeDevCapsDefParseHexId(const char *xpath, return 0; } + static int -virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -1033,28 +1046,28 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node; - if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->usb_dev.bus, def, - _("no USB bus number supplied for '%s'"), - _("invalid USB bus number supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./bus[1])", ctxt, + &data->usb_dev.bus, def, + _("no USB bus number supplied for '%s'"), + _("invalid USB bus number supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong("number(./device[1])", ctxt, - &data->usb_dev.device, def, - _("no USB device number supplied for '%s'"), - _("invalid USB device number supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./device[1])", ctxt, + &data->usb_dev.device, def, + _("no USB device number supplied for '%s'"), + _("invalid USB device number supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, - &data->usb_dev.vendor, def, - _("no USB vendor ID supplied for '%s'"), - _("invalid USB vendor ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, + &data->usb_dev.vendor, def, + _("no USB vendor ID supplied for '%s'"), + _("invalid USB vendor ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, - &data->usb_dev.product, def, - _("no USB product ID supplied for '%s'"), - _("invalid USB product ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, + &data->usb_dev.product, def, + _("no USB product ID supplied for '%s'"), + _("invalid USB product ID supplied for '%s'")) < 0) goto out; data->usb_dev.vendor_name = virXPathString("string(./vendor[1])", ctxt); @@ -1066,10 +1079,11 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, return ret; } + static int -virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr iommuGroupNode, - virNodeDevCapDataPtr data) +nodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr iommuGroupNode, + virNodeDevCapDataPtr data) { xmlNodePtr origNode = ctxt->node; xmlNodePtr *addrNodes = NULL; @@ -1122,10 +1136,11 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, return ret; } + static int -virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr linkNode, - virPCIELinkPtr lnk) +nodeDevPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr linkNode, + virPCIELinkPtr lnk) { xmlNodePtr origNode = ctxt->node; int ret = -1, speed; @@ -1168,10 +1183,11 @@ virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, return ret; } + static int -virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr pciExpressNode, - virPCIEDeviceInfoPtr pci_express) +nodeDevPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr pciExpressNode, + virPCIEDeviceInfoPtr pci_express) { xmlNodePtr lnk, origNode = ctxt->node; int ret = -1; @@ -1182,8 +1198,8 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, if (VIR_ALLOC(pci_express->link_cap) < 0) goto cleanup; - if (virPCIEDeviceInfoLinkParseXML(ctxt, lnk, - pci_express->link_cap) < 0) + if (nodeDevPCIEDeviceInfoLinkParseXML(ctxt, lnk, + pci_express->link_cap) < 0) goto cleanup; } @@ -1191,8 +1207,8 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, if (VIR_ALLOC(pci_express->link_sta) < 0) goto cleanup; - if (virPCIEDeviceInfoLinkParseXML(ctxt, lnk, - pci_express->link_sta) < 0) + if (nodeDevPCIEDeviceInfoLinkParseXML(ctxt, lnk, + pci_express->link_sta) < 0) goto cleanup; } @@ -1204,9 +1220,9 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, static int -virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr node, + virNodeDevCapDataPtr data) { char *maxFuncsStr = virXMLPropString(node, "maxCount"); char *type = virXMLPropString(node, "type"); @@ -1292,10 +1308,10 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, static int -virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode, iommuGroupNode, pciExpress; xmlNodePtr *nodes = NULL; @@ -1308,40 +1324,40 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node; - if (virNodeDevCapsDefParseULong("number(./domain[1])", ctxt, - &data->pci_dev.domain, def, - _("no PCI domain ID supplied for '%s'"), - _("invalid PCI domain ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./domain[1])", ctxt, + &data->pci_dev.domain, def, + _("no PCI domain ID supplied for '%s'"), + _("invalid PCI domain ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->pci_dev.bus, def, - _("no PCI bus ID supplied for '%s'"), - _("invalid PCI bus ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./bus[1])", ctxt, + &data->pci_dev.bus, def, + _("no PCI bus ID supplied for '%s'"), + _("invalid PCI bus ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong("number(./slot[1])", ctxt, - &data->pci_dev.slot, def, - _("no PCI slot ID supplied for '%s'"), - _("invalid PCI slot ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./slot[1])", ctxt, + &data->pci_dev.slot, def, + _("no PCI slot ID supplied for '%s'"), + _("invalid PCI slot ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseULong("number(./function[1])", ctxt, - &data->pci_dev.function, def, - _("no PCI function ID supplied for '%s'"), - _("invalid PCI function ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./function[1])", ctxt, + &data->pci_dev.function, def, + _("no PCI function ID supplied for '%s'"), + _("invalid PCI function ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, - &data->pci_dev.vendor, def, - _("no PCI vendor ID supplied for '%s'"), - _("invalid PCI vendor ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, + &data->pci_dev.vendor, def, + _("no PCI vendor ID supplied for '%s'"), + _("invalid PCI vendor ID supplied for '%s'")) < 0) goto out; - if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, - &data->pci_dev.product, def, - _("no PCI product ID supplied for '%s'"), - _("invalid PCI product ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, + &data->pci_dev.product, def, + _("no PCI product ID supplied for '%s'"), + _("invalid PCI product ID supplied for '%s'")) < 0) goto out; data->pci_dev.vendor_name = virXPathString("string(./vendor[1])", ctxt); @@ -1351,30 +1367,30 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, goto out; for (i = 0; i < n; i++) { - if (virNodeDevPCICapabilityParseXML(ctxt, nodes[i], data) < 0) + if (nodeDevPCICapabilityParseXML(ctxt, nodes[i], data) < 0) goto out; } VIR_FREE(nodes); if ((iommuGroupNode = virXPathNode("./iommuGroup[1]", ctxt))) { - if (virNodeDevCapPCIDevIommuGroupParseXML(ctxt, iommuGroupNode, - data) < 0) { + if (nodeDevCapPCIDevIommuGroupParseXML(ctxt, iommuGroupNode, + data) < 0) { goto out; } } /* The default value is -1 since zero is valid NUMA node number */ data->pci_dev.numa_node = -1; - if (virNodeDevCapsDefParseIntOptional("number(./numa[1]/@node)", ctxt, - &data->pci_dev.numa_node, def, - _("invalid NUMA node ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseIntOptional("number(./numa[1]/@node)", ctxt, + &data->pci_dev.numa_node, def, + _("invalid NUMA node ID supplied for '%s'")) < 0) goto out; if ((pciExpress = virXPathNode("./pci-express[1]", ctxt))) { if (VIR_ALLOC(pci_express) < 0) goto out; - if (virPCIEDeviceInfoParseXML(ctxt, pciExpress, pci_express) < 0) + if (nodeDevPCIEDeviceInfoParseXML(ctxt, pciExpress, pci_express) < 0) goto out; data->pci_dev.pci_express = pci_express; @@ -1391,11 +1407,12 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, return ret; } + static int -virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -1435,12 +1452,13 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, return ret; } + static virNodeDevCapsDefPtr -virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - int create, - const char *virt_type) +nodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + int create, + const char *virt_type) { virNodeDevCapsDefPtr caps; char *tmp; @@ -1467,37 +1485,37 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, switch (caps->data.type) { case VIR_NODE_DEV_CAP_SYSTEM: - ret = virNodeDevCapSystemParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapSystemParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_PCI_DEV: - ret = virNodeDevCapPCIDevParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapPCIDevParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_USB_DEV: - ret = virNodeDevCapUSBDevParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapUSBDevParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_USB_INTERFACE: - ret = virNodeDevCapUSBInterfaceParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapUSBInterfaceParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_NET: - ret = virNodeDevCapNetParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapNetParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_SCSI_HOST: - ret = virNodeDevCapSCSIHostParseXML(ctxt, def, node, - &caps->data, - create, - virt_type); + ret = nodeDevCapSCSIHostParseXML(ctxt, def, node, + &caps->data, + create, + virt_type); break; case VIR_NODE_DEV_CAP_SCSI_TARGET: - ret = virNodeDevCapSCSITargetParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapSCSITargetParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_SCSI: - ret = virNodeDevCapSCSIParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapSCSIParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_STORAGE: - ret = virNodeDevCapStorageParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapStorageParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_DRM: - ret = virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapDRMParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: @@ -1519,10 +1537,11 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, return NULL; } + static virNodeDeviceDefPtr -virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, - int create, - const char *virt_type) +nodeDeviceDefParseXML(xmlXPathContextPtr ctxt, + int create, + const char *virt_type) { virNodeDeviceDefPtr def; virNodeDevCapsDefPtr *next_cap; @@ -1614,10 +1633,10 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, next_cap = &def->caps; for (i = 0; i < n; i++) { - *next_cap = virNodeDevCapsDefParseXML(ctxt, def, - nodes[i], - create, - virt_type); + *next_cap = nodeDevCapsDefParseXML(ctxt, def, + nodes[i], + create, + virt_type); if (!*next_cap) goto error; @@ -1633,6 +1652,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, return NULL; } + virNodeDeviceDefPtr virNodeDeviceDefParseNode(xmlDocPtr xml, xmlNodePtr root, @@ -1657,18 +1677,19 @@ virNodeDeviceDefParseNode(xmlDocPtr xml, } ctxt->node = root; - def = virNodeDeviceDefParseXML(ctxt, create, virt_type); + def = nodeDeviceDefParseXML(ctxt, create, virt_type); cleanup: xmlXPathFreeContext(ctxt); return def; } + static virNodeDeviceDefPtr -virNodeDeviceDefParse(const char *str, - const char *filename, - int create, - const char *virt_type) +nodeDeviceDefParse(const char *str, + const char *filename, + int create, + const char *virt_type) { xmlDocPtr xml; virNodeDeviceDefPtr def = NULL; @@ -1682,22 +1703,25 @@ virNodeDeviceDefParse(const char *str, return def; } + virNodeDeviceDefPtr virNodeDeviceDefParseString(const char *str, int create, const char *virt_type) { - return virNodeDeviceDefParse(str, NULL, create, virt_type); + return nodeDeviceDefParse(str, NULL, create, virt_type); } + virNodeDeviceDefPtr virNodeDeviceDefParseFile(const char *filename, int create, const char *virt_type) { - return virNodeDeviceDefParse(NULL, filename, create, virt_type); + return nodeDeviceDefParse(NULL, filename, create, virt_type); } + /* * Return fc_host dev's WWNN and WWPN */ diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 83f7217..a416fb8 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -33,7 +33,9 @@ VIR_LOG_INIT("conf.virnodedeviceobj"); -int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) +int +virNodeDeviceHasCap(const virNodeDeviceObj *dev, + const char *cap) { virNodeDevCapsDefPtr caps = dev->def->caps; const char *fc_host_cap = @@ -58,7 +60,7 @@ int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) } -/* virNodeDeviceFindFCCapDef: +/* nodeDeviceFindFCCapDef: * @dev: Pointer to current device * * Search the device object 'caps' array for fc_host capability. @@ -67,7 +69,7 @@ int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) * Pointer to the caps or NULL if not found */ static virNodeDevCapsDefPtr -virNodeDeviceFindFCCapDef(const virNodeDeviceObj *dev) +nodeDeviceFindFCCapDef(const virNodeDeviceObj *dev) { virNodeDevCapsDefPtr caps = dev->def->caps; @@ -125,8 +127,9 @@ virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, } -virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, - const char *name) +virNodeDeviceObjPtr +virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, + const char *name) { size_t i; @@ -142,16 +145,16 @@ virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, static virNodeDeviceObjPtr -virNodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, - const char *parent_wwnn, - const char *parent_wwpn) +nodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, + const char *parent_wwnn, + const char *parent_wwpn) { size_t i; for (i = 0; i < devs->count; i++) { virNodeDevCapsDefPtr cap; virNodeDeviceObjLock(devs->objs[i]); - if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) && + if ((cap = nodeDeviceFindFCCapDef(devs->objs[i])) && STREQ_NULLABLE(cap->data.scsi_host.wwnn, parent_wwnn) && STREQ_NULLABLE(cap->data.scsi_host.wwpn, parent_wwpn)) return devs->objs[i]; @@ -163,15 +166,15 @@ virNodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, static virNodeDeviceObjPtr -virNodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs, - const char *parent_fabric_wwn) +nodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs, + const char *parent_fabric_wwn) { size_t i; for (i = 0; i < devs->count; i++) { virNodeDevCapsDefPtr cap; virNodeDeviceObjLock(devs->objs[i]); - if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) && + if ((cap = nodeDeviceFindFCCapDef(devs->objs[i])) && STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_wwn)) return devs->objs[i]; virNodeDeviceObjUnlock(devs->objs[i]); @@ -182,8 +185,8 @@ virNodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs, static virNodeDeviceObjPtr -virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, - const char *cap) +nodeDeviceFindByCap(virNodeDeviceObjListPtr devs, + const char *cap) { size_t i; @@ -198,7 +201,8 @@ virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, } -void virNodeDeviceObjFree(virNodeDeviceObjPtr dev) +void +virNodeDeviceObjFree(virNodeDeviceObjPtr dev) { if (!dev) return; @@ -212,7 +216,9 @@ void virNodeDeviceObjFree(virNodeDeviceObjPtr dev) VIR_FREE(dev); } -void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) + +void +virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) { size_t i; for (i = 0; i < devs->count; i++) @@ -221,8 +227,10 @@ void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) devs->count = 0; } -virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def) + +virNodeDeviceObjPtr +virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def) { virNodeDeviceObjPtr device; @@ -254,8 +262,10 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, } -void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr *dev) + +void +virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr *dev) { size_t i; @@ -279,7 +289,7 @@ void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, /* * Return the NPIV dev's parent device name */ -/* virNodeDeviceFindFCParentHost: +/* nodeDeviceFindFCParentHost: * @parent: Pointer to node device object * * Search the capabilities for the device to find the FC capabilities @@ -289,7 +299,7 @@ void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, * parent_host value on success (>= 0), -1 otherwise. */ static int -virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) +nodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) { virNodeDevCapsDefPtr cap = virNodeDeviceFindVPORTCapDef(parent); @@ -306,9 +316,9 @@ virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) static int -virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_name) +nodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_name) { virNodeDeviceObjPtr parent = NULL; int ret; @@ -320,7 +330,7 @@ virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, return -1; } - ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent); virNodeDeviceObjUnlock(parent); @@ -329,22 +339,22 @@ virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, static int -virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_wwnn, - const char *parent_wwpn) +nodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_wwnn, + const char *parent_wwpn) { virNodeDeviceObjPtr parent = NULL; int ret; - if (!(parent = virNodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwpn))) { + if (!(parent = nodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwpn))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); return -1; } - ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent); virNodeDeviceObjUnlock(parent); @@ -353,21 +363,21 @@ virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs, static int -virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_fabric_wwn) +nodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_fabric_wwn) { virNodeDeviceObjPtr parent = NULL; int ret; - if (!(parent = virNodeDeviceFindByFabricWWN(devs, parent_fabric_wwn))) { + if (!(parent = nodeDeviceFindByFabricWWN(devs, parent_fabric_wwn))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); return -1; } - ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent); virNodeDeviceObjUnlock(parent); @@ -376,19 +386,19 @@ virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, static int -virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) +nodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) { virNodeDeviceObjPtr parent = NULL; const char *cap = virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); int ret; - if (!(parent = virNodeDeviceFindByCap(devs, cap))) { + if (!(parent = nodeDeviceFindByCap(devs, cap))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not find any vport capable device")); return -1; } - ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent); virNodeDeviceObjUnlock(parent); @@ -404,38 +414,42 @@ virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, int parent_host = -1; if (def->parent) { - parent_host = virNodeDeviceGetParentHostByParent(devs, def->name, - def->parent); + parent_host = nodeDeviceGetParentHostByParent(devs, def->name, + def->parent); } else if (def->parent_wwnn && def->parent_wwpn) { - parent_host = virNodeDeviceGetParentHostByWWNs(devs, def->name, - def->parent_wwnn, - def->parent_wwpn); + parent_host = nodeDeviceGetParentHostByWWNs(devs, def->name, + def->parent_wwnn, + def->parent_wwpn); } else if (def->parent_fabric_wwn) { parent_host = - virNodeDeviceGetParentHostByFabricWWN(devs, def->name, - def->parent_fabric_wwn); + nodeDeviceGetParentHostByFabricWWN(devs, def->name, + def->parent_fabric_wwn); } else if (create == CREATE_DEVICE) { /* Try to find a vport capable scsi_host when no parent supplied */ - parent_host = virNodeDeviceFindVportParentHost(devs); + parent_host = nodeDeviceFindVportParentHost(devs); } return parent_host; } -void virNodeDeviceObjLock(virNodeDeviceObjPtr obj) +void +virNodeDeviceObjLock(virNodeDeviceObjPtr obj) { virMutexLock(&obj->lock); } -void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) + +void +virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) { virMutexUnlock(&obj->lock); } + static bool -virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, - int type) +nodeDeviceCapMatch(virNodeDeviceObjPtr devobj, + int type) { virNodeDevCapsDefPtr cap = NULL; @@ -459,11 +473,12 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, return false; } + #define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \ - virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG)) + nodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG)) static bool -virNodeDeviceMatch(virNodeDeviceObjPtr devobj, - unsigned int flags) +nodeDeviceMatch(virNodeDeviceObjPtr devobj, + unsigned int flags) { /* filter by cap type */ if (flags & VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP) { @@ -487,6 +502,7 @@ virNodeDeviceMatch(virNodeDeviceObjPtr devobj, } #undef MATCH + int virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjList devobjs, @@ -507,7 +523,7 @@ virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjPtr devobj = devobjs.objs[i]; virNodeDeviceObjLock(devobj); if ((!filter || filter(conn, devobj->def)) && - virNodeDeviceMatch(devobj, flags)) { + nodeDeviceMatch(devobj, flags)) { if (devices) { if (!(device = virGetNodeDevice(conn, devobj->def->name)) || VIR_STRDUP(device->parent, devobj->def->parent) < 0) { -- 2.9.3

On Wed, Mar 01, 2017 at 19:27:15 -0500, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..09e815a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -72,9 +72,9 @@ VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, "render")
static int -virNodeDevCapsDefParseString(const char *xpath, - xmlXPathContextPtr ctxt, - char **string) +nodeDevCapsDefParseString(const char *xpath, + xmlXPathContextPtr ctxt, + char **string)
Please don't remove the vir prefix. The coding style tries to converge to having them everywhere.

On 03/02/2017 09:58 AM, Peter Krempa wrote:
On Wed, Mar 01, 2017 at 19:27:15 -0500, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..09e815a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -72,9 +72,9 @@ VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, "render")
static int -virNodeDevCapsDefParseString(const char *xpath, - xmlXPathContextPtr ctxt, - char **string) +nodeDevCapsDefParseString(const char *xpath, + xmlXPathContextPtr ctxt, + char **string)
Please don't remove the vir prefix. The coding style tries to converge to having them everywhere.
Why? If a function is static, we can be sure it's not called from outside of the file. Moreover, I'd direct your attention to recent commit of f557b3351e0b6d for instance. In fact whole qemu driver serves as a great example: it's "static int qemuDomain*()" not "static vir virQEMUDomain*()". In fact, I'd suggest the opposite rule - use "vir" prefix only if function is shared between modules. For instance virFileCopyACLs should have the vir prefix because it's exported. virFileRewriteStrHelper should not have the prefix because it's static. The advantage of this approach is that one can immediately tell just from the name if the function is exported or not. Michal

On Thu, Mar 02, 2017 at 10:04:24 +0100, Michal Privoznik wrote:
On 03/02/2017 09:58 AM, Peter Krempa wrote:
On Wed, Mar 01, 2017 at 19:27:15 -0500, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..09e815a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -72,9 +72,9 @@ VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, "render")
static int -virNodeDevCapsDefParseString(const char *xpath, - xmlXPathContextPtr ctxt, - char **string) +nodeDevCapsDefParseString(const char *xpath, + xmlXPathContextPtr ctxt, + char **string)
Please don't remove the vir prefix. The coding style tries to converge to having them everywhere.
Why? If a function is static, we can be sure it's not called from outside of the file. Moreover, I'd direct your attention to recent
The static function name may still show up in logs and backtraces. It's better to see what belongs to libvirt and what does not.
commit of f557b3351e0b6d for instance. In fact whole qemu driver serves as a great example: it's "static int qemuDomain*()" not "static vir virQEMUDomain*()".
Well, if somebody changes the whole src/qemu_driver.c to use the vir prefix I'll use the vir prefix. It's called consistency.
In fact, I'd suggest the opposite rule - use "vir" prefix only if function is shared between modules. For instance virFileCopyACLs should have the vir prefix because it's exported. virFileRewriteStrHelper should not have the prefix because it's static.
If we codify this rule, this will mean that once we will export the function you'll have to rename it. Also once you unexport it, you'll have to rename it. I think that's silly. I'd stick with the prefix everywhere.
The advantage of this approach is that one can immediately tell just from the name if the function is exported or not.
I don't think this is very useful. If you are refactoring it you should check all callers anyways and other than that the information is not very useful.

On 03/02/2017 10:16 AM, Peter Krempa wrote:
On Thu, Mar 02, 2017 at 10:04:24 +0100, Michal Privoznik wrote:
On 03/02/2017 09:58 AM, Peter Krempa wrote:
On Wed, Mar 01, 2017 at 19:27:15 -0500, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..09e815a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -72,9 +72,9 @@ VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, "render")
static int -virNodeDevCapsDefParseString(const char *xpath, - xmlXPathContextPtr ctxt, - char **string) +nodeDevCapsDefParseString(const char *xpath, + xmlXPathContextPtr ctxt, + char **string)
Please don't remove the vir prefix. The coding style tries to converge to having them everywhere.
Why? If a function is static, we can be sure it's not called from outside of the file. Moreover, I'd direct your attention to recent
The static function name may still show up in logs and backtraces. It's better to see what belongs to libvirt and what does not.
I don't know about your backtraces, but mine show the filename too. Either actual source file or .so file where the symbol comes from. We can rely on that. Or if a static function of ours calls a function from another library, it's going to be visible too: #0 virExposedAPI #1 someStaticFunc #2 someOtherStaticFunc #3 glfs_creat #4 yetAnotherStaticFunc Frankly, I don't have any difficulties determining the boundaries of libvirt's part of the stack.
commit of f557b3351e0b6d for instance. In fact whole qemu driver serves as a great example: it's "static int qemuDomain*()" not "static vir virQEMUDomain*()".
Well, if somebody changes the whole src/qemu_driver.c to use the vir prefix I'll use the vir prefix. It's called consistency.
No. I'm against that change. qemuDomain*() makes perfect sense. It's in qemu driver, it's static, it shows up in backtrace, etc.
In fact, I'd suggest the opposite rule - use "vir" prefix only if function is shared between modules. For instance virFileCopyACLs should have the vir prefix because it's exported. virFileRewriteStrHelper should not have the prefix because it's static.
If we codify this rule, this will mean that once we will export the function you'll have to rename it. Also once you unexport it, you'll have to rename it. I think that's silly. I'd stick with the prefix everywhere.
Yes when you want to make a change you have to make a change. As I replied to Dan, exporting a func would require change in just one file. and the change is going to be small anyway.
The advantage of this approach is that one can immediately tell just from the name if the function is exported or not.
I don't think this is very useful. If you are refactoring it you should check all callers anyways and other than that the information is not very useful.
If a function is static, all you need to check is just that one file. You don't need to grep for other locations.

On Thu, Mar 02, 2017 at 10:47:20 +0100, Michal Privoznik wrote:
On 03/02/2017 10:16 AM, Peter Krempa wrote:
On Thu, Mar 02, 2017 at 10:04:24 +0100, Michal Privoznik wrote:
On 03/02/2017 09:58 AM, Peter Krempa wrote:
On Wed, Mar 01, 2017 at 19:27:15 -0500, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-)
[...]
The static function name may still show up in logs and backtraces. It's better to see what belongs to libvirt and what does not.
I don't know about your backtraces, but mine show the filename too. Either actual source file or .so file where the symbol comes from. We can rely on that. Or if a static function of ours calls a function from another library, it's going to be visible too:
#0 virExposedAPI #1 someStaticFunc #2 someOtherStaticFunc #3 glfs_creat #4 yetAnotherStaticFunc
Let's try some real example where our namespace collides with others: #0 0x00007fdaa6651770 in udev_device_get_devtype () from /lib64/libudev.so.1 #1 0x00007fda989e9ea6 in udevGetDeviceType (type=0x55c03b7df050, device=0x55c03b7ae650) at node_device/node_device_udev.c:992 #2 udevAddOneDevice (device=device@entry=0x55c03b7ae650) at node_device/node_device_udev.c:1194 #3 0x00007fda989ebb9a in udevEventHandleCallback (watch=watch@entry=8, fd=<optimized out>, events=events@entry=1, data=data@entry=0x0) at node_device/node_device_udev.c:1405 Yes you can see it by looking at 'from' or due to the fact that libudev uses undescores rather than camel case, but on first glance the difference is impossible to spot.

On Thu, Mar 02, 2017 at 10:04:24AM +0100, Michal Privoznik wrote:
On 03/02/2017 09:58 AM, Peter Krempa wrote:
On Wed, Mar 01, 2017 at 19:27:15 -0500, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..09e815a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -72,9 +72,9 @@ VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, "render")
static int -virNodeDevCapsDefParseString(const char *xpath, - xmlXPathContextPtr ctxt, - char **string) +nodeDevCapsDefParseString(const char *xpath, + xmlXPathContextPtr ctxt, + char **string)
Please don't remove the vir prefix. The coding style tries to converge to having them everywhere.
Why? If a function is static, we can be sure it's not called from outside of the file. Moreover, I'd direct your attention to recent commit of f557b3351e0b6d for instance. In fact whole qemu driver serves as a great example: it's "static int qemuDomain*()" not "static vir virQEMUDomain*()".
In fact, I'd suggest the opposite rule - use "vir" prefix only if function is shared between modules. For instance virFileCopyACLs should have the vir prefix because it's exported. virFileRewriteStrHelper should not have the prefix because it's static. The advantage of this approach is that one can immediately tell just from the name if the function is exported or not.
No, this is a bad rule because it causes us to rename code when we inevitably make static functions non-static. We want a naming rule that is standardized & stable long term. Convering to use 'vir' prefix everywhere gives us that. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|

On 03/02/2017 10:30 AM, Daniel P. Berrange wrote:
On Thu, Mar 02, 2017 at 10:04:24AM +0100, Michal Privoznik wrote:
On 03/02/2017 09:58 AM, Peter Krempa wrote:
On Wed, Mar 01, 2017 at 19:27:15 -0500, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..09e815a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -72,9 +72,9 @@ VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, "render")
static int -virNodeDevCapsDefParseString(const char *xpath, - xmlXPathContextPtr ctxt, - char **string) +nodeDevCapsDefParseString(const char *xpath, + xmlXPathContextPtr ctxt, + char **string)
Please don't remove the vir prefix. The coding style tries to converge to having them everywhere.
Why? If a function is static, we can be sure it's not called from outside of the file. Moreover, I'd direct your attention to recent commit of f557b3351e0b6d for instance. In fact whole qemu driver serves as a great example: it's "static int qemuDomain*()" not "static vir virQEMUDomain*()".
In fact, I'd suggest the opposite rule - use "vir" prefix only if function is shared between modules. For instance virFileCopyACLs should have the vir prefix because it's exported. virFileRewriteStrHelper should not have the prefix because it's static. The advantage of this approach is that one can immediately tell just from the name if the function is exported or not.
No, this is a bad rule because it causes us to rename code when we inevitably make static functions non-static. We want a naming rule that is standardized & stable long term. Convering to use 'vir' prefix everywhere gives us that.
I fail to see why would renaming be a problem. Going from static to non-static would require to change all the callers in just one file (which is not going to have much callers anyway). Going the opposite direction - well, there are no callers in other files anyway. If there were we couldn't make the funtion static. But okay, my phrasing was probably not the best. I wouldn't make it a rule that everybody has to follow. It's just that it makes sense to me to have static functions without vir- prefix. Michal

On Thu, Mar 02, 2017 at 10:35:57AM +0100, Michal Privoznik wrote:
On 03/02/2017 10:30 AM, Daniel P. Berrange wrote:
On Thu, Mar 02, 2017 at 10:04:24AM +0100, Michal Privoznik wrote:
On 03/02/2017 09:58 AM, Peter Krempa wrote:
On Wed, Mar 01, 2017 at 19:27:15 -0500, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..09e815a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -72,9 +72,9 @@ VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, "render")
static int -virNodeDevCapsDefParseString(const char *xpath, - xmlXPathContextPtr ctxt, - char **string) +nodeDevCapsDefParseString(const char *xpath, + xmlXPathContextPtr ctxt, + char **string)
Please don't remove the vir prefix. The coding style tries to converge to having them everywhere.
Why? If a function is static, we can be sure it's not called from outside of the file. Moreover, I'd direct your attention to recent commit of f557b3351e0b6d for instance. In fact whole qemu driver serves as a great example: it's "static int qemuDomain*()" not "static vir virQEMUDomain*()".
In fact, I'd suggest the opposite rule - use "vir" prefix only if function is shared between modules. For instance virFileCopyACLs should have the vir prefix because it's exported. virFileRewriteStrHelper should not have the prefix because it's static. The advantage of this approach is that one can immediately tell just from the name if the function is exported or not.
No, this is a bad rule because it causes us to rename code when we inevitably make static functions non-static. We want a naming rule that is standardized & stable long term. Convering to use 'vir' prefix everywhere gives us that.
I fail to see why would renaming be a problem. Going from static to non-static would require to change all the callers in just one file (which is not going to have much callers anyway). Going the opposite direction - well, there are no callers in other files anyway. If there were we couldn't make the funtion static.
Even though all the code may be in one file, it can still create a huge amount of code churn. eg if we make qemuDomObjFromDomain non-static, that'd involve updating 125 lines in the qemu_driver.c file. That's alot of self-inflicted pain for backporting patches that come afterwards. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|

On Wed, Mar 01, 2017 at 07:27:15PM -0500, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
I don't thing that this is necessary and it can create a confusion about function naming in the future. IMHO the *static* keyword is good enough to determine which are local or not. And we also use *vir* prefix to distinguish libvirt functions from other libraries in debug logs or in backtrace, etc. Already existing functions without *vir* prefix are old once that where introduced before we started using that prefix. Pavel
Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..09e815a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -72,9 +72,9 @@ VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, "render")
static int -virNodeDevCapsDefParseString(const char *xpath, - xmlXPathContextPtr ctxt, - char **string) +nodeDevCapsDefParseString(const char *xpath, + xmlXPathContextPtr ctxt, + char **string) { char *s;
@@ -86,7 +86,8 @@ virNodeDevCapsDefParseString(const char *xpath, }
-void virNodeDeviceDefFree(virNodeDeviceDefPtr def) +void +virNodeDeviceDefFree(virNodeDeviceDefPtr def) { virNodeDevCapsDefPtr caps;
@@ -116,9 +117,9 @@ void virNodeDeviceDefFree(virNodeDeviceDefPtr def)
static void -virPCIELinkFormat(virBufferPtr buf, - virPCIELinkPtr lnk, - const char *attrib) +nodeDevPCIELinkFormat(virBufferPtr buf, + virPCIELinkPtr lnk, + const char *attrib) { if (!lnk) return; @@ -133,9 +134,10 @@ virPCIELinkFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); }
+ static void -virPCIEDeviceInfoFormat(virBufferPtr buf, - virPCIEDeviceInfoPtr info) +nodeDevPCIEDeviceInfoFormat(virBufferPtr buf, + virPCIEDeviceInfoPtr info) { if (!info->link_cap && !info->link_sta) { virBufferAddLit(buf, "<pci-express/>\n"); @@ -145,14 +147,16 @@ virPCIEDeviceInfoFormat(virBufferPtr buf, virBufferAddLit(buf, "<pci-express>\n"); virBufferAdjustIndent(buf, 2);
- virPCIELinkFormat(buf, info->link_cap, "cap"); - virPCIELinkFormat(buf, info->link_sta, "sta"); + nodeDevPCIELinkFormat(buf, info->link_cap, "cap"); + nodeDevPCIELinkFormat(buf, info->link_sta, "sta");
virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</pci-express>\n"); }
-char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) + +char * +virNodeDeviceDefFormat(const virNodeDeviceDef *def) { virBuffer buf = VIR_BUFFER_INITIALIZER; virNodeDevCapsDefPtr caps; @@ -305,7 +309,7 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) data->pci_dev.numa_node);
if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCIE) - virPCIEDeviceInfoFormat(&buf, data->pci_dev.pci_express); + nodeDevPCIEDeviceInfoFormat(&buf, data->pci_dev.pci_express); break; case VIR_NODE_DEV_CAP_USB_DEV: virBufferAsprintf(&buf, "<bus>%d</bus>\n", data->usb_dev.bus); @@ -489,8 +493,9 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) return virBufferContentAndReset(&buf); }
+ /** - * virNodeDevCapsDefParseIntOptional: + * nodeDevCapsDefParseIntOptional: * @xpath: XPath to evaluate * @ctxt: Context * @value: Where to store parsed value @@ -502,11 +507,11 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) * 1 on success */ static int -virNodeDevCapsDefParseIntOptional(const char *xpath, - xmlXPathContextPtr ctxt, - int *value, - virNodeDeviceDefPtr def, - const char *invalid_error_fmt) +nodeDevCapsDefParseIntOptional(const char *xpath, + xmlXPathContextPtr ctxt, + int *value, + virNodeDeviceDefPtr def, + const char *invalid_error_fmt) { int ret; int val; @@ -524,13 +529,14 @@ virNodeDevCapsDefParseIntOptional(const char *xpath, return 1; }
+ static int -virNodeDevCapsDefParseULong(const char *xpath, - xmlXPathContextPtr ctxt, - unsigned *value, - virNodeDeviceDefPtr def, - const char *missing_error_fmt, - const char *invalid_error_fmt) +nodeDevCapsDefParseULong(const char *xpath, + xmlXPathContextPtr ctxt, + unsigned *value, + virNodeDeviceDefPtr def, + const char *missing_error_fmt, + const char *invalid_error_fmt) { int ret; unsigned long val; @@ -547,13 +553,14 @@ virNodeDevCapsDefParseULong(const char *xpath, return 0; }
+ static int -virNodeDevCapsDefParseULongLong(const char *xpath, - xmlXPathContextPtr ctxt, - unsigned long long *value, - virNodeDeviceDefPtr def, - const char *missing_error_fmt, - const char *invalid_error_fmt) +nodeDevCapsDefParseULongLong(const char *xpath, + xmlXPathContextPtr ctxt, + unsigned long long *value, + virNodeDeviceDefPtr def, + const char *missing_error_fmt, + const char *invalid_error_fmt) { int ret; unsigned long long val; @@ -570,11 +577,12 @@ virNodeDevCapsDefParseULongLong(const char *xpath, return 0; }
+ static int -virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1, val; @@ -600,11 +608,12 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode, *nodes = NULL; size_t i; @@ -657,9 +666,9 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, data->storage.media_label = virXPathString("string(./media_label[1])", ctxt);
val = 0; - if (virNodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def, - _("no removable media size supplied for '%s'"), - _("invalid removable media size supplied for '%s'")) < 0) { + if (nodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def, + _("no removable media size supplied for '%s'"), + _("invalid removable media size supplied for '%s'")) < 0) { ctxt->node = orignode2; VIR_FREE(type); goto out; @@ -680,9 +689,9 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
if (!(data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) { val = 0; - if (virNodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def, - _("no size supplied for '%s'"), - _("invalid size supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def, + _("no size supplied for '%s'"), + _("invalid size supplied for '%s'")) < 0) goto out; data->storage.size = val; } @@ -694,11 +703,12 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -706,28 +716,28 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node;
- if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, - &data->scsi.host, def, - _("no SCSI host ID supplied for '%s'"), - _("invalid SCSI host ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./host[1])", ctxt, + &data->scsi.host, def, + _("no SCSI host ID supplied for '%s'"), + _("invalid SCSI host ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->scsi.bus, def, - _("no SCSI bus ID supplied for '%s'"), - _("invalid SCSI bus ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./bus[1])", ctxt, + &data->scsi.bus, def, + _("no SCSI bus ID supplied for '%s'"), + _("invalid SCSI bus ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./target[1])", ctxt, - &data->scsi.target, def, - _("no SCSI target ID supplied for '%s'"), + if (nodeDevCapsDefParseULong("number(./target[1])", ctxt, + &data->scsi.target, def, + _("no SCSI target ID supplied for '%s'"), _("invalid SCSI target ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./lun[1])", ctxt, - &data->scsi.lun, def, - _("no SCSI LUN ID supplied for '%s'"), - _("invalid SCSI LUN ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./lun[1])", ctxt, + &data->scsi.lun, def, + _("no SCSI LUN ID supplied for '%s'"), + _("invalid SCSI LUN ID supplied for '%s'")) < 0) goto out;
data->scsi.type = virXPathString("string(./type[1])", ctxt); @@ -740,10 +750,10 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt,
static int -virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -768,12 +778,12 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt,
static int -virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data, - int create, - const char *virt_type) +nodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data, + int create, + const char *virt_type) { xmlNodePtr orignode, *nodes = NULL; int ret = -1, n = 0; @@ -784,17 +794,17 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, ctxt->node = node;
if (create == EXISTING_DEVICE) { - if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, - &data->scsi_host.host, def, - _("no SCSI host ID supplied for '%s'"), - _("invalid SCSI host ID supplied for '%s'")) < 0) { + if (nodeDevCapsDefParseULong("number(./host[1])", ctxt, + &data->scsi_host.host, def, + _("no SCSI host ID supplied for '%s'"), + _("invalid SCSI host ID supplied for '%s'")) < 0) { goto out; } /* Optional unique_id value */ data->scsi_host.unique_id = -1; - if (virNodeDevCapsDefParseIntOptional("number(./unique_id[1])", ctxt, - &data->scsi_host.unique_id, def, - _("invalid unique_id supplied for '%s'")) < 0) { + if (nodeDevCapsDefParseIntOptional("number(./unique_id[1])", ctxt, + &data->scsi_host.unique_id, def, + _("invalid unique_id supplied for '%s'")) < 0) { goto out; } } @@ -825,9 +835,9 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, orignode2 = ctxt->node; ctxt->node = nodes[i];
- if (virNodeDevCapsDefParseString("string(./wwnn[1])", - ctxt, - &data->scsi_host.wwnn) < 0) { + if (nodeDevCapsDefParseString("string(./wwnn[1])", + ctxt, + &data->scsi_host.wwnn) < 0) { if (virRandomGenerateWWN(&data->scsi_host.wwnn, virt_type) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("no WWNN supplied for '%s', and " @@ -837,9 +847,9 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, } }
- if (virNodeDevCapsDefParseString("string(./wwpn[1])", - ctxt, - &data->scsi_host.wwpn) < 0) { + if (nodeDevCapsDefParseString("string(./wwpn[1])", + ctxt, + &data->scsi_host.wwpn) < 0) { if (virRandomGenerateWWN(&data->scsi_host.wwpn, virt_type) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("no WWPN supplied for '%s', and " @@ -849,9 +859,9 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, } }
- if (virNodeDevCapsDefParseString("string(./fabric_wwn[1])", - ctxt, - &data->scsi_host.fabric_wwn) < 0) + if (nodeDevCapsDefParseString("string(./fabric_wwn[1])", + ctxt, + &data->scsi_host.fabric_wwn) < 0) VIR_DEBUG("No fabric_wwn defined for '%s'", def->name);
ctxt->node = orignode2; @@ -877,10 +887,10 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
static int -virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapNetParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode, lnk; size_t i = -1; @@ -954,11 +964,12 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -966,27 +977,27 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node;
- if (virNodeDevCapsDefParseULong("number(./number[1])", ctxt, - &data->usb_if.number, def, - _("no USB interface number supplied for '%s'"), - _("invalid USB interface number supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./number[1])", ctxt, + &data->usb_if.number, def, + _("no USB interface number supplied for '%s'"), + _("invalid USB interface number supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./class[1])", ctxt, - &data->usb_if._class, def, - _("no USB interface class supplied for '%s'"), - _("invalid USB interface class supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./class[1])", ctxt, + &data->usb_if._class, def, + _("no USB interface class supplied for '%s'"), + _("invalid USB interface class supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./subclass[1])", ctxt, - &data->usb_if.subclass, def, - _("no USB interface subclass supplied for '%s'"), - _("invalid USB interface subclass supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./subclass[1])", ctxt, + &data->usb_if.subclass, def, + _("no USB interface subclass supplied for '%s'"), + _("invalid USB interface subclass supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./protocol[1])", ctxt, - &data->usb_if.protocol, def, - _("no USB interface protocol supplied for '%s'"), + if (nodeDevCapsDefParseULong("number(./protocol[1])", ctxt, + &data->usb_if.protocol, def, + _("no USB interface protocol supplied for '%s'"), _("invalid USB interface protocol supplied for '%s'")) < 0) goto out;
@@ -998,13 +1009,14 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapsDefParseHexId(const char *xpath, - xmlXPathContextPtr ctxt, - unsigned *value, - virNodeDeviceDefPtr def, - const char *missing_error_fmt, - const char *invalid_error_fmt) +nodeDevCapsDefParseHexId(const char *xpath, + xmlXPathContextPtr ctxt, + unsigned *value, + virNodeDeviceDefPtr def, + const char *missing_error_fmt, + const char *invalid_error_fmt) { int ret; unsigned long val; @@ -1021,11 +1033,12 @@ virNodeDevCapsDefParseHexId(const char *xpath, return 0; }
+ static int -virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -1033,28 +1046,28 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node;
- if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->usb_dev.bus, def, - _("no USB bus number supplied for '%s'"), - _("invalid USB bus number supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./bus[1])", ctxt, + &data->usb_dev.bus, def, + _("no USB bus number supplied for '%s'"), + _("invalid USB bus number supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./device[1])", ctxt, - &data->usb_dev.device, def, - _("no USB device number supplied for '%s'"), - _("invalid USB device number supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./device[1])", ctxt, + &data->usb_dev.device, def, + _("no USB device number supplied for '%s'"), + _("invalid USB device number supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, - &data->usb_dev.vendor, def, - _("no USB vendor ID supplied for '%s'"), - _("invalid USB vendor ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, + &data->usb_dev.vendor, def, + _("no USB vendor ID supplied for '%s'"), + _("invalid USB vendor ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, - &data->usb_dev.product, def, - _("no USB product ID supplied for '%s'"), - _("invalid USB product ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, + &data->usb_dev.product, def, + _("no USB product ID supplied for '%s'"), + _("invalid USB product ID supplied for '%s'")) < 0) goto out;
data->usb_dev.vendor_name = virXPathString("string(./vendor[1])", ctxt); @@ -1066,10 +1079,11 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr iommuGroupNode, - virNodeDevCapDataPtr data) +nodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr iommuGroupNode, + virNodeDevCapDataPtr data) { xmlNodePtr origNode = ctxt->node; xmlNodePtr *addrNodes = NULL; @@ -1122,10 +1136,11 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr linkNode, - virPCIELinkPtr lnk) +nodeDevPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr linkNode, + virPCIELinkPtr lnk) { xmlNodePtr origNode = ctxt->node; int ret = -1, speed; @@ -1168,10 +1183,11 @@ virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr pciExpressNode, - virPCIEDeviceInfoPtr pci_express) +nodeDevPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr pciExpressNode, + virPCIEDeviceInfoPtr pci_express) { xmlNodePtr lnk, origNode = ctxt->node; int ret = -1; @@ -1182,8 +1198,8 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, if (VIR_ALLOC(pci_express->link_cap) < 0) goto cleanup;
- if (virPCIEDeviceInfoLinkParseXML(ctxt, lnk, - pci_express->link_cap) < 0) + if (nodeDevPCIEDeviceInfoLinkParseXML(ctxt, lnk, + pci_express->link_cap) < 0) goto cleanup; }
@@ -1191,8 +1207,8 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, if (VIR_ALLOC(pci_express->link_sta) < 0) goto cleanup;
- if (virPCIEDeviceInfoLinkParseXML(ctxt, lnk, - pci_express->link_sta) < 0) + if (nodeDevPCIEDeviceInfoLinkParseXML(ctxt, lnk, + pci_express->link_sta) < 0) goto cleanup; }
@@ -1204,9 +1220,9 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt,
static int -virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr node, + virNodeDevCapDataPtr data) { char *maxFuncsStr = virXMLPropString(node, "maxCount"); char *type = virXMLPropString(node, "type"); @@ -1292,10 +1308,10 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
static int -virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode, iommuGroupNode, pciExpress; xmlNodePtr *nodes = NULL; @@ -1308,40 +1324,40 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node;
- if (virNodeDevCapsDefParseULong("number(./domain[1])", ctxt, - &data->pci_dev.domain, def, - _("no PCI domain ID supplied for '%s'"), - _("invalid PCI domain ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./domain[1])", ctxt, + &data->pci_dev.domain, def, + _("no PCI domain ID supplied for '%s'"), + _("invalid PCI domain ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->pci_dev.bus, def, - _("no PCI bus ID supplied for '%s'"), - _("invalid PCI bus ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./bus[1])", ctxt, + &data->pci_dev.bus, def, + _("no PCI bus ID supplied for '%s'"), + _("invalid PCI bus ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./slot[1])", ctxt, - &data->pci_dev.slot, def, - _("no PCI slot ID supplied for '%s'"), - _("invalid PCI slot ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./slot[1])", ctxt, + &data->pci_dev.slot, def, + _("no PCI slot ID supplied for '%s'"), + _("invalid PCI slot ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./function[1])", ctxt, - &data->pci_dev.function, def, - _("no PCI function ID supplied for '%s'"), - _("invalid PCI function ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./function[1])", ctxt, + &data->pci_dev.function, def, + _("no PCI function ID supplied for '%s'"), + _("invalid PCI function ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, - &data->pci_dev.vendor, def, - _("no PCI vendor ID supplied for '%s'"), - _("invalid PCI vendor ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, + &data->pci_dev.vendor, def, + _("no PCI vendor ID supplied for '%s'"), + _("invalid PCI vendor ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, - &data->pci_dev.product, def, - _("no PCI product ID supplied for '%s'"), - _("invalid PCI product ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, + &data->pci_dev.product, def, + _("no PCI product ID supplied for '%s'"), + _("invalid PCI product ID supplied for '%s'")) < 0) goto out;
data->pci_dev.vendor_name = virXPathString("string(./vendor[1])", ctxt); @@ -1351,30 +1367,30 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, goto out;
for (i = 0; i < n; i++) { - if (virNodeDevPCICapabilityParseXML(ctxt, nodes[i], data) < 0) + if (nodeDevPCICapabilityParseXML(ctxt, nodes[i], data) < 0) goto out; } VIR_FREE(nodes);
if ((iommuGroupNode = virXPathNode("./iommuGroup[1]", ctxt))) { - if (virNodeDevCapPCIDevIommuGroupParseXML(ctxt, iommuGroupNode, - data) < 0) { + if (nodeDevCapPCIDevIommuGroupParseXML(ctxt, iommuGroupNode, + data) < 0) { goto out; } }
/* The default value is -1 since zero is valid NUMA node number */ data->pci_dev.numa_node = -1; - if (virNodeDevCapsDefParseIntOptional("number(./numa[1]/@node)", ctxt, - &data->pci_dev.numa_node, def, - _("invalid NUMA node ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseIntOptional("number(./numa[1]/@node)", ctxt, + &data->pci_dev.numa_node, def, + _("invalid NUMA node ID supplied for '%s'")) < 0) goto out;
if ((pciExpress = virXPathNode("./pci-express[1]", ctxt))) { if (VIR_ALLOC(pci_express) < 0) goto out;
- if (virPCIEDeviceInfoParseXML(ctxt, pciExpress, pci_express) < 0) + if (nodeDevPCIEDeviceInfoParseXML(ctxt, pciExpress, pci_express) < 0) goto out;
data->pci_dev.pci_express = pci_express; @@ -1391,11 +1407,12 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -1435,12 +1452,13 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static virNodeDevCapsDefPtr -virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - int create, - const char *virt_type) +nodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + int create, + const char *virt_type) { virNodeDevCapsDefPtr caps; char *tmp; @@ -1467,37 +1485,37 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt,
switch (caps->data.type) { case VIR_NODE_DEV_CAP_SYSTEM: - ret = virNodeDevCapSystemParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapSystemParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_PCI_DEV: - ret = virNodeDevCapPCIDevParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapPCIDevParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_USB_DEV: - ret = virNodeDevCapUSBDevParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapUSBDevParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_USB_INTERFACE: - ret = virNodeDevCapUSBInterfaceParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapUSBInterfaceParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_NET: - ret = virNodeDevCapNetParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapNetParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_SCSI_HOST: - ret = virNodeDevCapSCSIHostParseXML(ctxt, def, node, - &caps->data, - create, - virt_type); + ret = nodeDevCapSCSIHostParseXML(ctxt, def, node, + &caps->data, + create, + virt_type); break; case VIR_NODE_DEV_CAP_SCSI_TARGET: - ret = virNodeDevCapSCSITargetParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapSCSITargetParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_SCSI: - ret = virNodeDevCapSCSIParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapSCSIParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_STORAGE: - ret = virNodeDevCapStorageParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapStorageParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_DRM: - ret = virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapDRMParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: @@ -1519,10 +1537,11 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, return NULL; }
+ static virNodeDeviceDefPtr -virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, - int create, - const char *virt_type) +nodeDeviceDefParseXML(xmlXPathContextPtr ctxt, + int create, + const char *virt_type) { virNodeDeviceDefPtr def; virNodeDevCapsDefPtr *next_cap; @@ -1614,10 +1633,10 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
next_cap = &def->caps; for (i = 0; i < n; i++) { - *next_cap = virNodeDevCapsDefParseXML(ctxt, def, - nodes[i], - create, - virt_type); + *next_cap = nodeDevCapsDefParseXML(ctxt, def, + nodes[i], + create, + virt_type); if (!*next_cap) goto error;
@@ -1633,6 +1652,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, return NULL; }
+ virNodeDeviceDefPtr virNodeDeviceDefParseNode(xmlDocPtr xml, xmlNodePtr root, @@ -1657,18 +1677,19 @@ virNodeDeviceDefParseNode(xmlDocPtr xml, }
ctxt->node = root; - def = virNodeDeviceDefParseXML(ctxt, create, virt_type); + def = nodeDeviceDefParseXML(ctxt, create, virt_type);
cleanup: xmlXPathFreeContext(ctxt); return def; }
+ static virNodeDeviceDefPtr -virNodeDeviceDefParse(const char *str, - const char *filename, - int create, - const char *virt_type) +nodeDeviceDefParse(const char *str, + const char *filename, + int create, + const char *virt_type) { xmlDocPtr xml; virNodeDeviceDefPtr def = NULL; @@ -1682,22 +1703,25 @@ virNodeDeviceDefParse(const char *str, return def; }
+ virNodeDeviceDefPtr virNodeDeviceDefParseString(const char *str, int create, const char *virt_type) { - return virNodeDeviceDefParse(str, NULL, create, virt_type); + return nodeDeviceDefParse(str, NULL, create, virt_type); }
+ virNodeDeviceDefPtr virNodeDeviceDefParseFile(const char *filename, int create, const char *virt_type) { - return virNodeDeviceDefParse(NULL, filename, create, virt_type); + return nodeDeviceDefParse(NULL, filename, create, virt_type); }
+ /* * Return fc_host dev's WWNN and WWPN */ diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 83f7217..a416fb8 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -33,7 +33,9 @@ VIR_LOG_INIT("conf.virnodedeviceobj");
-int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) +int +virNodeDeviceHasCap(const virNodeDeviceObj *dev, + const char *cap) { virNodeDevCapsDefPtr caps = dev->def->caps; const char *fc_host_cap = @@ -58,7 +60,7 @@ int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) }
-/* virNodeDeviceFindFCCapDef: +/* nodeDeviceFindFCCapDef: * @dev: Pointer to current device * * Search the device object 'caps' array for fc_host capability. @@ -67,7 +69,7 @@ int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) * Pointer to the caps or NULL if not found */ static virNodeDevCapsDefPtr -virNodeDeviceFindFCCapDef(const virNodeDeviceObj *dev) +nodeDeviceFindFCCapDef(const virNodeDeviceObj *dev) { virNodeDevCapsDefPtr caps = dev->def->caps;
@@ -125,8 +127,9 @@ virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, }
-virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, - const char *name) +virNodeDeviceObjPtr +virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, + const char *name) { size_t i;
@@ -142,16 +145,16 @@ virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs,
static virNodeDeviceObjPtr -virNodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, - const char *parent_wwnn, - const char *parent_wwpn) +nodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, + const char *parent_wwnn, + const char *parent_wwpn) { size_t i;
for (i = 0; i < devs->count; i++) { virNodeDevCapsDefPtr cap; virNodeDeviceObjLock(devs->objs[i]); - if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) && + if ((cap = nodeDeviceFindFCCapDef(devs->objs[i])) && STREQ_NULLABLE(cap->data.scsi_host.wwnn, parent_wwnn) && STREQ_NULLABLE(cap->data.scsi_host.wwpn, parent_wwpn)) return devs->objs[i]; @@ -163,15 +166,15 @@ virNodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs,
static virNodeDeviceObjPtr -virNodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs, - const char *parent_fabric_wwn) +nodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs, + const char *parent_fabric_wwn) { size_t i;
for (i = 0; i < devs->count; i++) { virNodeDevCapsDefPtr cap; virNodeDeviceObjLock(devs->objs[i]); - if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) && + if ((cap = nodeDeviceFindFCCapDef(devs->objs[i])) && STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_wwn)) return devs->objs[i]; virNodeDeviceObjUnlock(devs->objs[i]); @@ -182,8 +185,8 @@ virNodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs,
static virNodeDeviceObjPtr -virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, - const char *cap) +nodeDeviceFindByCap(virNodeDeviceObjListPtr devs, + const char *cap) { size_t i;
@@ -198,7 +201,8 @@ virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, }
-void virNodeDeviceObjFree(virNodeDeviceObjPtr dev) +void +virNodeDeviceObjFree(virNodeDeviceObjPtr dev) { if (!dev) return; @@ -212,7 +216,9 @@ void virNodeDeviceObjFree(virNodeDeviceObjPtr dev) VIR_FREE(dev); }
-void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) + +void +virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) { size_t i; for (i = 0; i < devs->count; i++) @@ -221,8 +227,10 @@ void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) devs->count = 0; }
-virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def) + +virNodeDeviceObjPtr +virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def) { virNodeDeviceObjPtr device;
@@ -254,8 +262,10 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs,
}
-void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr *dev) + +void +virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr *dev) { size_t i;
@@ -279,7 +289,7 @@ void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, /* * Return the NPIV dev's parent device name */ -/* virNodeDeviceFindFCParentHost: +/* nodeDeviceFindFCParentHost: * @parent: Pointer to node device object * * Search the capabilities for the device to find the FC capabilities @@ -289,7 +299,7 @@ void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, * parent_host value on success (>= 0), -1 otherwise. */ static int -virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) +nodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) { virNodeDevCapsDefPtr cap = virNodeDeviceFindVPORTCapDef(parent);
@@ -306,9 +316,9 @@ virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent)
static int -virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_name) +nodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_name) { virNodeDeviceObjPtr parent = NULL; int ret; @@ -320,7 +330,7 @@ virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, return -1; }
- ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent);
virNodeDeviceObjUnlock(parent);
@@ -329,22 +339,22 @@ virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs,
static int -virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_wwnn, - const char *parent_wwpn) +nodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_wwnn, + const char *parent_wwpn) { virNodeDeviceObjPtr parent = NULL; int ret;
- if (!(parent = virNodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwpn))) { + if (!(parent = nodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwpn))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); return -1; }
- ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent);
virNodeDeviceObjUnlock(parent);
@@ -353,21 +363,21 @@ virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs,
static int -virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_fabric_wwn) +nodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_fabric_wwn) { virNodeDeviceObjPtr parent = NULL; int ret;
- if (!(parent = virNodeDeviceFindByFabricWWN(devs, parent_fabric_wwn))) { + if (!(parent = nodeDeviceFindByFabricWWN(devs, parent_fabric_wwn))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); return -1; }
- ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent);
virNodeDeviceObjUnlock(parent);
@@ -376,19 +386,19 @@ virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs,
static int -virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) +nodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) { virNodeDeviceObjPtr parent = NULL; const char *cap = virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); int ret;
- if (!(parent = virNodeDeviceFindByCap(devs, cap))) { + if (!(parent = nodeDeviceFindByCap(devs, cap))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not find any vport capable device")); return -1; }
- ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent);
virNodeDeviceObjUnlock(parent);
@@ -404,38 +414,42 @@ virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, int parent_host = -1;
if (def->parent) { - parent_host = virNodeDeviceGetParentHostByParent(devs, def->name, - def->parent); + parent_host = nodeDeviceGetParentHostByParent(devs, def->name, + def->parent); } else if (def->parent_wwnn && def->parent_wwpn) { - parent_host = virNodeDeviceGetParentHostByWWNs(devs, def->name, - def->parent_wwnn, - def->parent_wwpn); + parent_host = nodeDeviceGetParentHostByWWNs(devs, def->name, + def->parent_wwnn, + def->parent_wwpn); } else if (def->parent_fabric_wwn) { parent_host = - virNodeDeviceGetParentHostByFabricWWN(devs, def->name, - def->parent_fabric_wwn); + nodeDeviceGetParentHostByFabricWWN(devs, def->name, + def->parent_fabric_wwn); } else if (create == CREATE_DEVICE) { /* Try to find a vport capable scsi_host when no parent supplied */ - parent_host = virNodeDeviceFindVportParentHost(devs); + parent_host = nodeDeviceFindVportParentHost(devs); }
return parent_host; }
-void virNodeDeviceObjLock(virNodeDeviceObjPtr obj) +void +virNodeDeviceObjLock(virNodeDeviceObjPtr obj) { virMutexLock(&obj->lock); }
-void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) + +void +virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) { virMutexUnlock(&obj->lock); }
+ static bool -virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, - int type) +nodeDeviceCapMatch(virNodeDeviceObjPtr devobj, + int type) { virNodeDevCapsDefPtr cap = NULL;
@@ -459,11 +473,12 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, return false; }
+ #define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \ - virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG)) + nodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG)) static bool -virNodeDeviceMatch(virNodeDeviceObjPtr devobj, - unsigned int flags) +nodeDeviceMatch(virNodeDeviceObjPtr devobj, + unsigned int flags) { /* filter by cap type */ if (flags & VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP) { @@ -487,6 +502,7 @@ virNodeDeviceMatch(virNodeDeviceObjPtr devobj, } #undef MATCH
+ int virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjList devobjs, @@ -507,7 +523,7 @@ virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjPtr devobj = devobjs.objs[i]; virNodeDeviceObjLock(devobj); if ((!filter || filter(conn, devobj->def)) && - virNodeDeviceMatch(devobj, flags)) { + nodeDeviceMatch(devobj, flags)) { if (devices) { if (!(device = virGetNodeDevice(conn, devobj->def->name)) || VIR_STRDUP(device->parent, devobj->def->parent) < 0) { -- 2.9.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 03/01/2017 07:27 PM, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
Rather than trying to respond individually to points raised... I'll just go with one... I can remove the naming change that's not a problem... It's here primarily for discussion purposes, but also because I do find it easier to read code and be able to easily distinguish local/static from external simply by the name. I certainly agree that "external" functions should have the "vir" prefix, but local/static helpers are different. I also think that my "focus" was more towards the src/conf and src/util sources. The drivers use a different naming model. Trying not expand the discussion beyond conf and util. In fact this is even more focused to the conf files which currently have varying styles... The stack trace argument wasn't my focus. IIRC you'd need to have debug symbols available anyway which may not necessarily be the case when you get one of those from an env that didn't load them. Even then - it's really simple to tell if a "vir" related function is involved as long as we require extern functions to be prefixed with "vir". Regardless, I find myself reading code more than working through stack traces on an daily basis. I don't agree that "static" is good enough especially when you're reading through code, but perhaps that's just a style thing for me. Yes, it's "easy" to go look up the function, but that wasn't the point. Why look it up if you can have an otherwise visual cue. Taking the opposite argument that it is required that every new helper should have a "vir" prefix I think is overkill, especially when the helper function only has one or two callers. Examples of these are plentiful. I'm not about to change every module to follow this style, but if I'm touching a bunch of the conf modules so it's possible to adjust now once rather than later function by function. When we decided to use 2 spaces between every function as a common coding style, we didn't require the first person to make all the changes. Similarly trying to keep one argument per line for each API. In any case, coding style arguments can be like a religious war and could go on forever with no clear winner and lots of good arguments. I can rework this patch to just do the match of more modern libvirt techniques described in the next paragraph and drop the renaming. It's not that important. John
Cleanup spacing between functions, function defs, etc. to match more modern techniques used in libvirt
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/node_device_conf.c | 476 +++++++++++++++++++++++--------------------- src/conf/virnodedeviceobj.c | 128 ++++++------ 2 files changed, 322 insertions(+), 282 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..09e815a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -72,9 +72,9 @@ VIR_ENUM_IMPL(virNodeDevDRM, VIR_NODE_DEV_DRM_LAST, "render")
static int -virNodeDevCapsDefParseString(const char *xpath, - xmlXPathContextPtr ctxt, - char **string) +nodeDevCapsDefParseString(const char *xpath, + xmlXPathContextPtr ctxt, + char **string) { char *s;
@@ -86,7 +86,8 @@ virNodeDevCapsDefParseString(const char *xpath, }
-void virNodeDeviceDefFree(virNodeDeviceDefPtr def) +void +virNodeDeviceDefFree(virNodeDeviceDefPtr def) { virNodeDevCapsDefPtr caps;
@@ -116,9 +117,9 @@ void virNodeDeviceDefFree(virNodeDeviceDefPtr def)
static void -virPCIELinkFormat(virBufferPtr buf, - virPCIELinkPtr lnk, - const char *attrib) +nodeDevPCIELinkFormat(virBufferPtr buf, + virPCIELinkPtr lnk, + const char *attrib) { if (!lnk) return; @@ -133,9 +134,10 @@ virPCIELinkFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); }
+ static void -virPCIEDeviceInfoFormat(virBufferPtr buf, - virPCIEDeviceInfoPtr info) +nodeDevPCIEDeviceInfoFormat(virBufferPtr buf, + virPCIEDeviceInfoPtr info) { if (!info->link_cap && !info->link_sta) { virBufferAddLit(buf, "<pci-express/>\n"); @@ -145,14 +147,16 @@ virPCIEDeviceInfoFormat(virBufferPtr buf, virBufferAddLit(buf, "<pci-express>\n"); virBufferAdjustIndent(buf, 2);
- virPCIELinkFormat(buf, info->link_cap, "cap"); - virPCIELinkFormat(buf, info->link_sta, "sta"); + nodeDevPCIELinkFormat(buf, info->link_cap, "cap"); + nodeDevPCIELinkFormat(buf, info->link_sta, "sta");
virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</pci-express>\n"); }
-char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) + +char * +virNodeDeviceDefFormat(const virNodeDeviceDef *def) { virBuffer buf = VIR_BUFFER_INITIALIZER; virNodeDevCapsDefPtr caps; @@ -305,7 +309,7 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) data->pci_dev.numa_node);
if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCIE) - virPCIEDeviceInfoFormat(&buf, data->pci_dev.pci_express); + nodeDevPCIEDeviceInfoFormat(&buf, data->pci_dev.pci_express); break; case VIR_NODE_DEV_CAP_USB_DEV: virBufferAsprintf(&buf, "<bus>%d</bus>\n", data->usb_dev.bus); @@ -489,8 +493,9 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) return virBufferContentAndReset(&buf); }
+ /** - * virNodeDevCapsDefParseIntOptional: + * nodeDevCapsDefParseIntOptional: * @xpath: XPath to evaluate * @ctxt: Context * @value: Where to store parsed value @@ -502,11 +507,11 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) * 1 on success */ static int -virNodeDevCapsDefParseIntOptional(const char *xpath, - xmlXPathContextPtr ctxt, - int *value, - virNodeDeviceDefPtr def, - const char *invalid_error_fmt) +nodeDevCapsDefParseIntOptional(const char *xpath, + xmlXPathContextPtr ctxt, + int *value, + virNodeDeviceDefPtr def, + const char *invalid_error_fmt) { int ret; int val; @@ -524,13 +529,14 @@ virNodeDevCapsDefParseIntOptional(const char *xpath, return 1; }
+ static int -virNodeDevCapsDefParseULong(const char *xpath, - xmlXPathContextPtr ctxt, - unsigned *value, - virNodeDeviceDefPtr def, - const char *missing_error_fmt, - const char *invalid_error_fmt) +nodeDevCapsDefParseULong(const char *xpath, + xmlXPathContextPtr ctxt, + unsigned *value, + virNodeDeviceDefPtr def, + const char *missing_error_fmt, + const char *invalid_error_fmt) { int ret; unsigned long val; @@ -547,13 +553,14 @@ virNodeDevCapsDefParseULong(const char *xpath, return 0; }
+ static int -virNodeDevCapsDefParseULongLong(const char *xpath, - xmlXPathContextPtr ctxt, - unsigned long long *value, - virNodeDeviceDefPtr def, - const char *missing_error_fmt, - const char *invalid_error_fmt) +nodeDevCapsDefParseULongLong(const char *xpath, + xmlXPathContextPtr ctxt, + unsigned long long *value, + virNodeDeviceDefPtr def, + const char *missing_error_fmt, + const char *invalid_error_fmt) { int ret; unsigned long long val; @@ -570,11 +577,12 @@ virNodeDevCapsDefParseULongLong(const char *xpath, return 0; }
+ static int -virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1, val; @@ -600,11 +608,12 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode, *nodes = NULL; size_t i; @@ -657,9 +666,9 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, data->storage.media_label = virXPathString("string(./media_label[1])", ctxt);
val = 0; - if (virNodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def, - _("no removable media size supplied for '%s'"), - _("invalid removable media size supplied for '%s'")) < 0) { + if (nodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def, + _("no removable media size supplied for '%s'"), + _("invalid removable media size supplied for '%s'")) < 0) { ctxt->node = orignode2; VIR_FREE(type); goto out; @@ -680,9 +689,9 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
if (!(data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) { val = 0; - if (virNodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def, - _("no size supplied for '%s'"), - _("invalid size supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def, + _("no size supplied for '%s'"), + _("invalid size supplied for '%s'")) < 0) goto out; data->storage.size = val; } @@ -694,11 +703,12 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -706,28 +716,28 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node;
- if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, - &data->scsi.host, def, - _("no SCSI host ID supplied for '%s'"), - _("invalid SCSI host ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./host[1])", ctxt, + &data->scsi.host, def, + _("no SCSI host ID supplied for '%s'"), + _("invalid SCSI host ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->scsi.bus, def, - _("no SCSI bus ID supplied for '%s'"), - _("invalid SCSI bus ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./bus[1])", ctxt, + &data->scsi.bus, def, + _("no SCSI bus ID supplied for '%s'"), + _("invalid SCSI bus ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./target[1])", ctxt, - &data->scsi.target, def, - _("no SCSI target ID supplied for '%s'"), + if (nodeDevCapsDefParseULong("number(./target[1])", ctxt, + &data->scsi.target, def, + _("no SCSI target ID supplied for '%s'"), _("invalid SCSI target ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./lun[1])", ctxt, - &data->scsi.lun, def, - _("no SCSI LUN ID supplied for '%s'"), - _("invalid SCSI LUN ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./lun[1])", ctxt, + &data->scsi.lun, def, + _("no SCSI LUN ID supplied for '%s'"), + _("invalid SCSI LUN ID supplied for '%s'")) < 0) goto out;
data->scsi.type = virXPathString("string(./type[1])", ctxt); @@ -740,10 +750,10 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt,
static int -virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -768,12 +778,12 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt,
static int -virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data, - int create, - const char *virt_type) +nodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data, + int create, + const char *virt_type) { xmlNodePtr orignode, *nodes = NULL; int ret = -1, n = 0; @@ -784,17 +794,17 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, ctxt->node = node;
if (create == EXISTING_DEVICE) { - if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, - &data->scsi_host.host, def, - _("no SCSI host ID supplied for '%s'"), - _("invalid SCSI host ID supplied for '%s'")) < 0) { + if (nodeDevCapsDefParseULong("number(./host[1])", ctxt, + &data->scsi_host.host, def, + _("no SCSI host ID supplied for '%s'"), + _("invalid SCSI host ID supplied for '%s'")) < 0) { goto out; } /* Optional unique_id value */ data->scsi_host.unique_id = -1; - if (virNodeDevCapsDefParseIntOptional("number(./unique_id[1])", ctxt, - &data->scsi_host.unique_id, def, - _("invalid unique_id supplied for '%s'")) < 0) { + if (nodeDevCapsDefParseIntOptional("number(./unique_id[1])", ctxt, + &data->scsi_host.unique_id, def, + _("invalid unique_id supplied for '%s'")) < 0) { goto out; } } @@ -825,9 +835,9 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, orignode2 = ctxt->node; ctxt->node = nodes[i];
- if (virNodeDevCapsDefParseString("string(./wwnn[1])", - ctxt, - &data->scsi_host.wwnn) < 0) { + if (nodeDevCapsDefParseString("string(./wwnn[1])", + ctxt, + &data->scsi_host.wwnn) < 0) { if (virRandomGenerateWWN(&data->scsi_host.wwnn, virt_type) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("no WWNN supplied for '%s', and " @@ -837,9 +847,9 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, } }
- if (virNodeDevCapsDefParseString("string(./wwpn[1])", - ctxt, - &data->scsi_host.wwpn) < 0) { + if (nodeDevCapsDefParseString("string(./wwpn[1])", + ctxt, + &data->scsi_host.wwpn) < 0) { if (virRandomGenerateWWN(&data->scsi_host.wwpn, virt_type) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("no WWPN supplied for '%s', and " @@ -849,9 +859,9 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, } }
- if (virNodeDevCapsDefParseString("string(./fabric_wwn[1])", - ctxt, - &data->scsi_host.fabric_wwn) < 0) + if (nodeDevCapsDefParseString("string(./fabric_wwn[1])", + ctxt, + &data->scsi_host.fabric_wwn) < 0) VIR_DEBUG("No fabric_wwn defined for '%s'", def->name);
ctxt->node = orignode2; @@ -877,10 +887,10 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
static int -virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapNetParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode, lnk; size_t i = -1; @@ -954,11 +964,12 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -966,27 +977,27 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node;
- if (virNodeDevCapsDefParseULong("number(./number[1])", ctxt, - &data->usb_if.number, def, - _("no USB interface number supplied for '%s'"), - _("invalid USB interface number supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./number[1])", ctxt, + &data->usb_if.number, def, + _("no USB interface number supplied for '%s'"), + _("invalid USB interface number supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./class[1])", ctxt, - &data->usb_if._class, def, - _("no USB interface class supplied for '%s'"), - _("invalid USB interface class supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./class[1])", ctxt, + &data->usb_if._class, def, + _("no USB interface class supplied for '%s'"), + _("invalid USB interface class supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./subclass[1])", ctxt, - &data->usb_if.subclass, def, - _("no USB interface subclass supplied for '%s'"), - _("invalid USB interface subclass supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./subclass[1])", ctxt, + &data->usb_if.subclass, def, + _("no USB interface subclass supplied for '%s'"), + _("invalid USB interface subclass supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./protocol[1])", ctxt, - &data->usb_if.protocol, def, - _("no USB interface protocol supplied for '%s'"), + if (nodeDevCapsDefParseULong("number(./protocol[1])", ctxt, + &data->usb_if.protocol, def, + _("no USB interface protocol supplied for '%s'"), _("invalid USB interface protocol supplied for '%s'")) < 0) goto out;
@@ -998,13 +1009,14 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapsDefParseHexId(const char *xpath, - xmlXPathContextPtr ctxt, - unsigned *value, - virNodeDeviceDefPtr def, - const char *missing_error_fmt, - const char *invalid_error_fmt) +nodeDevCapsDefParseHexId(const char *xpath, + xmlXPathContextPtr ctxt, + unsigned *value, + virNodeDeviceDefPtr def, + const char *missing_error_fmt, + const char *invalid_error_fmt) { int ret; unsigned long val; @@ -1021,11 +1033,12 @@ virNodeDevCapsDefParseHexId(const char *xpath, return 0; }
+ static int -virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -1033,28 +1046,28 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node;
- if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->usb_dev.bus, def, - _("no USB bus number supplied for '%s'"), - _("invalid USB bus number supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./bus[1])", ctxt, + &data->usb_dev.bus, def, + _("no USB bus number supplied for '%s'"), + _("invalid USB bus number supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./device[1])", ctxt, - &data->usb_dev.device, def, - _("no USB device number supplied for '%s'"), - _("invalid USB device number supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./device[1])", ctxt, + &data->usb_dev.device, def, + _("no USB device number supplied for '%s'"), + _("invalid USB device number supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, - &data->usb_dev.vendor, def, - _("no USB vendor ID supplied for '%s'"), - _("invalid USB vendor ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, + &data->usb_dev.vendor, def, + _("no USB vendor ID supplied for '%s'"), + _("invalid USB vendor ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, - &data->usb_dev.product, def, - _("no USB product ID supplied for '%s'"), - _("invalid USB product ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, + &data->usb_dev.product, def, + _("no USB product ID supplied for '%s'"), + _("invalid USB product ID supplied for '%s'")) < 0) goto out;
data->usb_dev.vendor_name = virXPathString("string(./vendor[1])", ctxt); @@ -1066,10 +1079,11 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr iommuGroupNode, - virNodeDevCapDataPtr data) +nodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr iommuGroupNode, + virNodeDevCapDataPtr data) { xmlNodePtr origNode = ctxt->node; xmlNodePtr *addrNodes = NULL; @@ -1122,10 +1136,11 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr linkNode, - virPCIELinkPtr lnk) +nodeDevPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr linkNode, + virPCIELinkPtr lnk) { xmlNodePtr origNode = ctxt->node; int ret = -1, speed; @@ -1168,10 +1183,11 @@ virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr pciExpressNode, - virPCIEDeviceInfoPtr pci_express) +nodeDevPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr pciExpressNode, + virPCIEDeviceInfoPtr pci_express) { xmlNodePtr lnk, origNode = ctxt->node; int ret = -1; @@ -1182,8 +1198,8 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, if (VIR_ALLOC(pci_express->link_cap) < 0) goto cleanup;
- if (virPCIEDeviceInfoLinkParseXML(ctxt, lnk, - pci_express->link_cap) < 0) + if (nodeDevPCIEDeviceInfoLinkParseXML(ctxt, lnk, + pci_express->link_cap) < 0) goto cleanup; }
@@ -1191,8 +1207,8 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, if (VIR_ALLOC(pci_express->link_sta) < 0) goto cleanup;
- if (virPCIEDeviceInfoLinkParseXML(ctxt, lnk, - pci_express->link_sta) < 0) + if (nodeDevPCIEDeviceInfoLinkParseXML(ctxt, lnk, + pci_express->link_sta) < 0) goto cleanup; }
@@ -1204,9 +1220,9 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt,
static int -virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, + xmlNodePtr node, + virNodeDevCapDataPtr data) { char *maxFuncsStr = virXMLPropString(node, "maxCount"); char *type = virXMLPropString(node, "type"); @@ -1292,10 +1308,10 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
static int -virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode, iommuGroupNode, pciExpress; xmlNodePtr *nodes = NULL; @@ -1308,40 +1324,40 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, orignode = ctxt->node; ctxt->node = node;
- if (virNodeDevCapsDefParseULong("number(./domain[1])", ctxt, - &data->pci_dev.domain, def, - _("no PCI domain ID supplied for '%s'"), - _("invalid PCI domain ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./domain[1])", ctxt, + &data->pci_dev.domain, def, + _("no PCI domain ID supplied for '%s'"), + _("invalid PCI domain ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->pci_dev.bus, def, - _("no PCI bus ID supplied for '%s'"), - _("invalid PCI bus ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./bus[1])", ctxt, + &data->pci_dev.bus, def, + _("no PCI bus ID supplied for '%s'"), + _("invalid PCI bus ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./slot[1])", ctxt, - &data->pci_dev.slot, def, - _("no PCI slot ID supplied for '%s'"), - _("invalid PCI slot ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./slot[1])", ctxt, + &data->pci_dev.slot, def, + _("no PCI slot ID supplied for '%s'"), + _("invalid PCI slot ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseULong("number(./function[1])", ctxt, - &data->pci_dev.function, def, - _("no PCI function ID supplied for '%s'"), - _("invalid PCI function ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseULong("number(./function[1])", ctxt, + &data->pci_dev.function, def, + _("no PCI function ID supplied for '%s'"), + _("invalid PCI function ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, - &data->pci_dev.vendor, def, - _("no PCI vendor ID supplied for '%s'"), - _("invalid PCI vendor ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, + &data->pci_dev.vendor, def, + _("no PCI vendor ID supplied for '%s'"), + _("invalid PCI vendor ID supplied for '%s'")) < 0) goto out;
- if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, - &data->pci_dev.product, def, - _("no PCI product ID supplied for '%s'"), - _("invalid PCI product ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, + &data->pci_dev.product, def, + _("no PCI product ID supplied for '%s'"), + _("invalid PCI product ID supplied for '%s'")) < 0) goto out;
data->pci_dev.vendor_name = virXPathString("string(./vendor[1])", ctxt); @@ -1351,30 +1367,30 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, goto out;
for (i = 0; i < n; i++) { - if (virNodeDevPCICapabilityParseXML(ctxt, nodes[i], data) < 0) + if (nodeDevPCICapabilityParseXML(ctxt, nodes[i], data) < 0) goto out; } VIR_FREE(nodes);
if ((iommuGroupNode = virXPathNode("./iommuGroup[1]", ctxt))) { - if (virNodeDevCapPCIDevIommuGroupParseXML(ctxt, iommuGroupNode, - data) < 0) { + if (nodeDevCapPCIDevIommuGroupParseXML(ctxt, iommuGroupNode, + data) < 0) { goto out; } }
/* The default value is -1 since zero is valid NUMA node number */ data->pci_dev.numa_node = -1; - if (virNodeDevCapsDefParseIntOptional("number(./numa[1]/@node)", ctxt, - &data->pci_dev.numa_node, def, - _("invalid NUMA node ID supplied for '%s'")) < 0) + if (nodeDevCapsDefParseIntOptional("number(./numa[1]/@node)", ctxt, + &data->pci_dev.numa_node, def, + _("invalid NUMA node ID supplied for '%s'")) < 0) goto out;
if ((pciExpress = virXPathNode("./pci-express[1]", ctxt))) { if (VIR_ALLOC(pci_express) < 0) goto out;
- if (virPCIEDeviceInfoParseXML(ctxt, pciExpress, pci_express) < 0) + if (nodeDevPCIEDeviceInfoParseXML(ctxt, pciExpress, pci_express) < 0) goto out;
data->pci_dev.pci_express = pci_express; @@ -1391,11 +1407,12 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static int -virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - virNodeDevCapDataPtr data) +nodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + virNodeDevCapDataPtr data) { xmlNodePtr orignode; int ret = -1; @@ -1435,12 +1452,13 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, return ret; }
+ static virNodeDevCapsDefPtr -virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, - virNodeDeviceDefPtr def, - xmlNodePtr node, - int create, - const char *virt_type) +nodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, + virNodeDeviceDefPtr def, + xmlNodePtr node, + int create, + const char *virt_type) { virNodeDevCapsDefPtr caps; char *tmp; @@ -1467,37 +1485,37 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt,
switch (caps->data.type) { case VIR_NODE_DEV_CAP_SYSTEM: - ret = virNodeDevCapSystemParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapSystemParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_PCI_DEV: - ret = virNodeDevCapPCIDevParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapPCIDevParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_USB_DEV: - ret = virNodeDevCapUSBDevParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapUSBDevParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_USB_INTERFACE: - ret = virNodeDevCapUSBInterfaceParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapUSBInterfaceParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_NET: - ret = virNodeDevCapNetParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapNetParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_SCSI_HOST: - ret = virNodeDevCapSCSIHostParseXML(ctxt, def, node, - &caps->data, - create, - virt_type); + ret = nodeDevCapSCSIHostParseXML(ctxt, def, node, + &caps->data, + create, + virt_type); break; case VIR_NODE_DEV_CAP_SCSI_TARGET: - ret = virNodeDevCapSCSITargetParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapSCSITargetParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_SCSI: - ret = virNodeDevCapSCSIParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapSCSIParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_STORAGE: - ret = virNodeDevCapStorageParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapStorageParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_DRM: - ret = virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data); + ret = nodeDevCapDRMParseXML(ctxt, def, node, &caps->data); break; case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: @@ -1519,10 +1537,11 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, return NULL; }
+ static virNodeDeviceDefPtr -virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, - int create, - const char *virt_type) +nodeDeviceDefParseXML(xmlXPathContextPtr ctxt, + int create, + const char *virt_type) { virNodeDeviceDefPtr def; virNodeDevCapsDefPtr *next_cap; @@ -1614,10 +1633,10 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
next_cap = &def->caps; for (i = 0; i < n; i++) { - *next_cap = virNodeDevCapsDefParseXML(ctxt, def, - nodes[i], - create, - virt_type); + *next_cap = nodeDevCapsDefParseXML(ctxt, def, + nodes[i], + create, + virt_type); if (!*next_cap) goto error;
@@ -1633,6 +1652,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, return NULL; }
+ virNodeDeviceDefPtr virNodeDeviceDefParseNode(xmlDocPtr xml, xmlNodePtr root, @@ -1657,18 +1677,19 @@ virNodeDeviceDefParseNode(xmlDocPtr xml, }
ctxt->node = root; - def = virNodeDeviceDefParseXML(ctxt, create, virt_type); + def = nodeDeviceDefParseXML(ctxt, create, virt_type);
cleanup: xmlXPathFreeContext(ctxt); return def; }
+ static virNodeDeviceDefPtr -virNodeDeviceDefParse(const char *str, - const char *filename, - int create, - const char *virt_type) +nodeDeviceDefParse(const char *str, + const char *filename, + int create, + const char *virt_type) { xmlDocPtr xml; virNodeDeviceDefPtr def = NULL; @@ -1682,22 +1703,25 @@ virNodeDeviceDefParse(const char *str, return def; }
+ virNodeDeviceDefPtr virNodeDeviceDefParseString(const char *str, int create, const char *virt_type) { - return virNodeDeviceDefParse(str, NULL, create, virt_type); + return nodeDeviceDefParse(str, NULL, create, virt_type); }
+ virNodeDeviceDefPtr virNodeDeviceDefParseFile(const char *filename, int create, const char *virt_type) { - return virNodeDeviceDefParse(NULL, filename, create, virt_type); + return nodeDeviceDefParse(NULL, filename, create, virt_type); }
+ /* * Return fc_host dev's WWNN and WWPN */ diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 83f7217..a416fb8 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -33,7 +33,9 @@ VIR_LOG_INIT("conf.virnodedeviceobj");
-int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) +int +virNodeDeviceHasCap(const virNodeDeviceObj *dev, + const char *cap) { virNodeDevCapsDefPtr caps = dev->def->caps; const char *fc_host_cap = @@ -58,7 +60,7 @@ int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) }
-/* virNodeDeviceFindFCCapDef: +/* nodeDeviceFindFCCapDef: * @dev: Pointer to current device * * Search the device object 'caps' array for fc_host capability. @@ -67,7 +69,7 @@ int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) * Pointer to the caps or NULL if not found */ static virNodeDevCapsDefPtr -virNodeDeviceFindFCCapDef(const virNodeDeviceObj *dev) +nodeDeviceFindFCCapDef(const virNodeDeviceObj *dev) { virNodeDevCapsDefPtr caps = dev->def->caps;
@@ -125,8 +127,9 @@ virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, }
-virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, - const char *name) +virNodeDeviceObjPtr +virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, + const char *name) { size_t i;
@@ -142,16 +145,16 @@ virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs,
static virNodeDeviceObjPtr -virNodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, - const char *parent_wwnn, - const char *parent_wwpn) +nodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, + const char *parent_wwnn, + const char *parent_wwpn) { size_t i;
for (i = 0; i < devs->count; i++) { virNodeDevCapsDefPtr cap; virNodeDeviceObjLock(devs->objs[i]); - if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) && + if ((cap = nodeDeviceFindFCCapDef(devs->objs[i])) && STREQ_NULLABLE(cap->data.scsi_host.wwnn, parent_wwnn) && STREQ_NULLABLE(cap->data.scsi_host.wwpn, parent_wwpn)) return devs->objs[i]; @@ -163,15 +166,15 @@ virNodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs,
static virNodeDeviceObjPtr -virNodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs, - const char *parent_fabric_wwn) +nodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs, + const char *parent_fabric_wwn) { size_t i;
for (i = 0; i < devs->count; i++) { virNodeDevCapsDefPtr cap; virNodeDeviceObjLock(devs->objs[i]); - if ((cap = virNodeDeviceFindFCCapDef(devs->objs[i])) && + if ((cap = nodeDeviceFindFCCapDef(devs->objs[i])) && STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_wwn)) return devs->objs[i]; virNodeDeviceObjUnlock(devs->objs[i]); @@ -182,8 +185,8 @@ virNodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs,
static virNodeDeviceObjPtr -virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, - const char *cap) +nodeDeviceFindByCap(virNodeDeviceObjListPtr devs, + const char *cap) { size_t i;
@@ -198,7 +201,8 @@ virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, }
-void virNodeDeviceObjFree(virNodeDeviceObjPtr dev) +void +virNodeDeviceObjFree(virNodeDeviceObjPtr dev) { if (!dev) return; @@ -212,7 +216,9 @@ void virNodeDeviceObjFree(virNodeDeviceObjPtr dev) VIR_FREE(dev); }
-void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) + +void +virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) { size_t i; for (i = 0; i < devs->count; i++) @@ -221,8 +227,10 @@ void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) devs->count = 0; }
-virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def) + +virNodeDeviceObjPtr +virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def) { virNodeDeviceObjPtr device;
@@ -254,8 +262,10 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs,
}
-void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr *dev) + +void +virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr *dev) { size_t i;
@@ -279,7 +289,7 @@ void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, /* * Return the NPIV dev's parent device name */ -/* virNodeDeviceFindFCParentHost: +/* nodeDeviceFindFCParentHost: * @parent: Pointer to node device object * * Search the capabilities for the device to find the FC capabilities @@ -289,7 +299,7 @@ void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, * parent_host value on success (>= 0), -1 otherwise. */ static int -virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) +nodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) { virNodeDevCapsDefPtr cap = virNodeDeviceFindVPORTCapDef(parent);
@@ -306,9 +316,9 @@ virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent)
static int -virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_name) +nodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_name) { virNodeDeviceObjPtr parent = NULL; int ret; @@ -320,7 +330,7 @@ virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, return -1; }
- ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent);
virNodeDeviceObjUnlock(parent);
@@ -329,22 +339,22 @@ virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs,
static int -virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_wwnn, - const char *parent_wwpn) +nodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_wwnn, + const char *parent_wwpn) { virNodeDeviceObjPtr parent = NULL; int ret;
- if (!(parent = virNodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwpn))) { + if (!(parent = nodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwpn))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); return -1; }
- ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent);
virNodeDeviceObjUnlock(parent);
@@ -353,21 +363,21 @@ virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs,
static int -virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_fabric_wwn) +nodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_fabric_wwn) { virNodeDeviceObjPtr parent = NULL; int ret;
- if (!(parent = virNodeDeviceFindByFabricWWN(devs, parent_fabric_wwn))) { + if (!(parent = nodeDeviceFindByFabricWWN(devs, parent_fabric_wwn))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); return -1; }
- ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent);
virNodeDeviceObjUnlock(parent);
@@ -376,19 +386,19 @@ virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs,
static int -virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) +nodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) { virNodeDeviceObjPtr parent = NULL; const char *cap = virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); int ret;
- if (!(parent = virNodeDeviceFindByCap(devs, cap))) { + if (!(parent = nodeDeviceFindByCap(devs, cap))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not find any vport capable device")); return -1; }
- ret = virNodeDeviceFindFCParentHost(parent); + ret = nodeDeviceFindFCParentHost(parent);
virNodeDeviceObjUnlock(parent);
@@ -404,38 +414,42 @@ virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, int parent_host = -1;
if (def->parent) { - parent_host = virNodeDeviceGetParentHostByParent(devs, def->name, - def->parent); + parent_host = nodeDeviceGetParentHostByParent(devs, def->name, + def->parent); } else if (def->parent_wwnn && def->parent_wwpn) { - parent_host = virNodeDeviceGetParentHostByWWNs(devs, def->name, - def->parent_wwnn, - def->parent_wwpn); + parent_host = nodeDeviceGetParentHostByWWNs(devs, def->name, + def->parent_wwnn, + def->parent_wwpn); } else if (def->parent_fabric_wwn) { parent_host = - virNodeDeviceGetParentHostByFabricWWN(devs, def->name, - def->parent_fabric_wwn); + nodeDeviceGetParentHostByFabricWWN(devs, def->name, + def->parent_fabric_wwn); } else if (create == CREATE_DEVICE) { /* Try to find a vport capable scsi_host when no parent supplied */ - parent_host = virNodeDeviceFindVportParentHost(devs); + parent_host = nodeDeviceFindVportParentHost(devs); }
return parent_host; }
-void virNodeDeviceObjLock(virNodeDeviceObjPtr obj) +void +virNodeDeviceObjLock(virNodeDeviceObjPtr obj) { virMutexLock(&obj->lock); }
-void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) + +void +virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) { virMutexUnlock(&obj->lock); }
+ static bool -virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, - int type) +nodeDeviceCapMatch(virNodeDeviceObjPtr devobj, + int type) { virNodeDevCapsDefPtr cap = NULL;
@@ -459,11 +473,12 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, return false; }
+ #define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \ - virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG)) + nodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG)) static bool -virNodeDeviceMatch(virNodeDeviceObjPtr devobj, - unsigned int flags) +nodeDeviceMatch(virNodeDeviceObjPtr devobj, + unsigned int flags) { /* filter by cap type */ if (flags & VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP) { @@ -487,6 +502,7 @@ virNodeDeviceMatch(virNodeDeviceObjPtr devobj, } #undef MATCH
+ int virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjList devobjs, @@ -507,7 +523,7 @@ virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjPtr devobj = devobjs.objs[i]; virNodeDeviceObjLock(devobj); if ((!filter || filter(conn, devobj->def)) && - virNodeDeviceMatch(devobj, flags)) { + nodeDeviceMatch(devobj, flags)) { if (devices) { if (!(device = virGetNodeDevice(conn, devobj->def->name)) || VIR_STRDUP(device->parent, devobj->def->parent) < 0) {

On Thu, Mar 02, 2017 at 08:04:32AM -0500, John Ferlan wrote:
On 03/01/2017 07:27 PM, John Ferlan wrote:
Alter the static functions from virNodeDev* to just nodeDev* as a visual cue to determine which are local or not when reading code.
Rather than trying to respond individually to points raised... I'll just go with one...
[snip]
I can rework this patch to just do the match of more modern libvirt techniques described in the next paragraph and drop the renaming. It's not that important.
One thing I noticed is that we don't appear to have documented our preferred naming conventions for files, struct, variables, functions, etc, in the hacking file. This is a problem because our code is not entirely consistent due to the conventions having changed over time. This missing doc something we should fix, so that in future we can avoid needing to debate it and just point to the documented conventions. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr/ :|

Use "virNodeDeviceObj" as a prefix for any external API in virnodedeviceobj Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virnodedeviceobj.c | 28 ++++++++++++++-------------- src/conf/virnodedeviceobj.h | 18 +++++++++--------- src/node_device/node_device_driver.c | 24 ++++++++++++------------ src/node_device/node_device_hal.c | 10 ++++------ src/node_device/node_device_udev.c | 12 ++++++------ src/test/test_driver.c | 28 ++++++++++++++-------------- 6 files changed, 59 insertions(+), 61 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index a416fb8..ee0b2ae 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -34,8 +34,8 @@ VIR_LOG_INIT("conf.virnodedeviceobj"); int -virNodeDeviceHasCap(const virNodeDeviceObj *dev, - const char *cap) +virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, + const char *cap) { virNodeDevCapsDefPtr caps = dev->def->caps; const char *fc_host_cap = @@ -109,8 +109,8 @@ virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *dev) virNodeDeviceObjPtr -virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) +virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) { size_t i; @@ -128,8 +128,8 @@ virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr -virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, - const char *name) +virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs, + const char *name) { size_t i; @@ -192,7 +192,7 @@ nodeDeviceFindByCap(virNodeDeviceObjListPtr devs, for (i = 0; i < devs->count; i++) { virNodeDeviceObjLock(devs->objs[i]); - if (virNodeDeviceHasCap(devs->objs[i], cap)) + if (virNodeDeviceObjHasCap(devs->objs[i], cap)) return devs->objs[i]; virNodeDeviceObjUnlock(devs->objs[i]); } @@ -229,12 +229,12 @@ virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) virNodeDeviceObjPtr -virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def) +virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def) { virNodeDeviceObjPtr device; - if ((device = virNodeDeviceFindByName(devs, def->name))) { + if ((device = virNodeDeviceObjFindByName(devs, def->name))) { virNodeDeviceDefFree(device->def); device->def = def; return device; @@ -323,7 +323,7 @@ nodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr parent = NULL; int ret; - if (!(parent = virNodeDeviceFindByName(devs, parent_name))) { + if (!(parent = virNodeDeviceObjFindByName(devs, parent_name))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); @@ -407,9 +407,9 @@ nodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) int -virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create) +virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create) { int parent_host = -1; diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 6ad7fb1..b4409b7 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -40,24 +40,24 @@ struct _virNodeDeviceDriverState { }; -int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap); +int virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, const char *cap); -virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, +virNodeDeviceObjPtr virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs, const char *name); virNodeDeviceObjPtr -virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) +virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) ATTRIBUTE_NONNULL(2); -virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def); +virNodeDeviceObjPtr virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def); void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr *dev); -int virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create); +int virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create); void virNodeDeviceObjFree(virNodeDeviceObjPtr dev); diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 5d57006..0869b1b 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -173,7 +173,7 @@ nodeNumOfDevices(virConnectPtr conn, virNodeDeviceObjLock(obj); if (virNodeNumOfDevicesCheckACL(conn, obj->def) && ((cap == NULL) || - virNodeDeviceHasCap(obj, cap))) + virNodeDeviceObjHasCap(obj, cap))) ++ndevs; virNodeDeviceObjUnlock(obj); } @@ -202,7 +202,7 @@ nodeListDevices(virConnectPtr conn, virNodeDeviceObjLock(obj); if (virNodeListDevicesCheckACL(conn, obj->def) && (cap == NULL || - virNodeDeviceHasCap(obj, cap))) { + virNodeDeviceObjHasCap(obj, cap))) { if (VIR_STRDUP(names[ndevs++], obj->def->name) < 0) { virNodeDeviceObjUnlock(obj); goto failure; @@ -249,7 +249,7 @@ nodeDeviceLookupByName(virConnectPtr conn, const char *name) virNodeDevicePtr ret = NULL; nodeDeviceLock(); - obj = virNodeDeviceFindByName(&driver->devs, name); + obj = virNodeDeviceObjFindByName(&driver->devs, name); nodeDeviceUnlock(); if (!obj) { @@ -337,7 +337,7 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev, virCheckFlags(0, NULL); nodeDeviceLock(); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); if (!obj) { @@ -370,7 +370,7 @@ nodeDeviceGetParent(virNodeDevicePtr dev) char *ret = NULL; nodeDeviceLock(); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); if (!obj) { @@ -407,7 +407,7 @@ nodeDeviceNumOfCaps(virNodeDevicePtr dev) int ret = -1; nodeDeviceLock(); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); if (!obj) { @@ -452,7 +452,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) int ret = -1; nodeDeviceLock(); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); if (!obj) { @@ -590,8 +590,8 @@ nodeDeviceCreateXML(virConnectPtr conn, if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) goto cleanup; - if ((parent_host = virNodeDeviceGetParentHost(&driver->devs, def, - CREATE_DEVICE)) < 0) + if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def, + CREATE_DEVICE)) < 0) goto cleanup; if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) @@ -625,7 +625,7 @@ nodeDeviceDestroy(virNodeDevicePtr dev) int parent_host = -1; nodeDeviceLock(); - if (!(obj = virNodeDeviceFindByName(&driver->devs, dev->name))) { + if (!(obj = virNodeDeviceObjFindByName(&driver->devs, dev->name))) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); @@ -645,8 +645,8 @@ nodeDeviceDestroy(virNodeDevicePtr dev) def = obj->def; virNodeDeviceObjUnlock(obj); obj = NULL; - if ((parent_host = virNodeDeviceGetParentHost(&driver->devs, def, - EXISTING_DEVICE)) < 0) + if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def, + EXISTING_DEVICE)) < 0) goto cleanup; if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0) diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index fb7bf25..f17618c 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -493,9 +493,7 @@ dev_create(const char *udi) /* Some devices don't have a path in sysfs, so ignore failure */ (void)get_str_prop(ctx, udi, "linux.sysfs_path", &devicePath); - dev = virNodeDeviceAssignDef(&driver->devs, - def); - + dev = virNodeDeviceObjAssignDef(&driver->devs, def); if (!dev) { VIR_FREE(devicePath); goto failure; @@ -525,7 +523,7 @@ dev_refresh(const char *udi) virNodeDeviceObjPtr dev; nodeDeviceLock(); - dev = virNodeDeviceFindByName(&driver->devs, name); + dev = virNodeDeviceObjFindByName(&driver->devs, name); if (dev) { /* Simply "rediscover" device -- incrementally handling changes * to sub-capabilities (like net.80203) is nasty ... so avoid it. @@ -557,7 +555,7 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED, virNodeDeviceObjPtr dev; nodeDeviceLock(); - dev = virNodeDeviceFindByName(&driver->devs, name); + dev = virNodeDeviceObjFindByName(&driver->devs, name); VIR_DEBUG("%s", name); if (dev) virNodeDeviceObjRemove(&driver->devs, &dev); @@ -575,7 +573,7 @@ device_cap_added(LibHalContext *ctx, virNodeDeviceObjPtr dev; nodeDeviceLock(); - dev = virNodeDeviceFindByName(&driver->devs, name); + dev = virNodeDeviceObjFindByName(&driver->devs, name); nodeDeviceUnlock(); VIR_DEBUG("%s %s", cap, name); if (dev) { diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 1016075..6bc0a53 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1099,7 +1099,7 @@ static int udevRemoveOneDevice(struct udev_device *device) int ret = -1; name = udev_device_get_syspath(device); - dev = virNodeDeviceFindBySysfsPath(&driver->devs, name); + dev = virNodeDeviceObjFindBySysfsPath(&driver->devs, name); if (!dev) { VIR_DEBUG("Failed to find device to remove that has udev name '%s'", @@ -1146,8 +1146,8 @@ static int udevSetParent(struct udev_device *device, goto cleanup; } - dev = virNodeDeviceFindBySysfsPath(&driver->devs, - parent_sysfs_path); + dev = virNodeDeviceObjFindBySysfsPath(&driver->devs, + parent_sysfs_path); if (dev != NULL) { if (VIR_STRDUP(def->parent, dev->def->name) < 0) { virNodeDeviceObjUnlock(dev); @@ -1203,7 +1203,7 @@ static int udevAddOneDevice(struct udev_device *device) if (udevSetParent(device, def) != 0) goto cleanup; - dev = virNodeDeviceFindByName(&driver->devs, def->name); + dev = virNodeDeviceObjFindByName(&driver->devs, def->name); if (dev) { virNodeDeviceObjUnlock(dev); new_device = false; @@ -1211,7 +1211,7 @@ static int udevAddOneDevice(struct udev_device *device) /* If this is a device change, the old definition will be freed * and the current definition will take its place. */ - dev = virNodeDeviceAssignDef(&driver->devs, def); + dev = virNodeDeviceObjAssignDef(&driver->devs, def); if (dev == NULL) goto cleanup; @@ -1492,7 +1492,7 @@ static int udevSetupSystemDev(void) udevGetDMIData(&def->caps->data); #endif - dev = virNodeDeviceAssignDef(&driver->devs, def); + dev = virNodeDeviceObjAssignDef(&driver->devs, def); if (dev == NULL) goto cleanup; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c6214c6..61c82b9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1166,7 +1166,7 @@ testParseNodedevs(testDriverPtr privconn, if (!def) goto error; - if (!(obj = virNodeDeviceAssignDef(&privconn->devs, def))) { + if (!(obj = virNodeDeviceObjAssignDef(&privconn->devs, def))) { virNodeDeviceDefFree(def); goto error; } @@ -5424,7 +5424,7 @@ testNodeNumOfDevices(virConnectPtr conn, testDriverLock(driver); for (i = 0; i < driver->devs.count; i++) if ((cap == NULL) || - virNodeDeviceHasCap(driver->devs.objs[i], cap)) + virNodeDeviceObjHasCap(driver->devs.objs[i], cap)) ++ndevs; testDriverUnlock(driver); @@ -5448,7 +5448,7 @@ testNodeListDevices(virConnectPtr conn, for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) { virNodeDeviceObjLock(driver->devs.objs[i]); if (cap == NULL || - virNodeDeviceHasCap(driver->devs.objs[i], cap)) { + virNodeDeviceObjHasCap(driver->devs.objs[i], cap)) { if (VIR_STRDUP(names[ndevs++], driver->devs.objs[i]->def->name) < 0) { virNodeDeviceObjUnlock(driver->devs.objs[i]); goto failure; @@ -5476,7 +5476,7 @@ testNodeDeviceLookupByName(virConnectPtr conn, const char *name) virNodeDevicePtr ret = NULL; testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, name); + obj = virNodeDeviceObjFindByName(&driver->devs, name); testDriverUnlock(driver); if (!obj) { @@ -5508,7 +5508,7 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, virCheckFlags(0, NULL); testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver); if (!obj) { @@ -5534,7 +5534,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) char *ret = NULL; testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver); if (!obj) { @@ -5568,7 +5568,7 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) int ret = -1; testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver); if (!obj) { @@ -5599,7 +5599,7 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) int ret = -1; testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver); if (!obj) { @@ -5647,7 +5647,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, * using the scsi_host11 definition, changing the name and the * scsi_host capability fields before calling virNodeDeviceAssignDef * to add the def to the node device objects list. */ - if (!(objcopy = virNodeDeviceFindByName(&driver->devs, "scsi_host11"))) + if (!(objcopy = virNodeDeviceObjFindByName(&driver->devs, "scsi_host11"))) goto cleanup; xml = virNodeDeviceDefFormat(objcopy->def); @@ -5687,7 +5687,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, caps = caps->next; } - if (!(obj = virNodeDeviceAssignDef(&driver->devs, def))) + if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def))) goto cleanup; def = NULL; @@ -5730,7 +5730,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, /* Unlike the "real" code we don't need the parent_host in order to * call virVHBAManageVport, but still let's make sure the code finds * something valid and no one messed up the mock environment. */ - if (virNodeDeviceGetParentHost(&driver->devs, def, CREATE_DEVICE) < 0) + if (virNodeDeviceObjGetParentHost(&driver->devs, def, CREATE_DEVICE) < 0) goto cleanup; /* In the real code, we'd call virVHBAManageVport followed by @@ -5772,7 +5772,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virObjectEventPtr event = NULL; testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver); if (!obj) { @@ -5796,8 +5796,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) /* We do this just for basic validation, but also avoid finding a * vport capable HBA if for some reason our vHBA doesn't exist */ - if (virNodeDeviceGetParentHost(&driver->devs, obj->def, - EXISTING_DEVICE) < 0) { + if (virNodeDeviceObjGetParentHost(&driver->devs, obj->def, + EXISTING_DEVICE) < 0) { obj = NULL; goto out; } -- 2.9.3

On 03/01/2017 07:27 PM, John Ferlan wrote:
Use "virNodeDeviceObj" as a prefix for any external API in virnodedeviceobj
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virnodedeviceobj.c | 28 ++++++++++++++-------------- src/conf/virnodedeviceobj.h | 18 +++++++++--------- src/node_device/node_device_driver.c | 24 ++++++++++++------------ src/node_device/node_device_hal.c | 10 ++++------ src/node_device/node_device_udev.c | 12 ++++++------ src/test/test_driver.c | 28 ++++++++++++++-------------- 6 files changed, 59 insertions(+), 61 deletions(-)
Ugh... Forgot to commit: diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8639979..aed1d3d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -949,11 +949,11 @@ virDomainObjListRename; # conf/virnodedeviceobj.h -virNodeDeviceAssignDef; -virNodeDeviceFindByName; -virNodeDeviceFindBySysfsPath; -virNodeDeviceGetParentHost; -virNodeDeviceHasCap; +virNodeDeviceObjAssignDef; +virNodeDeviceObjFindByName; +virNodeDeviceObjFindBySysfsPath; +virNodeDeviceObjGetParentHost; +virNodeDeviceObjHasCap; virNodeDeviceObjListExport; virNodeDeviceObjListFree; virNodeDeviceObjLock; before sending... John
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index a416fb8..ee0b2ae 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -34,8 +34,8 @@ VIR_LOG_INIT("conf.virnodedeviceobj");
int -virNodeDeviceHasCap(const virNodeDeviceObj *dev, - const char *cap) +virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, + const char *cap) { virNodeDevCapsDefPtr caps = dev->def->caps; const char *fc_host_cap = @@ -109,8 +109,8 @@ virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *dev)
virNodeDeviceObjPtr -virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) +virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) { size_t i;
@@ -128,8 +128,8 @@ virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs,
virNodeDeviceObjPtr -virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, - const char *name) +virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs, + const char *name) { size_t i;
@@ -192,7 +192,7 @@ nodeDeviceFindByCap(virNodeDeviceObjListPtr devs,
for (i = 0; i < devs->count; i++) { virNodeDeviceObjLock(devs->objs[i]); - if (virNodeDeviceHasCap(devs->objs[i], cap)) + if (virNodeDeviceObjHasCap(devs->objs[i], cap)) return devs->objs[i]; virNodeDeviceObjUnlock(devs->objs[i]); } @@ -229,12 +229,12 @@ virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs)
virNodeDeviceObjPtr -virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def) +virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def) { virNodeDeviceObjPtr device;
- if ((device = virNodeDeviceFindByName(devs, def->name))) { + if ((device = virNodeDeviceObjFindByName(devs, def->name))) { virNodeDeviceDefFree(device->def); device->def = def; return device; @@ -323,7 +323,7 @@ nodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr parent = NULL; int ret;
- if (!(parent = virNodeDeviceFindByName(devs, parent_name))) { + if (!(parent = virNodeDeviceObjFindByName(devs, parent_name))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); @@ -407,9 +407,9 @@ nodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs)
int -virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create) +virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create) { int parent_host = -1;
diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 6ad7fb1..b4409b7 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -40,24 +40,24 @@ struct _virNodeDeviceDriverState { };
-int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap); +int virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, const char *cap);
-virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, +virNodeDeviceObjPtr virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs, const char *name); virNodeDeviceObjPtr -virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) +virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) ATTRIBUTE_NONNULL(2);
-virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def); +virNodeDeviceObjPtr virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def);
void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr *dev);
-int virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create); +int virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create);
void virNodeDeviceObjFree(virNodeDeviceObjPtr dev);
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 5d57006..0869b1b 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -173,7 +173,7 @@ nodeNumOfDevices(virConnectPtr conn, virNodeDeviceObjLock(obj); if (virNodeNumOfDevicesCheckACL(conn, obj->def) && ((cap == NULL) || - virNodeDeviceHasCap(obj, cap))) + virNodeDeviceObjHasCap(obj, cap))) ++ndevs; virNodeDeviceObjUnlock(obj); } @@ -202,7 +202,7 @@ nodeListDevices(virConnectPtr conn, virNodeDeviceObjLock(obj); if (virNodeListDevicesCheckACL(conn, obj->def) && (cap == NULL || - virNodeDeviceHasCap(obj, cap))) { + virNodeDeviceObjHasCap(obj, cap))) { if (VIR_STRDUP(names[ndevs++], obj->def->name) < 0) { virNodeDeviceObjUnlock(obj); goto failure; @@ -249,7 +249,7 @@ nodeDeviceLookupByName(virConnectPtr conn, const char *name) virNodeDevicePtr ret = NULL;
nodeDeviceLock(); - obj = virNodeDeviceFindByName(&driver->devs, name); + obj = virNodeDeviceObjFindByName(&driver->devs, name); nodeDeviceUnlock();
if (!obj) { @@ -337,7 +337,7 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev, virCheckFlags(0, NULL);
nodeDeviceLock(); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock();
if (!obj) { @@ -370,7 +370,7 @@ nodeDeviceGetParent(virNodeDevicePtr dev) char *ret = NULL;
nodeDeviceLock(); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock();
if (!obj) { @@ -407,7 +407,7 @@ nodeDeviceNumOfCaps(virNodeDevicePtr dev) int ret = -1;
nodeDeviceLock(); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock();
if (!obj) { @@ -452,7 +452,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) int ret = -1;
nodeDeviceLock(); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock();
if (!obj) { @@ -590,8 +590,8 @@ nodeDeviceCreateXML(virConnectPtr conn, if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) goto cleanup;
- if ((parent_host = virNodeDeviceGetParentHost(&driver->devs, def, - CREATE_DEVICE)) < 0) + if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def, + CREATE_DEVICE)) < 0) goto cleanup;
if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) @@ -625,7 +625,7 @@ nodeDeviceDestroy(virNodeDevicePtr dev) int parent_host = -1;
nodeDeviceLock(); - if (!(obj = virNodeDeviceFindByName(&driver->devs, dev->name))) { + if (!(obj = virNodeDeviceObjFindByName(&driver->devs, dev->name))) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); @@ -645,8 +645,8 @@ nodeDeviceDestroy(virNodeDevicePtr dev) def = obj->def; virNodeDeviceObjUnlock(obj); obj = NULL; - if ((parent_host = virNodeDeviceGetParentHost(&driver->devs, def, - EXISTING_DEVICE)) < 0) + if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def, + EXISTING_DEVICE)) < 0) goto cleanup;
if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0) diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index fb7bf25..f17618c 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -493,9 +493,7 @@ dev_create(const char *udi) /* Some devices don't have a path in sysfs, so ignore failure */ (void)get_str_prop(ctx, udi, "linux.sysfs_path", &devicePath);
- dev = virNodeDeviceAssignDef(&driver->devs, - def); - + dev = virNodeDeviceObjAssignDef(&driver->devs, def); if (!dev) { VIR_FREE(devicePath); goto failure; @@ -525,7 +523,7 @@ dev_refresh(const char *udi) virNodeDeviceObjPtr dev;
nodeDeviceLock(); - dev = virNodeDeviceFindByName(&driver->devs, name); + dev = virNodeDeviceObjFindByName(&driver->devs, name); if (dev) { /* Simply "rediscover" device -- incrementally handling changes * to sub-capabilities (like net.80203) is nasty ... so avoid it. @@ -557,7 +555,7 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED, virNodeDeviceObjPtr dev;
nodeDeviceLock(); - dev = virNodeDeviceFindByName(&driver->devs, name); + dev = virNodeDeviceObjFindByName(&driver->devs, name); VIR_DEBUG("%s", name); if (dev) virNodeDeviceObjRemove(&driver->devs, &dev); @@ -575,7 +573,7 @@ device_cap_added(LibHalContext *ctx, virNodeDeviceObjPtr dev;
nodeDeviceLock(); - dev = virNodeDeviceFindByName(&driver->devs, name); + dev = virNodeDeviceObjFindByName(&driver->devs, name); nodeDeviceUnlock(); VIR_DEBUG("%s %s", cap, name); if (dev) { diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 1016075..6bc0a53 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1099,7 +1099,7 @@ static int udevRemoveOneDevice(struct udev_device *device) int ret = -1;
name = udev_device_get_syspath(device); - dev = virNodeDeviceFindBySysfsPath(&driver->devs, name); + dev = virNodeDeviceObjFindBySysfsPath(&driver->devs, name);
if (!dev) { VIR_DEBUG("Failed to find device to remove that has udev name '%s'", @@ -1146,8 +1146,8 @@ static int udevSetParent(struct udev_device *device, goto cleanup; }
- dev = virNodeDeviceFindBySysfsPath(&driver->devs, - parent_sysfs_path); + dev = virNodeDeviceObjFindBySysfsPath(&driver->devs, + parent_sysfs_path); if (dev != NULL) { if (VIR_STRDUP(def->parent, dev->def->name) < 0) { virNodeDeviceObjUnlock(dev); @@ -1203,7 +1203,7 @@ static int udevAddOneDevice(struct udev_device *device) if (udevSetParent(device, def) != 0) goto cleanup;
- dev = virNodeDeviceFindByName(&driver->devs, def->name); + dev = virNodeDeviceObjFindByName(&driver->devs, def->name); if (dev) { virNodeDeviceObjUnlock(dev); new_device = false; @@ -1211,7 +1211,7 @@ static int udevAddOneDevice(struct udev_device *device)
/* If this is a device change, the old definition will be freed * and the current definition will take its place. */ - dev = virNodeDeviceAssignDef(&driver->devs, def); + dev = virNodeDeviceObjAssignDef(&driver->devs, def); if (dev == NULL) goto cleanup;
@@ -1492,7 +1492,7 @@ static int udevSetupSystemDev(void) udevGetDMIData(&def->caps->data); #endif
- dev = virNodeDeviceAssignDef(&driver->devs, def); + dev = virNodeDeviceObjAssignDef(&driver->devs, def); if (dev == NULL) goto cleanup;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c6214c6..61c82b9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1166,7 +1166,7 @@ testParseNodedevs(testDriverPtr privconn, if (!def) goto error;
- if (!(obj = virNodeDeviceAssignDef(&privconn->devs, def))) { + if (!(obj = virNodeDeviceObjAssignDef(&privconn->devs, def))) { virNodeDeviceDefFree(def); goto error; } @@ -5424,7 +5424,7 @@ testNodeNumOfDevices(virConnectPtr conn, testDriverLock(driver); for (i = 0; i < driver->devs.count; i++) if ((cap == NULL) || - virNodeDeviceHasCap(driver->devs.objs[i], cap)) + virNodeDeviceObjHasCap(driver->devs.objs[i], cap)) ++ndevs; testDriverUnlock(driver);
@@ -5448,7 +5448,7 @@ testNodeListDevices(virConnectPtr conn, for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) { virNodeDeviceObjLock(driver->devs.objs[i]); if (cap == NULL || - virNodeDeviceHasCap(driver->devs.objs[i], cap)) { + virNodeDeviceObjHasCap(driver->devs.objs[i], cap)) { if (VIR_STRDUP(names[ndevs++], driver->devs.objs[i]->def->name) < 0) { virNodeDeviceObjUnlock(driver->devs.objs[i]); goto failure; @@ -5476,7 +5476,7 @@ testNodeDeviceLookupByName(virConnectPtr conn, const char *name) virNodeDevicePtr ret = NULL;
testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, name); + obj = virNodeDeviceObjFindByName(&driver->devs, name); testDriverUnlock(driver);
if (!obj) { @@ -5508,7 +5508,7 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, virCheckFlags(0, NULL);
testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver);
if (!obj) { @@ -5534,7 +5534,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) char *ret = NULL;
testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver);
if (!obj) { @@ -5568,7 +5568,7 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) int ret = -1;
testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver);
if (!obj) { @@ -5599,7 +5599,7 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) int ret = -1;
testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver);
if (!obj) { @@ -5647,7 +5647,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, * using the scsi_host11 definition, changing the name and the * scsi_host capability fields before calling virNodeDeviceAssignDef * to add the def to the node device objects list. */ - if (!(objcopy = virNodeDeviceFindByName(&driver->devs, "scsi_host11"))) + if (!(objcopy = virNodeDeviceObjFindByName(&driver->devs, "scsi_host11"))) goto cleanup;
xml = virNodeDeviceDefFormat(objcopy->def); @@ -5687,7 +5687,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, caps = caps->next; }
- if (!(obj = virNodeDeviceAssignDef(&driver->devs, def))) + if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def))) goto cleanup; def = NULL;
@@ -5730,7 +5730,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, /* Unlike the "real" code we don't need the parent_host in order to * call virVHBAManageVport, but still let's make sure the code finds * something valid and no one messed up the mock environment. */ - if (virNodeDeviceGetParentHost(&driver->devs, def, CREATE_DEVICE) < 0) + if (virNodeDeviceObjGetParentHost(&driver->devs, def, CREATE_DEVICE) < 0) goto cleanup;
/* In the real code, we'd call virVHBAManageVport followed by @@ -5772,7 +5772,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virObjectEventPtr event = NULL;
testDriverLock(driver); - obj = virNodeDeviceFindByName(&driver->devs, dev->name); + obj = virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver);
if (!obj) { @@ -5796,8 +5796,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
/* We do this just for basic validation, but also avoid finding a * vport capable HBA if for some reason our vHBA doesn't exist */ - if (virNodeDeviceGetParentHost(&driver->devs, obj->def, - EXISTING_DEVICE) < 0) { + if (virNodeDeviceObjGetParentHost(&driver->devs, obj->def, + EXISTING_DEVICE) < 0) { obj = NULL; goto out; }

On 03/02/2017 01:29 AM, John Ferlan wrote:
On 03/01/2017 07:27 PM, John Ferlan wrote:
Use "virNodeDeviceObj" as a prefix for any external API in virnodedeviceobj
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virnodedeviceobj.c | 28 ++++++++++++++-------------- src/conf/virnodedeviceobj.h | 18 +++++++++--------- src/node_device/node_device_driver.c | 24 ++++++++++++------------ src/node_device/node_device_hal.c | 10 ++++------ src/node_device/node_device_udev.c | 12 ++++++------ src/test/test_driver.c | 28 ++++++++++++++-------------- 6 files changed, 59 insertions(+), 61 deletions(-)
Ugh... Forgot to commit:
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8639979..aed1d3d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -949,11 +949,11 @@ virDomainObjListRename;
# conf/virnodedeviceobj.h -virNodeDeviceAssignDef; -virNodeDeviceFindByName; -virNodeDeviceFindBySysfsPath; -virNodeDeviceGetParentHost; -virNodeDeviceHasCap; +virNodeDeviceObjAssignDef; +virNodeDeviceObjFindByName; +virNodeDeviceObjFindBySysfsPath; +virNodeDeviceObjGetParentHost; +virNodeDeviceObjHasCap; virNodeDeviceObjListExport; virNodeDeviceObjListFree; virNodeDeviceObjLock;
before sending...
ACK series with this squashed in. Michal

On 03/02/2017 01:29 AM, John Ferlan wrote:
On 03/01/2017 07:27 PM, John Ferlan wrote:
Use "virNodeDeviceObj" as a prefix for any external API in virnodedeviceobj
Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/conf/virnodedeviceobj.c | 28 ++++++++++++++-------------- src/conf/virnodedeviceobj.h | 18 +++++++++--------- src/node_device/node_device_driver.c | 24 ++++++++++++------------ src/node_device/node_device_hal.c | 10 ++++------ src/node_device/node_device_udev.c | 12 ++++++------ src/test/test_driver.c | 28 ++++++++++++++-------------- 6 files changed, 59 insertions(+), 61 deletions(-)
Ugh... Forgot to commit:
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8639979..aed1d3d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -949,11 +949,11 @@ virDomainObjListRename;
# conf/virnodedeviceobj.h -virNodeDeviceAssignDef; -virNodeDeviceFindByName; -virNodeDeviceFindBySysfsPath; -virNodeDeviceGetParentHost; -virNodeDeviceHasCap; +virNodeDeviceObjAssignDef; +virNodeDeviceObjFindByName; +virNodeDeviceObjFindBySysfsPath; +virNodeDeviceObjGetParentHost; +virNodeDeviceObjHasCap; virNodeDeviceObjListExport; virNodeDeviceObjListFree; virNodeDeviceObjLock;
before sending...
ACK series with this squashed in. Michal
participants (5)
-
Daniel P. Berrange
-
John Ferlan
-
Michal Privoznik
-
Pavel Hrdina
-
Peter Krempa