From 652a2ec63051f1c4570f49858db445b686abbb0e Mon Sep 17 00:00:00 2001 From: Osier Yang Date: Tue, 8 Jan 2013 01:05:28 +0800 Subject: [PATCH] nodedev: Introduce two new flags for listAll API VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST to filter the FC HBA, and VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS to filter the FC HBA which supports vport. --- include/libvirt/libvirt.h.in | 20 +++++++++++--------- src/conf/node_device_conf.c | 29 ++++++++++++++++++++++++++--- src/conf/node_device_conf.h | 6 +++++- src/libvirt.c | 2 ++ tools/virsh-nodedev.c | 6 ++++++ tools/virsh.pod | 7 ++++--- 6 files changed, 54 insertions(+), 16 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 45b56387a1..518f0fe5ec 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -3247,15 +3247,17 @@ int virNodeListDevices (virConnectPtr conn, * type. */ typedef enum { - VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM = 1 << 0, /* System capability */ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV = 1 << 1, /* PCI device */ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV = 1 << 2, /* USB device */ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE = 1 << 3, /* USB interface */ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET = 1 << 4, /* Network device */ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST = 1 << 5, /* SCSI Host Bus Adapter */ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET = 1 << 6, /* SCSI Target */ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI = 1 << 7, /* SCSI device */ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE = 1 << 8, /* Storage device */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM = 1 << 0, /* System capability */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV = 1 << 1, /* PCI device */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV = 1 << 2, /* USB device */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE = 1 << 3, /* USB interface */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET = 1 << 4, /* Network device */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST = 1 << 5, /* SCSI Host Bus Adapter */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET = 1 << 6, /* SCSI Target */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI = 1 << 7, /* SCSI device */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE = 1 << 8, /* Storage device */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST = 1 << 9, /* FC Host Bus Adapter */ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS = 1 << 10, /* Capable of vport */ } virConnectListAllNodeDeviceFlags; int virConnectListAllNodeDevices (virConnectPtr conn, diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index e7072981a4..f743b26b1b 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -49,7 +49,9 @@ VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST, "scsi_host", "scsi_target", "scsi", - "storage") + "storage", + "fc_host", + "vports") VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST, "80203", @@ -466,8 +468,10 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDefPtr def) virBufferAddLit(&buf, " \n"); break; + case VIR_NODE_DEV_CAP_FC_HOST: + case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_LAST: - /* ignore special LAST value */ + default: break; } @@ -1408,7 +1412,10 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps) VIR_FREE(data->storage.serial); VIR_FREE(data->storage.media_label); break; + case VIR_NODE_DEV_CAP_FC_HOST: + case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_LAST: + default: /* This case is here to shutup the compiler */ break; } @@ -1436,6 +1443,18 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, for (cap = devobj->def->caps; cap; cap = cap->next) { if (type == cap->type) return true; + + if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST) { + if (type == VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST && + (cap->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) + return true; + + if (type == VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS && + (cap->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)) + return true; + } } return false; @@ -1465,7 +1484,11 @@ virNodeDeviceMatch(virNodeDeviceObjPtr devobj, (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI) && virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_SCSI)) || (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE) && - virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_STORAGE)))) + virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_STORAGE)) || + (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST) && + virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_FC_HOST)) || + (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS) && + virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_VPORTS)))) return false; } diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index fb1267f987..2946026c40 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -46,6 +46,8 @@ enum virNodeDevCapType { VIR_NODE_DEV_CAP_SCSI_TARGET, /* SCSI Target */ VIR_NODE_DEV_CAP_SCSI, /* SCSI device */ VIR_NODE_DEV_CAP_STORAGE, /* Storage device */ + VIR_NODE_DEV_CAP_FC_HOST, /* FC Host Bus Adapter */ + VIR_NODE_DEV_CAP_VPORTS, /* HBA which is capable of vports */ VIR_NODE_DEV_CAP_LAST }; @@ -263,7 +265,9 @@ void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj); VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI | \ - VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE) + VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE | \ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST | \ + VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS) int virNodeDeviceList(virConnectPtr conn, virNodeDeviceObjList devobjs, diff --git a/src/libvirt.c b/src/libvirt.c index 02d5dd94a7..1624776be1 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -14253,6 +14253,8 @@ error: * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI * VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE + * VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST + * VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS * * Returns the number of node devices found or -1 and sets @devices to NULL in * case of error. On success, the array stored into @devices is guaranteed to diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 394208e4df..9c0bd90e93 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -447,6 +447,12 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) case VIR_NODE_DEV_CAP_STORAGE: flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE; break; + case VIR_NODE_DEV_CAP_FC_HOST: + flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST; + break; + case VIR_NODE_DEV_CAP_VPORTS: + flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS; + break; default: break; } diff --git a/tools/virsh.pod b/tools/virsh.pod index 07e7c24aba..e7e82e35d4 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1998,9 +1998,10 @@ List all of the devices available on the node that are known by libvirt. I is used to filter the list by capability types, the types must be separated by comma, e.g. --cap pci,scsi, valid capability types include 'system', 'pci', 'usb_device', 'usb', 'net', 'scsi_host', 'scsi_target', -'scsi', 'storage'. If I<--tree> is used, the output is formatted in a tree -representing parents of each node. I and I<--tree> are mutually -exclusive. +'scsi', 'storage', 'fc_host', 'vports'. If I<--tree> is used, the output +is formatted in a tree representing parents of each node. I and +I<--tree> are mutually exclusive. + =item B I Declare that I is no longer in use by any guests, and that -- GitLab