2017-02-28 18:24:26 +00:00
|
|
|
/*
|
|
|
|
* virnodedeviceobj.c: node device object handling
|
|
|
|
* (derived from node_device_conf.c)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "node_device_conf.h"
|
|
|
|
|
|
|
|
#include "viralloc.h"
|
|
|
|
#include "virnodedeviceobj.h"
|
|
|
|
#include "virerror.h"
|
2017-06-29 19:50:06 +00:00
|
|
|
#include "virhash.h"
|
2017-02-28 18:24:26 +00:00
|
|
|
#include "virlog.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NODEDEV
|
|
|
|
|
|
|
|
VIR_LOG_INIT("conf.virnodedeviceobj");
|
|
|
|
|
2017-05-12 17:56:14 +00:00
|
|
|
struct _virNodeDeviceObj {
|
2017-05-15 15:00:59 +00:00
|
|
|
virObjectLockable parent;
|
2017-05-12 17:56:14 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceDef *def; /* device definition */
|
2018-02-23 23:09:20 +00:00
|
|
|
bool skipUpdateCaps; /* whether to skip checking host caps,
|
|
|
|
used by testdriver */
|
2020-07-09 15:39:34 +00:00
|
|
|
bool active;
|
2021-01-15 22:41:51 +00:00
|
|
|
bool persistent;
|
2021-05-26 20:09:29 +00:00
|
|
|
bool autostart;
|
2017-05-12 17:56:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _virNodeDeviceObjList {
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWLockable parent;
|
2017-06-29 19:50:06 +00:00
|
|
|
|
|
|
|
/* name string -> virNodeDeviceObj mapping
|
|
|
|
* for O(1), lockless lookup-by-name */
|
2020-10-22 17:04:18 +00:00
|
|
|
GHashTable *objs;
|
2017-06-29 19:50:06 +00:00
|
|
|
|
2017-05-12 17:56:14 +00:00
|
|
|
};
|
|
|
|
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virClass *virNodeDeviceObjClass;
|
|
|
|
static virClass *virNodeDeviceObjListClass;
|
2017-05-15 15:00:59 +00:00
|
|
|
static void virNodeDeviceObjDispose(void *opaque);
|
2017-06-29 19:50:06 +00:00
|
|
|
static void virNodeDeviceObjListDispose(void *opaque);
|
2018-01-11 12:43:29 +00:00
|
|
|
static bool virNodeDeviceObjHasCap(const virNodeDeviceObj *obj, int type);
|
2017-05-15 15:00:59 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
virNodeDeviceObjOnceInit(void)
|
|
|
|
{
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(virNodeDeviceObj, virClassForObjectLockable()))
|
2017-05-15 15:00:59 +00:00
|
|
|
return -1;
|
|
|
|
|
2018-04-17 15:42:33 +00:00
|
|
|
if (!VIR_CLASS_NEW(virNodeDeviceObjList, virClassForObjectRWLockable()))
|
2017-06-29 19:50:06 +00:00
|
|
|
return -1;
|
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:23:29 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(virNodeDeviceObj);
|
2017-05-15 15:00:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
virNodeDeviceObjDispose(void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = opaque;
|
2017-05-15 15:00:59 +00:00
|
|
|
|
|
|
|
virNodeDeviceDefFree(obj->def);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNodeDeviceObj *
|
2017-05-12 17:34:23 +00:00
|
|
|
virNodeDeviceObjNew(void)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj;
|
2017-05-12 17:34:23 +00:00
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
if (virNodeDeviceObjInitialize() < 0)
|
2017-05-12 17:34:23 +00:00
|
|
|
return NULL;
|
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
if (!(obj = virObjectLockableNew(virNodeDeviceObjClass)))
|
2017-05-12 17:34:23 +00:00
|
|
|
return NULL;
|
2017-05-15 15:00:59 +00:00
|
|
|
|
|
|
|
virObjectLock(obj);
|
2017-05-12 17:34:23 +00:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjEndAPI(virNodeDeviceObj **obj)
|
2017-05-15 15:00:59 +00:00
|
|
|
{
|
|
|
|
if (!*obj)
|
|
|
|
return;
|
|
|
|
|
|
|
|
virObjectUnlock(*obj);
|
|
|
|
virObjectUnref(*obj);
|
|
|
|
*obj = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceDef *
|
|
|
|
virNodeDeviceObjGetDef(virNodeDeviceObj *obj)
|
2017-06-03 11:36:01 +00:00
|
|
|
{
|
|
|
|
return obj->def;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-09 22:01:57 +00:00
|
|
|
static bool
|
2018-01-11 12:43:29 +00:00
|
|
|
virNodeDeviceObjHasCapStr(const virNodeDeviceObj *obj,
|
|
|
|
const char *cap)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2018-01-23 11:38:26 +00:00
|
|
|
int type;
|
|
|
|
|
|
|
|
if ((type = virNodeDevCapTypeFromString(cap)) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return virNodeDeviceObjHasCap(obj, type);
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* virNodeDeviceFindFCCapDef:
|
2017-05-12 15:17:26 +00:00
|
|
|
* @obj: Pointer to current device
|
2017-02-28 18:24:26 +00:00
|
|
|
*
|
|
|
|
* Search the device object 'caps' array for fc_host capability.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Pointer to the caps or NULL if not found
|
|
|
|
*/
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNodeDevCapsDef *
|
2017-05-12 15:17:26 +00:00
|
|
|
virNodeDeviceFindFCCapDef(const virNodeDeviceObj *obj)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDevCapsDef *caps = obj->def->caps;
|
2017-02-28 18:24:26 +00:00
|
|
|
|
|
|
|
while (caps) {
|
|
|
|
if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST &&
|
|
|
|
(caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST))
|
|
|
|
break;
|
|
|
|
|
|
|
|
caps = caps->next;
|
|
|
|
}
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* virNodeDeviceFindVPORTCapDef:
|
2017-05-12 15:17:26 +00:00
|
|
|
* @obj: Pointer to current device
|
2017-02-28 18:24:26 +00:00
|
|
|
*
|
|
|
|
* Search the device object 'caps' array for vport_ops capability.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Pointer to the caps or NULL if not found
|
|
|
|
*/
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNodeDevCapsDef *
|
2017-05-12 15:17:26 +00:00
|
|
|
virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *obj)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDevCapsDef *caps = obj->def->caps;
|
2017-02-28 18:24:26 +00:00
|
|
|
|
|
|
|
while (caps) {
|
|
|
|
if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST &&
|
|
|
|
(caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS))
|
|
|
|
break;
|
|
|
|
|
|
|
|
caps = caps->next;
|
|
|
|
}
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListSearch(virNodeDeviceObjList *devs,
|
2017-06-29 19:50:06 +00:00
|
|
|
virHashSearcher callback,
|
|
|
|
const void *data)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj;
|
2017-06-29 19:50:06 +00:00
|
|
|
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWLockRead(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
obj = virHashSearch(devs->objs, callback, data, NULL);
|
|
|
|
virObjectRef(obj);
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWUnlock(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
|
|
|
|
if (obj)
|
|
|
|
virObjectLock(obj);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virNodeDeviceObjListFindBySysfsPathCallback(const void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2017-06-29 19:50:06 +00:00
|
|
|
const void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = (virNodeDeviceObj *) payload;
|
2017-06-29 19:50:06 +00:00
|
|
|
const char *sysfs_path = opaque;
|
|
|
|
int want = 0;
|
|
|
|
|
|
|
|
virObjectLock(obj);
|
2019-01-18 07:49:37 +00:00
|
|
|
if (obj->def->sysfs_path &&
|
|
|
|
STREQ_NULLABLE(obj->def->sysfs_path, sysfs_path))
|
2017-06-29 19:50:06 +00:00
|
|
|
want = 1;
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
return want;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjList *devs,
|
2017-05-12 18:47:17 +00:00
|
|
|
const char *sysfs_path)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2017-06-29 19:50:06 +00:00
|
|
|
return virNodeDeviceObjListSearch(devs,
|
|
|
|
virNodeDeviceObjListFindBySysfsPathCallback,
|
|
|
|
sysfs_path);
|
|
|
|
}
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-05-15 14:20:51 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListFindByNameLocked(virNodeDeviceObjList *devs,
|
2017-06-29 19:50:06 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
return virObjectRef(virHashLookup(devs->objs, name));
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListFindByName(virNodeDeviceObjList *devs,
|
2017-05-12 18:47:17 +00:00
|
|
|
const char *name)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj;
|
2017-05-15 14:20:51 +00:00
|
|
|
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWLockRead(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
obj = virNodeDeviceObjListFindByNameLocked(devs, name);
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWUnlock(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
if (obj)
|
2017-05-15 15:00:59 +00:00
|
|
|
virObjectLock(obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct virNodeDeviceObjListFindByWWNsData {
|
|
|
|
const char *parent_wwnn;
|
|
|
|
const char *parent_wwpn;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virNodeDeviceObjListFindByWWNsCallback(const void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2017-06-29 19:50:06 +00:00
|
|
|
const void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = (virNodeDeviceObj *) payload;
|
2017-06-29 19:50:06 +00:00
|
|
|
struct virNodeDeviceObjListFindByWWNsData *data =
|
|
|
|
(struct virNodeDeviceObjListFindByWWNsData *) opaque;
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDevCapsDef *cap;
|
2017-06-29 19:50:06 +00:00
|
|
|
int want = 0;
|
|
|
|
|
|
|
|
virObjectLock(obj);
|
|
|
|
if ((cap = virNodeDeviceFindFCCapDef(obj)) &&
|
|
|
|
STREQ_NULLABLE(cap->data.scsi_host.wwnn, data->parent_wwnn) &&
|
|
|
|
STREQ_NULLABLE(cap->data.scsi_host.wwpn, data->parent_wwpn) &&
|
|
|
|
virNodeDeviceFindVPORTCapDef(obj))
|
|
|
|
want = 1;
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
return want;
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListFindByWWNs(virNodeDeviceObjList *devs,
|
2017-05-12 18:47:17 +00:00
|
|
|
const char *parent_wwnn,
|
|
|
|
const char *parent_wwpn)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2017-06-29 19:50:06 +00:00
|
|
|
struct virNodeDeviceObjListFindByWWNsData data = {
|
|
|
|
.parent_wwnn = parent_wwnn, .parent_wwpn = parent_wwpn };
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
return virNodeDeviceObjListSearch(devs,
|
|
|
|
virNodeDeviceObjListFindByWWNsCallback,
|
|
|
|
&data);
|
|
|
|
}
|
2017-05-15 14:20:51 +00:00
|
|
|
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
static int
|
|
|
|
virNodeDeviceObjListFindByFabricWWNCallback(const void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2017-06-29 19:50:06 +00:00
|
|
|
const void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = (virNodeDeviceObj *) payload;
|
2017-06-29 19:50:06 +00:00
|
|
|
const char *matchstr = opaque;
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDevCapsDef *cap;
|
2017-06-29 19:50:06 +00:00
|
|
|
int want = 0;
|
|
|
|
|
|
|
|
virObjectLock(obj);
|
|
|
|
if ((cap = virNodeDeviceFindFCCapDef(obj)) &&
|
|
|
|
STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, matchstr) &&
|
|
|
|
virNodeDeviceFindVPORTCapDef(obj))
|
|
|
|
want = 1;
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
return want;
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListFindByFabricWWN(virNodeDeviceObjList *devs,
|
2017-05-12 18:47:17 +00:00
|
|
|
const char *parent_fabric_wwn)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2017-06-29 19:50:06 +00:00
|
|
|
return virNodeDeviceObjListSearch(devs,
|
|
|
|
virNodeDeviceObjListFindByFabricWWNCallback,
|
|
|
|
parent_fabric_wwn);
|
|
|
|
}
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-05-15 14:20:51 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
static int
|
|
|
|
virNodeDeviceObjListFindByCapCallback(const void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2017-06-29 19:50:06 +00:00
|
|
|
const void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = (virNodeDeviceObj *) payload;
|
2017-06-29 19:50:06 +00:00
|
|
|
const char *matchstr = opaque;
|
|
|
|
int want = 0;
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
virObjectLock(obj);
|
2018-01-11 12:43:29 +00:00
|
|
|
if (virNodeDeviceObjHasCapStr(obj, matchstr))
|
2017-06-29 19:50:06 +00:00
|
|
|
want = 1;
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
return want;
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListFindByCap(virNodeDeviceObjList *devs,
|
2017-05-12 18:47:17 +00:00
|
|
|
const char *cap)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2017-06-29 19:50:06 +00:00
|
|
|
return virNodeDeviceObjListSearch(devs,
|
|
|
|
virNodeDeviceObjListFindByCapCallback,
|
|
|
|
cap);
|
|
|
|
}
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-05-15 14:20:51 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
struct virNodeDeviceObjListFindSCSIHostByWWNsData {
|
|
|
|
const char *wwnn;
|
|
|
|
const char *wwpn;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virNodeDeviceObjListFindSCSIHostByWWNsCallback(const void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2017-06-29 19:50:06 +00:00
|
|
|
const void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = (virNodeDeviceObj *) payload;
|
2017-06-29 19:50:06 +00:00
|
|
|
struct virNodeDeviceObjListFindSCSIHostByWWNsData *data =
|
|
|
|
(struct virNodeDeviceObjListFindSCSIHostByWWNsData *) opaque;
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDevCapsDef *cap;
|
2017-06-29 19:50:06 +00:00
|
|
|
int want = 0;
|
|
|
|
|
|
|
|
virObjectLock(obj);
|
|
|
|
cap = obj->def->caps;
|
|
|
|
|
|
|
|
while (cap) {
|
|
|
|
if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
|
|
|
|
virNodeDeviceGetSCSIHostCaps(&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, data->wwnn) &&
|
|
|
|
STREQ(cap->data.scsi_host.wwpn, data->wwpn)) {
|
|
|
|
want = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cap = cap->next;
|
|
|
|
}
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
virObjectUnlock(obj);
|
|
|
|
return want;
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjList *devs,
|
2017-05-12 19:31:10 +00:00
|
|
|
const char *wwnn,
|
|
|
|
const char *wwpn)
|
|
|
|
{
|
2017-06-29 19:50:06 +00:00
|
|
|
struct virNodeDeviceObjListFindSCSIHostByWWNsData data = {
|
|
|
|
.wwnn = wwnn, .wwpn = wwpn };
|
2017-05-12 19:31:10 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
return virNodeDeviceObjListSearch(devs,
|
|
|
|
virNodeDeviceObjListFindSCSIHostByWWNsCallback,
|
|
|
|
&data);
|
|
|
|
}
|
2017-05-12 19:31:10 +00:00
|
|
|
|
2021-07-16 19:33:50 +00:00
|
|
|
|
|
|
|
typedef struct _FindMediatedDeviceData FindMediatedDeviceData;
|
|
|
|
struct _FindMediatedDeviceData {
|
|
|
|
const char *uuid;
|
|
|
|
const char *parent_addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-06-18 21:05:59 +00:00
|
|
|
static int
|
|
|
|
virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(const void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2020-06-18 21:05:59 +00:00
|
|
|
const void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = (virNodeDeviceObj *) payload;
|
2021-07-16 19:33:50 +00:00
|
|
|
const FindMediatedDeviceData* data = opaque;
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDevCapsDef *cap;
|
2020-06-18 21:05:59 +00:00
|
|
|
int want = 0;
|
|
|
|
|
|
|
|
virObjectLock(obj);
|
|
|
|
|
|
|
|
for (cap = obj->def->caps; cap != NULL; cap = cap->next) {
|
|
|
|
if (cap->data.type == VIR_NODE_DEV_CAP_MDEV) {
|
2021-07-16 19:33:50 +00:00
|
|
|
if (STREQ(cap->data.mdev.uuid, data->uuid) &&
|
|
|
|
STREQ(cap->data.mdev.parent_addr, data->parent_addr)) {
|
2020-06-18 21:05:59 +00:00
|
|
|
want = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
return want;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjList *devs,
|
2021-07-16 19:33:50 +00:00
|
|
|
const char *uuid,
|
|
|
|
const char *parent_addr)
|
2020-06-18 21:05:59 +00:00
|
|
|
{
|
2021-07-16 19:33:50 +00:00
|
|
|
const FindMediatedDeviceData data = {uuid, parent_addr};
|
2020-06-18 21:05:59 +00:00
|
|
|
return virNodeDeviceObjListSearch(devs,
|
|
|
|
virNodeDeviceObjListFindMediatedDeviceByUUIDCallback,
|
2021-07-16 19:33:50 +00:00
|
|
|
&data);
|
2020-06-18 21:05:59 +00:00
|
|
|
}
|
2017-05-12 19:31:10 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
static void
|
|
|
|
virNodeDeviceObjListDispose(void *obj)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjList *devs = obj;
|
2017-06-29 19:50:06 +00:00
|
|
|
|
|
|
|
virHashFree(devs->objs);
|
2017-05-12 19:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjList *
|
2017-05-12 17:51:25 +00:00
|
|
|
virNodeDeviceObjListNew(void)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjList *devs;
|
2017-05-12 17:51:25 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
if (virNodeDeviceObjInitialize() < 0)
|
2017-05-12 17:51:25 +00:00
|
|
|
return NULL;
|
2017-06-29 19:50:06 +00:00
|
|
|
|
2017-10-09 20:55:23 +00:00
|
|
|
if (!(devs = virObjectRWLockableNew(virNodeDeviceObjListClass)))
|
2017-06-29 19:50:06 +00:00
|
|
|
return NULL;
|
|
|
|
|
2021-07-06 08:06:35 +00:00
|
|
|
devs->objs = virHashNew(virObjectFreeHashData);
|
2017-06-29 19:50:06 +00:00
|
|
|
|
2017-05-12 17:51:25 +00:00
|
|
|
return devs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-02 13:39:11 +00:00
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjListFree(virNodeDeviceObjList *devs)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2017-06-29 19:50:06 +00:00
|
|
|
virObjectUnref(devs);
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 13:39:11 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListAssignDef(virNodeDeviceObjList *devs,
|
|
|
|
virNodeDeviceDef *def)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj;
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWLockWrite(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
|
|
|
|
if ((obj = virNodeDeviceObjListFindByNameLocked(devs, def->name))) {
|
|
|
|
virObjectLock(obj);
|
2017-05-12 15:17:26 +00:00
|
|
|
virNodeDeviceDefFree(obj->def);
|
|
|
|
obj->def = def;
|
2017-06-29 19:50:06 +00:00
|
|
|
} else {
|
|
|
|
if (!(obj = virNodeDeviceObjNew()))
|
|
|
|
goto cleanup;
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
if (virHashAddEntry(devs->objs, def->name, obj) < 0) {
|
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
obj->def = def;
|
|
|
|
virObjectRef(obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
cleanup:
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWUnlock(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
return obj;
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 13:39:11 +00:00
|
|
|
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjListRemove(virNodeDeviceObjList *devs,
|
|
|
|
virNodeDeviceObj *obj)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2017-06-29 19:50:06 +00:00
|
|
|
if (!obj)
|
|
|
|
return;
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
virObjectRef(obj);
|
|
|
|
virObjectUnlock(obj);
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWLockWrite(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
virObjectLock(obj);
|
2020-10-15 16:30:35 +00:00
|
|
|
virNodeDeviceObjListRemoveLocked(devs, obj);
|
2017-06-29 19:50:06 +00:00
|
|
|
virObjectUnlock(obj);
|
|
|
|
virObjectUnref(obj);
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWUnlock(devs);
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-15 16:30:35 +00:00
|
|
|
/* The caller must hold lock on 'devs' */
|
|
|
|
void
|
|
|
|
virNodeDeviceObjListRemoveLocked(virNodeDeviceObjList *devs,
|
|
|
|
virNodeDeviceObj *dev)
|
|
|
|
{
|
|
|
|
virHashRemoveEntry(devs->objs, dev->def->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-28 18:24:26 +00:00
|
|
|
/*
|
|
|
|
* Return the NPIV dev's parent device name
|
|
|
|
*/
|
|
|
|
/* virNodeDeviceFindFCParentHost:
|
2017-05-12 15:17:26 +00:00
|
|
|
* @obj: Pointer to node device object
|
2017-02-28 18:24:26 +00:00
|
|
|
*
|
|
|
|
* Search the capabilities for the device to find the FC capabilities
|
|
|
|
* in order to set the parent_host value.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* parent_host value on success (>= 0), -1 otherwise.
|
|
|
|
*/
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceFindFCParentHost(virNodeDeviceObj *obj)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDevCapsDef *cap = virNodeDeviceFindVPORTCapDef(obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
|
|
|
if (!cap) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Parent device %s is not capable "
|
|
|
|
"of vport operations"),
|
2017-05-12 15:17:26 +00:00
|
|
|
obj->def->name);
|
2017-02-28 18:24:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cap->data.scsi_host.host;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjListGetParentHostByParent(virNodeDeviceObjList *devs,
|
2017-05-12 18:47:17 +00:00
|
|
|
const char *dev_name,
|
|
|
|
const char *parent_name)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = NULL;
|
2017-02-28 18:24:26 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-05-12 18:47:17 +00:00
|
|
|
if (!(obj = virNodeDeviceObjListFindByName(devs, parent_name))) {
|
2017-02-28 18:24:26 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find parent device for '%s'"),
|
|
|
|
dev_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-12 15:17:26 +00:00
|
|
|
ret = virNodeDeviceFindFCParentHost(obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjListGetParentHostByWWNs(virNodeDeviceObjList *devs,
|
2017-05-12 18:47:17 +00:00
|
|
|
const char *dev_name,
|
|
|
|
const char *parent_wwnn,
|
|
|
|
const char *parent_wwpn)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = NULL;
|
2017-02-28 18:24:26 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-05-12 18:47:17 +00:00
|
|
|
if (!(obj = virNodeDeviceObjListFindByWWNs(devs, parent_wwnn,
|
|
|
|
parent_wwpn))) {
|
2017-02-28 18:24:26 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find parent device for '%s'"),
|
|
|
|
dev_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-12 15:17:26 +00:00
|
|
|
ret = virNodeDeviceFindFCParentHost(obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjListGetParentHostByFabricWWN(virNodeDeviceObjList *devs,
|
2017-05-12 18:47:17 +00:00
|
|
|
const char *dev_name,
|
|
|
|
const char *parent_fabric_wwn)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = NULL;
|
2017-02-28 18:24:26 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-05-12 18:47:17 +00:00
|
|
|
if (!(obj = virNodeDeviceObjListFindByFabricWWN(devs, parent_fabric_wwn))) {
|
2017-02-28 18:24:26 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find parent device for '%s'"),
|
|
|
|
dev_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-12 15:17:26 +00:00
|
|
|
ret = virNodeDeviceFindFCParentHost(obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjListFindVportParentHost(virNodeDeviceObjList *devs)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = NULL;
|
2017-02-28 18:24:26 +00:00
|
|
|
const char *cap = virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS);
|
|
|
|
int ret;
|
|
|
|
|
2017-05-12 18:47:17 +00:00
|
|
|
if (!(obj = virNodeDeviceObjListFindByCap(devs, cap))) {
|
2017-02-28 18:24:26 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Could not find any vport capable device"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-05-12 15:17:26 +00:00
|
|
|
ret = virNodeDeviceFindFCParentHost(obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-05-15 15:00:59 +00:00
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjListGetParentHost(virNodeDeviceObjList *devs,
|
|
|
|
virNodeDeviceDef *def)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
|
|
|
int parent_host = -1;
|
|
|
|
|
|
|
|
if (def->parent) {
|
2017-05-12 18:47:17 +00:00
|
|
|
parent_host = virNodeDeviceObjListGetParentHostByParent(devs, def->name,
|
|
|
|
def->parent);
|
2017-02-28 18:24:26 +00:00
|
|
|
} else if (def->parent_wwnn && def->parent_wwpn) {
|
2017-05-12 18:47:17 +00:00
|
|
|
parent_host = virNodeDeviceObjListGetParentHostByWWNs(devs, def->name,
|
|
|
|
def->parent_wwnn,
|
|
|
|
def->parent_wwpn);
|
2017-02-28 18:24:26 +00:00
|
|
|
} else if (def->parent_fabric_wwn) {
|
|
|
|
parent_host =
|
2017-05-12 18:47:17 +00:00
|
|
|
virNodeDeviceObjListGetParentHostByFabricWWN(devs, def->name,
|
|
|
|
def->parent_fabric_wwn);
|
2017-07-20 13:17:22 +00:00
|
|
|
} else {
|
2017-02-28 18:24:26 +00:00
|
|
|
/* Try to find a vport capable scsi_host when no parent supplied */
|
2017-05-12 18:47:17 +00:00
|
|
|
parent_host = virNodeDeviceObjListFindVportParentHost(devs);
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent_host;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
2018-01-11 12:43:29 +00:00
|
|
|
virNodeDeviceObjHasCap(const virNodeDeviceObj *obj,
|
|
|
|
int type)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDevCapsDef *cap = NULL;
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-05-12 15:17:26 +00:00
|
|
|
for (cap = obj->def->caps; cap; cap = cap->next) {
|
2017-02-28 18:24:26 +00:00
|
|
|
if (type == cap->data.type)
|
|
|
|
return true;
|
|
|
|
|
2017-05-25 19:43:45 +00:00
|
|
|
switch (cap->data.type) {
|
|
|
|
case VIR_NODE_DEV_CAP_PCI_DEV:
|
|
|
|
if (type == VIR_NODE_DEV_CAP_MDEV_TYPES &&
|
|
|
|
(cap->data.pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_MDEV))
|
|
|
|
return true;
|
2021-10-20 08:30:33 +00:00
|
|
|
if (type == VIR_NODE_DEV_CAP_VPD &&
|
|
|
|
(cap->data.pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_VPD))
|
|
|
|
return true;
|
2017-05-25 19:43:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_NODE_DEV_CAP_SCSI_HOST:
|
2017-02-28 18:24:26 +00:00
|
|
|
if (type == VIR_NODE_DEV_CAP_FC_HOST &&
|
2017-05-25 19:43:45 +00:00
|
|
|
(cap->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST))
|
2017-02-28 18:24:26 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (type == VIR_NODE_DEV_CAP_VPORTS &&
|
2017-05-25 19:43:45 +00:00
|
|
|
(cap->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS))
|
2017-02-28 18:24:26 +00:00
|
|
|
return true;
|
2017-05-25 19:43:45 +00:00
|
|
|
break;
|
2017-03-06 16:17:34 +00:00
|
|
|
|
2020-11-11 12:45:22 +00:00
|
|
|
case VIR_NODE_DEV_CAP_CSS_DEV:
|
|
|
|
if (type == VIR_NODE_DEV_CAP_MDEV_TYPES &&
|
|
|
|
(cap->data.ccw_dev.flags & VIR_NODE_DEV_CAP_FLAG_CSS_MDEV))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
2020-12-03 17:59:43 +00:00
|
|
|
case VIR_NODE_DEV_CAP_AP_MATRIX:
|
|
|
|
if (type == VIR_NODE_DEV_CAP_MDEV_TYPES &&
|
|
|
|
(cap->data.ap_matrix.flags & VIR_NODE_DEV_CAP_FLAG_AP_MATRIX_MDEV))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
2017-05-25 19:43:45 +00:00
|
|
|
case VIR_NODE_DEV_CAP_SYSTEM:
|
|
|
|
case VIR_NODE_DEV_CAP_USB_DEV:
|
|
|
|
case VIR_NODE_DEV_CAP_USB_INTERFACE:
|
|
|
|
case VIR_NODE_DEV_CAP_NET:
|
|
|
|
case VIR_NODE_DEV_CAP_SCSI_TARGET:
|
|
|
|
case VIR_NODE_DEV_CAP_SCSI:
|
|
|
|
case VIR_NODE_DEV_CAP_STORAGE:
|
|
|
|
case VIR_NODE_DEV_CAP_FC_HOST:
|
|
|
|
case VIR_NODE_DEV_CAP_VPORTS:
|
|
|
|
case VIR_NODE_DEV_CAP_SCSI_GENERIC:
|
|
|
|
case VIR_NODE_DEV_CAP_DRM:
|
|
|
|
case VIR_NODE_DEV_CAP_MDEV_TYPES:
|
|
|
|
case VIR_NODE_DEV_CAP_MDEV:
|
|
|
|
case VIR_NODE_DEV_CAP_CCW_DEV:
|
2020-10-14 17:08:30 +00:00
|
|
|
case VIR_NODE_DEV_CAP_VDPA:
|
2020-12-03 17:59:33 +00:00
|
|
|
case VIR_NODE_DEV_CAP_AP_CARD:
|
2020-12-03 17:59:35 +00:00
|
|
|
case VIR_NODE_DEV_CAP_AP_QUEUE:
|
2021-10-20 08:30:33 +00:00
|
|
|
case VIR_NODE_DEV_CAP_VPD:
|
2017-05-25 19:43:45 +00:00
|
|
|
case VIR_NODE_DEV_CAP_LAST:
|
|
|
|
break;
|
2017-03-06 16:17:34 +00:00
|
|
|
}
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-02 13:39:11 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
struct virNodeDeviceCountData {
|
|
|
|
virConnectPtr conn;
|
2017-08-16 13:23:27 +00:00
|
|
|
virNodeDeviceObjListFilter filter;
|
2017-06-29 19:50:06 +00:00
|
|
|
const char *matchstr;
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virNodeDeviceObjListNumOfDevicesCallback(void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2017-06-29 19:50:06 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = payload;
|
|
|
|
virNodeDeviceDef *def;
|
2017-06-29 19:50:06 +00:00
|
|
|
struct virNodeDeviceCountData *data = opaque;
|
2017-08-16 13:23:27 +00:00
|
|
|
virNodeDeviceObjListFilter filter = data->filter;
|
2017-06-29 19:50:06 +00:00
|
|
|
|
|
|
|
virObjectLock(obj);
|
|
|
|
def = obj->def;
|
2017-08-16 13:23:27 +00:00
|
|
|
if ((!filter || filter(data->conn, def)) &&
|
2018-01-11 12:43:29 +00:00
|
|
|
(!data->matchstr || virNodeDeviceObjHasCapStr(obj, data->matchstr)))
|
2017-06-29 19:50:06 +00:00
|
|
|
data->count++;
|
|
|
|
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-19 11:49:38 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjListNumOfDevices(virNodeDeviceObjList *devs,
|
2017-05-12 18:47:17 +00:00
|
|
|
virConnectPtr conn,
|
|
|
|
const char *cap,
|
2017-08-16 13:23:27 +00:00
|
|
|
virNodeDeviceObjListFilter filter)
|
2017-03-19 11:49:38 +00:00
|
|
|
{
|
2017-06-29 19:50:06 +00:00
|
|
|
struct virNodeDeviceCountData data = {
|
2017-08-16 13:23:27 +00:00
|
|
|
.conn = conn, .filter = filter, .matchstr = cap, .count = 0 };
|
2017-03-19 11:49:38 +00:00
|
|
|
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWLockRead(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
virHashForEach(devs->objs, virNodeDeviceObjListNumOfDevicesCallback, &data);
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWUnlock(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
|
|
|
|
return data.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct virNodeDeviceGetNamesData {
|
|
|
|
virConnectPtr conn;
|
2017-08-16 13:23:27 +00:00
|
|
|
virNodeDeviceObjListFilter filter;
|
2017-06-29 19:50:06 +00:00
|
|
|
const char *matchstr;
|
|
|
|
int nnames;
|
|
|
|
char **names;
|
|
|
|
int maxnames;
|
|
|
|
bool error;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virNodeDeviceObjListGetNamesCallback(void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2017-06-29 19:50:06 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = payload;
|
|
|
|
virNodeDeviceDef *def;
|
2017-06-29 19:50:06 +00:00
|
|
|
struct virNodeDeviceGetNamesData *data = opaque;
|
2017-08-16 13:23:27 +00:00
|
|
|
virNodeDeviceObjListFilter filter = data->filter;
|
2017-06-29 19:50:06 +00:00
|
|
|
|
|
|
|
if (data->error)
|
|
|
|
return 0;
|
|
|
|
|
2018-01-02 09:18:17 +00:00
|
|
|
if (data->nnames >= data->maxnames)
|
|
|
|
return 0;
|
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
virObjectLock(obj);
|
|
|
|
def = obj->def;
|
|
|
|
|
2017-08-16 13:23:27 +00:00
|
|
|
if ((!filter || filter(data->conn, def)) &&
|
2018-01-11 12:43:29 +00:00
|
|
|
(!data->matchstr || virNodeDeviceObjHasCapStr(obj, data->matchstr))) {
|
2019-10-20 11:49:46 +00:00
|
|
|
data->names[data->nnames] = g_strdup(def->name);
|
2017-06-29 19:50:06 +00:00
|
|
|
data->nnames++;
|
|
|
|
}
|
2017-03-19 11:49:38 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
virObjectUnlock(obj);
|
|
|
|
return 0;
|
2017-03-19 11:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-19 19:51:03 +00:00
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjListGetNames(virNodeDeviceObjList *devs,
|
2017-05-12 18:47:17 +00:00
|
|
|
virConnectPtr conn,
|
2017-08-16 13:23:27 +00:00
|
|
|
virNodeDeviceObjListFilter filter,
|
2017-05-12 18:47:17 +00:00
|
|
|
const char *cap,
|
|
|
|
char **const names,
|
|
|
|
int maxnames)
|
2017-03-19 19:51:03 +00:00
|
|
|
{
|
2017-06-29 19:50:06 +00:00
|
|
|
struct virNodeDeviceGetNamesData data = {
|
2017-08-16 13:23:27 +00:00
|
|
|
.conn = conn, .filter = filter, .matchstr = cap, .names = names,
|
2017-06-29 19:50:06 +00:00
|
|
|
.nnames = 0, .maxnames = maxnames, .error = false };
|
2017-03-19 19:51:03 +00:00
|
|
|
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWLockRead(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
virHashForEach(devs->objs, virNodeDeviceObjListGetNamesCallback, &data);
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWUnlock(devs);
|
2017-06-29 19:50:06 +00:00
|
|
|
|
|
|
|
if (data.error)
|
|
|
|
goto error;
|
2017-03-19 19:51:03 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
return data.nnames;
|
2017-03-19 19:51:03 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
error:
|
|
|
|
while (--data.nnames)
|
|
|
|
VIR_FREE(data.names[data.nnames]);
|
2017-03-19 19:51:03 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-10 18:54:50 +00:00
|
|
|
#define MATCH_CAP(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \
|
|
|
|
virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_ ## FLAG))
|
|
|
|
#define MATCH(FLAG) (flags & (FLAG))
|
|
|
|
|
2017-02-28 18:24:26 +00:00
|
|
|
static bool
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjMatch(virNodeDeviceObj *obj,
|
2018-08-13 15:55:16 +00:00
|
|
|
unsigned int flags)
|
2017-02-28 18:24:26 +00:00
|
|
|
{
|
2018-01-18 14:25:49 +00:00
|
|
|
/* Refresh the capabilities first, e.g. due to a driver change */
|
2018-02-23 23:09:20 +00:00
|
|
|
if (!obj->skipUpdateCaps &&
|
|
|
|
virNodeDeviceUpdateCaps(obj->def) < 0)
|
2018-01-18 14:25:49 +00:00
|
|
|
return false;
|
|
|
|
|
2017-02-28 18:24:26 +00:00
|
|
|
/* filter by cap type */
|
|
|
|
if (flags & VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP) {
|
2020-07-10 18:54:50 +00:00
|
|
|
if (!(MATCH_CAP(SYSTEM) ||
|
|
|
|
MATCH_CAP(PCI_DEV) ||
|
|
|
|
MATCH_CAP(USB_DEV) ||
|
|
|
|
MATCH_CAP(USB_INTERFACE) ||
|
|
|
|
MATCH_CAP(NET) ||
|
|
|
|
MATCH_CAP(SCSI_HOST) ||
|
|
|
|
MATCH_CAP(SCSI_TARGET) ||
|
|
|
|
MATCH_CAP(SCSI) ||
|
|
|
|
MATCH_CAP(STORAGE) ||
|
|
|
|
MATCH_CAP(FC_HOST) ||
|
|
|
|
MATCH_CAP(VPORTS) ||
|
|
|
|
MATCH_CAP(SCSI_GENERIC) ||
|
|
|
|
MATCH_CAP(DRM) ||
|
|
|
|
MATCH_CAP(MDEV_TYPES) ||
|
|
|
|
MATCH_CAP(MDEV) ||
|
|
|
|
MATCH_CAP(CCW_DEV) ||
|
|
|
|
MATCH_CAP(CSS_DEV) ||
|
|
|
|
MATCH_CAP(VDPA) ||
|
|
|
|
MATCH_CAP(AP_CARD) ||
|
|
|
|
MATCH_CAP(AP_QUEUE) ||
|
2021-10-20 08:30:33 +00:00
|
|
|
MATCH_CAP(AP_MATRIX) ||
|
|
|
|
MATCH_CAP(VPD)))
|
2020-07-10 18:54:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & (VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_ACTIVE)) {
|
|
|
|
if (!((MATCH(VIR_CONNECT_LIST_NODE_DEVICES_ACTIVE) &&
|
|
|
|
virNodeDeviceObjIsActive(obj)) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_NODE_DEVICES_INACTIVE) &&
|
|
|
|
!virNodeDeviceObjIsActive(obj))))
|
2017-02-28 18:24:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#undef MATCH
|
2020-07-10 18:54:50 +00:00
|
|
|
#undef MATCH_CAP
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-03-02 13:39:11 +00:00
|
|
|
|
2018-08-13 15:55:14 +00:00
|
|
|
typedef struct _virNodeDeviceObjListExportData virNodeDeviceObjListExportData;
|
|
|
|
struct _virNodeDeviceObjListExportData {
|
2017-06-29 19:50:06 +00:00
|
|
|
virConnectPtr conn;
|
2017-08-16 13:23:27 +00:00
|
|
|
virNodeDeviceObjListFilter filter;
|
2017-06-29 19:50:06 +00:00
|
|
|
unsigned int flags;
|
|
|
|
virNodeDevicePtr *devices;
|
|
|
|
int ndevices;
|
|
|
|
bool error;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
virNodeDeviceObjListExportCallback(void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2017-06-29 19:50:06 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObj *obj = payload;
|
|
|
|
virNodeDeviceDef *def;
|
|
|
|
virNodeDeviceObjListExportData *data = opaque;
|
2017-06-29 19:50:06 +00:00
|
|
|
virNodeDevicePtr device = NULL;
|
|
|
|
|
|
|
|
if (data->error)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
virObjectLock(obj);
|
|
|
|
def = obj->def;
|
|
|
|
|
2017-08-16 13:23:27 +00:00
|
|
|
if ((!data->filter || data->filter(data->conn, def)) &&
|
2018-08-13 15:55:16 +00:00
|
|
|
virNodeDeviceObjMatch(obj, data->flags)) {
|
2017-06-29 19:50:06 +00:00
|
|
|
if (data->devices) {
|
2019-10-20 11:49:46 +00:00
|
|
|
if (!(device = virGetNodeDevice(data->conn, def->name))) {
|
2017-06-29 19:50:06 +00:00
|
|
|
virObjectUnref(device);
|
|
|
|
data->error = true;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2019-10-20 11:49:46 +00:00
|
|
|
device->parentName = g_strdup(def->parent);
|
2017-06-29 19:50:06 +00:00
|
|
|
data->devices[data->ndevices] = device;
|
|
|
|
}
|
|
|
|
data->ndevices++;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectUnlock(obj);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-28 18:24:26 +00:00
|
|
|
int
|
|
|
|
virNodeDeviceObjListExport(virConnectPtr conn,
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjList *devs,
|
2017-02-28 18:24:26 +00:00
|
|
|
virNodeDevicePtr **devices,
|
2017-08-16 13:23:27 +00:00
|
|
|
virNodeDeviceObjListFilter filter,
|
2017-02-28 18:24:26 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
2018-08-13 15:55:14 +00:00
|
|
|
virNodeDeviceObjListExportData data = {
|
2017-08-16 13:23:27 +00:00
|
|
|
.conn = conn, .filter = filter, .flags = flags,
|
2017-06-29 19:50:06 +00:00
|
|
|
.devices = NULL, .ndevices = 0, .error = false };
|
|
|
|
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWLockRead(devs);
|
2020-10-07 19:15:50 +00:00
|
|
|
if (devices)
|
2020-10-12 17:45:37 +00:00
|
|
|
data.devices = g_new0(virNodeDevicePtr, virHashSize(devs->objs) + 1);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
virHashForEach(devs->objs, virNodeDeviceObjListExportCallback, &data);
|
2017-10-09 20:55:23 +00:00
|
|
|
virObjectRWUnlock(devs);
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
if (data.error)
|
|
|
|
goto cleanup;
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
if (data.devices) {
|
2021-03-19 23:37:05 +00:00
|
|
|
VIR_REALLOC_N(data.devices, data.ndevices + 1);
|
2017-06-29 19:50:06 +00:00
|
|
|
*devices = data.devices;
|
|
|
|
}
|
2017-02-28 18:24:26 +00:00
|
|
|
|
2017-06-29 19:50:06 +00:00
|
|
|
return data.ndevices;
|
2017-02-28 18:24:26 +00:00
|
|
|
|
|
|
|
cleanup:
|
2017-06-29 19:50:06 +00:00
|
|
|
virObjectListFree(data.devices);
|
|
|
|
return -1;
|
2017-02-28 18:24:26 +00:00
|
|
|
}
|
2018-02-23 23:09:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virNodeDeviceObjSetSkipUpdateCaps(virNodeDeviceObj *obj,
|
2018-02-23 23:09:20 +00:00
|
|
|
bool skipUpdateCaps)
|
|
|
|
{
|
|
|
|
obj->skipUpdateCaps = skipUpdateCaps;
|
|
|
|
}
|
2020-07-09 15:39:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
virNodeDeviceObjIsActive(virNodeDeviceObj *obj)
|
|
|
|
{
|
|
|
|
return obj->active;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virNodeDeviceObjSetActive(virNodeDeviceObj *obj,
|
|
|
|
bool active)
|
|
|
|
{
|
|
|
|
obj->active = active;
|
|
|
|
}
|
2021-01-15 22:41:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
virNodeDeviceObjIsPersistent(virNodeDeviceObj *obj)
|
|
|
|
{
|
|
|
|
return obj->persistent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj,
|
|
|
|
bool persistent)
|
|
|
|
{
|
|
|
|
obj->persistent = persistent;
|
|
|
|
}
|
2020-10-15 16:30:35 +00:00
|
|
|
|
|
|
|
|
2021-05-26 20:09:29 +00:00
|
|
|
bool
|
|
|
|
virNodeDeviceObjIsAutostart(virNodeDeviceObj *obj)
|
|
|
|
{
|
|
|
|
return obj->autostart;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
virNodeDeviceObjSetAutostart(virNodeDeviceObj *obj,
|
|
|
|
bool autostart)
|
|
|
|
{
|
|
|
|
obj->autostart = autostart;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-15 22:07:32 +00:00
|
|
|
typedef struct _PredicateHelperData PredicateHelperData;
|
|
|
|
struct _PredicateHelperData {
|
|
|
|
virNodeDeviceObjListPredicate predicate;
|
2020-10-15 16:30:35 +00:00
|
|
|
void *opaque;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int virNodeDeviceObjListRemoveHelper(void *key G_GNUC_UNUSED,
|
|
|
|
void *value,
|
|
|
|
void *opaque)
|
|
|
|
{
|
2021-07-15 22:07:32 +00:00
|
|
|
PredicateHelperData *data = opaque;
|
2020-10-15 16:30:35 +00:00
|
|
|
|
2021-07-15 22:07:32 +00:00
|
|
|
return data->predicate(value, data->opaque);
|
2020-10-15 16:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceObjListForEachRemove
|
|
|
|
* @devs: Pointer to object list
|
|
|
|
* @callback: function to call for each device object
|
|
|
|
* @opaque: Opaque data to use as argument to helper
|
|
|
|
*
|
|
|
|
* For each object in @devs, call the @callback helper using @opaque as
|
|
|
|
* an argument. If @callback returns true, that item will be removed from the
|
|
|
|
* object list.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs,
|
2021-07-15 22:07:32 +00:00
|
|
|
virNodeDeviceObjListPredicate callback,
|
2020-10-15 16:30:35 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
2021-07-15 22:07:32 +00:00
|
|
|
PredicateHelperData data = {
|
|
|
|
.predicate = callback,
|
2020-10-15 16:30:35 +00:00
|
|
|
.opaque = opaque
|
|
|
|
};
|
|
|
|
|
|
|
|
virObjectRWLockWrite(devs);
|
|
|
|
g_hash_table_foreach_remove(devs->objs,
|
|
|
|
virNodeDeviceObjListRemoveHelper,
|
|
|
|
&data);
|
|
|
|
virObjectRWUnlock(devs);
|
|
|
|
}
|
2021-07-15 22:07:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int virNodeDeviceObjListFindHelper(const void *payload,
|
|
|
|
const char *name G_GNUC_UNUSED,
|
|
|
|
const void *opaque)
|
|
|
|
{
|
|
|
|
PredicateHelperData *data = (PredicateHelperData *) opaque;
|
|
|
|
virNodeDeviceObj *obj = (virNodeDeviceObj *) payload;
|
|
|
|
|
|
|
|
return data->predicate(obj, data->opaque);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virNodeDeviceObjListFind
|
|
|
|
* @devs: Pointer to object list
|
|
|
|
* @predicate: function to test the device for a certain property
|
|
|
|
* @opaque: Opaque data to use as argument to helper
|
|
|
|
*
|
|
|
|
* For each object in @devs, call the @predicate helper using @opaque as
|
|
|
|
* an argument until it returns TRUE. The list may not be modified while
|
|
|
|
* iterating.
|
|
|
|
*/
|
|
|
|
virNodeDeviceObj *
|
|
|
|
virNodeDeviceObjListFind(virNodeDeviceObjList *devs,
|
|
|
|
virNodeDeviceObjListPredicate predicate,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
PredicateHelperData data = {
|
|
|
|
.predicate = predicate,
|
|
|
|
.opaque = opaque
|
|
|
|
};
|
|
|
|
|
|
|
|
return virNodeDeviceObjListSearch(devs,
|
|
|
|
virNodeDeviceObjListFindHelper,
|
|
|
|
&data);
|
|
|
|
}
|