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.
This commit is contained in:
Osier Yang 2013-01-08 01:05:28 +08:00
parent ab4b000188
commit 652a2ec630
6 changed files with 54 additions and 16 deletions

View File

@ -3256,6 +3256,8 @@ typedef enum {
VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET = 1 << 6, /* SCSI Target */ 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_SCSI = 1 << 7, /* SCSI device */
VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE = 1 << 8, /* Storage 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; } virConnectListAllNodeDeviceFlags;
int virConnectListAllNodeDevices (virConnectPtr conn, int virConnectListAllNodeDevices (virConnectPtr conn,

View File

@ -49,7 +49,9 @@ VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST,
"scsi_host", "scsi_host",
"scsi_target", "scsi_target",
"scsi", "scsi",
"storage") "storage",
"fc_host",
"vports")
VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST, VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST,
"80203", "80203",
@ -466,8 +468,10 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDefPtr def)
virBufferAddLit(&buf, virBufferAddLit(&buf,
" <capability type='hotpluggable' />\n"); " <capability type='hotpluggable' />\n");
break; break;
case VIR_NODE_DEV_CAP_FC_HOST:
case VIR_NODE_DEV_CAP_VPORTS:
case VIR_NODE_DEV_CAP_LAST: case VIR_NODE_DEV_CAP_LAST:
/* ignore special LAST value */ default:
break; break;
} }
@ -1408,7 +1412,10 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
VIR_FREE(data->storage.serial); VIR_FREE(data->storage.serial);
VIR_FREE(data->storage.media_label); VIR_FREE(data->storage.media_label);
break; break;
case VIR_NODE_DEV_CAP_FC_HOST:
case VIR_NODE_DEV_CAP_VPORTS:
case VIR_NODE_DEV_CAP_LAST: case VIR_NODE_DEV_CAP_LAST:
default:
/* This case is here to shutup the compiler */ /* This case is here to shutup the compiler */
break; break;
} }
@ -1436,6 +1443,18 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj,
for (cap = devobj->def->caps; cap; cap = cap->next) { for (cap = devobj->def->caps; cap; cap = cap->next) {
if (type == cap->type) if (type == cap->type)
return true; 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; return false;
@ -1465,7 +1484,11 @@ virNodeDeviceMatch(virNodeDeviceObjPtr devobj,
(MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI) && (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI) &&
virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_SCSI)) || virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_SCSI)) ||
(MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE) && (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; return false;
} }

View File

@ -46,6 +46,8 @@ enum virNodeDevCapType {
VIR_NODE_DEV_CAP_SCSI_TARGET, /* SCSI Target */ VIR_NODE_DEV_CAP_SCSI_TARGET, /* SCSI Target */
VIR_NODE_DEV_CAP_SCSI, /* SCSI device */ VIR_NODE_DEV_CAP_SCSI, /* SCSI device */
VIR_NODE_DEV_CAP_STORAGE, /* Storage 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 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_HOST | \
VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET | \ VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET | \
VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI | \ 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, int virNodeDeviceList(virConnectPtr conn,
virNodeDeviceObjList devobjs, virNodeDeviceObjList devobjs,

View File

@ -14253,6 +14253,8 @@ error:
* VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET * VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET
* VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI * 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
* *
* Returns the number of node devices found or -1 and sets @devices to NULL in * 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 * case of error. On success, the array stored into @devices is guaranteed to

View File

@ -447,6 +447,12 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
case VIR_NODE_DEV_CAP_STORAGE: case VIR_NODE_DEV_CAP_STORAGE:
flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE; flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE;
break; 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: default:
break; break;
} }

View File

@ -1998,9 +1998,10 @@ List all of the devices available on the node that are known by libvirt.
I<cap> is used to filter the list by capability types, the types must be I<cap> 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 separated by comma, e.g. --cap pci,scsi, valid capability types include
'system', 'pci', 'usb_device', 'usb', 'net', 'scsi_host', 'scsi_target', 'system', 'pci', 'usb_device', 'usb', 'net', 'scsi_host', 'scsi_target',
'scsi', 'storage'. If I<--tree> is used, the output is formatted in a tree 'scsi', 'storage', 'fc_host', 'vports'. If I<--tree> is used, the output
representing parents of each node. I<cap> and I<--tree> are mutually is formatted in a tree representing parents of each node. I<cap> and
exclusive. I<--tree> are mutually exclusive.
=item B<nodedev-reattach> I<nodedev> =item B<nodedev-reattach> I<nodedev>
Declare that I<nodedev> is no longer in use by any guests, and that Declare that I<nodedev> is no longer in use by any guests, and that