提交 922af89e 编写于 作者: J John Ferlan

nodedev: Introduce virNodeDeviceObjGetDef

In preparation for privatizing the virNodeDeviceObj - create an accessor
for the @def field and then use it for various callers.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 95ea171b
...@@ -33,6 +33,13 @@ ...@@ -33,6 +33,13 @@
VIR_LOG_INIT("conf.virnodedeviceobj"); VIR_LOG_INIT("conf.virnodedeviceobj");
virNodeDeviceDefPtr
virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj)
{
return obj->def;
}
static int static int
virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, virNodeDeviceObjHasCap(const virNodeDeviceObj *dev,
const char *cap) const char *cap)
......
...@@ -40,6 +40,9 @@ struct _virNodeDeviceDriverState { ...@@ -40,6 +40,9 @@ struct _virNodeDeviceDriverState {
}; };
virNodeDeviceDefPtr
virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj);
virNodeDeviceObjPtr virNodeDeviceObjPtr
virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs, virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs,
const char *name); const char *name);
......
...@@ -959,6 +959,7 @@ virNetworkObjUpdateAssignDef; ...@@ -959,6 +959,7 @@ virNetworkObjUpdateAssignDef;
virNodeDeviceObjAssignDef; virNodeDeviceObjAssignDef;
virNodeDeviceObjFindByName; virNodeDeviceObjFindByName;
virNodeDeviceObjFindBySysfsPath; virNodeDeviceObjFindBySysfsPath;
virNodeDeviceObjGetDef;
virNodeDeviceObjGetNames; virNodeDeviceObjGetNames;
virNodeDeviceObjGetParentHost; virNodeDeviceObjGetParentHost;
virNodeDeviceObjListExport; virNodeDeviceObjListExport;
......
...@@ -259,16 +259,18 @@ nodeDeviceLookupByName(virConnectPtr conn, ...@@ -259,16 +259,18 @@ nodeDeviceLookupByName(virConnectPtr conn,
const char *name) const char *name)
{ {
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virNodeDeviceDefPtr def;
virNodeDevicePtr ret = NULL; virNodeDevicePtr ret = NULL;
if (!(obj = nodeDeviceObjFindByName(name))) if (!(obj = nodeDeviceObjFindByName(name)))
return NULL; return NULL;
def = virNodeDeviceObjGetDef(obj);
if (virNodeDeviceLookupByNameEnsureACL(conn, obj->def) < 0) if (virNodeDeviceLookupByNameEnsureACL(conn, def) < 0)
goto cleanup; goto cleanup;
if ((ret = virGetNodeDevice(conn, name))) { if ((ret = virGetNodeDevice(conn, name))) {
if (VIR_STRDUP(ret->parent, obj->def->parent) < 0) { if (VIR_STRDUP(ret->parent, def->parent) < 0) {
virObjectUnref(ret); virObjectUnref(ret);
ret = NULL; ret = NULL;
} }
...@@ -290,6 +292,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, ...@@ -290,6 +292,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
virNodeDeviceObjListPtr devs = &driver->devs; virNodeDeviceObjListPtr devs = &driver->devs;
virNodeDevCapsDefPtr cap = NULL; virNodeDevCapsDefPtr cap = NULL;
virNodeDeviceObjPtr obj = NULL; virNodeDeviceObjPtr obj = NULL;
virNodeDeviceDefPtr def;
virNodeDevicePtr dev = NULL; virNodeDevicePtr dev = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
...@@ -299,7 +302,8 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, ...@@ -299,7 +302,8 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
for (i = 0; i < devs->count; i++) { for (i = 0; i < devs->count; i++) {
obj = devs->objs[i]; obj = devs->objs[i];
virNodeDeviceObjLock(obj); virNodeDeviceObjLock(obj);
cap = obj->def->caps; def = virNodeDeviceObjGetDef(obj);
cap = def->caps;
while (cap) { while (cap) {
if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) { if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
...@@ -309,11 +313,11 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, ...@@ -309,11 +313,11 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
if (STREQ(cap->data.scsi_host.wwnn, wwnn) && if (STREQ(cap->data.scsi_host.wwnn, wwnn) &&
STREQ(cap->data.scsi_host.wwpn, wwpn)) { STREQ(cap->data.scsi_host.wwpn, wwpn)) {
if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, obj->def) < 0) if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
goto error; goto error;
if ((dev = virGetNodeDevice(conn, obj->def->name))) { if ((dev = virGetNodeDevice(conn, def->name))) {
if (VIR_STRDUP(dev->parent, obj->def->parent) < 0) { if (VIR_STRDUP(dev->parent, def->parent) < 0) {
virObjectUnref(dev); virObjectUnref(dev);
dev = NULL; dev = NULL;
} }
...@@ -344,23 +348,25 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev, ...@@ -344,23 +348,25 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev,
unsigned int flags) unsigned int flags)
{ {
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virNodeDeviceDefPtr def;
char *ret = NULL; char *ret = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
if (!(obj = nodeDeviceObjFindByName(dev->name))) if (!(obj = nodeDeviceObjFindByName(dev->name)))
return NULL; return NULL;
def = virNodeDeviceObjGetDef(obj);
if (virNodeDeviceGetXMLDescEnsureACL(dev->conn, obj->def) < 0) if (virNodeDeviceGetXMLDescEnsureACL(dev->conn, def) < 0)
goto cleanup; goto cleanup;
if (nodeDeviceUpdateDriverName(obj->def) < 0) if (nodeDeviceUpdateDriverName(def) < 0)
goto cleanup; goto cleanup;
if (nodeDeviceUpdateCaps(obj->def) < 0) if (nodeDeviceUpdateCaps(def) < 0)
goto cleanup; goto cleanup;
ret = virNodeDeviceDefFormat(obj->def); ret = virNodeDeviceDefFormat(def);
cleanup: cleanup:
virNodeDeviceObjUnlock(obj); virNodeDeviceObjUnlock(obj);
...@@ -372,16 +378,18 @@ char * ...@@ -372,16 +378,18 @@ char *
nodeDeviceGetParent(virNodeDevicePtr dev) nodeDeviceGetParent(virNodeDevicePtr dev)
{ {
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virNodeDeviceDefPtr def;
char *ret = NULL; char *ret = NULL;
if (!(obj = nodeDeviceObjFindByName(dev->name))) if (!(obj = nodeDeviceObjFindByName(dev->name)))
return NULL; return NULL;
def = virNodeDeviceObjGetDef(obj);
if (virNodeDeviceGetParentEnsureACL(dev->conn, obj->def) < 0) if (virNodeDeviceGetParentEnsureACL(dev->conn, def) < 0)
goto cleanup; goto cleanup;
if (obj->def->parent) { if (def->parent) {
if (VIR_STRDUP(ret, obj->def->parent) < 0) if (VIR_STRDUP(ret, def->parent) < 0)
goto cleanup; goto cleanup;
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -398,17 +406,19 @@ int ...@@ -398,17 +406,19 @@ int
nodeDeviceNumOfCaps(virNodeDevicePtr dev) nodeDeviceNumOfCaps(virNodeDevicePtr dev)
{ {
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virNodeDeviceDefPtr def;
virNodeDevCapsDefPtr caps; virNodeDevCapsDefPtr caps;
int ncaps = 0; int ncaps = 0;
int ret = -1; int ret = -1;
if (!(obj = nodeDeviceObjFindByName(dev->name))) if (!(obj = nodeDeviceObjFindByName(dev->name)))
return -1; return -1;
def = virNodeDeviceObjGetDef(obj);
if (virNodeDeviceNumOfCapsEnsureACL(dev->conn, obj->def) < 0) if (virNodeDeviceNumOfCapsEnsureACL(dev->conn, def) < 0)
goto cleanup; goto cleanup;
for (caps = obj->def->caps; caps; caps = caps->next) { for (caps = def->caps; caps; caps = caps->next) {
++ncaps; ++ncaps;
if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) { if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
...@@ -437,17 +447,19 @@ nodeDeviceListCaps(virNodeDevicePtr dev, ...@@ -437,17 +447,19 @@ nodeDeviceListCaps(virNodeDevicePtr dev,
int maxnames) int maxnames)
{ {
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virNodeDeviceDefPtr def;
virNodeDevCapsDefPtr caps; virNodeDevCapsDefPtr caps;
int ncaps = 0; int ncaps = 0;
int ret = -1; int ret = -1;
if (!(obj = nodeDeviceObjFindByName(dev->name))) if (!(obj = nodeDeviceObjFindByName(dev->name)))
return -1; return -1;
def = virNodeDeviceObjGetDef(obj);
if (virNodeDeviceListCapsEnsureACL(dev->conn, obj->def) < 0) if (virNodeDeviceListCapsEnsureACL(dev->conn, def) < 0)
goto cleanup; 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) if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->data.type)) < 0)
goto cleanup; goto cleanup;
...@@ -611,20 +623,20 @@ nodeDeviceDestroy(virNodeDevicePtr dev) ...@@ -611,20 +623,20 @@ nodeDeviceDestroy(virNodeDevicePtr dev)
if (!(obj = nodeDeviceObjFindByName(dev->name))) if (!(obj = nodeDeviceObjFindByName(dev->name)))
return -1; return -1;
def = virNodeDeviceObjGetDef(obj);
nodeDeviceLock(); nodeDeviceLock();
if (virNodeDeviceDestroyEnsureACL(dev->conn, obj->def) < 0) if (virNodeDeviceDestroyEnsureACL(dev->conn, def) < 0)
goto cleanup; goto cleanup;
if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) < 0) if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) < 0)
goto cleanup; goto cleanup;
/* virNodeDeviceGetParentHost will cause the device object's lock /* virNodeDeviceGetParentHost will cause the device object's lock
* to be taken, so grab the object def which will have the various * to be taken, so grab the object def which will have the various
* fields used to search (name, parent, parent_wwnn, parent_wwpn, * fields used to search (name, parent, parent_wwnn, parent_wwpn,
* or parent_fabric_wwn) and drop the object lock. */ * or parent_fabric_wwn) and drop the object lock. */
def = obj->def;
virNodeDeviceObjUnlock(obj); virNodeDeviceObjUnlock(obj);
obj = NULL; obj = NULL;
if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def, if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def,
......
...@@ -459,6 +459,7 @@ dev_create(const char *udi) ...@@ -459,6 +459,7 @@ dev_create(const char *udi)
char *parent_key = NULL; char *parent_key = NULL;
virNodeDeviceObjPtr dev = NULL; virNodeDeviceObjPtr dev = NULL;
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
virNodeDeviceDefPtr objdef;
const char *name = hal_name(udi); const char *name = hal_name(udi);
int rv; int rv;
char *privData; char *privData;
...@@ -493,15 +494,15 @@ dev_create(const char *udi) ...@@ -493,15 +494,15 @@ dev_create(const char *udi)
/* Some devices don't have a path in sysfs, so ignore failure */ /* Some devices don't have a path in sysfs, so ignore failure */
(void)get_str_prop(ctx, udi, "linux.sysfs_path", &devicePath); (void)get_str_prop(ctx, udi, "linux.sysfs_path", &devicePath);
dev = virNodeDeviceObjAssignDef(&driver->devs, def); if (!(dev = virNodeDeviceObjAssignDef(&driver->devs, def))) {
if (!dev) {
VIR_FREE(devicePath); VIR_FREE(devicePath);
goto failure; goto failure;
} }
objdef = virNodeDeviceObjGetDef(dev);
dev->privateData = privData; dev->privateData = privData;
dev->privateFree = free_udi; dev->privateFree = free_udi;
dev->def->sysfs_path = devicePath; objdef->sysfs_path = devicePath;
virNodeDeviceObjUnlock(dev); virNodeDeviceObjUnlock(dev);
...@@ -571,13 +572,15 @@ device_cap_added(LibHalContext *ctx, ...@@ -571,13 +572,15 @@ device_cap_added(LibHalContext *ctx,
{ {
const char *name = hal_name(udi); const char *name = hal_name(udi);
virNodeDeviceObjPtr dev; virNodeDeviceObjPtr dev;
virNodeDeviceDefPtr def;
nodeDeviceLock(); nodeDeviceLock();
dev = virNodeDeviceObjFindByName(&driver->devs, name); dev = virNodeDeviceObjFindByName(&driver->devs, name);
nodeDeviceUnlock(); nodeDeviceUnlock();
VIR_DEBUG("%s %s", cap, name); VIR_DEBUG("%s %s", cap, name);
if (dev) { if (dev) {
(void)gather_capability(ctx, udi, cap, &dev->def->caps); def = virNodeDeviceObjGetDef(dev);
(void)gather_capability(ctx, udi, cap, &def->caps);
virNodeDeviceObjUnlock(dev); virNodeDeviceObjUnlock(dev);
} else { } else {
VIR_DEBUG("no device named %s", name); VIR_DEBUG("no device named %s", name);
......
...@@ -1313,9 +1313,9 @@ static int ...@@ -1313,9 +1313,9 @@ static int
udevRemoveOneDevice(struct udev_device *device) udevRemoveOneDevice(struct udev_device *device)
{ {
virNodeDeviceObjPtr dev = NULL; virNodeDeviceObjPtr dev = NULL;
virNodeDeviceDefPtr def;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
const char *name = NULL; const char *name = NULL;
int ret = -1;
name = udev_device_get_syspath(device); name = udev_device_get_syspath(device);
dev = virNodeDeviceObjFindBySysfsPath(&driver->devs, name); dev = virNodeDeviceObjFindBySysfsPath(&driver->devs, name);
...@@ -1323,22 +1323,21 @@ udevRemoveOneDevice(struct udev_device *device) ...@@ -1323,22 +1323,21 @@ udevRemoveOneDevice(struct udev_device *device)
if (!dev) { if (!dev) {
VIR_DEBUG("Failed to find device to remove that has udev name '%s'", VIR_DEBUG("Failed to find device to remove that has udev name '%s'",
name); name);
goto cleanup; return -1;
} }
def = virNodeDeviceObjGetDef(dev);
event = virNodeDeviceEventLifecycleNew(dev->def->name, event = virNodeDeviceEventLifecycleNew(def->name,
VIR_NODE_DEVICE_EVENT_DELETED, VIR_NODE_DEVICE_EVENT_DELETED,
0); 0);
VIR_DEBUG("Removing device '%s' with sysfs path '%s'", VIR_DEBUG("Removing device '%s' with sysfs path '%s'",
dev->def->name, name); def->name, name);
virNodeDeviceObjRemove(&driver->devs, &dev); virNodeDeviceObjRemove(&driver->devs, &dev);
ret = 0;
cleanup:
if (event) if (event)
virObjectEventStateQueue(driver->nodeDeviceEventState, event); virObjectEventStateQueue(driver->nodeDeviceEventState, event);
return ret; return 0;
} }
...@@ -1349,6 +1348,7 @@ udevSetParent(struct udev_device *device, ...@@ -1349,6 +1348,7 @@ udevSetParent(struct udev_device *device,
struct udev_device *parent_device = NULL; struct udev_device *parent_device = NULL;
const char *parent_sysfs_path = NULL; const char *parent_sysfs_path = NULL;
virNodeDeviceObjPtr dev = NULL; virNodeDeviceObjPtr dev = NULL;
virNodeDeviceDefPtr objdef;
int ret = -1; int ret = -1;
parent_device = device; parent_device = device;
...@@ -1369,7 +1369,8 @@ udevSetParent(struct udev_device *device, ...@@ -1369,7 +1369,8 @@ udevSetParent(struct udev_device *device,
dev = virNodeDeviceObjFindBySysfsPath(&driver->devs, dev = virNodeDeviceObjFindBySysfsPath(&driver->devs,
parent_sysfs_path); parent_sysfs_path);
if (dev != NULL) { if (dev != NULL) {
if (VIR_STRDUP(def->parent, dev->def->name) < 0) { objdef = virNodeDeviceObjGetDef(dev);
if (VIR_STRDUP(def->parent, objdef->name) < 0) {
virNodeDeviceObjUnlock(dev); virNodeDeviceObjUnlock(dev);
goto cleanup; goto cleanup;
} }
...@@ -1396,6 +1397,7 @@ udevAddOneDevice(struct udev_device *device) ...@@ -1396,6 +1397,7 @@ udevAddOneDevice(struct udev_device *device)
{ {
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
virNodeDeviceObjPtr dev = NULL; virNodeDeviceObjPtr dev = NULL;
virNodeDeviceDefPtr objdef;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
bool new_device = true; bool new_device = true;
int ret = -1; int ret = -1;
...@@ -1435,13 +1437,14 @@ udevAddOneDevice(struct udev_device *device) ...@@ -1435,13 +1437,14 @@ udevAddOneDevice(struct udev_device *device)
dev = virNodeDeviceObjAssignDef(&driver->devs, def); dev = virNodeDeviceObjAssignDef(&driver->devs, def);
if (dev == NULL) if (dev == NULL)
goto cleanup; goto cleanup;
objdef = virNodeDeviceObjGetDef(dev);
if (new_device) if (new_device)
event = virNodeDeviceEventLifecycleNew(dev->def->name, event = virNodeDeviceEventLifecycleNew(objdef->name,
VIR_NODE_DEVICE_EVENT_CREATED, VIR_NODE_DEVICE_EVENT_CREATED,
0); 0);
else else
event = virNodeDeviceEventUpdateNew(dev->def->name); event = virNodeDeviceEventUpdateNew(objdef->name);
virNodeDeviceObjUnlock(dev); virNodeDeviceObjUnlock(dev);
......
...@@ -5322,13 +5322,15 @@ testNodeDeviceLookupByName(virConnectPtr conn, const char *name) ...@@ -5322,13 +5322,15 @@ testNodeDeviceLookupByName(virConnectPtr conn, const char *name)
{ {
testDriverPtr driver = conn->privateData; testDriverPtr driver = conn->privateData;
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virNodeDeviceDefPtr def;
virNodeDevicePtr ret = NULL; virNodeDevicePtr ret = NULL;
if (!(obj = testNodeDeviceObjFindByName(driver, name))) if (!(obj = testNodeDeviceObjFindByName(driver, name)))
goto cleanup; goto cleanup;
def = virNodeDeviceObjGetDef(obj);
if ((ret = virGetNodeDevice(conn, name))) { if ((ret = virGetNodeDevice(conn, name))) {
if (VIR_STRDUP(ret->parent, obj->def->parent) < 0) { if (VIR_STRDUP(ret->parent, def->parent) < 0) {
virObjectUnref(ret); virObjectUnref(ret);
ret = NULL; ret = NULL;
} }
...@@ -5353,7 +5355,7 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, ...@@ -5353,7 +5355,7 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev,
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name))) if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
goto cleanup; goto cleanup;
ret = virNodeDeviceDefFormat(obj->def); ret = virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj));
cleanup: cleanup:
if (obj) if (obj)
...@@ -5366,13 +5368,15 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) ...@@ -5366,13 +5368,15 @@ testNodeDeviceGetParent(virNodeDevicePtr dev)
{ {
testDriverPtr driver = dev->conn->privateData; testDriverPtr driver = dev->conn->privateData;
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virNodeDeviceDefPtr def;
char *ret = NULL; char *ret = NULL;
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name))) if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
goto cleanup; goto cleanup;
def = virNodeDeviceObjGetDef(obj);
if (obj->def->parent) { if (def->parent) {
ignore_value(VIR_STRDUP(ret, obj->def->parent)); ignore_value(VIR_STRDUP(ret, def->parent));
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no parent for this device")); "%s", _("no parent for this device"));
...@@ -5390,14 +5394,16 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) ...@@ -5390,14 +5394,16 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev)
{ {
testDriverPtr driver = dev->conn->privateData; testDriverPtr driver = dev->conn->privateData;
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virNodeDeviceDefPtr def;
virNodeDevCapsDefPtr caps; virNodeDevCapsDefPtr caps;
int ncaps = 0; int ncaps = 0;
int ret = -1; int ret = -1;
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name))) if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
goto cleanup; goto cleanup;
def = virNodeDeviceObjGetDef(obj);
for (caps = obj->def->caps; caps; caps = caps->next) for (caps = def->caps; caps; caps = caps->next)
++ncaps; ++ncaps;
ret = ncaps; ret = ncaps;
...@@ -5413,14 +5419,16 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) ...@@ -5413,14 +5419,16 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
{ {
testDriverPtr driver = dev->conn->privateData; testDriverPtr driver = dev->conn->privateData;
virNodeDeviceObjPtr obj; virNodeDeviceObjPtr obj;
virNodeDeviceDefPtr def;
virNodeDevCapsDefPtr caps; virNodeDevCapsDefPtr caps;
int ncaps = 0; int ncaps = 0;
int ret = -1; int ret = -1;
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name))) if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
goto cleanup; goto cleanup;
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) if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->data.type)) < 0)
goto cleanup; goto cleanup;
} }
...@@ -5447,6 +5455,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, ...@@ -5447,6 +5455,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
virNodeDevCapsDefPtr caps; virNodeDevCapsDefPtr caps;
virNodeDeviceObjPtr obj = NULL, objcopy = NULL; virNodeDeviceObjPtr obj = NULL, objcopy = NULL;
virNodeDeviceDefPtr objdef;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
/* In the real code, we'd call virVHBAManageVport which would take the /* In the real code, we'd call virVHBAManageVport which would take the
...@@ -5461,7 +5470,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, ...@@ -5461,7 +5470,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
if (!(objcopy = virNodeDeviceObjFindByName(&driver->devs, "scsi_host11"))) if (!(objcopy = virNodeDeviceObjFindByName(&driver->devs, "scsi_host11")))
goto cleanup; goto cleanup;
xml = virNodeDeviceDefFormat(objcopy->def); xml = virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy));
virNodeDeviceObjUnlock(objcopy); virNodeDeviceObjUnlock(objcopy);
if (!xml) if (!xml)
goto cleanup; goto cleanup;
...@@ -5501,8 +5510,9 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, ...@@ -5501,8 +5510,9 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def))) if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def)))
goto cleanup; goto cleanup;
def = NULL; def = NULL;
objdef = virNodeDeviceObjGetDef(obj);
event = virNodeDeviceEventLifecycleNew(obj->def->name, event = virNodeDeviceEventLifecycleNew(objdef->name,
VIR_NODE_DEVICE_EVENT_CREATED, VIR_NODE_DEVICE_EVENT_CREATED,
0); 0);
testObjectEventQueue(driver, event); testObjectEventQueue(driver, event);
...@@ -5524,6 +5534,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, ...@@ -5524,6 +5534,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
char *wwnn = NULL, *wwpn = NULL; char *wwnn = NULL, *wwpn = NULL;
virNodeDevicePtr dev = NULL, ret = NULL; virNodeDevicePtr dev = NULL, ret = NULL;
virNodeDeviceObjPtr obj = NULL; virNodeDeviceObjPtr obj = NULL;
virNodeDeviceDefPtr objdef;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
...@@ -5551,8 +5562,9 @@ testNodeDeviceCreateXML(virConnectPtr conn, ...@@ -5551,8 +5562,9 @@ testNodeDeviceCreateXML(virConnectPtr conn,
* work properly, we need to drop our lock */ * work properly, we need to drop our lock */
if (!(obj = testNodeDeviceMockCreateVport(driver, wwnn, wwpn))) if (!(obj = testNodeDeviceMockCreateVport(driver, wwnn, wwpn)))
goto cleanup; goto cleanup;
objdef = virNodeDeviceObjGetDef(obj);
if (!(dev = virGetNodeDevice(conn, obj->def->name))) if (!(dev = virGetNodeDevice(conn, objdef->name)))
goto cleanup; goto cleanup;
VIR_FREE(dev->parent); VIR_FREE(dev->parent);
...@@ -5579,16 +5591,18 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) ...@@ -5579,16 +5591,18 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
int ret = 0; int ret = 0;
testDriverPtr driver = dev->conn->privateData; testDriverPtr driver = dev->conn->privateData;
virNodeDeviceObjPtr obj = NULL; virNodeDeviceObjPtr obj = NULL;
virNodeDeviceDefPtr def;
char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL; char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
if (!(obj = testNodeDeviceObjFindByName(driver, dev->name))) if (!(obj = testNodeDeviceObjFindByName(driver, dev->name)))
goto out; goto out;
def = virNodeDeviceObjGetDef(obj);
if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1) if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1)
goto out; goto out;
if (VIR_STRDUP(parent_name, obj->def->parent) < 0) if (VIR_STRDUP(parent_name, def->parent) < 0)
goto out; goto out;
/* virNodeDeviceGetParentHost will cause the device object's lock to be /* virNodeDeviceGetParentHost will cause the device object's lock to be
...@@ -5599,7 +5613,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) ...@@ -5599,7 +5613,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
/* We do this just for basic validation, but also avoid finding a /* We do this just for basic validation, but also avoid finding a
* vport capable HBA if for some reason our vHBA doesn't exist */ * 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) { EXISTING_DEVICE) < 0) {
obj = NULL; obj = NULL;
goto out; goto out;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册