From nobody Sun Apr 28 00:07:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; envelope-from=libvir-list-bounces@redhat.com; helo=mx4-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mx.zohomail.com with SMTPS id 1488471505713191.1677648462462; Thu, 2 Mar 2017 08:18:25 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v22GEXU4004005; Thu, 2 Mar 2017 11:14:33 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v22GEV95021762 for ; Thu, 2 Mar 2017 11:14:31 -0500 Received: from localhost.localdomain.com (ovpn-116-78.phx2.redhat.com [10.3.116.78]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v22GEUfg018752 for ; Thu, 2 Mar 2017 11:14:31 -0500 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 2 Mar 2017 11:14:22 -0500 Message-Id: <20170302161427.31535-2-jferlan@redhat.com> In-Reply-To: <20170302161427.31535-1-jferlan@redhat.com> References: <20170302161427.31535-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/6] conf: Introduce virnodedeviceobj X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D = \ =20 # Network driver generic impl APIs NODE_DEVICE_CONF_SOURCES =3D \ - 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 =20 CPU_CONF_SOURCES =3D \ 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; } =20 -int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) -{ - virNodeDevCapsDefPtr caps =3D dev->def->caps; - const char *fc_host_cap =3D - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_FC_HOST); - const char *vports_cap =3D - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); - - while (caps) { - if (STREQ(cap, virNodeDevCapTypeToString(caps->data.type))) - return 1; - else if (caps->data.type =3D=3D 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 =3D 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 =3D dev->def->caps; - - while (caps) { - if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST && - (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOS= T)) - break; - - caps =3D 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 =3D dev->def->caps; - - while (caps) { - if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST && - (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_= OPS)) - break; - - caps =3D caps->next; - } - return caps; -} - - -virNodeDeviceObjPtr -virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) -{ - size_t i; - - for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjLock(devs->objs[i]); - if ((devs->objs[i]->def->sysfs_path !=3D 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 =3D 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 =3D 0; i < devs->count; i++) { - virNodeDevCapsDefPtr cap; - virNodeDeviceObjLock(devs->objs[i]); - if ((cap =3D 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 =3D 0; i < devs->count; i++) { - virNodeDevCapsDefPtr cap; - virNodeDeviceObjLock(devs->objs[i]); - if ((cap =3D virNodeDeviceFindFCCapDef(devs->objs[i])) && - STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_w= wn)) - return devs->objs[i]; - virNodeDeviceObjUnlock(devs->objs[i]); - } - - return NULL; -} - - -static virNodeDeviceObjPtr -virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, - const char *cap) -{ - size_t i; - - for (i =3D 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; -} - =20 void virNodeDeviceDefFree(virNodeDeviceDefPtr def) { @@ -278,82 +114,6 @@ void virNodeDeviceDefFree(virNodeDeviceDefPtr def) VIR_FREE(def); } =20 -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 =3D 0; i < devs->count; i++) - virNodeDeviceObjFree(devs->objs[i]); - VIR_FREE(devs->objs); - devs->count =3D 0; -} - -virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def) -{ - virNodeDeviceObjPtr device; - - if ((device =3D virNodeDeviceFindByName(devs, def->name))) { - virNodeDeviceDefFree(device->def); - device->def =3D 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 =3D def; - - return device; - -} - -void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr *dev) -{ - size_t i; - - virNodeDeviceObjUnlock(*dev); - - for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjLock(*dev); - if (devs->objs[i] =3D=3D *dev) { - virNodeDeviceObjUnlock(*dev); - virNodeDeviceObjFree(devs->objs[i]); - *dev =3D NULL; - - VIR_DELETE_ELEMENT(devs->objs, i, devs->count); - break; - } - virNodeDeviceObjUnlock(*dev); - } -} =20 static void virPCIELinkFormat(virBufferPtr buf, @@ -1976,152 +1736,6 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, return ret; } =20 -/* - * 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 (>=3D 0), -1 otherwise. - */ -static int -virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) -{ - virNodeDevCapsDefPtr cap =3D 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 =3D NULL; - int ret; - - if (!(parent =3D virNodeDeviceFindByName(devs, parent_name))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find parent device for '%s'"), - dev_name); - return -1; - } - - ret =3D 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 =3D NULL; - int ret; - - if (!(parent =3D virNodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwp= n))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find parent device for '%s'"), - dev_name); - return -1; - } - - ret =3D virNodeDeviceFindFCParentHost(parent); - - virNodeDeviceObjUnlock(parent); - - return ret; -} - - -static int -virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_fabric_wwn) -{ - virNodeDeviceObjPtr parent =3D NULL; - int ret; - - if (!(parent =3D virNodeDeviceFindByFabricWWN(devs, parent_fabric_wwn)= )) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find parent device for '%s'"), - dev_name); - return -1; - } - - ret =3D virNodeDeviceFindFCParentHost(parent); - - virNodeDeviceObjUnlock(parent); - - return ret; -} - - -static int -virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) -{ - virNodeDeviceObjPtr parent =3D NULL; - const char *cap =3D virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); - int ret; - - if (!(parent =3D virNodeDeviceFindByCap(devs, cap))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not find any vport capable device")); - return -1; - } - - ret =3D virNodeDeviceFindFCParentHost(parent); - - virNodeDeviceObjUnlock(parent); - - return ret; -} - - -int -virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create) -{ - int parent_host =3D -1; - - if (def->parent) { - parent_host =3D virNodeDeviceGetParentHostByParent(devs, def->name, - def->parent); - } else if (def->parent_wwnn && def->parent_wwpn) { - parent_host =3D virNodeDeviceGetParentHostByWWNs(devs, def->name, - def->parent_wwnn, - def->parent_wwpn); - } else if (def->parent_fabric_wwn) { - parent_host =3D - virNodeDeviceGetParentHostByFabricWWN(devs, def->name, - def->parent_fabric_wwn); - } else if (create =3D=3D CREATE_DEVICE) { - /* Try to find a vport capable scsi_host when no parent supplied */ - parent_host =3D virNodeDeviceFindVportParentHost(devs); - } - - return parent_host; -} - =20 void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) { @@ -2198,125 +1812,6 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr cap= s) } =20 =20 -void virNodeDeviceObjLock(virNodeDeviceObjPtr obj) -{ - virMutexLock(&obj->lock); -} - -void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) -{ - virMutexUnlock(&obj->lock); -} - -static bool -virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, - int type) -{ - virNodeDevCapsDefPtr cap =3D NULL; - - for (cap =3D devobj->def->caps; cap; cap =3D cap->next) { - if (type =3D=3D cap->data.type) - return true; - - if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST) { - if (type =3D=3D VIR_NODE_DEV_CAP_FC_HOST && - (cap->data.scsi_host.flags & - VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) - return true; - - if (type =3D=3D 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_ ## FL= AG)) -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 =3D NULL; - virNodeDevicePtr device =3D NULL; - int ndevices =3D 0; - int ret =3D -1; - size_t i; - - if (devices && VIR_ALLOC_N(tmp_devices, devobjs.count + 1) < 0) - goto cleanup; - - for (i =3D 0; i < devobjs.count; i++) { - virNodeDeviceObjPtr devobj =3D devobjs.objs[i]; - virNodeDeviceObjLock(devobj); - if ((!filter || filter(conn, devobj->def)) && - virNodeDeviceMatch(devobj, flags)) { - if (devices) { - if (!(device =3D virGetNodeDevice(conn, devobj->def->name)= ) || - VIR_STRDUP(device->parent, devobj->def->parent) < 0) { - virObjectUnref(device); - virNodeDeviceObjUnlock(devobj); - goto cleanup; - } - tmp_devices[ndevices] =3D device; - } - ndevices++; - } - virNodeDeviceObjUnlock(devobj); - } - - if (tmp_devices) { - /* trim the array to the final size */ - ignore_value(VIR_REALLOC_N(tmp_devices, ndevices + 1)); - *devices =3D tmp_devices; - tmp_devices =3D NULL; - } - - ret =3D ndevices; - - cleanup: - if (tmp_devices) { - for (i =3D 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" =20 # include =20 @@ -253,34 +251,6 @@ struct _virNodeDeviceObjList { virNodeDeviceObjPtr *objs; }; =20 -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); =20 virNodeDeviceDefPtr virNodeDeviceDefParseString(const char *str, @@ -298,21 +268,10 @@ int virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, char **wwnn, char **wwpn); =20 -int virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create); - void virNodeDeviceDefFree(virNodeDeviceDefPtr def); =20 -void virNodeDeviceObjFree(virNodeDeviceObjPtr dev); - -void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs); - void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); =20 -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) =20 -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); =20 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 + * . + */ + +#include + +#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 =3D dev->def->caps; + const char *fc_host_cap =3D + virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_FC_HOST); + const char *vports_cap =3D + virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); + + while (caps) { + if (STREQ(cap, virNodeDevCapTypeToString(caps->data.type))) + return 1; + else if (caps->data.type =3D=3D 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 =3D 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 =3D dev->def->caps; + + while (caps) { + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST && + (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOS= T)) + break; + + caps =3D 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 =3D dev->def->caps; + + while (caps) { + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST && + (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_= OPS)) + break; + + caps =3D caps->next; + } + return caps; +} + + +virNodeDeviceObjPtr +virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) +{ + size_t i; + + for (i =3D 0; i < devs->count; i++) { + virNodeDeviceObjLock(devs->objs[i]); + if ((devs->objs[i]->def->sysfs_path !=3D 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 =3D 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 =3D 0; i < devs->count; i++) { + virNodeDevCapsDefPtr cap; + virNodeDeviceObjLock(devs->objs[i]); + if ((cap =3D 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 =3D 0; i < devs->count; i++) { + virNodeDevCapsDefPtr cap; + virNodeDeviceObjLock(devs->objs[i]); + if ((cap =3D virNodeDeviceFindFCCapDef(devs->objs[i])) && + STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_w= wn)) + return devs->objs[i]; + virNodeDeviceObjUnlock(devs->objs[i]); + } + + return NULL; +} + + +static virNodeDeviceObjPtr +virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, + const char *cap) +{ + size_t i; + + for (i =3D 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 =3D 0; i < devs->count; i++) + virNodeDeviceObjFree(devs->objs[i]); + VIR_FREE(devs->objs); + devs->count =3D 0; +} + +virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def) +{ + virNodeDeviceObjPtr device; + + if ((device =3D virNodeDeviceFindByName(devs, def->name))) { + virNodeDeviceDefFree(device->def); + device->def =3D 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 =3D def; + + return device; + +} + +void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr *dev) +{ + size_t i; + + virNodeDeviceObjUnlock(*dev); + + for (i =3D 0; i < devs->count; i++) { + virNodeDeviceObjLock(*dev); + if (devs->objs[i] =3D=3D *dev) { + virNodeDeviceObjUnlock(*dev); + virNodeDeviceObjFree(devs->objs[i]); + *dev =3D 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 (>=3D 0), -1 otherwise. + */ +static int +virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) +{ + virNodeDevCapsDefPtr cap =3D 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 =3D NULL; + int ret; + + if (!(parent =3D virNodeDeviceFindByName(devs, parent_name))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find parent device for '%s'"), + dev_name); + return -1; + } + + ret =3D 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 =3D NULL; + int ret; + + if (!(parent =3D virNodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwp= n))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find parent device for '%s'"), + dev_name); + return -1; + } + + ret =3D virNodeDeviceFindFCParentHost(parent); + + virNodeDeviceObjUnlock(parent); + + return ret; +} + + +static int +virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_fabric_wwn) +{ + virNodeDeviceObjPtr parent =3D NULL; + int ret; + + if (!(parent =3D virNodeDeviceFindByFabricWWN(devs, parent_fabric_wwn)= )) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find parent device for '%s'"), + dev_name); + return -1; + } + + ret =3D virNodeDeviceFindFCParentHost(parent); + + virNodeDeviceObjUnlock(parent); + + return ret; +} + + +static int +virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) +{ + virNodeDeviceObjPtr parent =3D NULL; + const char *cap =3D virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); + int ret; + + if (!(parent =3D virNodeDeviceFindByCap(devs, cap))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not find any vport capable device")); + return -1; + } + + ret =3D virNodeDeviceFindFCParentHost(parent); + + virNodeDeviceObjUnlock(parent); + + return ret; +} + + +int +virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create) +{ + int parent_host =3D -1; + + if (def->parent) { + parent_host =3D virNodeDeviceGetParentHostByParent(devs, def->name, + def->parent); + } else if (def->parent_wwnn && def->parent_wwpn) { + parent_host =3D virNodeDeviceGetParentHostByWWNs(devs, def->name, + def->parent_wwnn, + def->parent_wwpn); + } else if (def->parent_fabric_wwn) { + parent_host =3D + virNodeDeviceGetParentHostByFabricWWN(devs, def->name, + def->parent_fabric_wwn); + } else if (create =3D=3D CREATE_DEVICE) { + /* Try to find a vport capable scsi_host when no parent supplied */ + parent_host =3D 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 =3D NULL; + + for (cap =3D devobj->def->caps; cap; cap =3D cap->next) { + if (type =3D=3D cap->data.type) + return true; + + if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST) { + if (type =3D=3D VIR_NODE_DEV_CAP_FC_HOST && + (cap->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) + return true; + + if (type =3D=3D 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_ ## FL= AG)) +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 =3D NULL; + virNodeDevicePtr device =3D NULL; + int ndevices =3D 0; + int ret =3D -1; + size_t i; + + if (devices && VIR_ALLOC_N(tmp_devices, devobjs.count + 1) < 0) + goto cleanup; + + for (i =3D 0; i < devobjs.count; i++) { + virNodeDeviceObjPtr devobj =3D devobjs.objs[i]; + virNodeDeviceObjLock(devobj); + if ((!filter || filter(conn, devobj->def)) && + virNodeDeviceMatch(devobj, flags)) { + if (devices) { + if (!(device =3D virGetNodeDevice(conn, devobj->def->name)= ) || + VIR_STRDUP(device->parent, devobj->def->parent) < 0) { + virObjectUnref(device); + virNodeDeviceObjUnlock(devobj); + goto cleanup; + } + tmp_devices[ndevices] =3D device; + } + ndevices++; + } + virNodeDeviceObjUnlock(devobj); + } + + if (tmp_devices) { + /* trim the array to the final size */ + ignore_value(VIR_REALLOC_N(tmp_devices, ndevices + 1)); + *devices =3D tmp_devices; + tmp_devices =3D NULL; + } + + ret =3D ndevices; + + cleanup: + if (tmp_devices) { + for (i =3D 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 + * . + */ + +#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; =20 =20 # conf/node_device_event.h @@ -958,6 +948,19 @@ virDomainObjListRemoveLocked; virDomainObjListRename; =20 =20 +# 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_de= vice_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 @@ =20 # include "internal.h" # include "driver.h" -# include "node_device_conf.h" +# include "virnodedeviceobj.h" =20 # define LINUX_NEW_DEVICE_WAIT_TIME 60 =20 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" --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:07:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1488471485592173.5380431014205; Thu, 2 Mar 2017 08:18:05 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v22GEbTc030679; Thu, 2 Mar 2017 11:14:37 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v22GEWrV021768 for ; Thu, 2 Mar 2017 11:14:32 -0500 Received: from localhost.localdomain.com (ovpn-116-78.phx2.redhat.com [10.3.116.78]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v22GEUfh018752 for ; Thu, 2 Mar 2017 11:14:32 -0500 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 2 Mar 2017 11:14:23 -0500 Message-Id: <20170302161427.31535-3-jferlan@redhat.com> In-Reply-To: <20170302161427.31535-1-jferlan@redhat.com> References: <20170302161427.31535-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/6] conf: Adjust coding style for nodedev conf sources X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Alter the format of the code to follow more recent style guidelines of two empty lines between functions, function delcs with "[static] type" on one line followed by function name with arguments to functions each on one line. Signed-off-by: John Ferlan --- src/conf/node_device_conf.c | 31 ++++++++++++++++++++++++++++--- src/conf/virnodedeviceobj.c | 38 +++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index bc36527..20c2bcf 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -86,7 +86,8 @@ virNodeDevCapsDefParseString(const char *xpath, } =20 =20 -void virNodeDeviceDefFree(virNodeDeviceDefPtr def) +void +virNodeDeviceDefFree(virNodeDeviceDefPtr def) { virNodeDevCapsDefPtr caps; =20 @@ -133,6 +134,7 @@ virPCIELinkFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } =20 + static void virPCIEDeviceInfoFormat(virBufferPtr buf, virPCIEDeviceInfoPtr info) @@ -152,7 +154,9 @@ virPCIEDeviceInfoFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); } =20 -char *virNodeDeviceDefFormat(const virNodeDeviceDef *def) + +char * +virNodeDeviceDefFormat(const virNodeDeviceDef *def) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; virNodeDevCapsDefPtr caps; @@ -489,6 +493,7 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *de= f) return virBufferContentAndReset(&buf); } =20 + /** * virNodeDevCapsDefParseIntOptional: * @xpath: XPath to evaluate @@ -524,6 +529,7 @@ virNodeDevCapsDefParseIntOptional(const char *xpath, return 1; } =20 + static int virNodeDevCapsDefParseULong(const char *xpath, xmlXPathContextPtr ctxt, @@ -547,6 +553,7 @@ virNodeDevCapsDefParseULong(const char *xpath, return 0; } =20 + static int virNodeDevCapsDefParseULongLong(const char *xpath, xmlXPathContextPtr ctxt, @@ -570,6 +577,7 @@ virNodeDevCapsDefParseULongLong(const char *xpath, return 0; } =20 + static int virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, @@ -600,6 +608,7 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, return ret; } =20 + static int virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, @@ -694,6 +703,7 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, return ret; } =20 + static int virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, @@ -954,6 +964,7 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, return ret; } =20 + static int virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, @@ -998,6 +1009,7 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr c= txt, return ret; } =20 + static int virNodeDevCapsDefParseHexId(const char *xpath, xmlXPathContextPtr ctxt, @@ -1021,6 +1033,7 @@ virNodeDevCapsDefParseHexId(const char *xpath, return 0; } =20 + static int virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, @@ -1066,6 +1079,7 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, return ret; } =20 + static int virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, xmlNodePtr iommuGroupNode, @@ -1122,6 +1136,7 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContext= Ptr ctxt, return ret; } =20 + static int virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, xmlNodePtr linkNode, @@ -1168,6 +1183,7 @@ virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt, return ret; } =20 + static int virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, xmlNodePtr pciExpressNode, @@ -1391,6 +1407,7 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, return ret; } =20 + static int virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, @@ -1435,6 +1452,7 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, return ret; } =20 + static virNodeDevCapsDefPtr virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, @@ -1519,6 +1537,7 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, return NULL; } =20 + static virNodeDeviceDefPtr virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, int create, @@ -1633,6 +1652,7 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt, return NULL; } =20 + virNodeDeviceDefPtr virNodeDeviceDefParseNode(xmlDocPtr xml, xmlNodePtr root, @@ -1664,6 +1684,7 @@ virNodeDeviceDefParseNode(xmlDocPtr xml, return def; } =20 + static virNodeDeviceDefPtr virNodeDeviceDefParse(const char *str, const char *filename, @@ -1682,6 +1703,7 @@ virNodeDeviceDefParse(const char *str, return def; } =20 + virNodeDeviceDefPtr virNodeDeviceDefParseString(const char *str, int create, @@ -1690,6 +1712,7 @@ virNodeDeviceDefParseString(const char *str, return virNodeDeviceDefParse(str, NULL, create, virt_type); } =20 + virNodeDeviceDefPtr virNodeDeviceDefParseFile(const char *filename, int create, @@ -1698,6 +1721,7 @@ virNodeDeviceDefParseFile(const char *filename, return virNodeDeviceDefParse(NULL, filename, create, virt_type); } =20 + /* * Return fc_host dev's WWNN and WWPN */ @@ -1737,7 +1761,8 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, } =20 =20 -void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) +void +virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) { size_t i =3D 0; virNodeDevCapDataPtr data =3D &caps->data; diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 83f7217..f37e597 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -33,7 +33,9 @@ VIR_LOG_INIT("conf.virnodedeviceobj"); =20 =20 -int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap) +int +virNodeDeviceHasCap(const virNodeDeviceObj *dev, + const char *cap) { virNodeDevCapsDefPtr caps =3D dev->def->caps; const char *fc_host_cap =3D @@ -125,8 +127,9 @@ virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr de= vs, } =20 =20 -virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, - const char *name) +virNodeDeviceObjPtr +virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, + const char *name) { size_t i; =20 @@ -198,7 +201,8 @@ virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, } =20 =20 -void virNodeDeviceObjFree(virNodeDeviceObjPtr dev) +void +virNodeDeviceObjFree(virNodeDeviceObjPtr dev) { if (!dev) return; @@ -212,7 +216,9 @@ void virNodeDeviceObjFree(virNodeDeviceObjPtr dev) VIR_FREE(dev); } =20 -void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) + +void +virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) { size_t i; for (i =3D 0; i < devs->count; i++) @@ -221,8 +227,10 @@ void virNodeDeviceObjListFree(virNodeDeviceObjListPtr = devs) devs->count =3D 0; } =20 -virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def) + +virNodeDeviceObjPtr +virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def) { virNodeDeviceObjPtr device; =20 @@ -254,8 +262,10 @@ virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDevi= ceObjListPtr devs, =20 } =20 -void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr *dev) + +void +virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr *dev) { size_t i; =20 @@ -423,16 +433,20 @@ virNodeDeviceGetParentHost(virNodeDeviceObjListPtr de= vs, } =20 =20 -void virNodeDeviceObjLock(virNodeDeviceObjPtr obj) +void +virNodeDeviceObjLock(virNodeDeviceObjPtr obj) { virMutexLock(&obj->lock); } =20 -void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) + +void +virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) { virMutexUnlock(&obj->lock); } =20 + static bool virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, int type) @@ -459,6 +473,7 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, return false; } =20 + #define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)= ) && \ virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FL= AG)) static bool @@ -487,6 +502,7 @@ virNodeDeviceMatch(virNodeDeviceObjPtr devobj, } #undef MATCH =20 + int virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjList devobjs, --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:07:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; envelope-from=libvir-list-bounces@redhat.com; helo=mx6-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) by mx.zohomail.com with SMTPS id 1488471532050813.6574245898652; Thu, 2 Mar 2017 08:18:52 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v22GFUFB012356; Thu, 2 Mar 2017 11:15:31 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v22GEW1K021773 for ; Thu, 2 Mar 2017 11:14:32 -0500 Received: from localhost.localdomain.com (ovpn-116-78.phx2.redhat.com [10.3.116.78]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v22GEUfi018752 for ; Thu, 2 Mar 2017 11:14:32 -0500 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 2 Mar 2017 11:14:24 -0500 Message-Id: <20170302161427.31535-4-jferlan@redhat.com> In-Reply-To: <20170302161427.31535-1-jferlan@redhat.com> References: <20170302161427.31535-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/6] conf: Use consistent function name prefixes for virnodedeviceobj X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use "virNodeDeviceObj" as a prefix for any external API in virnodedeviceobj Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 28 ++++++++++++++-------------- src/conf/virnodedeviceobj.h | 18 +++++++++--------- src/libvirt_private.syms | 10 +++++----- 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 ++++++++++++++-------------- 7 files changed, 64 insertions(+), 66 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index f37e597..3fe3ae5 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -34,8 +34,8 @@ VIR_LOG_INIT("conf.virnodedeviceobj"); =20 =20 int -virNodeDeviceHasCap(const virNodeDeviceObj *dev, - const char *cap) +virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, + const char *cap) { virNodeDevCapsDefPtr caps =3D dev->def->caps; const char *fc_host_cap =3D @@ -109,8 +109,8 @@ virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *de= v) =20 =20 virNodeDeviceObjPtr -virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) +virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) { size_t i; =20 @@ -128,8 +128,8 @@ virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr de= vs, =20 =20 virNodeDeviceObjPtr -virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, - const char *name) +virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs, + const char *name) { size_t i; =20 @@ -192,7 +192,7 @@ virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, =20 for (i =3D 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) =20 =20 virNodeDeviceObjPtr -virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def) +virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def) { virNodeDeviceObjPtr device; =20 - if ((device =3D virNodeDeviceFindByName(devs, def->name))) { + if ((device =3D virNodeDeviceObjFindByName(devs, def->name))) { virNodeDeviceDefFree(device->def); device->def =3D def; return device; @@ -323,7 +323,7 @@ virNodeDeviceGetParentHostByParent(virNodeDeviceObjList= Ptr devs, virNodeDeviceObjPtr parent =3D NULL; int ret; =20 - if (!(parent =3D virNodeDeviceFindByName(devs, parent_name))) { + if (!(parent =3D virNodeDeviceObjFindByName(devs, parent_name))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); @@ -407,9 +407,9 @@ virNodeDeviceFindVportParentHost(virNodeDeviceObjListPt= r devs) =20 =20 int -virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create) +virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create) { int parent_host =3D -1; =20 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 { }; =20 =20 -int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap); +int virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, const char *cap); =20 -virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs, +virNodeDeviceObjPtr virNodeDeviceObjFindByName(virNodeDeviceObjListPtr dev= s, const char *name); virNodeDeviceObjPtr -virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) +virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) ATTRIBUTE_NONNULL(2); =20 -virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def); +virNodeDeviceObjPtr virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def); =20 void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr *dev); =20 -int virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create); +int virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create); =20 void virNodeDeviceObjFree(virNodeDeviceObjPtr dev); =20 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; =20 =20 # conf/virnodedeviceobj.h -virNodeDeviceAssignDef; -virNodeDeviceFindByName; -virNodeDeviceFindBySysfsPath; -virNodeDeviceGetParentHost; -virNodeDeviceHasCap; +virNodeDeviceObjAssignDef; +virNodeDeviceObjFindByName; +virNodeDeviceObjFindBySysfsPath; +virNodeDeviceObjGetParentHost; +virNodeDeviceObjHasCap; virNodeDeviceObjListExport; virNodeDeviceObjListFree; virNodeDeviceObjLock; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_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 =3D=3D 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 =3D=3D 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 =3D NULL; =20 nodeDeviceLock(); - obj =3D virNodeDeviceFindByName(&driver->devs, name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, name); nodeDeviceUnlock(); =20 if (!obj) { @@ -337,7 +337,7 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev, virCheckFlags(0, NULL); =20 nodeDeviceLock(); - obj =3D virNodeDeviceFindByName(&driver->devs, dev->name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); =20 if (!obj) { @@ -370,7 +370,7 @@ nodeDeviceGetParent(virNodeDevicePtr dev) char *ret =3D NULL; =20 nodeDeviceLock(); - obj =3D virNodeDeviceFindByName(&driver->devs, dev->name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); =20 if (!obj) { @@ -407,7 +407,7 @@ nodeDeviceNumOfCaps(virNodeDevicePtr dev) int ret =3D -1; =20 nodeDeviceLock(); - obj =3D virNodeDeviceFindByName(&driver->devs, dev->name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); =20 if (!obj) { @@ -452,7 +452,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const n= ames, int maxnames) int ret =3D -1; =20 nodeDeviceLock(); - obj =3D virNodeDeviceFindByName(&driver->devs, dev->name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); =20 if (!obj) { @@ -590,8 +590,8 @@ nodeDeviceCreateXML(virConnectPtr conn, if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) goto cleanup; =20 - if ((parent_host =3D virNodeDeviceGetParentHost(&driver->devs, def, - CREATE_DEVICE)) < 0) + if ((parent_host =3D virNodeDeviceObjGetParentHost(&driver->devs, def, + CREATE_DEVICE)) < 0) goto cleanup; =20 if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) @@ -625,7 +625,7 @@ nodeDeviceDestroy(virNodeDevicePtr dev) int parent_host =3D -1; =20 nodeDeviceLock(); - if (!(obj =3D virNodeDeviceFindByName(&driver->devs, dev->name))) { + if (!(obj =3D 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 =3D obj->def; virNodeDeviceObjUnlock(obj); obj =3D NULL; - if ((parent_host =3D virNodeDeviceGetParentHost(&driver->devs, def, - EXISTING_DEVICE)) < 0) + if ((parent_host =3D virNodeDeviceObjGetParentHost(&driver->devs, def, + EXISTING_DEVICE)) < 0) goto cleanup; =20 if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0) diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_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); =20 - dev =3D virNodeDeviceAssignDef(&driver->devs, - def); - + dev =3D virNodeDeviceObjAssignDef(&driver->devs, def); if (!dev) { VIR_FREE(devicePath); goto failure; @@ -525,7 +523,7 @@ dev_refresh(const char *udi) virNodeDeviceObjPtr dev; =20 nodeDeviceLock(); - dev =3D virNodeDeviceFindByName(&driver->devs, name); + dev =3D 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; =20 nodeDeviceLock(); - dev =3D virNodeDeviceFindByName(&driver->devs, name); + dev =3D 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; =20 nodeDeviceLock(); - dev =3D virNodeDeviceFindByName(&driver->devs, name); + dev =3D 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_devi= ce_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 *de= vice) int ret =3D -1; =20 name =3D udev_device_get_syspath(device); - dev =3D virNodeDeviceFindBySysfsPath(&driver->devs, name); + dev =3D virNodeDeviceObjFindBySysfsPath(&driver->devs, name); =20 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; } =20 - dev =3D virNodeDeviceFindBySysfsPath(&driver->devs, - parent_sysfs_path); + dev =3D virNodeDeviceObjFindBySysfsPath(&driver->devs, + parent_sysfs_path); if (dev !=3D NULL) { if (VIR_STRDUP(def->parent, dev->def->name) < 0) { virNodeDeviceObjUnlock(dev); @@ -1203,7 +1203,7 @@ static int udevAddOneDevice(struct udev_device *devic= e) if (udevSetParent(device, def) !=3D 0) goto cleanup; =20 - dev =3D virNodeDeviceFindByName(&driver->devs, def->name); + dev =3D virNodeDeviceObjFindByName(&driver->devs, def->name); if (dev) { virNodeDeviceObjUnlock(dev); new_device =3D false; @@ -1211,7 +1211,7 @@ static int udevAddOneDevice(struct udev_device *devic= e) =20 /* If this is a device change, the old definition will be freed * and the current definition will take its place. */ - dev =3D virNodeDeviceAssignDef(&driver->devs, def); + dev =3D virNodeDeviceObjAssignDef(&driver->devs, def); if (dev =3D=3D NULL) goto cleanup; =20 @@ -1492,7 +1492,7 @@ static int udevSetupSystemDev(void) udevGetDMIData(&def->caps->data); #endif =20 - dev =3D virNodeDeviceAssignDef(&driver->devs, def); + dev =3D virNodeDeviceObjAssignDef(&driver->devs, def); if (dev =3D=3D NULL) goto cleanup; =20 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; =20 - if (!(obj =3D virNodeDeviceAssignDef(&privconn->devs, def))) { + if (!(obj =3D virNodeDeviceObjAssignDef(&privconn->devs, def))) { virNodeDeviceDefFree(def); goto error; } @@ -5424,7 +5424,7 @@ testNodeNumOfDevices(virConnectPtr conn, testDriverLock(driver); for (i =3D 0; i < driver->devs.count; i++) if ((cap =3D=3D NULL) || - virNodeDeviceHasCap(driver->devs.objs[i], cap)) + virNodeDeviceObjHasCap(driver->devs.objs[i], cap)) ++ndevs; testDriverUnlock(driver); =20 @@ -5448,7 +5448,7 @@ testNodeListDevices(virConnectPtr conn, for (i =3D 0; i < driver->devs.count && ndevs < maxnames; i++) { virNodeDeviceObjLock(driver->devs.objs[i]); if (cap =3D=3D 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 =3D NULL; =20 testDriverLock(driver); - obj =3D virNodeDeviceFindByName(&driver->devs, name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, name); testDriverUnlock(driver); =20 if (!obj) { @@ -5508,7 +5508,7 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, virCheckFlags(0, NULL); =20 testDriverLock(driver); - obj =3D virNodeDeviceFindByName(&driver->devs, dev->name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver); =20 if (!obj) { @@ -5534,7 +5534,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) char *ret =3D NULL; =20 testDriverLock(driver); - obj =3D virNodeDeviceFindByName(&driver->devs, dev->name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver); =20 if (!obj) { @@ -5568,7 +5568,7 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) int ret =3D -1; =20 testDriverLock(driver); - obj =3D virNodeDeviceFindByName(&driver->devs, dev->name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver); =20 if (!obj) { @@ -5599,7 +5599,7 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **c= onst names, int maxnames) int ret =3D -1; =20 testDriverLock(driver); - obj =3D virNodeDeviceFindByName(&driver->devs, dev->name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver); =20 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 =3D virNodeDeviceFindByName(&driver->devs, "scsi_host11"= ))) + if (!(objcopy =3D virNodeDeviceObjFindByName(&driver->devs, "scsi_host= 11"))) goto cleanup; =20 xml =3D virNodeDeviceDefFormat(objcopy->def); @@ -5687,7 +5687,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, caps =3D caps->next; } =20 - if (!(obj =3D virNodeDeviceAssignDef(&driver->devs, def))) + if (!(obj =3D virNodeDeviceObjAssignDef(&driver->devs, def))) goto cleanup; def =3D NULL; =20 @@ -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; =20 /* In the real code, we'd call virVHBAManageVport followed by @@ -5772,7 +5772,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virObjectEventPtr event =3D NULL; =20 testDriverLock(driver); - obj =3D virNodeDeviceFindByName(&driver->devs, dev->name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, dev->name); testDriverUnlock(driver); =20 if (!obj) { @@ -5796,8 +5796,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) =20 /* 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 =3D NULL; goto out; } --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:07:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1488471520232774.20520593237; Thu, 2 Mar 2017 08:18:40 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v22GFUq4031276; Thu, 2 Mar 2017 11:15:30 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v22GEXb3021779 for ; Thu, 2 Mar 2017 11:14:33 -0500 Received: from localhost.localdomain.com (ovpn-116-78.phx2.redhat.com [10.3.116.78]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v22GEUfj018752 for ; Thu, 2 Mar 2017 11:14:32 -0500 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 2 Mar 2017 11:14:25 -0500 Message-Id: <20170302161427.31535-5-jferlan@redhat.com> In-Reply-To: <20170302161427.31535-1-jferlan@redhat.com> References: <20170302161427.31535-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 4/6] conf: Alter coding style of nodedev function prototypes X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In an effort to be consistent with the source module, alter the function prototypes to follow the similar style of source with the "type" on one line followed by the function name and arguments on subsequent lines with with argument getting it's own line. Signed-off-by: John Ferlan --- src/conf/node_device_conf.h | 46 ++++++++++++++++++++++--------------- src/conf/virnodedeviceobj.h | 56 ++++++++++++++++++++++++++++-------------= ---- 2 files changed, 63 insertions(+), 39 deletions(-) diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 6c94262..f05e61b 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -251,26 +251,35 @@ struct _virNodeDeviceObjList { virNodeDeviceObjPtr *objs; }; =20 -char *virNodeDeviceDefFormat(const virNodeDeviceDef *def); +char * +virNodeDeviceDefFormat(const virNodeDeviceDef *def); =20 -virNodeDeviceDefPtr virNodeDeviceDefParseString(const char *str, - int create, - const char *virt_type); -virNodeDeviceDefPtr virNodeDeviceDefParseFile(const char *filename, - int create, - const char *virt_type); -virNodeDeviceDefPtr virNodeDeviceDefParseNode(xmlDocPtr xml, - xmlNodePtr root, - int create, - const char *virt_type); +virNodeDeviceDefPtr +virNodeDeviceDefParseString(const char *str, + int create, + const char *virt_type); =20 -int virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, - char **wwnn, - char **wwpn); +virNodeDeviceDefPtr +virNodeDeviceDefParseFile(const char *filename, + int create, + const char *virt_type); =20 -void virNodeDeviceDefFree(virNodeDeviceDefPtr def); +virNodeDeviceDefPtr +virNodeDeviceDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + int create, + const char *virt_type); =20 -void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); +int +virNodeDeviceGetWWNs(virNodeDeviceDefPtr def, + char **wwnn, + char **wwpn); + +void +virNodeDeviceDefFree(virNodeDeviceDefPtr def); + +void +virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); =20 # define VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP \ (VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM | \ @@ -287,7 +296,8 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps); VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM) =20 -char *virNodeDeviceGetParentName(virConnectPtr conn, - const char *nodedev_name); +char * +virNodeDeviceGetParentName(virConnectPtr conn, + const char *nodedev_name); =20 #endif /* __VIR_NODE_DEVICE_CONF_H__ */ diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index b4409b7..e32bbf8 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -40,39 +40,53 @@ struct _virNodeDeviceDriverState { }; =20 =20 -int virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, const char *cap); +int +virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, + const char *cap); + +virNodeDeviceObjPtr +virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs, + const char *name); =20 -virNodeDeviceObjPtr virNodeDeviceObjFindByName(virNodeDeviceObjListPtr dev= s, - const char *name); virNodeDeviceObjPtr virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr devs, const char *sysfs_path) ATTRIBUTE_NONNULL(2); =20 -virNodeDeviceObjPtr virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def); +virNodeDeviceObjPtr +virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def); + +void +virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr *dev); =20 -void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr *dev); +int +virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create); =20 -int virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create); +void +virNodeDeviceObjFree(virNodeDeviceObjPtr dev); =20 -void virNodeDeviceObjFree(virNodeDeviceObjPtr dev); +void +virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs); =20 -void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs); +void +virNodeDeviceObjLock(virNodeDeviceObjPtr obj); =20 -void virNodeDeviceObjLock(virNodeDeviceObjPtr obj); -void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj); +void +virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj); =20 -typedef bool (*virNodeDeviceObjListFilter)(virConnectPtr conn, - virNodeDeviceDefPtr def); +typedef bool +(*virNodeDeviceObjListFilter)(virConnectPtr conn, + virNodeDeviceDefPtr def); =20 -int virNodeDeviceObjListExport(virConnectPtr conn, - virNodeDeviceObjList devobjs, - virNodeDevicePtr **devices, - virNodeDeviceObjListFilter filter, - unsigned int flags); +int +virNodeDeviceObjListExport(virConnectPtr conn, + virNodeDeviceObjList devobjs, + virNodeDevicePtr **devices, + virNodeDeviceObjListFilter filter, + unsigned int flags); =20 #endif /* __VIRNODEDEVICEOBJ_H__ */ --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:07:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1488471564728518.344580051097; Thu, 2 Mar 2017 08:19:24 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v22GGAHD003910; Thu, 2 Mar 2017 11:16:10 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v22GEXNl021786 for ; Thu, 2 Mar 2017 11:14:33 -0500 Received: from localhost.localdomain.com (ovpn-116-78.phx2.redhat.com [10.3.116.78]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v22GEUfk018752 for ; Thu, 2 Mar 2017 11:14:33 -0500 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 2 Mar 2017 11:14:26 -0500 Message-Id: <20170302161427.31535-6-jferlan@redhat.com> In-Reply-To: <20170302161427.31535-1-jferlan@redhat.com> References: <20170302161427.31535-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 5/6] conf: Clean up the _virNodeDevCapData X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than a bunch of embedded union structs, let's create structs for each of the structs within the union and make the struct easier to read. Signed-off-by: John Ferlan --- src/conf/node_device_conf.h | 224 ++++++++++++++++++++++++----------------= ---- 1 file changed, 125 insertions(+), 99 deletions(-) diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index f05e61b..1107a88 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -103,108 +103,134 @@ typedef enum { =20 VIR_ENUM_DECL(virNodeDevDRM) =20 +typedef struct _virNodeDevCapSystemHardware { + char *vendor_name; + char *version; + char *serial; + unsigned char uuid[VIR_UUID_BUFLEN]; +} virNodeDevSystemHardware, *virNodeDevSystemHardwarePtr; + +typedef struct _virNodeDevCapSystemFirmware { + char *vendor_name; + char *version; + char *release_date; +} virNodeDevSystemFirmware, *virNodeDevSystemFirmwarePtr; + +typedef struct _virNodeDevCapSystem { + char *product_name; + virNodeDevSystemHardware hardware; + virNodeDevSystemFirmware firmware; +} virNodeDevCapSystem, *virNodeDevCapSystemPtr; + +typedef struct _virNodeDevCapPCIDev { + unsigned int domain; + unsigned int bus; + unsigned int slot; + unsigned int function; + unsigned int product; + unsigned int vendor; + unsigned int class; + char *product_name; + char *vendor_name; + virPCIDeviceAddressPtr physical_function; + virPCIDeviceAddressPtr *virtual_functions; + size_t num_virtual_functions; + unsigned int max_virtual_functions; + unsigned int flags; + virPCIDeviceAddressPtr *iommuGroupDevices; + size_t nIommuGroupDevices; + unsigned int iommuGroupNumber; + int numa_node; + virPCIEDeviceInfoPtr pci_express; + int hdrType; /* enum virPCIHeaderType or -1 */ +} virNodeDevCapPCIDev, *virNodeDevCapPCIDevPtr; + +typedef struct _virNodeDevCapUSBDev { + unsigned int bus; + unsigned int device; + unsigned int product; + unsigned int vendor; + char *product_name; + char *vendor_name; +} virNodeDevCapUSBDev, *virNodeDevCapUSBDevPtr; + +typedef struct _virNodeDevCapUSBIf { + unsigned int number; + unsigned int _class; /* "class" is reserved in C */ + unsigned int subclass; + unsigned int protocol; + char *description; +} virNodeDevCapUSBIf, *virNodeDevCapUSBIfPtr; + +typedef struct _virNodeDevCapNet { + char *address; + unsigned int address_len; + char *ifname; + virNetDevIfLink lnk; + virNodeDevNetCapType subtype; /* LAST -> no subtype */ + virBitmapPtr features; /* enum virNetDevFeature */ +} virNodeDevCapNet, *virNodeDevCapNetPtr; + +typedef struct _virNodeDevCapSCSIHost { + unsigned int host; + int unique_id; + char *wwnn; + char *wwpn; + char *fabric_wwn; + unsigned int flags; + int max_vports; + int vports; +} virNodeDevCapSCSIHost, *virNodeDevCapSCSIHostPtr; + +typedef struct _virNodeDevCapSCSITarget { + char *name; +} virNodeDevCapSCSITarget, *virNodeDevCapSCSITargetPtr; + +typedef struct _virNodeDevCapSCSI { + unsigned int host; + unsigned int bus; + unsigned int target; + unsigned int lun; + char *type; +} virNodeDevCapSCSI, *virNodeDevCapSCSIPtr; + +typedef struct _virNodeDevCapStorage { + unsigned long long size; + unsigned long long num_blocks; + unsigned long long logical_block_size; + unsigned long long removable_media_size; + char *block; + char *bus; + char *drive_type; + char *model; + char *vendor; + char *serial; + char *media_label; + unsigned int flags; /* virNodeDevStorageCapFlags bits */ +} virNodeDevCapStorage, *virNodeDevCapStoragePtr; + +typedef struct _virNodeDevCapSCSIGeneric { + char *path; +} virNodeDevCapSCSIGeneric, *virNodeDevCapSCSIGenericPtr; + +typedef struct _virNodeDevCapDRM { + virNodeDevDRMType type; +} virNodeDevCapDRM, *virNodeDevCapDRMPtr; + typedef struct _virNodeDevCapData { virNodeDevCapType type; union { - struct { - char *product_name; - struct { - char *vendor_name; - char *version; - char *serial; - unsigned char uuid[VIR_UUID_BUFLEN]; - } hardware; - struct { - char *vendor_name; - char *version; - char *release_date; - } firmware; - } system; - struct { - unsigned int domain; - unsigned int bus; - unsigned int slot; - unsigned int function; - unsigned int product; - unsigned int vendor; - unsigned int class; - char *product_name; - char *vendor_name; - virPCIDeviceAddressPtr physical_function; - virPCIDeviceAddressPtr *virtual_functions; - size_t num_virtual_functions; - unsigned int max_virtual_functions; - unsigned int flags; - virPCIDeviceAddressPtr *iommuGroupDevices; - size_t nIommuGroupDevices; - unsigned int iommuGroupNumber; - int numa_node; - virPCIEDeviceInfoPtr pci_express; - int hdrType; /* enum virPCIHeaderType or -1 */ - } pci_dev; - struct { - unsigned int bus; - unsigned int device; - unsigned int product; - unsigned int vendor; - char *product_name; - char *vendor_name; - } usb_dev; - struct { - unsigned int number; - unsigned int _class; /* "class" is reserved in C */ - unsigned int subclass; - unsigned int protocol; - char *description; - } usb_if; - struct { - char *address; - unsigned int address_len; - char *ifname; - virNetDevIfLink lnk; - virNodeDevNetCapType subtype; /* LAST -> no subtype */ - virBitmapPtr features; /* enum virNetDevFeature */ - } net; - struct { - unsigned int host; - int unique_id; - char *wwnn; - char *wwpn; - char *fabric_wwn; - unsigned int flags; - int max_vports; - int vports; - } scsi_host; - struct { - char *name; - } scsi_target; - struct { - unsigned int host; - unsigned int bus; - unsigned int target; - unsigned int lun; - char *type; - } scsi; - struct { - unsigned long long size; - unsigned long long num_blocks; - unsigned long long logical_block_size; - unsigned long long removable_media_size; - char *block; - char *bus; - char *drive_type; - char *model; - char *vendor; - char *serial; - char *media_label; - unsigned int flags; /* virNodeDevStorageCapFlags bits */ - } storage; - struct { - char *path; - } sg; /* SCSI generic device */ - struct { - virNodeDevDRMType type; - } drm; + virNodeDevCapSystem system; + virNodeDevCapPCIDev pci_dev; + virNodeDevCapUSBDev usb_dev; + virNodeDevCapUSBIf usb_if; + virNodeDevCapNet net; + virNodeDevCapSCSIHost scsi_host; + virNodeDevCapSCSITarget scsi_target; + virNodeDevCapSCSI scsi; + virNodeDevCapStorage storage; + virNodeDevCapSCSIGeneric sg; + virNodeDevCapDRM drm; }; } virNodeDevCapData, *virNodeDevCapDataPtr; =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun Apr 28 00:07:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; envelope-from=libvir-list-bounces@redhat.com; helo=mx4-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mx.zohomail.com with SMTPS id 1488471567864482.2823212154733; Thu, 2 Mar 2017 08:19:27 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v22GFVIV004060; Thu, 2 Mar 2017 11:15:31 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v22GEYSX021798 for ; Thu, 2 Mar 2017 11:14:34 -0500 Received: from localhost.localdomain.com (ovpn-116-78.phx2.redhat.com [10.3.116.78]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v22GEUfl018752 for ; Thu, 2 Mar 2017 11:14:33 -0500 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 2 Mar 2017 11:14:27 -0500 Message-Id: <20170302161427.31535-7-jferlan@redhat.com> In-Reply-To: <20170302161427.31535-1-jferlan@redhat.com> References: <20170302161427.31535-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 6/6] nodedev: Reduce virNodeDevCapDataPtr usage X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Replace with more data specific pointer types. Signed-off-by: John Ferlan --- src/conf/node_device_conf.c | 221 +++++++++++++++-----------= ---- src/node_device/node_device_driver.c | 6 +- src/node_device/node_device_hal.c | 4 +- src/node_device/node_device_linux_sysfs.c | 134 +++++++++--------- src/node_device/node_device_linux_sysfs.h | 4 +- src/node_device/node_device_udev.c | 186 ++++++++++++------------- 6 files changed, 281 insertions(+), 274 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 20c2bcf..0a4f0d2 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -582,7 +582,7 @@ static int virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, - virNodeDevCapDataPtr data) + virNodeDevCapDRMPtr drm) { xmlNodePtr orignode; int ret =3D -1, val; @@ -598,7 +598,7 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, _("unknown drm type '%s' for '%s'"), type, def->nam= e); goto out; } - data->drm.type =3D val; + drm->type =3D val; =20 ret =3D 0; =20 @@ -613,7 +613,7 @@ static int virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, - virNodeDevCapDataPtr data) + virNodeDevCapStoragePtr storage) { xmlNodePtr orignode, *nodes =3D NULL; size_t i; @@ -623,19 +623,19 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, orignode =3D ctxt->node; ctxt->node =3D node; =20 - data->storage.block =3D virXPathString("string(./block[1])", ctxt); - if (!data->storage.block) { + storage->block =3D virXPathString("string(./block[1])", ctxt); + if (!storage->block) { virReportError(VIR_ERR_INTERNAL_ERROR, _("no block device path supplied for '%s'"), def->name); goto out; } =20 - data->storage.bus =3D virXPathString("string(./bus[1])", ctxt); - data->storage.drive_type =3D virXPathString("string(./drive_type[1])",= ctxt); - data->storage.model =3D virXPathString("string(./model[1])", ctxt= ); - data->storage.vendor =3D virXPathString("string(./vendor[1])", ctx= t); - data->storage.serial =3D virXPathString("string(./serial[1])", ctx= t); + storage->bus =3D virXPathString("string(./bus[1])", ctxt); + storage->drive_type =3D virXPathString("string(./drive_type[1])", ctxt= ); + storage->model =3D virXPathString("string(./model[1])", ctxt); + storage->vendor =3D virXPathString("string(./vendor[1])", ctxt); + storage->serial =3D virXPathString("string(./serial[1])", ctxt); =20 if ((n =3D virXPathNodeSet("./capability", ctxt, &nodes)) < 0) goto out; @@ -651,19 +651,19 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, } =20 if (STREQ(type, "hotpluggable")) { - data->storage.flags |=3D VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE; + storage->flags |=3D VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE; } else if (STREQ(type, "removable")) { xmlNodePtr orignode2; =20 - data->storage.flags |=3D VIR_NODE_DEV_CAP_STORAGE_REMOVABLE; + storage->flags |=3D VIR_NODE_DEV_CAP_STORAGE_REMOVABLE; =20 orignode2 =3D ctxt->node; ctxt->node =3D nodes[i]; =20 if (virXPathBoolean("count(./media_available[. =3D '1']) > 0",= ctxt)) - data->storage.flags |=3D VIR_NODE_DEV_CAP_STORAGE_REMOVABL= E_MEDIA_AVAILABLE; + storage->flags |=3D VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MED= IA_AVAILABLE; =20 - data->storage.media_label =3D virXPathString("string(./media_l= abel[1])", ctxt); + storage->media_label =3D virXPathString("string(./media_label[= 1])", ctxt); =20 val =3D 0; if (virNodeDevCapsDefParseULongLong("number(./media_size[1])",= ctxt, &val, def, @@ -673,7 +673,7 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, VIR_FREE(type); goto out; } - data->storage.removable_media_size =3D val; + storage->removable_media_size =3D val; =20 ctxt->node =3D orignode2; } else { @@ -687,13 +687,13 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, VIR_FREE(type); } =20 - if (!(data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) { + if (!(storage->flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) { val =3D 0; if (virNodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &va= l, def, _("no size supplied for '%s'"), _("invalid size supplied for '= %s'")) < 0) goto out; - data->storage.size =3D val; + storage->size =3D val; } =20 ret =3D 0; @@ -708,7 +708,7 @@ static int virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, - virNodeDevCapDataPtr data) + virNodeDevCapSCSIPtr scsi) { xmlNodePtr orignode; int ret =3D -1; @@ -717,30 +717,30 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, ctxt->node =3D node; =20 if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, - &data->scsi.host, def, + &scsi->host, def, _("no SCSI host ID supplied for '%s'"), _("invalid SCSI host ID supplied for '= %s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->scsi.bus, def, + &scsi->bus, def, _("no SCSI bus ID supplied for '%s'"), _("invalid SCSI bus ID supplied for '%= s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseULong("number(./target[1])", ctxt, - &data->scsi.target, def, + &scsi->target, def, _("no SCSI target ID supplied for '%s'= "), _("invalid SCSI target ID supplied for= '%s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseULong("number(./lun[1])", ctxt, - &data->scsi.lun, def, + &scsi->lun, def, _("no SCSI LUN ID supplied for '%s'"), _("invalid SCSI LUN ID supplied for '%= s'")) < 0) goto out; =20 - data->scsi.type =3D virXPathString("string(./type[1])", ctxt); + scsi->type =3D virXPathString("string(./type[1])", ctxt); =20 ret =3D 0; out: @@ -753,7 +753,7 @@ static int virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, - virNodeDevCapDataPtr data) + virNodeDevCapSCSITargetPtr scsi_target) { xmlNodePtr orignode; int ret =3D -1; @@ -761,8 +761,8 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, orignode =3D ctxt->node; ctxt->node =3D node; =20 - data->scsi_target.name =3D virXPathString("string(./target[1])", ctxt); - if (!data->scsi_target.name) { + scsi_target->name =3D virXPathString("string(./target[1])", ctxt); + if (!scsi_target->name) { virReportError(VIR_ERR_INTERNAL_ERROR, _("no target name supplied for '%s'"), def->name); @@ -781,7 +781,7 @@ static int virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, - virNodeDevCapDataPtr data, + virNodeDevCapSCSIHostPtr scsi_host, int create, const char *virt_type) { @@ -795,15 +795,15 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, =20 if (create =3D=3D EXISTING_DEVICE) { if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, - &data->scsi_host.host, def, + &scsi_host->host, def, _("no SCSI host ID supplied for '%= s'"), _("invalid SCSI host ID supplied f= or '%s'")) < 0) { goto out; } /* Optional unique_id value */ - data->scsi_host.unique_id =3D -1; + scsi_host->unique_id =3D -1; if (virNodeDevCapsDefParseIntOptional("number(./unique_id[1])", ct= xt, - &data->scsi_host.unique_id, = def, + &scsi_host->unique_id, def, _("invalid unique_id supplie= d for '%s'")) < 0) { goto out; } @@ -824,21 +824,21 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, =20 if (STREQ(type, "vport_ops")) { =20 - data->scsi_host.flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; + scsi_host->flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; =20 } else if (STREQ(type, "fc_host")) { =20 xmlNodePtr orignode2; =20 - data->scsi_host.flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST; + scsi_host->flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST; =20 orignode2 =3D ctxt->node; ctxt->node =3D nodes[i]; =20 if (virNodeDevCapsDefParseString("string(./wwnn[1])", ctxt, - &data->scsi_host.wwnn) < 0) { - if (virRandomGenerateWWN(&data->scsi_host.wwnn, virt_type)= < 0) { + &scsi_host->wwnn) < 0) { + if (virRandomGenerateWWN(&scsi_host->wwnn, virt_type) < 0)= { virReportError(VIR_ERR_INTERNAL_ERROR, _("no WWNN supplied for '%s', and " "auto-generation failed"), @@ -849,8 +849,8 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, =20 if (virNodeDevCapsDefParseString("string(./wwpn[1])", ctxt, - &data->scsi_host.wwpn) < 0) { - if (virRandomGenerateWWN(&data->scsi_host.wwpn, virt_type)= < 0) { + &scsi_host->wwpn) < 0) { + if (virRandomGenerateWWN(&scsi_host->wwpn, virt_type) < 0)= { virReportError(VIR_ERR_INTERNAL_ERROR, _("no WWPN supplied for '%s', and " "auto-generation failed"), @@ -861,7 +861,7 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, =20 if (virNodeDevCapsDefParseString("string(./fabric_wwn[1])", ctxt, - &data->scsi_host.fabric_wwn) = < 0) + &scsi_host->fabric_wwn) < 0) VIR_DEBUG("No fabric_wwn defined for '%s'", def->name); =20 ctxt->node =3D orignode2; @@ -890,7 +890,7 @@ static int virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, - virNodeDevCapDataPtr data) + virNodeDevCapNetPtr net) { xmlNodePtr orignode, lnk; size_t i =3D -1; @@ -901,21 +901,21 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, orignode =3D ctxt->node; ctxt->node =3D node; =20 - data->net.ifname =3D virXPathString("string(./interface[1])", ctxt); - if (!data->net.ifname) { + net->ifname =3D virXPathString("string(./interface[1])", ctxt); + if (!net->ifname) { virReportError(VIR_ERR_INTERNAL_ERROR, _("no network interface supplied for '%s'"), def->name); goto out; } =20 - data->net.address =3D virXPathString("string(./address[1])", ctxt); + net->address =3D virXPathString("string(./address[1])", ctxt); =20 if ((n =3D virXPathNodeSet("./feature", ctxt, &nodes)) < 0) goto out; =20 if (n > 0) { - if (!(data->net.features =3D virBitmapNew(VIR_NET_DEV_FEAT_LAST))) + if (!(net->features =3D virBitmapNew(VIR_NET_DEV_FEAT_LAST))) goto out; } =20 @@ -933,11 +933,11 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, tmp); goto out; } - ignore_value(virBitmapSetBit(data->net.features, val)); + ignore_value(virBitmapSetBit(net->features, val)); VIR_FREE(tmp); } =20 - data->net.subtype =3D VIR_NODE_DEV_CAP_NET_LAST; + net->subtype =3D VIR_NODE_DEV_CAP_NET_LAST; =20 tmp =3D virXPathString("string(./capability/@type)", ctxt); if (tmp) { @@ -949,11 +949,11 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, def->name); goto out; } - data->net.subtype =3D val; + net->subtype =3D val; } =20 lnk =3D virXPathNode("./link", ctxt); - if (lnk && virInterfaceLinkParseXML(lnk, &data->net.lnk) < 0) + if (lnk && virInterfaceLinkParseXML(lnk, &net->lnk) < 0) goto out; =20 ret =3D 0; @@ -969,7 +969,7 @@ static int virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, - virNodeDevCapDataPtr data) + virNodeDevCapUSBIfPtr usb_if) { xmlNodePtr orignode; int ret =3D -1; @@ -978,30 +978,30 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr = ctxt, ctxt->node =3D node; =20 if (virNodeDevCapsDefParseULong("number(./number[1])", ctxt, - &data->usb_if.number, def, + &usb_if->number, def, _("no USB interface number supplied fo= r '%s'"), _("invalid USB interface number suppli= ed for '%s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseULong("number(./class[1])", ctxt, - &data->usb_if._class, def, + &usb_if->_class, def, _("no USB interface class supplied for= '%s'"), _("invalid USB interface class supplie= d for '%s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseULong("number(./subclass[1])", ctxt, - &data->usb_if.subclass, def, + &usb_if->subclass, def, _("no USB interface subclass supplied = for '%s'"), _("invalid USB interface subclass supp= lied for '%s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseULong("number(./protocol[1])", ctxt, - &data->usb_if.protocol, def, + &usb_if->protocol, def, _("no USB interface protocol supplied = for '%s'"), _("invalid USB interface protocol supp= lied for '%s'")) < 0) goto out; =20 - data->usb_if.description =3D virXPathString("string(./description[1])"= , ctxt); + usb_if->description =3D virXPathString("string(./description[1])", ctx= t); =20 ret =3D 0; out: @@ -1038,7 +1038,7 @@ static int virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, - virNodeDevCapDataPtr data) + virNodeDevCapUSBDevPtr usb_dev) { xmlNodePtr orignode; int ret =3D -1; @@ -1047,31 +1047,31 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, ctxt->node =3D node; =20 if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->usb_dev.bus, def, + &usb_dev->bus, def, _("no USB bus number supplied for '%s'= "), _("invalid USB bus number supplied for= '%s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseULong("number(./device[1])", ctxt, - &data->usb_dev.device, def, + &usb_dev->device, def, _("no USB device number supplied for '= %s'"), _("invalid USB device number supplied = for '%s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, - &data->usb_dev.vendor, def, + &usb_dev->vendor, def, _("no USB vendor ID supplied for '%s'"= ), _("invalid USB vendor ID supplied for = '%s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, - &data->usb_dev.product, def, + &usb_dev->product, def, _("no USB product ID supplied for '%s'= "), _("invalid USB product ID supplied for= '%s'")) < 0) goto out; =20 - data->usb_dev.vendor_name =3D virXPathString("string(./vendor[1])", c= txt); - data->usb_dev.product_name =3D virXPathString("string(./product[1])", = ctxt); + usb_dev->vendor_name =3D virXPathString("string(./vendor[1])", ctxt); + usb_dev->product_name =3D virXPathString("string(./product[1])", ctxt); =20 ret =3D 0; out: @@ -1083,7 +1083,7 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, static int virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, xmlNodePtr iommuGroupNode, - virNodeDevCapDataPtr data) + virNodeDevCapPCIDevPtr pci_dev) { xmlNodePtr origNode =3D ctxt->node; xmlNodePtr *addrNodes =3D NULL; @@ -1101,7 +1101,7 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContext= Ptr ctxt, goto cleanup; } if (virStrToLong_ui(numberStr, NULL, 10, - &data->pci_dev.iommuGroupNumber) < 0) { + &pci_dev->iommuGroupNumber) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid iommuGroup number attribute '%s'"), numberStr); @@ -1121,8 +1121,8 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContext= Ptr ctxt, pciAddr->bus =3D addr.bus; pciAddr->slot =3D addr.slot; pciAddr->function =3D addr.function; - if (VIR_APPEND_ELEMENT(data->pci_dev.iommuGroupDevices, - data->pci_dev.nIommuGroupDevices, + if (VIR_APPEND_ELEMENT(pci_dev->iommuGroupDevices, + pci_dev->nIommuGroupDevices, pciAddr) < 0) goto cleanup; } @@ -1222,7 +1222,7 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt, static int virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, xmlNodePtr node, - virNodeDevCapDataPtr data) + virNodeDevCapPCIDevPtr pci_dev) { char *maxFuncsStr =3D virXMLPropString(node, "maxCount"); char *type =3D virXMLPropString(node, "type"); @@ -1241,7 +1241,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ct= xt, if (STREQ(type, "phys_function")) { xmlNodePtr address =3D virXPathNode("./address[1]", ctxt); =20 - if (VIR_ALLOC(data->pci_dev.physical_function) < 0) + if (VIR_ALLOC(pci_dev->physical_function) < 0) goto out; =20 if (!address) { @@ -1251,10 +1251,10 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr = ctxt, } =20 if (virPCIDeviceAddressParseXML(address, - data->pci_dev.physical_function) <= 0) + pci_dev->physical_function) < 0) goto out; =20 - data->pci_dev.flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTI= ON; + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; } else if (STREQ(type, "virt_functions")) { int naddresses; =20 @@ -1263,13 +1263,13 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr = ctxt, =20 if (maxFuncsStr && virStrToLong_uip(maxFuncsStr, NULL, 10, - &data->pci_dev.max_virtual_functions) < 0) { + &pci_dev->max_virtual_functions) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Malformed 'maxCount' parameter")); goto out; } =20 - if (VIR_ALLOC_N(data->pci_dev.virtual_functions, naddresses) < 0) + if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0) goto out; =20 for (i =3D 0; i < naddresses; i++) { @@ -1283,18 +1283,18 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr = ctxt, goto out; } =20 - if (VIR_APPEND_ELEMENT(data->pci_dev.virtual_functions, - data->pci_dev.num_virtual_functions, + if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions, + pci_dev->num_virtual_functions, addr) < 0) goto out; } =20 - data->pci_dev.flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTIO= N; + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; } else { int hdrType =3D virPCIHeaderTypeFromString(type); =20 - if (hdrType > 0 && !data->pci_dev.hdrType) - data->pci_dev.hdrType =3D hdrType; + if (hdrType > 0 && !pci_dev->hdrType) + pci_dev->hdrType =3D hdrType; } =20 ret =3D 0; @@ -1311,7 +1311,7 @@ static int virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, - virNodeDevCapDataPtr data) + virNodeDevCapPCIDevPtr pci_dev) { xmlNodePtr orignode, iommuGroupNode, pciExpress; xmlNodePtr *nodes =3D NULL; @@ -1325,64 +1325,64 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, ctxt->node =3D node; =20 if (virNodeDevCapsDefParseULong("number(./domain[1])", ctxt, - &data->pci_dev.domain, def, + &pci_dev->domain, def, _("no PCI domain ID supplied for '%s'"= ), _("invalid PCI domain ID supplied for = '%s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, - &data->pci_dev.bus, def, + &pci_dev->bus, def, _("no PCI bus ID supplied for '%s'"), _("invalid PCI bus ID supplied for '%s= '")) < 0) goto out; =20 if (virNodeDevCapsDefParseULong("number(./slot[1])", ctxt, - &data->pci_dev.slot, def, + &pci_dev->slot, def, _("no PCI slot ID supplied for '%s'"), _("invalid PCI slot ID supplied for '%= s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseULong("number(./function[1])", ctxt, - &data->pci_dev.function, def, + &pci_dev->function, def, _("no PCI function ID supplied for '%s= '"), _("invalid PCI function ID supplied fo= r '%s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, - &data->pci_dev.vendor, def, + &pci_dev->vendor, def, _("no PCI vendor ID supplied for '%s'"= ), _("invalid PCI vendor ID supplied for = '%s'")) < 0) goto out; =20 if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, - &data->pci_dev.product, def, + &pci_dev->product, def, _("no PCI product ID supplied for '%s'= "), _("invalid PCI product ID supplied for= '%s'")) < 0) goto out; =20 - data->pci_dev.vendor_name =3D virXPathString("string(./vendor[1])", c= txt); - data->pci_dev.product_name =3D virXPathString("string(./product[1])", = ctxt); + pci_dev->vendor_name =3D virXPathString("string(./vendor[1])", ctxt); + pci_dev->product_name =3D virXPathString("string(./product[1])", ctxt); =20 if ((n =3D virXPathNodeSet("./capability", ctxt, &nodes)) < 0) goto out; =20 for (i =3D 0; i < n; i++) { - if (virNodeDevPCICapabilityParseXML(ctxt, nodes[i], data) < 0) + if (virNodeDevPCICapabilityParseXML(ctxt, nodes[i], pci_dev) < 0) goto out; } VIR_FREE(nodes); =20 if ((iommuGroupNode =3D virXPathNode("./iommuGroup[1]", ctxt))) { if (virNodeDevCapPCIDevIommuGroupParseXML(ctxt, iommuGroupNode, - data) < 0) { + pci_dev) < 0) { goto out; } } =20 /* The default value is -1 since zero is valid NUMA node number */ - data->pci_dev.numa_node =3D -1; + pci_dev->numa_node =3D -1; if (virNodeDevCapsDefParseIntOptional("number(./numa[1]/@node)", ctxt, - &data->pci_dev.numa_node, def, + &pci_dev->numa_node, def, _("invalid NUMA node ID supplied= for '%s'")) < 0) goto out; =20 @@ -1393,9 +1393,9 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, if (virPCIEDeviceInfoParseXML(ctxt, pciExpress, pci_express) < 0) goto out; =20 - data->pci_dev.pci_express =3D pci_express; + pci_dev->pci_express =3D pci_express; pci_express =3D NULL; - data->pci_dev.flags |=3D VIR_NODE_DEV_CAP_FLAG_PCIE; + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCIE; } =20 ret =3D 0; @@ -1412,8 +1412,10 @@ static int virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, virNodeDeviceDefPtr def, xmlNodePtr node, - virNodeDevCapDataPtr data) + virNodeDevCapSystemPtr system) { + virNodeDevSystemHardwarePtr hardware =3D &system->hardware; + virNodeDevSystemFirmwarePtr firmware =3D &system->firmware; xmlNodePtr orignode; int ret =3D -1; char *tmp; @@ -1421,11 +1423,11 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, orignode =3D ctxt->node; ctxt->node =3D node; =20 - data->system.product_name =3D virXPathString("string(./product[1])", c= txt); + system->product_name =3D virXPathString("string(./product[1])", ctxt); =20 - data->system.hardware.vendor_name =3D virXPathString("string(./hardwar= e/vendor[1])", ctxt); - data->system.hardware.version =3D virXPathString("string(./hardwar= e/version[1])", ctxt); - data->system.hardware.serial =3D virXPathString("string(./hardwar= e/serial[1])", ctxt); + hardware->vendor_name =3D virXPathString("string(./hardware/vendor[1])= ", ctxt); + hardware->version =3D virXPathString("string(./hardware/version[1]= )", ctxt); + hardware->serial =3D virXPathString("string(./hardware/serial[1])= ", ctxt); =20 tmp =3D virXPathString("string(./hardware/uuid[1])", ctxt); if (!tmp) { @@ -1434,7 +1436,7 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, goto out; } =20 - if (virUUIDParse(tmp, data->system.hardware.uuid) < 0) { + if (virUUIDParse(tmp, hardware->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("malformed uuid element for '%s'"), def->name); VIR_FREE(tmp); @@ -1442,9 +1444,9 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, } VIR_FREE(tmp); =20 - data->system.firmware.vendor_name =3D virXPathString("string(./firmwa= re/vendor[1])", ctxt); - data->system.firmware.version =3D virXPathString("string(./firmwa= re/version[1])", ctxt); - data->system.firmware.release_date =3D virXPathString("string(./firmwa= re/release_date[1])", ctxt); + firmware->vendor_name =3D virXPathString("string(./firmware/vendor[1]= )", ctxt); + firmware->version =3D virXPathString("string(./firmware/version[1= ])", ctxt); + firmware->release_date =3D virXPathString("string(./firmware/release_d= ate[1])", ctxt); =20 ret =3D 0; out: @@ -1485,37 +1487,40 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, =20 switch (caps->data.type) { case VIR_NODE_DEV_CAP_SYSTEM: - ret =3D virNodeDevCapSystemParseXML(ctxt, def, node, &caps->data); + ret =3D virNodeDevCapSystemParseXML(ctxt, def, node, &caps->data.s= ystem); break; case VIR_NODE_DEV_CAP_PCI_DEV: - ret =3D virNodeDevCapPCIDevParseXML(ctxt, def, node, &caps->data); + ret =3D virNodeDevCapPCIDevParseXML(ctxt, def, node, &caps->data.p= ci_dev); break; case VIR_NODE_DEV_CAP_USB_DEV: - ret =3D virNodeDevCapUSBDevParseXML(ctxt, def, node, &caps->data); + ret =3D virNodeDevCapUSBDevParseXML(ctxt, def, node, &caps->data.u= sb_dev); break; case VIR_NODE_DEV_CAP_USB_INTERFACE: - ret =3D virNodeDevCapUSBInterfaceParseXML(ctxt, def, node, &caps->= data); + ret =3D virNodeDevCapUSBInterfaceParseXML(ctxt, def, node, + &caps->data.usb_if); break; case VIR_NODE_DEV_CAP_NET: - ret =3D virNodeDevCapNetParseXML(ctxt, def, node, &caps->data); + ret =3D virNodeDevCapNetParseXML(ctxt, def, node, &caps->data.net); break; case VIR_NODE_DEV_CAP_SCSI_HOST: ret =3D virNodeDevCapSCSIHostParseXML(ctxt, def, node, - &caps->data, + &caps->data.scsi_host, create, virt_type); break; case VIR_NODE_DEV_CAP_SCSI_TARGET: - ret =3D virNodeDevCapSCSITargetParseXML(ctxt, def, node, &caps->da= ta); + ret =3D virNodeDevCapSCSITargetParseXML(ctxt, def, node, + &caps->data.scsi_target); break; case VIR_NODE_DEV_CAP_SCSI: - ret =3D virNodeDevCapSCSIParseXML(ctxt, def, node, &caps->data); + ret =3D virNodeDevCapSCSIParseXML(ctxt, def, node, &caps->data.scs= i); break; case VIR_NODE_DEV_CAP_STORAGE: - ret =3D virNodeDevCapStorageParseXML(ctxt, def, node, &caps->data); + ret =3D virNodeDevCapStorageParseXML(ctxt, def, node, + &caps->data.storage); break; case VIR_NODE_DEV_CAP_DRM: - ret =3D virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data); + ret =3D virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data.drm); break; case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_VPORTS: diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 0869b1b..39fd438 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -54,7 +54,7 @@ static int update_caps(virNodeDeviceObjPtr dev) while (cap) { switch (cap->data.type) { case VIR_NODE_DEV_CAP_SCSI_HOST: - nodeDeviceSysfsGetSCSIHostCaps(&dev->def->caps->data); + nodeDeviceSysfsGetSCSIHostCaps(&dev->def->caps->data.scsi_host= ); break; case VIR_NODE_DEV_CAP_NET: if (virNetDevGetLinkInfo(cap->data.net.ifname, &cap->data.net.= lnk) < 0) @@ -65,7 +65,7 @@ static int update_caps(virNodeDeviceObjPtr dev) break; case VIR_NODE_DEV_CAP_PCI_DEV: if (nodeDeviceSysfsGetPCIRelatedDevCaps(dev->def->sysfs_path, - &dev->def->caps->data) = < 0) + &dev->def->caps->data.p= ci_dev) < 0) return -1; break; =20 @@ -297,7 +297,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, =20 while (cap) { if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST) { - nodeDeviceSysfsGetSCSIHostCaps(&cap->data); + nodeDeviceSysfsGetSCSIHostCaps(&cap->data.scsi_host); if (cap->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { if (STREQ(cap->data.scsi_host.wwnn, wwnn) && diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index f17618c..81e5ecc 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -153,7 +153,7 @@ gather_pci_cap(LibHalContext *ctx, const char *udi, ignore_value(virStrToLong_ui(p+1, &p, 16, &d->pci_dev.function= )); } =20 - if (nodeDeviceSysfsGetPCIRelatedDevCaps(sysfs_path, d) < 0) { + if (nodeDeviceSysfsGetPCIRelatedDevCaps(sysfs_path, &d->pci_dev) <= 0) { VIR_FREE(sysfs_path); return -1; } @@ -239,7 +239,7 @@ gather_scsi_host_cap(LibHalContext *ctx, const char *ud= i, =20 (void)get_int_prop(ctx, udi, "scsi_host.host", (int *)&d->scsi_host.ho= st); =20 - retval =3D nodeDeviceSysfsGetSCSIHostCaps(d); + retval =3D nodeDeviceSysfsGetSCSIHostCaps(&d->scsi_host); =20 if (retval =3D=3D -1) goto out; diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/no= de_device_linux_sysfs.c index 8ac8bf6..1b7aa94 100644 --- a/src/node_device/node_device_linux_sysfs.c +++ b/src/node_device/node_device_linux_sysfs.c @@ -44,65 +44,65 @@ VIR_LOG_INIT("node_device.node_device_linux_sysfs"); =20 int -nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d) +nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host) { char *tmp =3D NULL; int ret =3D -1; =20 - if ((d->scsi_host.unique_id =3D - virSCSIHostGetUniqueId(NULL, d->scsi_host.host)) < 0) { - VIR_DEBUG("Failed to read unique_id for host%d", d->scsi_host.host= ); - d->scsi_host.unique_id =3D -1; + if ((scsi_host->unique_id =3D + virSCSIHostGetUniqueId(NULL, scsi_host->host)) < 0) { + VIR_DEBUG("Failed to read unique_id for host%d", scsi_host->host); + scsi_host->unique_id =3D -1; } =20 - VIR_DEBUG("Checking if host%d is an FC HBA", d->scsi_host.host); + VIR_DEBUG("Checking if host%d is an FC HBA", scsi_host->host); =20 - if (virVHBAPathExists(NULL, d->scsi_host.host)) { - d->scsi_host.flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST; + if (virVHBAPathExists(NULL, scsi_host->host)) { + scsi_host->flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST; =20 - if (!(tmp =3D virVHBAGetConfig(NULL, d->scsi_host.host, "port_name= "))) { - VIR_WARN("Failed to read WWPN for host%d", d->scsi_host.host); + if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "port_name")= )) { + VIR_WARN("Failed to read WWPN for host%d", scsi_host->host); goto cleanup; } - VIR_FREE(d->scsi_host.wwpn); - VIR_STEAL_PTR(d->scsi_host.wwpn, tmp); + VIR_FREE(scsi_host->wwpn); + VIR_STEAL_PTR(scsi_host->wwpn, tmp); =20 - if (!(tmp =3D virVHBAGetConfig(NULL, d->scsi_host.host, "node_name= "))) { - VIR_WARN("Failed to read WWNN for host%d", d->scsi_host.host); + if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "node_name")= )) { + VIR_WARN("Failed to read WWNN for host%d", scsi_host->host); goto cleanup; } - VIR_FREE(d->scsi_host.wwnn); - VIR_STEAL_PTR(d->scsi_host.wwnn, tmp); + VIR_FREE(scsi_host->wwnn); + VIR_STEAL_PTR(scsi_host->wwnn, tmp); =20 - if ((tmp =3D virVHBAGetConfig(NULL, d->scsi_host.host, "fabric_nam= e"))) { - VIR_FREE(d->scsi_host.fabric_wwn); - VIR_STEAL_PTR(d->scsi_host.fabric_wwn, tmp); + if ((tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "fabric_name"= ))) { + VIR_FREE(scsi_host->fabric_wwn); + VIR_STEAL_PTR(scsi_host->fabric_wwn, tmp); } } =20 - if (virVHBAIsVportCapable(NULL, d->scsi_host.host)) { - d->scsi_host.flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; + if (virVHBAIsVportCapable(NULL, scsi_host->host)) { + scsi_host->flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; =20 - if (!(tmp =3D virVHBAGetConfig(NULL, d->scsi_host.host, + if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "max_npiv_vports"))) { VIR_WARN("Failed to read max_npiv_vports for host%d", - d->scsi_host.host); + scsi_host->host); goto cleanup; } =20 - if (virStrToLong_i(tmp, NULL, 10, &d->scsi_host.max_vports) < 0) { + if (virStrToLong_i(tmp, NULL, 10, &scsi_host->max_vports) < 0) { VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp); goto cleanup; } =20 - if (!(tmp =3D virVHBAGetConfig(NULL, d->scsi_host.host, + if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "npiv_vports_inuse"))) { VIR_WARN("Failed to read npiv_vports_inuse for host%d", - d->scsi_host.host); + scsi_host->host); goto cleanup; } =20 - if (virStrToLong_i(tmp, NULL, 10, &d->scsi_host.vports) < 0) { + if (virStrToLong_i(tmp, NULL, 10, &scsi_host->vports) < 0) { VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tm= p); goto cleanup; } @@ -112,12 +112,12 @@ nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d) cleanup: if (ret < 0) { /* Clear the two flags in case of producing confusing XML output */ - d->scsi_host.flags &=3D ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST | + scsi_host->flags &=3D ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST | VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS); =20 - VIR_FREE(d->scsi_host.wwnn); - VIR_FREE(d->scsi_host.wwpn); - VIR_FREE(d->scsi_host.fabric_wwn); + VIR_FREE(scsi_host->wwnn); + VIR_FREE(scsi_host->wwpn); + VIR_FREE(scsi_host->fabric_wwn); } VIR_FREE(tmp); return ret; @@ -126,37 +126,37 @@ nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d) =20 static int nodeDeviceSysfsGetPCISRIOVCaps(const char *sysfsPath, - virNodeDevCapDataPtr data) + virNodeDevCapPCIDevPtr pci_dev) { size_t i; int ret; =20 /* this could be a refresh, so clear out the old data */ - for (i =3D 0; i < data->pci_dev.num_virtual_functions; i++) - VIR_FREE(data->pci_dev.virtual_functions[i]); - VIR_FREE(data->pci_dev.virtual_functions); - data->pci_dev.num_virtual_functions =3D 0; - data->pci_dev.max_virtual_functions =3D 0; - data->pci_dev.flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; - data->pci_dev.flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; + for (i =3D 0; i < pci_dev->num_virtual_functions; i++) + VIR_FREE(pci_dev->virtual_functions[i]); + VIR_FREE(pci_dev->virtual_functions); + pci_dev->num_virtual_functions =3D 0; + pci_dev->max_virtual_functions =3D 0; + pci_dev->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; + pci_dev->flags &=3D ~VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; =20 ret =3D virPCIGetPhysicalFunction(sysfsPath, - &data->pci_dev.physical_function); + &pci_dev->physical_function); if (ret < 0) goto cleanup; =20 - if (data->pci_dev.physical_function) - data->pci_dev.flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTI= ON; + if (pci_dev->physical_function) + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; =20 - ret =3D virPCIGetVirtualFunctions(sysfsPath, &data->pci_dev.virtual_fu= nctions, - &data->pci_dev.num_virtual_functions, - &data->pci_dev.max_virtual_functions); + ret =3D virPCIGetVirtualFunctions(sysfsPath, &pci_dev->virtual_functio= ns, + &pci_dev->num_virtual_functions, + &pci_dev->max_virtual_functions); if (ret < 0) goto cleanup; =20 - if (data->pci_dev.num_virtual_functions > 0 || - data->pci_dev.max_virtual_functions > 0) - data->pci_dev.flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTIO= N; + if (pci_dev->num_virtual_functions > 0 || + pci_dev->max_virtual_functions > 0) + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; =20 cleanup: return ret; @@ -164,23 +164,23 @@ nodeDeviceSysfsGetPCISRIOVCaps(const char *sysfsPath, =20 =20 static int -nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapDataPtr data) +nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapPCIDevPtr pci_dev) { size_t i; int tmpGroup, ret =3D -1; virPCIDeviceAddress addr; =20 /* this could be a refresh, so clear out the old data */ - for (i =3D 0; i < data->pci_dev.nIommuGroupDevices; i++) - VIR_FREE(data->pci_dev.iommuGroupDevices[i]); - VIR_FREE(data->pci_dev.iommuGroupDevices); - data->pci_dev.nIommuGroupDevices =3D 0; - data->pci_dev.iommuGroupNumber =3D 0; - - addr.domain =3D data->pci_dev.domain; - addr.bus =3D data->pci_dev.bus; - addr.slot =3D data->pci_dev.slot; - addr.function =3D data->pci_dev.function; + for (i =3D 0; i < pci_dev->nIommuGroupDevices; i++) + VIR_FREE(pci_dev->iommuGroupDevices[i]); + VIR_FREE(pci_dev->iommuGroupDevices); + pci_dev->nIommuGroupDevices =3D 0; + pci_dev->iommuGroupNumber =3D 0; + + addr.domain =3D pci_dev->domain; + addr.bus =3D pci_dev->bus; + addr.slot =3D pci_dev->slot; + addr.function =3D pci_dev->function; tmpGroup =3D virPCIDeviceAddressGetIOMMUGroupNum(&addr); if (tmpGroup =3D=3D -1) { /* error was already reported */ @@ -192,10 +192,10 @@ nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapData= Ptr data) goto cleanup; } if (tmpGroup >=3D 0) { - if (virPCIDeviceAddressGetIOMMUGroupAddresses(&addr, &data->pci_de= v.iommuGroupDevices, - &data->pci_dev.nIomm= uGroupDevices) < 0) + if (virPCIDeviceAddressGetIOMMUGroupAddresses(&addr, &pci_dev->iom= muGroupDevices, + &pci_dev->nIommuGrou= pDevices) < 0) goto cleanup; - data->pci_dev.iommuGroupNumber =3D tmpGroup; + pci_dev->iommuGroupNumber =3D tmpGroup; } =20 ret =3D 0; @@ -212,11 +212,11 @@ nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapData= Ptr data) */ int nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath, - virNodeDevCapDataPtr data) + virNodeDevCapPCIDevPtr pci_dev) { - if (nodeDeviceSysfsGetPCISRIOVCaps(sysfsPath, data) < 0) + if (nodeDeviceSysfsGetPCISRIOVCaps(sysfsPath, pci_dev) < 0) return -1; - if (nodeDeviceSysfsGetPCIIOMMUGroupCaps(data) < 0) + if (nodeDeviceSysfsGetPCIIOMMUGroupCaps(pci_dev) < 0) return -1; return 0; } @@ -225,14 +225,14 @@ nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfs= Path, #else =20 int -nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d ATTRIBUTE_UNUSED) +nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host ATTRIBUT= E_UNUSED) { return -1; } =20 int nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath ATTRIBUTE_UNUSED, - virNodeDevCapDataPtr data ATTRIBUTE_UN= USED) + virNodeDevCapPCIDevPtr pci_dev ATTRIBU= TE_UNUSED) { return -1; } diff --git a/src/node_device/node_device_linux_sysfs.h b/src/node_device/no= de_device_linux_sysfs.h index e4afdd7..8deea66 100644 --- a/src/node_device/node_device_linux_sysfs.h +++ b/src/node_device/node_device_linux_sysfs.h @@ -25,8 +25,8 @@ =20 # include "node_device_conf.h" =20 -int nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d); +int nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host); int nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath, - virNodeDevCapDataPtr data); + virNodeDevCapPCIDevPtr pci_dev); =20 #endif /* __VIR_NODE_DEVICE_LINUX_SYSFS_H__ */ diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 6bc0a53..33611a6 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -317,7 +317,7 @@ static int udevProcessPCI(struct udev_device *device, virNodeDeviceDefPtr def) { const char *syspath =3D NULL; - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapPCIDevPtr pci_dev =3D &def->caps->data.pci_dev; virPCIEDeviceInfoPtr pci_express =3D NULL; virPCIDevicePtr pciDev =3D NULL; udevPrivate *priv =3D driver->privateData; @@ -326,30 +326,30 @@ static int udevProcessPCI(struct udev_device *device, =20 syspath =3D udev_device_get_syspath(device); =20 - if (udevGetUintProperty(device, "PCI_CLASS", &data->pci_dev.class, 16)= < 0) + if (udevGetUintProperty(device, "PCI_CLASS", &pci_dev->class, 16) < 0) goto cleanup; =20 if ((p =3D strrchr(syspath, '/')) =3D=3D NULL || - virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.domain) < 0 || p =3D= =3D NULL || - virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.bus) < 0 || p =3D=3D= NULL || - virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.slot) < 0 || p =3D= =3D NULL || - virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.function) < 0) { + virStrToLong_ui(p + 1, &p, 16, &pci_dev->domain) < 0 || p =3D=3D N= ULL || + virStrToLong_ui(p + 1, &p, 16, &pci_dev->bus) < 0 || p =3D=3D NULL= || + virStrToLong_ui(p + 1, &p, 16, &pci_dev->slot) < 0 || p =3D=3D NUL= L || + virStrToLong_ui(p + 1, &p, 16, &pci_dev->function) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse the PCI address from sysfs path:= '%s'"), syspath); goto cleanup; } =20 - if (udevGetUintSysfsAttr(device, "vendor", &data->pci_dev.vendor, 16) = < 0) + if (udevGetUintSysfsAttr(device, "vendor", &pci_dev->vendor, 16) < 0) goto cleanup; =20 - if (udevGetUintSysfsAttr(device, "device", &data->pci_dev.product, 16)= < 0) + if (udevGetUintSysfsAttr(device, "device", &pci_dev->product, 16) < 0) goto cleanup; =20 - if (udevTranslatePCIIds(data->pci_dev.vendor, - data->pci_dev.product, - &data->pci_dev.vendor_name, - &data->pci_dev.product_name) !=3D 0) { + if (udevTranslatePCIIds(pci_dev->vendor, + pci_dev->product, + &pci_dev->vendor_name, + &pci_dev->product_name) !=3D 0) { goto cleanup; } =20 @@ -358,23 +358,24 @@ static int udevProcessPCI(struct udev_device *device, =20 /* The default value is -1, because it can't be 0 * as zero is valid node number. */ - data->pci_dev.numa_node =3D -1; + pci_dev->numa_node =3D -1; if (udevGetIntSysfsAttr(device, "numa_node", - &data->pci_dev.numa_node, 10) < 0) + &pci_dev->numa_node, 10) < 0) goto cleanup; =20 - if (nodeDeviceSysfsGetPCIRelatedDevCaps(syspath, data) < 0) + if (nodeDeviceSysfsGetPCIRelatedDevCaps(syspath, + &def->caps->data.pci_dev) < 0) goto cleanup; =20 - if (!(pciDev =3D virPCIDeviceNew(data->pci_dev.domain, - data->pci_dev.bus, - data->pci_dev.slot, - data->pci_dev.function))) + if (!(pciDev =3D virPCIDeviceNew(pci_dev->domain, + pci_dev->bus, + pci_dev->slot, + pci_dev->function))) goto cleanup; =20 /* We need to be root to read PCI device configs */ if (priv->privileged) { - if (virPCIGetHeaderType(pciDev, &data->pci_dev.hdrType) < 0) + if (virPCIGetHeaderType(pciDev, &pci_dev->hdrType) < 0) goto cleanup; =20 if (virPCIDeviceIsPCIExpress(pciDev) > 0) { @@ -396,8 +397,8 @@ static int udevProcessPCI(struct udev_device *device, =20 pci_express->link_sta->port =3D -1; /* PCIe can't negotiat= e port. Yet :) */ } - data->pci_dev.flags |=3D VIR_NODE_DEV_CAP_FLAG_PCIE; - data->pci_dev.pci_express =3D pci_express; + pci_dev->flags |=3D VIR_NODE_DEV_CAP_FLAG_PCIE; + pci_dev->pci_express =3D pci_express; pci_express =3D NULL; } } @@ -430,7 +431,7 @@ static int drmGetMinorType(int minor) static int udevProcessDRMDevice(struct udev_device *device, virNodeDeviceDefPtr def) { - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapDRMPtr drm =3D &def->caps->data.drm; int minor; =20 if (udevGenerateDeviceName(device, def, NULL) !=3D 0) @@ -442,7 +443,7 @@ static int udevProcessDRMDevice(struct udev_device *dev= ice, if ((minor =3D drmGetMinorType(minor)) =3D=3D -1) return -1; =20 - data->drm.type =3D minor; + drm->type =3D minor; =20 return 0; } @@ -450,36 +451,36 @@ static int udevProcessDRMDevice(struct udev_device *d= evice, static int udevProcessUSBDevice(struct udev_device *device, virNodeDeviceDefPtr def) { - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapUSBDevPtr usb_dev =3D &def->caps->data.usb_dev; =20 - if (udevGetUintProperty(device, "BUSNUM", &data->usb_dev.bus, 10) < 0) + if (udevGetUintProperty(device, "BUSNUM", &usb_dev->bus, 10) < 0) return -1; - if (udevGetUintProperty(device, "DEVNUM", &data->usb_dev.device, 10) <= 0) + if (udevGetUintProperty(device, "DEVNUM", &usb_dev->device, 10) < 0) return -1; - if (udevGetUintProperty(device, "ID_VENDOR_ID", &data->usb_dev.vendor,= 16) < 0) + if (udevGetUintProperty(device, "ID_VENDOR_ID", &usb_dev->vendor, 16) = < 0) return -1; =20 if (udevGetStringProperty(device, "ID_VENDOR_FROM_DATABASE", - &data->usb_dev.vendor_name) < 0) + &usb_dev->vendor_name) < 0) return -1; =20 - if (!data->usb_dev.vendor_name && + if (!usb_dev->vendor_name && udevGetStringSysfsAttr(device, "manufacturer", - &data->usb_dev.vendor_name) < 0) + &usb_dev->vendor_name) < 0) return -1; =20 - if (udevGetUintProperty(device, "ID_MODEL_ID", &data->usb_dev.product,= 16) < 0) + if (udevGetUintProperty(device, "ID_MODEL_ID", &usb_dev->product, 16) = < 0) return -1; =20 if (udevGetStringProperty(device, "ID_MODEL_FROM_DATABASE", - &data->usb_dev.product_name) < 0) + &usb_dev->product_name) < 0) return -1; =20 - if (!data->usb_dev.product_name && + if (!usb_dev->product_name && udevGetStringSysfsAttr(device, "product", - &data->usb_dev.product_name) < 0) + &usb_dev->product_name) < 0) return -1; =20 if (udevGenerateDeviceName(device, def, NULL) !=3D 0) @@ -492,22 +493,22 @@ static int udevProcessUSBDevice(struct udev_device *d= evice, static int udevProcessUSBInterface(struct udev_device *device, virNodeDeviceDefPtr def) { - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapUSBIfPtr usb_if =3D &def->caps->data.usb_if; =20 if (udevGetUintSysfsAttr(device, "bInterfaceNumber", - &data->usb_if.number, 16) < 0) + &usb_if->number, 16) < 0) return -1; =20 if (udevGetUintSysfsAttr(device, "bInterfaceClass", - &data->usb_if._class, 16) < 0) + &usb_if->_class, 16) < 0) return -1; =20 if (udevGetUintSysfsAttr(device, "bInterfaceSubClass", - &data->usb_if.subclass, 16) < 0) + &usb_if->subclass, 16) < 0) return -1; =20 if (udevGetUintSysfsAttr(device, "bInterfaceProtocol", - &data->usb_if.protocol, 16) < 0) + &usb_if->protocol, 16) < 0) return -1; =20 if (udevGenerateDeviceName(device, def, NULL) !=3D 0) @@ -521,33 +522,33 @@ static int udevProcessNetworkInterface(struct udev_de= vice *device, virNodeDeviceDefPtr def) { const char *devtype =3D udev_device_get_devtype(device); - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapNetPtr net =3D &def->caps->data.net; =20 if (devtype && STREQ(devtype, "wlan")) { - data->net.subtype =3D VIR_NODE_DEV_CAP_NET_80211; + net->subtype =3D VIR_NODE_DEV_CAP_NET_80211; } else { - data->net.subtype =3D VIR_NODE_DEV_CAP_NET_80203; + net->subtype =3D VIR_NODE_DEV_CAP_NET_80203; } =20 if (udevGetStringProperty(device, "INTERFACE", - &data->net.ifname) < 0) + &net->ifname) < 0) return -1; =20 if (udevGetStringSysfsAttr(device, "address", - &data->net.address) < 0) + &net->address) < 0) return -1; =20 - if (udevGetUintSysfsAttr(device, "addr_len", &data->net.address_len, 0= ) < 0) + if (udevGetUintSysfsAttr(device, "addr_len", &net->address_len, 0) < 0) return -1; =20 - if (udevGenerateDeviceName(device, def, data->net.address) !=3D 0) + if (udevGenerateDeviceName(device, def, net->address) !=3D 0) return -1; =20 - if (virNetDevGetLinkInfo(data->net.ifname, &data->net.lnk) < 0) + if (virNetDevGetLinkInfo(net->ifname, &net->lnk) < 0) return -1; =20 - if (virNetDevGetFeatures(data->net.ifname, &data->net.features) < 0) + if (virNetDevGetFeatures(net->ifname, &net->features) < 0) return -1; =20 return 0; @@ -557,21 +558,21 @@ static int udevProcessNetworkInterface(struct udev_de= vice *device, static int udevProcessSCSIHost(struct udev_device *device ATTRIBUTE_UNUSED, virNodeDeviceDefPtr def) { - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapSCSIHostPtr scsi_host =3D &def->caps->data.scsi_host; char *filename =3D NULL; char *str; =20 filename =3D last_component(def->sysfs_path); =20 if (!(str =3D STRSKIP(filename, "host")) || - virStrToLong_ui(str, NULL, 0, &data->scsi_host.host) < 0) { + virStrToLong_ui(str, NULL, 0, &scsi_host->host) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse SCSI host '%s'"), filename); return -1; } =20 - nodeDeviceSysfsGetSCSIHostCaps(&def->caps->data); + nodeDeviceSysfsGetSCSIHostCaps(&def->caps->data.scsi_host); =20 if (udevGenerateDeviceName(device, def, NULL) !=3D 0) return -1; @@ -584,11 +585,11 @@ static int udevProcessSCSITarget(struct udev_device *= device ATTRIBUTE_UNUSED, virNodeDeviceDefPtr def) { const char *sysname =3D NULL; - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapSCSITargetPtr scsi_target =3D &def->caps->data.scsi_targe= t; =20 sysname =3D udev_device_get_sysname(device); =20 - if (VIR_STRDUP(data->scsi_target.name, sysname) < 0) + if (VIR_STRDUP(scsi_target->name, sysname) < 0) return -1; =20 if (udevGenerateDeviceName(device, def, NULL) !=3D 0) @@ -661,15 +662,15 @@ static int udevProcessSCSIDevice(struct udev_device *= device ATTRIBUTE_UNUSED, { int ret =3D -1; unsigned int tmp =3D 0; - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapSCSIPtr scsi =3D &def->caps->data.scsi; char *filename =3D NULL, *p =3D NULL; =20 filename =3D last_component(def->sysfs_path); =20 - if (virStrToLong_ui(filename, &p, 10, &data->scsi.host) < 0 || p =3D= =3D NULL || - virStrToLong_ui(p + 1, &p, 10, &data->scsi.bus) < 0 || p =3D=3D NU= LL || - virStrToLong_ui(p + 1, &p, 10, &data->scsi.target) < 0 || p =3D=3D= NULL || - virStrToLong_ui(p + 1, &p, 10, &data->scsi.lun) < 0) { + if (virStrToLong_ui(filename, &p, 10, &scsi->host) < 0 || p =3D=3D NUL= L || + virStrToLong_ui(p + 1, &p, 10, &scsi->bus) < 0 || p =3D=3D NULL || + virStrToLong_ui(p + 1, &p, 10, &scsi->target) < 0 || p =3D=3D NULL= || + virStrToLong_ui(p + 1, &p, 10, &scsi->lun) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse the SCSI address from filename: = '%s'"), filename); @@ -680,7 +681,7 @@ static int udevProcessSCSIDevice(struct udev_device *de= vice ATTRIBUTE_UNUSED, if (udevGetUintSysfsAttr(device, "type", &tmp, 0) < 0) goto cleanup; =20 - if (udevGetSCSIType(def, tmp, &data->scsi.type) < 0) + if (udevGetSCSIType(def, tmp, &scsi->type) < 0) goto cleanup; } =20 @@ -702,17 +703,16 @@ static int udevProcessSCSIDevice(struct udev_device *= device ATTRIBUTE_UNUSED, static int udevProcessDisk(struct udev_device *device, virNodeDeviceDefPtr def) { - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapStoragePtr storage =3D &def->caps->data.storage; =20 - if (udevGetUint64SysfsAttr(device, "size", &data->storage.num_blocks) = < 0) + if (udevGetUint64SysfsAttr(device, "size", &storage->num_blocks) < 0) return -1; =20 if (udevGetUint64SysfsAttr(device, "queue/logical_block_size", - &data->storage.logical_block_size) < 0) + &storage->logical_block_size) < 0) return -1; =20 - data->storage.size =3D data->storage.num_blocks * - data->storage.logical_block_size; + storage->size =3D storage->num_blocks * storage->logical_block_size; =20 return 0; } @@ -722,7 +722,7 @@ static int udevProcessRemoveableMedia(struct udev_devic= e *device, virNodeDeviceDefPtr def, int has_media) { - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapStoragePtr storage =3D &def->caps->data.storage; int is_removable =3D 0; =20 if (udevGetIntSysfsAttr(device, "removable", &is_removable, 0) < 0) @@ -737,15 +737,15 @@ static int udevProcessRemoveableMedia(struct udev_dev= ice *device, VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE; =20 if (udevGetStringProperty(device, "ID_FS_LABEL", - &data->storage.media_label) < 0) + &storage->media_label) < 0) return -1; =20 if (udevGetUint64SysfsAttr(device, "size", - &data->storage.num_blocks) < 0) + &storage->num_blocks) < 0) return -1; =20 if (udevGetUint64SysfsAttr(device, "queue/logical_block_size", - &data->storage.logical_block_size) < 0) + &storage->logical_block_size) < 0) return -1; =20 /* XXX This calculation is wrong for the qemu virtual cdrom @@ -800,18 +800,17 @@ static int udevProcessFloppy(struct udev_device *devi= ce, static int udevProcessSD(struct udev_device *device, virNodeDeviceDefPtr def) { - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapStoragePtr storage =3D &def->caps->data.storage; =20 if (udevGetUint64SysfsAttr(device, "size", - &data->storage.num_blocks) < 0) + &storage->num_blocks) < 0) return -1; =20 if (udevGetUint64SysfsAttr(device, "queue/logical_block_size", - &data->storage.logical_block_size) < 0) + &storage->logical_block_size) < 0) return -1; =20 - data->storage.size =3D data->storage.num_blocks * - data->storage.logical_block_size; + storage->size =3D storage->num_blocks * storage->logical_block_size; =20 return 0; } @@ -846,7 +845,7 @@ static int udevKludgeStorageType(virNodeDeviceDefPtr de= f) static int udevProcessStorage(struct udev_device *device, virNodeDeviceDefPtr def) { - virNodeDevCapDataPtr data =3D &def->caps->data; + virNodeDevCapStoragePtr storage =3D &def->caps->data.storage; int ret =3D -1; const char* devnode; =20 @@ -856,20 +855,20 @@ static int udevProcessStorage(struct udev_device *dev= ice, goto cleanup; } =20 - if (VIR_STRDUP(data->storage.block, devnode) < 0) + if (VIR_STRDUP(storage->block, devnode) < 0) goto cleanup; =20 - if (udevGetStringProperty(device, "ID_BUS", &data->storage.bus) < 0) + if (udevGetStringProperty(device, "ID_BUS", &storage->bus) < 0) goto cleanup; - if (udevGetStringProperty(device, "ID_SERIAL", &data->storage.serial) = < 0) + if (udevGetStringProperty(device, "ID_SERIAL", &storage->serial) < 0) goto cleanup; =20 - if (udevGetStringSysfsAttr(device, "device/vendor", &data->storage.ven= dor) < 0) + if (udevGetStringSysfsAttr(device, "device/vendor", &storage->vendor) = < 0) goto cleanup; if (def->caps->data.storage.vendor) virTrimSpaces(def->caps->data.storage.vendor, NULL); =20 - if (udevGetStringSysfsAttr(device, "device/model", &data->storage.mode= l) < 0) + if (udevGetStringSysfsAttr(device, "device/model", &storage->model) < = 0) goto cleanup; if (def->caps->data.storage.model) virTrimSpaces(def->caps->data.storage.model, NULL); @@ -878,10 +877,10 @@ static int udevProcessStorage(struct udev_device *dev= ice, * expected, so I don't see a problem with not having a property * for it. */ =20 - if (udevGetStringProperty(device, "ID_TYPE", &data->storage.drive_type= ) < 0) + if (udevGetStringProperty(device, "ID_TYPE", &storage->drive_type) < 0) goto cleanup; =20 - if (!data->storage.drive_type || + if (!storage->drive_type || STREQ(def->caps->data.storage.drive_type, "generic")) { int val =3D 0; const char *str =3D NULL; @@ -908,7 +907,7 @@ static int udevProcessStorage(struct udev_device *devic= e, } =20 if (str) { - if (VIR_STRDUP(data->storage.drive_type, str) < 0) + if (VIR_STRDUP(storage->drive_type, str) < 0) goto cleanup; } else { /* If udev doesn't have it, perhaps we can guess it. */ @@ -931,7 +930,7 @@ static int udevProcessStorage(struct udev_device *devic= e, goto cleanup; } =20 - if (udevGenerateDeviceName(device, def, data->storage.serial) !=3D 0) + if (udevGenerateDeviceName(device, def, storage->serial) !=3D 0) goto cleanup; =20 cleanup: @@ -1425,6 +1424,9 @@ udevGetDMIData(virNodeDevCapDataPtr data) { struct udev *udev =3D NULL; struct udev_device *device =3D NULL; + virNodeDevCapSystemPtr system =3D &data->system; + virNodeDevSystemHardwarePtr hardware =3D &data->system.hardware; + virNodeDevSystemFirmwarePtr firmware =3D &data->system.firmware; =20 udev =3D udev_monitor_get_udev(DRV_STATE_UDEV_MONITOR(driver)); =20 @@ -1440,29 +1442,29 @@ udevGetDMIData(virNodeDevCapDataPtr data) } =20 if (udevGetStringSysfsAttr(device, "product_name", - &data->system.product_name) < 0) + &system->product_name) < 0) goto cleanup; if (udevGetStringSysfsAttr(device, "sys_vendor", - &data->system.hardware.vendor_name) < 0) + &hardware->vendor_name) < 0) goto cleanup; if (udevGetStringSysfsAttr(device, "product_version", - &data->system.hardware.version) < 0) + &hardware->version) < 0) goto cleanup; if (udevGetStringSysfsAttr(device, "product_serial", - &data->system.hardware.serial) < 0) + &hardware->serial) < 0) goto cleanup; =20 - if (virGetHostUUID(data->system.hardware.uuid)) + if (virGetHostUUID(hardware->uuid)) goto cleanup; =20 if (udevGetStringSysfsAttr(device, "bios_vendor", - &data->system.firmware.vendor_name) < 0) + &firmware->vendor_name) < 0) goto cleanup; if (udevGetStringSysfsAttr(device, "bios_version", - &data->system.firmware.version) < 0) + &firmware->version) < 0) goto cleanup; if (udevGetStringSysfsAttr(device, "bios_date", - &data->system.firmware.release_date) < 0) + &firmware->release_date) < 0) goto cleanup; =20 cleanup: --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list