static int nodeListDevices(virConnectPtr conn, const char *cap, char **const names, int maxnames, unsigned int flags ATTRIBUTE_UNUSED) { virDeviceMonitorStatePtr driver = conn->devMonPrivateData; int ndevs = 0; unsigned int i; nodeDeviceLock(driver); for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) { virNodeDeviceObjLock(driver->devs.objs[i]); if (cap == NULL || virNodeDeviceHasCap(driver->devs.objs[i], cap)) { if ((names[ndevs++] = strdup(driver->devs.objs[i]->def->name)) == NULL) { virNodeDeviceObjUnlock(driver->devs.objs[i]); virReportOOMError(); goto failure; } } virNodeDeviceObjUnlock(driver->devs.objs[i]); } nodeDeviceUnlock(driver); return ndevs; failure: nodeDeviceUnlock(driver); --ndevs; while (--ndevs >= 0) VIR_FREE(names[ndevs]); return -1; }
virNodeDevicePtr nodeDeviceLookupByName(virConnectPtr conn, const char *name) { virNodeDeviceDriverStatePtr driver = conn->nodeDevicePrivateData; virNodeDeviceObjPtr obj; virNodeDevicePtr ret = NULL; nodeDeviceLock(driver); obj = virNodeDeviceFindByName(&driver->devs, name); nodeDeviceUnlock(driver); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, NULL); goto cleanup; } if (virNodeDeviceLookupByNameEnsureACL(conn, obj->def) < 0) goto cleanup; ret = virGetNodeDevice(conn, name); cleanup: if (obj) virNodeDeviceObjUnlock(obj); return ret; }
int nodeDeviceNumOfCaps(virNodeDevicePtr dev) { virNodeDeviceDriverStatePtr driver = dev->conn->nodeDevicePrivateData; virNodeDeviceObjPtr obj; virNodeDevCapsDefPtr caps; int ncaps = 0; int ret = -1; nodeDeviceLock(driver); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(driver); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; } if (virNodeDeviceNumOfCapsEnsureACL(dev->conn, obj->def) < 0) goto cleanup; for (caps = obj->def->caps; caps; caps = caps->next) ++ncaps; ret = ncaps; cleanup: if (obj) virNodeDeviceObjUnlock(obj); return ret; }
int nodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags) { int ndevs = 0; size_t i; if (virNodeNumOfDevicesEnsureACL(conn) < 0) return -1; virCheckFlags(0, -1); nodeDeviceLock(); for (i = 0; i < driver->devs.count; i++) { virNodeDeviceObjPtr obj = driver->devs.objs[i]; virNodeDeviceObjLock(obj); if (virNodeNumOfDevicesCheckACL(conn, obj->def) && ((cap == NULL) || virNodeDeviceHasCap(obj, cap))) ++ndevs; virNodeDeviceObjUnlock(obj); } nodeDeviceUnlock(); return ndevs; }
char * nodeDeviceGetParent(virNodeDevicePtr dev) { virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData; virNodeDeviceObjPtr obj; char *ret = NULL; nodeDeviceLock(driver); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(driver); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; } if (obj->def->parent) { ret = strdup(obj->def->parent); if (!ret) virReportOOMError(); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no parent for this device")); } cleanup: if (obj) virNodeDeviceObjUnlock(obj); return ret; }
virNodeDevicePtr nodeDeviceLookupByName(virConnectPtr conn, const char *name) { virNodeDeviceObjPtr obj; virNodeDevicePtr ret = NULL; nodeDeviceLock(); obj = virNodeDeviceFindByName(&driver->devs, name); nodeDeviceUnlock(); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), name); goto cleanup; } if (virNodeDeviceLookupByNameEnsureACL(conn, obj->def) < 0) goto cleanup; ret = virGetNodeDevice(conn, name); cleanup: if (obj) virNodeDeviceObjUnlock(obj); return ret; }
char * nodeDeviceGetXMLDesc(virNodeDevicePtr dev, unsigned int flags) { virNodeDeviceObjPtr obj; char *ret = NULL; virCheckFlags(0, NULL); nodeDeviceLock(); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; } if (virNodeDeviceGetXMLDescEnsureACL(dev->conn, obj->def) < 0) goto cleanup; update_driver_name(obj); if (update_caps(obj) < 0) goto cleanup; ret = virNodeDeviceDefFormat(obj->def); cleanup: if (obj) virNodeDeviceObjUnlock(obj); return ret; }
char * nodeDeviceGetParent(virNodeDevicePtr dev) { virNodeDeviceObjPtr obj; char *ret = NULL; nodeDeviceLock(); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; } if (virNodeDeviceGetParentEnsureACL(dev->conn, obj->def) < 0) goto cleanup; if (obj->def->parent) { if (VIR_STRDUP(ret, obj->def->parent) < 0) goto cleanup; } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("no parent for this device")); } cleanup: if (obj) virNodeDeviceObjUnlock(obj); return ret; }
static char *nodeDeviceDumpXML(virNodeDevicePtr dev, unsigned int flags ATTRIBUTE_UNUSED) { virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData; virNodeDeviceObjPtr obj; char *ret = NULL; nodeDeviceLock(driver); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(driver); if (!obj) { virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; } update_driver_name(obj); update_caps(obj); ret = virNodeDeviceDefFormat(obj->def); cleanup: if (obj) virNodeDeviceObjUnlock(obj); return ret; }
/* When large numbers of devices are present on the host, it's * possible for udev not to realize that it has work to do before we * get here. We thus keep trying to find the new device we just * created for up to LINUX_NEW_DEVICE_WAIT_TIME. Note that udev's * default settle time is 180 seconds, so once udev realizes that it * has work to do, it might take that long for the udev wait to * return. Thus the total maximum time for this function to return is * the udev settle time plus LINUX_NEW_DEVICE_WAIT_TIME. * * This whole area is a race, but if we retry the udev wait for * LINUX_NEW_DEVICE_WAIT_TIME seconds and there's still no device, * it's probably safe to assume it's not going to appear. */ static virNodeDevicePtr find_new_device(virConnectPtr conn, const char *wwnn, const char *wwpn) { virNodeDevicePtr dev = NULL; time_t start = 0, now = 0; /* The thread that creates the device takes the driver lock, so we * must release it in order to allow the device to be created. * We're not doing anything with the driver pointer at this point, * so it's safe to release it, assuming that the pointer itself * doesn't become invalid. */ nodeDeviceUnlock(); get_time(&start); while ((now - start) < LINUX_NEW_DEVICE_WAIT_TIME) { virFileWaitForDevices(); dev = nodeDeviceLookupSCSIHostByWWN(conn, wwnn, wwpn, 0); if (dev != NULL) break; sleep(5); if (get_time(&now) == -1) break; } nodeDeviceLock(); return dev; }
virNodeDevicePtr nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, const char *wwnn, const char *wwpn, unsigned int flags) { size_t i; virNodeDeviceObjListPtr devs = &driver->devs; virNodeDevCapsDefPtr cap = NULL; virNodeDeviceObjPtr obj = NULL; virNodeDeviceDefPtr def; virNodeDevicePtr dev = NULL; virCheckFlags(0, NULL); nodeDeviceLock(); for (i = 0; i < devs->count; i++) { obj = devs->objs[i]; virNodeDeviceObjLock(obj); def = virNodeDeviceObjGetDef(obj); cap = def->caps; while (cap) { if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) { 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) && STREQ(cap->data.scsi_host.wwpn, wwpn)) { if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0) goto error; if ((dev = virGetNodeDevice(conn, def->name))) { if (VIR_STRDUP(dev->parent, def->parent) < 0) { virObjectUnref(dev); dev = NULL; } } virNodeDeviceObjUnlock(obj); goto out; } } } cap = cap->next; } virNodeDeviceObjUnlock(obj); } out: nodeDeviceUnlock(); return dev; error: virNodeDeviceObjUnlock(obj); goto out; }
int nodeDeviceDestroy(virNodeDevicePtr dev) { int ret = -1; virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData; virNodeDeviceObjPtr obj = NULL; char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL; int parent_host = -1; nodeDeviceLock(driver); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(driver); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, NULL); goto out; } if (virNodeDeviceGetWWNs(obj->def, &wwnn, &wwpn) == -1) { goto out; } parent_name = strdup(obj->def->parent); /* virNodeDeviceGetParentHost will cause the device object's lock to be * taken, so we have to dup the parent's name and drop the lock * before calling it. We don't need the reference to the object * any more once we have the parent's name. */ virNodeDeviceObjUnlock(obj); obj = NULL; if (parent_name == NULL) { virReportOOMError(); goto out; } if (virNodeDeviceGetParentHost(&driver->devs, dev->name, parent_name, &parent_host) == -1) { goto out; } if (nodeDeviceVportCreateDelete(parent_host, wwpn, wwnn, VPORT_DELETE) == -1) { goto out; } ret = 0; out: if (obj) virNodeDeviceObjUnlock(obj); VIR_FREE(parent_name); VIR_FREE(wwnn); VIR_FREE(wwpn); return ret; }
virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags) { virNodeDeviceDriverStatePtr driver = conn->nodeDevicePrivateData; virNodeDeviceDefPtr def = NULL; char *wwnn = NULL, *wwpn = NULL; int parent_host = -1; virNodeDevicePtr dev = NULL; const char *virt_type = NULL; virCheckFlags(0, NULL); virt_type = virConnectGetType(conn); nodeDeviceLock(driver); def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt_type); if (def == NULL) { goto cleanup; } if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0) goto cleanup; if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) { goto cleanup; } if (virNodeDeviceGetParentHost(&driver->devs, def->name, def->parent, &parent_host) == -1) { goto cleanup; } if (virManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) == -1) { goto cleanup; } dev = find_new_device(conn, wwnn, wwpn); /* We don't check the return value, because one way or another, * we're returning what we get... */ if (dev == NULL) { virReportError(VIR_ERR_NO_NODE_DEVICE, NULL); } cleanup: nodeDeviceUnlock(driver); virNodeDeviceDefFree(def); VIR_FREE(wwnn); VIR_FREE(wwpn); return dev; }
int nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) { virNodeDeviceObjPtr obj; virNodeDevCapsDefPtr caps; int ncaps = 0; int ret = -1; nodeDeviceLock(); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; } if (virNodeDeviceListCapsEnsureACL(dev->conn, obj->def) < 0) goto cleanup; for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) { if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->data.type)) < 0) goto cleanup; if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) { if (ncaps < maxnames && caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_FC_HOST)) < 0) goto cleanup; } if (ncaps < maxnames && caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) { if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS)) < 0) goto cleanup; } } } ret = ncaps; cleanup: if (obj) virNodeDeviceObjUnlock(obj); if (ret == -1) { --ncaps; while (--ncaps >= 0) VIR_FREE(names[ncaps]); } return ret; }
int nodeListDevices(virConnectPtr conn, const char *cap, char **const names, int maxnames, unsigned int flags) { virNodeDeviceDriverStatePtr driver = conn->nodeDevicePrivateData; int ndevs = 0; size_t i; if (virNodeListDevicesEnsureACL(conn) < 0) return -1; virCheckFlags(0, -1); nodeDeviceLock(driver); for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) { virNodeDeviceObjPtr obj = driver->devs.objs[i]; virNodeDeviceObjLock(obj); if (virNodeListDevicesCheckACL(conn, obj->def) && (cap == NULL || virNodeDeviceHasCap(obj, cap))) { if (VIR_STRDUP(names[ndevs++], obj->def->name) < 0) { virNodeDeviceObjUnlock(obj); goto failure; } } virNodeDeviceObjUnlock(obj); } nodeDeviceUnlock(driver); return ndevs; failure: nodeDeviceUnlock(driver); --ndevs; while (--ndevs >= 0) VIR_FREE(names[ndevs]); return -1; }
static virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags ATTRIBUTE_UNUSED) { virDeviceMonitorStatePtr driver = conn->devMonPrivateData; virNodeDeviceDefPtr def = NULL; char *wwnn = NULL, *wwpn = NULL; int parent_host = -1; virNodeDevicePtr dev = NULL; nodeDeviceLock(driver); def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE); if (def == NULL) { goto cleanup; } if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) { goto cleanup; } if (virNodeDeviceGetParentHost(&driver->devs, def->name, def->parent, &parent_host) == -1) { goto cleanup; } if (nodeDeviceVportCreateDelete(parent_host, wwpn, wwnn, VPORT_CREATE) == -1) { goto cleanup; } dev = find_new_device(conn, wwnn, wwpn); /* We don't check the return value, because one way or another, * we're returning what we get... */ if (dev == NULL) { virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, NULL); } cleanup: nodeDeviceUnlock(driver); virNodeDeviceDefFree(def); VIR_FREE(wwnn); VIR_FREE(wwpn); return dev; }
virNodeDevicePtr nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, const char *wwnn, const char *wwpn, unsigned int flags) { size_t i; virNodeDeviceDriverStatePtr driver = conn->nodeDevicePrivateData; virNodeDeviceObjListPtr devs = &driver->devs; virNodeDevCapsDefPtr cap = NULL; virNodeDeviceObjPtr obj = NULL; virNodeDevicePtr dev = NULL; virCheckFlags(0, NULL); nodeDeviceLock(driver); for (i = 0; i < devs->count; i++) { obj = devs->objs[i]; virNodeDeviceObjLock(obj); cap = obj->def->caps; while (cap) { if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST) { detect_scsi_host_caps(&cap->data); if (cap->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { if (STREQ(cap->data.scsi_host.wwnn, wwnn) && STREQ(cap->data.scsi_host.wwpn, wwpn)) { if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, obj->def) < 0) goto out; dev = virGetNodeDevice(conn, obj->def->name); virNodeDeviceObjUnlock(obj); goto out; } } } cap = cap->next; } virNodeDeviceObjUnlock(obj); } out: nodeDeviceUnlock(driver); return dev; }
int nodeListAllNodeDevices(virConnectPtr conn, virNodeDevicePtr **devices, unsigned int flags) { virDeviceMonitorStatePtr driver = conn->devMonPrivateData; int ret = -1; virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP, -1); nodeDeviceLock(driver); ret = virNodeDeviceList(conn, driver->devs, devices, flags); nodeDeviceUnlock(driver); return ret; }
virNodeDevicePtr nodeDeviceCreateXML(virConnectPtr conn, const char *xmlDesc, unsigned int flags) { virNodeDeviceDefPtr def = NULL; char *wwnn = NULL, *wwpn = NULL; int parent_host = -1; virNodeDevicePtr dev = NULL; const char *virt_type = NULL; virCheckFlags(0, NULL); virt_type = virConnectGetType(conn); nodeDeviceLock(); if (!(def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt_type))) goto cleanup; if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0) goto cleanup; if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) goto cleanup; if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def, CREATE_DEVICE)) < 0) goto cleanup; if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) goto cleanup; dev = nodeDeviceFindNewDevice(conn, wwnn, wwpn); /* We don't check the return value, because one way or another, * we're returning what we get... */ if (dev == NULL) virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device for '%s' with matching " "wwnn '%s' and wwpn '%s'"), def->name, wwnn, wwpn); cleanup: nodeDeviceUnlock(); virNodeDeviceDefFree(def); VIR_FREE(wwnn); VIR_FREE(wwpn); return dev; }
static virNodeDeviceObjPtr nodeDeviceObjFindByName(const char *name) { virNodeDeviceObjPtr obj; nodeDeviceLock(); obj = virNodeDeviceObjFindByName(&driver->devs, name); nodeDeviceUnlock(); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), name); } return obj; }
static virNodeDevicePtr nodeDeviceLookupByWWN(virConnectPtr conn, const char *wwnn, const char *wwpn) { unsigned int i; virDeviceMonitorStatePtr driver = conn->devMonPrivateData; virNodeDeviceObjListPtr devs = &driver->devs; virNodeDevCapsDefPtr cap = NULL; virNodeDeviceObjPtr obj = NULL; virNodeDevicePtr dev = NULL; nodeDeviceLock(driver); for (i = 0; i < devs->count; i++) { obj = devs->objs[i]; virNodeDeviceObjLock(obj); cap = obj->def->caps; while (cap) { if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST) { check_fc_host(&cap->data); if (cap->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { if (STREQ(cap->data.scsi_host.wwnn, wwnn) && STREQ(cap->data.scsi_host.wwpn, wwpn)) { dev = virGetNodeDevice(conn, obj->def->name); virNodeDeviceObjUnlock(obj); goto out; } } } cap = cap->next; } virNodeDeviceObjUnlock(obj); } out: nodeDeviceUnlock(driver); return dev; }
int nodeDeviceNumOfCaps(virNodeDevicePtr dev) { virNodeDeviceObjPtr obj; virNodeDevCapsDefPtr caps; int ncaps = 0; int ret = -1; nodeDeviceLock(); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; } if (virNodeDeviceNumOfCapsEnsureACL(dev->conn, obj->def) < 0) goto cleanup; for (caps = obj->def->caps; caps; caps = caps->next) { ++ncaps; if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) { if (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) ncaps++; if (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) ncaps++; } } ret = ncaps; cleanup: if (obj) virNodeDeviceObjUnlock(obj); return ret; }
int nodeConnectListAllNodeDevices(virConnectPtr conn, virNodeDevicePtr **devices, unsigned int flags) { int ret = -1; virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP, -1); if (virConnectListAllNodeDevicesEnsureACL(conn) < 0) return -1; nodeDeviceLock(); ret = virNodeDeviceObjListExport(conn, driver->devs, devices, virConnectListAllNodeDevicesCheckACL, flags); nodeDeviceUnlock(); return ret; }
int nodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags) { int ndevs = 0; if (virNodeNumOfDevicesEnsureACL(conn) < 0) return -1; virCheckFlags(0, -1); nodeDeviceLock(); ndevs = virNodeDeviceObjNumOfDevices(&driver->devs, conn, cap, virNodeNumOfDevicesCheckACL); nodeDeviceUnlock(); return ndevs; }
int nodeDeviceDestroy(virNodeDevicePtr dev) { int ret = -1; virNodeDeviceObjPtr obj = NULL; virNodeDeviceDefPtr def; char *wwnn = NULL, *wwpn = NULL; int parent_host = -1; if (!(obj = nodeDeviceObjFindByName(dev->name))) return -1; def = virNodeDeviceObjGetDef(obj); nodeDeviceLock(); if (virNodeDeviceDestroyEnsureACL(dev->conn, def) < 0) goto cleanup; 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. */ virNodeDeviceObjUnlock(obj); obj = NULL; if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def, EXISTING_DEVICE)) < 0) goto cleanup; if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0) goto cleanup; ret = 0; cleanup: nodeDeviceUnlock(); virNodeDeviceObjUnlock(obj); VIR_FREE(wwnn); VIR_FREE(wwpn); return ret; }
static int nodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags ATTRIBUTE_UNUSED) { virDeviceMonitorStatePtr driver = conn->devMonPrivateData; int ndevs = 0; unsigned int i; nodeDeviceLock(driver); for (i = 0; i < driver->devs.count; i++) { virNodeDeviceObjLock(driver->devs.objs[i]); if ((cap == NULL) || virNodeDeviceHasCap(driver->devs.objs[i], cap)) ++ndevs; virNodeDeviceObjUnlock(driver->devs.objs[i]); } nodeDeviceUnlock(driver); return ndevs; }
static void dev_refresh(const char *udi) { const char *name = hal_name(udi); virNodeDeviceObjPtr dev; nodeDeviceLock(driverState); dev = virNodeDeviceFindByName(&driverState->devs, name); if (dev) { /* Simply "rediscover" device -- incrementally handling changes * to sub-capabilities (like net.80203) is nasty ... so avoid it. */ virNodeDeviceObjRemove(&driverState->devs, dev); } else VIR_DEBUG("no device named %s", name); nodeDeviceUnlock(driverState); if (dev) { dev_create(udi); } }
static int nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) { virDeviceMonitorStatePtr driver = dev->conn->devMonPrivateData; virNodeDeviceObjPtr obj; virNodeDevCapsDefPtr caps; int ncaps = 0; int ret = -1; nodeDeviceLock(driver); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(driver); if (!obj) { virNodeDeviceReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; } for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) { names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type)); if (names[ncaps++] == NULL) { virReportOOMError(); goto cleanup; } } ret = ncaps; cleanup: if (obj) virNodeDeviceObjUnlock(obj); if (ret == -1) { --ncaps; while (--ncaps >= 0) VIR_FREE(names[ncaps]); } return ret; }
int nodeListDevices(virConnectPtr conn, const char *cap, char **const names, int maxnames, unsigned int flags) { int nnames; if (virNodeListDevicesEnsureACL(conn) < 0) return -1; virCheckFlags(0, -1); nodeDeviceLock(); nnames = virNodeDeviceObjGetNames(&driver->devs, conn, virNodeListDevicesCheckACL, cap, names, maxnames); nodeDeviceUnlock(); return nnames; }
int nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) { virNodeDeviceDriverStatePtr driver = dev->conn->nodeDevicePrivateData; virNodeDeviceObjPtr obj; virNodeDevCapsDefPtr caps; int ncaps = 0; int ret = -1; nodeDeviceLock(driver); obj = virNodeDeviceFindByName(&driver->devs, dev->name); nodeDeviceUnlock(driver); if (!obj) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), dev->name); goto cleanup; } if (virNodeDeviceListCapsEnsureACL(dev->conn, obj->def) < 0) goto cleanup; for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) { if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->type)) < 0) goto cleanup; } ret = ncaps; cleanup: if (obj) virNodeDeviceObjUnlock(obj); if (ret == -1) { --ncaps; while (--ncaps >= 0) VIR_FREE(names[ncaps]); } return ret; }