In preparation for privatizing the virNodeDeviceObj - create an accessor
for the @def field and then use it for various callers.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virnodedeviceobj.c | 7 +++++
src/conf/virnodedeviceobj.h | 2 ++
src/libvirt_private.syms | 1 +
src/node_device/node_device_driver.c | 52 ++++++++++++++++++++++--------------
src/node_device/node_device_hal.c | 11 +++++---
src/node_device/node_device_udev.c | 35 ++++++++++++------------
src/test/test_driver.c | 38 +++++++++++++++++---------
7 files changed, 92 insertions(+), 54 deletions(-)
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index a2d09ad..1b9d032 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -33,6 +33,13 @@
VIR_LOG_INIT("conf.virnodedeviceobj");
+virNodeDeviceDefPtr
+virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj)
+{
+ return obj->def;
+}
+
+
static int
virNodeDeviceObjHasCap(const virNodeDeviceObj *obj,
const char *cap)
diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h
index b8b534b..135a424 100644
--- a/src/conf/virnodedeviceobj.h
+++ b/src/conf/virnodedeviceobj.h
@@ -39,6 +39,8 @@ struct _virNodeDeviceDriverState {
virObjectEventStatePtr nodeDeviceEventState;
};
+virNodeDeviceDefPtr
+virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj);
virNodeDeviceObjPtr
virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d361454..222e3b2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -955,6 +955,7 @@ virNetworkObjUpdateAssignDef;
virNodeDeviceObjAssignDef;
virNodeDeviceObjFindByName;
virNodeDeviceObjFindBySysfsPath;
+virNodeDeviceObjGetDef;
virNodeDeviceObjGetNames;
virNodeDeviceObjGetParentHost;
virNodeDeviceObjListExport;
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index d34f399..93aa2af 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -253,16 +253,18 @@ nodeDeviceLookupByName(virConnectPtr conn,
const char *name)
{
virNodeDeviceObjPtr obj;
+ virNodeDeviceDefPtr def;
virNodeDevicePtr device = NULL;
if (!(obj = nodeDeviceObjFindByName(name)))
return NULL;
+ def = virNodeDeviceObjGetDef(obj);
- if (virNodeDeviceLookupByNameEnsureACL(conn, obj->def) < 0)
+ if (virNodeDeviceLookupByNameEnsureACL(conn, def) < 0)
goto cleanup;
if ((device = virGetNodeDevice(conn, name))) {
- if (VIR_STRDUP(device->parent, obj->def->parent) < 0)
+ if (VIR_STRDUP(device->parent, def->parent) < 0)
virObjectUnref(device);
}
@@ -282,6 +284,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
virNodeDeviceObjListPtr devs = &driver->devs;
virNodeDevCapsDefPtr cap = NULL;
virNodeDeviceObjPtr obj = NULL;
+ virNodeDeviceDefPtr def;
virNodeDevicePtr device = NULL;
virCheckFlags(0, NULL);
@@ -291,7 +294,8 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
for (i = 0; i < devs->count; i++) {
obj = devs->objs[i];
virNodeDeviceObjLock(obj);
- cap = obj->def->caps;
+ def = virNodeDeviceObjGetDef(obj);
+ cap = def->caps;
while (cap) {
if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
@@ -301,11 +305,11 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
if (STREQ(cap->data.scsi_host.wwnn, wwnn) &&
STREQ(cap->data.scsi_host.wwpn, wwpn)) {
- if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, obj->def)
< 0)
+ if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
goto out;
- if ((device = virGetNodeDevice(conn, obj->def->name))) {
- if (VIR_STRDUP(device->parent, obj->def->parent)
< 0)
+ if ((device = virGetNodeDevice(conn, def->name))) {
+ if (VIR_STRDUP(device->parent, def->parent) < 0)
virObjectUnref(device);
}
virNodeDeviceObjUnlock(obj);
@@ -330,23 +334,25 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr device,
unsigned int flags)
{
virNodeDeviceObjPtr obj;
+ virNodeDeviceDefPtr def;
char *ret = NULL;
virCheckFlags(0, NULL);
if (!(obj = nodeDeviceObjFindByName(device->name)))
return NULL;
+ def = virNodeDeviceObjGetDef(obj);
- if (virNodeDeviceGetXMLDescEnsureACL(device->conn, obj->def) < 0)
+ if (virNodeDeviceGetXMLDescEnsureACL(device->conn, def) < 0)
goto cleanup;
- if (nodeDeviceUpdateDriverName(obj->def) < 0)
+ if (nodeDeviceUpdateDriverName(def) < 0)
goto cleanup;
- if (nodeDeviceUpdateCaps(obj->def) < 0)
+ if (nodeDeviceUpdateCaps(def) < 0)
goto cleanup;
- ret = virNodeDeviceDefFormat(obj->def);
+ ret = virNodeDeviceDefFormat(def);
cleanup:
virNodeDeviceObjUnlock(obj);
@@ -358,16 +364,18 @@ char *
nodeDeviceGetParent(virNodeDevicePtr device)
{
virNodeDeviceObjPtr obj;
+ virNodeDeviceDefPtr def;
char *ret = NULL;
if (!(obj = nodeDeviceObjFindByName(device->name)))
return NULL;
+ def = virNodeDeviceObjGetDef(obj);
- if (virNodeDeviceGetParentEnsureACL(device->conn, obj->def) < 0)
+ if (virNodeDeviceGetParentEnsureACL(device->conn, def) < 0)
goto cleanup;
- if (obj->def->parent) {
- if (VIR_STRDUP(ret, obj->def->parent) < 0)
+ if (def->parent) {
+ if (VIR_STRDUP(ret, def->parent) < 0)
goto cleanup;
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -384,17 +392,19 @@ int
nodeDeviceNumOfCaps(virNodeDevicePtr device)
{
virNodeDeviceObjPtr obj;
+ virNodeDeviceDefPtr def;
virNodeDevCapsDefPtr caps;
int ncaps = 0;
int ret = -1;
if (!(obj = nodeDeviceObjFindByName(device->name)))
return -1;
+ def = virNodeDeviceObjGetDef(obj);
- if (virNodeDeviceNumOfCapsEnsureACL(device->conn, obj->def) < 0)
+ if (virNodeDeviceNumOfCapsEnsureACL(device->conn, def) < 0)
goto cleanup;
- for (caps = obj->def->caps; caps; caps = caps->next) {
+ for (caps = def->caps; caps; caps = caps->next) {
++ncaps;
if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
@@ -423,17 +433,19 @@ nodeDeviceListCaps(virNodeDevicePtr device,
int maxnames)
{
virNodeDeviceObjPtr obj;
+ virNodeDeviceDefPtr def;
virNodeDevCapsDefPtr caps;
int ncaps = 0;
int ret = -1;
if (!(obj = nodeDeviceObjFindByName(device->name)))
return -1;
+ def = virNodeDeviceObjGetDef(obj);
- if (virNodeDeviceListCapsEnsureACL(device->conn, obj->def) < 0)
+ if (virNodeDeviceListCapsEnsureACL(device->conn, def) < 0)
goto cleanup;
- for (caps = obj->def->caps; caps && ncaps < maxnames; caps =
caps->next) {
+ for (caps = def->caps; caps && ncaps < maxnames; caps = caps->next)
{
if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->data.type))
< 0)
goto cleanup;
@@ -595,20 +607,20 @@ nodeDeviceDestroy(virNodeDevicePtr device)
if (!(obj = nodeDeviceObjFindByName(device->name)))
return -1;
+ def = virNodeDeviceObjGetDef(obj);
nodeDeviceLock();
- if (virNodeDeviceDestroyEnsureACL(device->conn, obj->def) < 0)
+ if (virNodeDeviceDestroyEnsureACL(device->conn, def) < 0)
goto cleanup;
- if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) < 0)
+ if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) < 0)
goto cleanup;
/* virNodeDeviceGetParentHost will cause the device object's lock
* to be taken, so grab the object def which will have the various
* fields used to search (name, parent, parent_wwnn, parent_wwpn,
* or parent_fabric_wwn) and drop the object lock. */
- def = obj->def;
virNodeDeviceObjUnlock(obj);
obj = NULL;
if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def,
diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index ff6200b..cde1c7b 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -459,6 +459,7 @@ dev_create(const char *udi)
char *parent_key = NULL;
virNodeDeviceObjPtr obj = NULL;
virNodeDeviceDefPtr def = NULL;
+ virNodeDeviceDefPtr objdef;
const char *name = hal_name(udi);
int rv;
char *privData;
@@ -493,15 +494,15 @@ 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);
- obj = virNodeDeviceObjAssignDef(&driver->devs, def);
- if (!obj) {
+ if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def))) {
VIR_FREE(devicePath);
goto failure;
}
+ objdef = virNodeDeviceObjGetDef(obj);
obj->privateData = privData;
obj->privateFree = free_udi;
- obj->def->sysfs_path = devicePath;
+ objdef->sysfs_path = devicePath;
virNodeDeviceObjUnlock(obj);
@@ -571,13 +572,15 @@ device_cap_added(LibHalContext *ctx,
{
const char *name = hal_name(udi);
virNodeDeviceObjPtr obj;
+ virNodeDeviceDefPtr def;
nodeDeviceLock();
obj = virNodeDeviceObjFindByName(&driver->devs, name);
nodeDeviceUnlock();
VIR_DEBUG("%s %s", cap, name);
if (obj) {
- (void)gather_capability(ctx, udi, cap, &obj->def->caps);
+ def = virNodeDeviceObjGetDef(obj);
+ (void)gather_capability(ctx, udi, cap, &def->caps);
virNodeDeviceObjUnlock(obj);
} else {
VIR_DEBUG("no device named %s", name);
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 42d3e73..83a8fcc 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1277,32 +1277,29 @@ static int
udevRemoveOneDevice(struct udev_device *device)
{
virNodeDeviceObjPtr obj = NULL;
+ virNodeDeviceDefPtr def;
virObjectEventPtr event = NULL;
const char *name = NULL;
- int ret = -1;
name = udev_device_get_syspath(device);
- obj = virNodeDeviceObjFindBySysfsPath(&driver->devs, name);
-
- if (!obj) {
+ if (!(obj = virNodeDeviceObjFindBySysfsPath(&driver->devs, name))) {
VIR_DEBUG("Failed to find device to remove that has udev name
'%s'",
name);
- goto cleanup;
+ return -1;
}
+ def = virNodeDeviceObjGetDef(obj);
- event = virNodeDeviceEventLifecycleNew(obj->def->name,
+ event = virNodeDeviceEventLifecycleNew(def->name,
VIR_NODE_DEVICE_EVENT_DELETED,
0);
VIR_DEBUG("Removing device '%s' with sysfs path '%s'",
- obj->def->name, name);
+ def->name, name);
virNodeDeviceObjRemove(&driver->devs, &obj);
- ret = 0;
- cleanup:
if (event)
virObjectEventStateQueue(driver->nodeDeviceEventState, event);
- return ret;
+ return 0;
}
@@ -1313,6 +1310,7 @@ udevSetParent(struct udev_device *device,
struct udev_device *parent_device = NULL;
const char *parent_sysfs_path = NULL;
virNodeDeviceObjPtr obj = NULL;
+ virNodeDeviceDefPtr objdef;
int ret = -1;
parent_device = device;
@@ -1330,10 +1328,10 @@ udevSetParent(struct udev_device *device,
goto cleanup;
}
- obj = virNodeDeviceObjFindBySysfsPath(&driver->devs,
- parent_sysfs_path);
- if (obj != NULL) {
- if (VIR_STRDUP(def->parent, obj->def->name) < 0) {
+ if ((obj = virNodeDeviceObjFindBySysfsPath(&driver->devs,
+ parent_sysfs_path))) {
+ objdef = virNodeDeviceObjGetDef(obj);
+ if (VIR_STRDUP(objdef->parent, def->name) < 0) {
virNodeDeviceObjUnlock(obj);
goto cleanup;
}
@@ -1360,6 +1358,7 @@ udevAddOneDevice(struct udev_device *device)
{
virNodeDeviceDefPtr def = NULL;
virNodeDeviceObjPtr obj = NULL;
+ virNodeDeviceDefPtr objdef;
virObjectEventPtr event = NULL;
bool new_device = true;
int ret = -1;
@@ -1396,16 +1395,16 @@ udevAddOneDevice(struct udev_device *device)
/* If this is a device change, the old definition will be freed
* and the current definition will take its place. */
- obj = virNodeDeviceObjAssignDef(&driver->devs, def);
- if (obj == NULL)
+ if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def)))
goto cleanup;
+ objdef = virNodeDeviceObjGetDef(obj);
if (new_device)
- event = virNodeDeviceEventLifecycleNew(obj->def->name,
+ event = virNodeDeviceEventLifecycleNew(objdef->name,
VIR_NODE_DEVICE_EVENT_CREATED,
0);
else
- event = virNodeDeviceEventUpdateNew(obj->def->name);
+ event = virNodeDeviceEventUpdateNew(objdef->name);
virNodeDeviceObjUnlock(obj);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 3389edd..206fdf9 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5319,13 +5319,15 @@ testNodeDeviceLookupByName(virConnectPtr conn, const char *name)
{
testDriverPtr driver = conn->privateData;
virNodeDeviceObjPtr obj;
+ virNodeDeviceDefPtr def;
virNodeDevicePtr ret = NULL;
if (!(obj = testNodeDeviceObjFindByName(driver, name)))
return NULL;
+ def = virNodeDeviceObjGetDef(obj);
if ((ret = virGetNodeDevice(conn, name))) {
- if (VIR_STRDUP(ret->parent, obj->def->parent) < 0)
+ if (VIR_STRDUP(ret->parent, def->parent) < 0)
virObjectUnref(ret);
}
@@ -5346,7 +5348,7 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev,
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
return NULL;
- ret = virNodeDeviceDefFormat(obj->def);
+ ret = virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj));
virNodeDeviceObjUnlock(obj);
return ret;
@@ -5357,13 +5359,15 @@ testNodeDeviceGetParent(virNodeDevicePtr dev)
{
testDriverPtr driver = dev->conn->privateData;
virNodeDeviceObjPtr obj;
+ virNodeDeviceDefPtr def;
char *ret = NULL;
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
return NULL;
+ def = virNodeDeviceObjGetDef(obj);
- if (obj->def->parent) {
- ignore_value(VIR_STRDUP(ret, obj->def->parent));
+ if (def->parent) {
+ ignore_value(VIR_STRDUP(ret, def->parent));
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no parent for this device"));
@@ -5379,13 +5383,15 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev)
{
testDriverPtr driver = dev->conn->privateData;
virNodeDeviceObjPtr obj;
+ virNodeDeviceDefPtr def;
virNodeDevCapsDefPtr caps;
int ncaps = 0;
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
return -1;
+ def = virNodeDeviceObjGetDef(obj);
- for (caps = obj->def->caps; caps; caps = caps->next)
+ for (caps = def->caps; caps; caps = caps->next)
++ncaps;
virNodeDeviceObjUnlock(obj);
@@ -5398,13 +5404,15 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names,
int maxnames)
{
testDriverPtr driver = dev->conn->privateData;
virNodeDeviceObjPtr obj;
+ virNodeDeviceDefPtr def;
virNodeDevCapsDefPtr caps;
int ncaps = 0;
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
return -1;
+ def = virNodeDeviceObjGetDef(obj);
- for (caps = obj->def->caps; caps && ncaps < maxnames; caps =
caps->next) {
+ for (caps = def->caps; caps && ncaps < maxnames; caps = caps->next)
{
if (VIR_STRDUP(names[ncaps],
virNodeDevCapTypeToString(caps->data.type)) < 0)
goto error;
@@ -5431,6 +5439,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
virNodeDeviceDefPtr def = NULL;
virNodeDevCapsDefPtr caps;
virNodeDeviceObjPtr obj = NULL, objcopy = NULL;
+ virNodeDeviceDefPtr objdef;
virObjectEventPtr event = NULL;
/* In the real code, we'd call virVHBAManageVport which would take the
@@ -5445,7 +5454,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
if (!(objcopy = virNodeDeviceObjFindByName(&driver->devs,
"scsi_host11")))
goto cleanup;
- xml = virNodeDeviceDefFormat(objcopy->def);
+ xml = virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy));
virNodeDeviceObjUnlock(objcopy);
if (!xml)
goto cleanup;
@@ -5485,8 +5494,9 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def)))
goto cleanup;
def = NULL;
+ objdef = virNodeDeviceObjGetDef(obj);
- event = virNodeDeviceEventLifecycleNew(obj->def->name,
+ event = virNodeDeviceEventLifecycleNew(objdef->name,
VIR_NODE_DEVICE_EVENT_CREATED,
0);
testObjectEventQueue(driver, event);
@@ -5508,6 +5518,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
char *wwnn = NULL, *wwpn = NULL;
virNodeDevicePtr dev = NULL, ret = NULL;
virNodeDeviceObjPtr obj = NULL;
+ virNodeDeviceDefPtr objdef;
virCheckFlags(0, NULL);
@@ -5535,8 +5546,9 @@ testNodeDeviceCreateXML(virConnectPtr conn,
* work properly, we need to drop our lock */
if (!(obj = testNodeDeviceMockCreateVport(driver, wwnn, wwpn)))
goto cleanup;
+ objdef = virNodeDeviceObjGetDef(obj);
- if (!(dev = virGetNodeDevice(conn, obj->def->name)))
+ if (!(dev = virGetNodeDevice(conn, objdef->name)))
goto cleanup;
VIR_FREE(dev->parent);
@@ -5563,16 +5575,18 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
int ret = 0;
testDriverPtr driver = dev->conn->privateData;
virNodeDeviceObjPtr obj = NULL;
+ virNodeDeviceDefPtr def;
char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL;
virObjectEventPtr event = NULL;
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
return -1;
+ def = virNodeDeviceObjGetDef(obj);
- if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1)
+ if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1)
goto cleanup;
- if (VIR_STRDUP(parent_name, obj->def->parent) < 0)
+ if (VIR_STRDUP(parent_name, def->parent) < 0)
goto cleanup;
/* virNodeDeviceGetParentHost will cause the device object's lock to be
@@ -5583,7 +5597,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
/* We do this just for basic validation, but also avoid finding a
* vport capable HBA if for some reason our vHBA doesn't exist */
- if (virNodeDeviceObjGetParentHost(&driver->devs, obj->def,
+ if (virNodeDeviceObjGetParentHost(&driver->devs, def,
EXISTING_DEVICE) < 0) {
obj = NULL;
goto cleanup;
--
2.9.4