1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-12 13:17:58 +03:00

nodedev: Reduce virNodeDevCapDataPtr usage

Replace with more data specific pointer types.
This commit is contained in:
John Ferlan 2017-03-02 10:59:25 -05:00
parent a6c3382e8e
commit dec6d9df5f
6 changed files with 281 additions and 275 deletions

View File

@ -582,7 +582,7 @@ static int
virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt, virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data) virNodeDevCapDRMPtr drm)
{ {
xmlNodePtr orignode; xmlNodePtr orignode;
int ret = -1, val; int ret = -1, val;
@ -598,7 +598,7 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt,
_("unknown drm type '%s' for '%s'"), type, def->name); _("unknown drm type '%s' for '%s'"), type, def->name);
goto out; goto out;
} }
data->drm.type = val; drm->type = val;
ret = 0; ret = 0;
@ -613,7 +613,7 @@ static int
virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt, virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data) virNodeDevCapStoragePtr storage)
{ {
xmlNodePtr orignode, *nodes = NULL; xmlNodePtr orignode, *nodes = NULL;
size_t i; size_t i;
@ -623,19 +623,19 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
orignode = ctxt->node; orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
data->storage.block = virXPathString("string(./block[1])", ctxt); storage->block = virXPathString("string(./block[1])", ctxt);
if (!data->storage.block) { if (!storage->block) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("no block device path supplied for '%s'"), _("no block device path supplied for '%s'"),
def->name); def->name);
goto out; goto out;
} }
data->storage.bus = virXPathString("string(./bus[1])", ctxt); storage->bus = virXPathString("string(./bus[1])", ctxt);
data->storage.drive_type = virXPathString("string(./drive_type[1])", ctxt); storage->drive_type = virXPathString("string(./drive_type[1])", ctxt);
data->storage.model = virXPathString("string(./model[1])", ctxt); storage->model = virXPathString("string(./model[1])", ctxt);
data->storage.vendor = virXPathString("string(./vendor[1])", ctxt); storage->vendor = virXPathString("string(./vendor[1])", ctxt);
data->storage.serial = virXPathString("string(./serial[1])", ctxt); storage->serial = virXPathString("string(./serial[1])", ctxt);
if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0)
goto out; goto out;
@ -651,19 +651,19 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
} }
if (STREQ(type, "hotpluggable")) { if (STREQ(type, "hotpluggable")) {
data->storage.flags |= VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE; storage->flags |= VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE;
} else if (STREQ(type, "removable")) { } else if (STREQ(type, "removable")) {
xmlNodePtr orignode2; xmlNodePtr orignode2;
data->storage.flags |= VIR_NODE_DEV_CAP_STORAGE_REMOVABLE; storage->flags |= VIR_NODE_DEV_CAP_STORAGE_REMOVABLE;
orignode2 = ctxt->node; orignode2 = ctxt->node;
ctxt->node = nodes[i]; ctxt->node = nodes[i];
if (virXPathBoolean("count(./media_available[. = '1']) > 0", ctxt)) if (virXPathBoolean("count(./media_available[. = '1']) > 0", ctxt))
data->storage.flags |= VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE; storage->flags |= VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE;
data->storage.media_label = virXPathString("string(./media_label[1])", ctxt); storage->media_label = virXPathString("string(./media_label[1])", ctxt);
val = 0; val = 0;
if (virNodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def, if (virNodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def,
@ -673,7 +673,7 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
VIR_FREE(type); VIR_FREE(type);
goto out; goto out;
} }
data->storage.removable_media_size = val; storage->removable_media_size = val;
ctxt->node = orignode2; ctxt->node = orignode2;
} else { } else {
@ -687,13 +687,13 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
VIR_FREE(type); VIR_FREE(type);
} }
if (!(data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) { if (!(storage->flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) {
val = 0; val = 0;
if (virNodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def, if (virNodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def,
_("no size supplied for '%s'"), _("no size supplied for '%s'"),
_("invalid size supplied for '%s'")) < 0) _("invalid size supplied for '%s'")) < 0)
goto out; goto out;
data->storage.size = val; storage->size = val;
} }
ret = 0; ret = 0;
@ -708,7 +708,7 @@ static int
virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt, virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data) virNodeDevCapSCSIPtr scsi)
{ {
xmlNodePtr orignode; xmlNodePtr orignode;
int ret = -1; int ret = -1;
@ -717,30 +717,30 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt,
ctxt->node = node; ctxt->node = node;
if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt,
&data->scsi.host, def, &scsi->host, def,
_("no SCSI host ID supplied for '%s'"), _("no SCSI host ID supplied for '%s'"),
_("invalid SCSI host ID supplied for '%s'")) < 0) _("invalid SCSI host ID supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt,
&data->scsi.bus, def, &scsi->bus, def,
_("no SCSI bus ID supplied for '%s'"), _("no SCSI bus ID supplied for '%s'"),
_("invalid SCSI bus ID supplied for '%s'")) < 0) _("invalid SCSI bus ID supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseULong("number(./target[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./target[1])", ctxt,
&data->scsi.target, def, &scsi->target, def,
_("no SCSI target ID supplied for '%s'"), _("no SCSI target ID supplied for '%s'"),
_("invalid SCSI target ID supplied for '%s'")) < 0) _("invalid SCSI target ID supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseULong("number(./lun[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./lun[1])", ctxt,
&data->scsi.lun, def, &scsi->lun, def,
_("no SCSI LUN ID supplied for '%s'"), _("no SCSI LUN ID supplied for '%s'"),
_("invalid SCSI LUN ID supplied for '%s'")) < 0) _("invalid SCSI LUN ID supplied for '%s'")) < 0)
goto out; goto out;
data->scsi.type = virXPathString("string(./type[1])", ctxt); scsi->type = virXPathString("string(./type[1])", ctxt);
ret = 0; ret = 0;
out: out:
@ -753,7 +753,7 @@ static int
virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt, virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data) virNodeDevCapSCSITargetPtr scsi_target)
{ {
xmlNodePtr orignode; xmlNodePtr orignode;
int ret = -1; int ret = -1;
@ -761,8 +761,8 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt,
orignode = ctxt->node; orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
data->scsi_target.name = virXPathString("string(./target[1])", ctxt); scsi_target->name = virXPathString("string(./target[1])", ctxt);
if (!data->scsi_target.name) { if (!scsi_target->name) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("no target name supplied for '%s'"), _("no target name supplied for '%s'"),
def->name); def->name);
@ -781,7 +781,7 @@ static int
virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt, virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data, virNodeDevCapSCSIHostPtr scsi_host,
int create, int create,
const char *virt_type) const char *virt_type)
{ {
@ -795,15 +795,15 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
if (create == EXISTING_DEVICE) { if (create == EXISTING_DEVICE) {
if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt,
&data->scsi_host.host, def, &scsi_host->host, def,
_("no SCSI host ID supplied for '%s'"), _("no SCSI host ID supplied for '%s'"),
_("invalid SCSI host ID supplied for '%s'")) < 0) { _("invalid SCSI host ID supplied for '%s'")) < 0) {
goto out; goto out;
} }
/* Optional unique_id value */ /* Optional unique_id value */
data->scsi_host.unique_id = -1; scsi_host->unique_id = -1;
if (virNodeDevCapsDefParseIntOptional("number(./unique_id[1])", ctxt, if (virNodeDevCapsDefParseIntOptional("number(./unique_id[1])", ctxt,
&data->scsi_host.unique_id, def, &scsi_host->unique_id, def,
_("invalid unique_id supplied for '%s'")) < 0) { _("invalid unique_id supplied for '%s'")) < 0) {
goto out; goto out;
} }
@ -824,21 +824,21 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
if (STREQ(type, "vport_ops")) { if (STREQ(type, "vport_ops")) {
data->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
} else if (STREQ(type, "fc_host")) { } else if (STREQ(type, "fc_host")) {
xmlNodePtr orignode2; xmlNodePtr orignode2;
data->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST; scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
orignode2 = ctxt->node; orignode2 = ctxt->node;
ctxt->node = nodes[i]; ctxt->node = nodes[i];
if (virNodeDevCapsDefParseString("string(./wwnn[1])", if (virNodeDevCapsDefParseString("string(./wwnn[1])",
ctxt, ctxt,
&data->scsi_host.wwnn) < 0) { &scsi_host->wwnn) < 0) {
if (virRandomGenerateWWN(&data->scsi_host.wwnn, virt_type) < 0) { if (virRandomGenerateWWN(&scsi_host->wwnn, virt_type) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("no WWNN supplied for '%s', and " _("no WWNN supplied for '%s', and "
"auto-generation failed"), "auto-generation failed"),
@ -849,8 +849,8 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
if (virNodeDevCapsDefParseString("string(./wwpn[1])", if (virNodeDevCapsDefParseString("string(./wwpn[1])",
ctxt, ctxt,
&data->scsi_host.wwpn) < 0) { &scsi_host->wwpn) < 0) {
if (virRandomGenerateWWN(&data->scsi_host.wwpn, virt_type) < 0) { if (virRandomGenerateWWN(&scsi_host->wwpn, virt_type) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("no WWPN supplied for '%s', and " _("no WWPN supplied for '%s', and "
"auto-generation failed"), "auto-generation failed"),
@ -861,7 +861,7 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
if (virNodeDevCapsDefParseString("string(./fabric_wwn[1])", if (virNodeDevCapsDefParseString("string(./fabric_wwn[1])",
ctxt, ctxt,
&data->scsi_host.fabric_wwn) < 0) &scsi_host->fabric_wwn) < 0)
VIR_DEBUG("No fabric_wwn defined for '%s'", def->name); VIR_DEBUG("No fabric_wwn defined for '%s'", def->name);
ctxt->node = orignode2; ctxt->node = orignode2;
@ -890,7 +890,7 @@ static int
virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data) virNodeDevCapNetPtr net)
{ {
xmlNodePtr orignode, lnk; xmlNodePtr orignode, lnk;
size_t i = -1; size_t i = -1;
@ -901,21 +901,21 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
orignode = ctxt->node; orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
data->net.ifname = virXPathString("string(./interface[1])", ctxt); net->ifname = virXPathString("string(./interface[1])", ctxt);
if (!data->net.ifname) { if (!net->ifname) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("no network interface supplied for '%s'"), _("no network interface supplied for '%s'"),
def->name); def->name);
goto out; goto out;
} }
data->net.address = virXPathString("string(./address[1])", ctxt); net->address = virXPathString("string(./address[1])", ctxt);
if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./feature", ctxt, &nodes)) < 0)
goto out; goto out;
if (n > 0) { if (n > 0) {
if (!(data->net.features = virBitmapNew(VIR_NET_DEV_FEAT_LAST))) if (!(net->features = virBitmapNew(VIR_NET_DEV_FEAT_LAST)))
goto out; goto out;
} }
@ -933,11 +933,11 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
tmp); tmp);
goto out; goto out;
} }
ignore_value(virBitmapSetBit(data->net.features, val)); ignore_value(virBitmapSetBit(net->features, val));
VIR_FREE(tmp); VIR_FREE(tmp);
} }
data->net.subtype = VIR_NODE_DEV_CAP_NET_LAST; net->subtype = VIR_NODE_DEV_CAP_NET_LAST;
tmp = virXPathString("string(./capability/@type)", ctxt); tmp = virXPathString("string(./capability/@type)", ctxt);
if (tmp) { if (tmp) {
@ -949,11 +949,11 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
def->name); def->name);
goto out; goto out;
} }
data->net.subtype = val; net->subtype = val;
} }
lnk = virXPathNode("./link", ctxt); lnk = virXPathNode("./link", ctxt);
if (lnk && virInterfaceLinkParseXML(lnk, &data->net.lnk) < 0) if (lnk && virInterfaceLinkParseXML(lnk, &net->lnk) < 0)
goto out; goto out;
ret = 0; ret = 0;
@ -969,7 +969,7 @@ static int
virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt, virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data) virNodeDevCapUSBIfPtr usb_if)
{ {
xmlNodePtr orignode; xmlNodePtr orignode;
int ret = -1; int ret = -1;
@ -978,30 +978,30 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt,
ctxt->node = node; ctxt->node = node;
if (virNodeDevCapsDefParseULong("number(./number[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./number[1])", ctxt,
&data->usb_if.number, def, &usb_if->number, def,
_("no USB interface number supplied for '%s'"), _("no USB interface number supplied for '%s'"),
_("invalid USB interface number supplied for '%s'")) < 0) _("invalid USB interface number supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseULong("number(./class[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./class[1])", ctxt,
&data->usb_if._class, def, &usb_if->_class, def,
_("no USB interface class supplied for '%s'"), _("no USB interface class supplied for '%s'"),
_("invalid USB interface class supplied for '%s'")) < 0) _("invalid USB interface class supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseULong("number(./subclass[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./subclass[1])", ctxt,
&data->usb_if.subclass, def, &usb_if->subclass, def,
_("no USB interface subclass supplied for '%s'"), _("no USB interface subclass supplied for '%s'"),
_("invalid USB interface subclass supplied for '%s'")) < 0) _("invalid USB interface subclass supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseULong("number(./protocol[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./protocol[1])", ctxt,
&data->usb_if.protocol, def, &usb_if->protocol, def,
_("no USB interface protocol supplied for '%s'"), _("no USB interface protocol supplied for '%s'"),
_("invalid USB interface protocol supplied for '%s'")) < 0) _("invalid USB interface protocol supplied for '%s'")) < 0)
goto out; goto out;
data->usb_if.description = virXPathString("string(./description[1])", ctxt); usb_if->description = virXPathString("string(./description[1])", ctxt);
ret = 0; ret = 0;
out: out:
@ -1038,7 +1038,7 @@ static int
virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt, virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data) virNodeDevCapUSBDevPtr usb_dev)
{ {
xmlNodePtr orignode; xmlNodePtr orignode;
int ret = -1; int ret = -1;
@ -1047,31 +1047,31 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt,
ctxt->node = node; ctxt->node = node;
if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt,
&data->usb_dev.bus, def, &usb_dev->bus, def,
_("no USB bus number supplied for '%s'"), _("no USB bus number supplied for '%s'"),
_("invalid USB bus number supplied for '%s'")) < 0) _("invalid USB bus number supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseULong("number(./device[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./device[1])", ctxt,
&data->usb_dev.device, def, &usb_dev->device, def,
_("no USB device number supplied for '%s'"), _("no USB device number supplied for '%s'"),
_("invalid USB device number supplied for '%s'")) < 0) _("invalid USB device number supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt,
&data->usb_dev.vendor, def, &usb_dev->vendor, def,
_("no USB vendor ID supplied for '%s'"), _("no USB vendor ID supplied for '%s'"),
_("invalid USB vendor ID supplied for '%s'")) < 0) _("invalid USB vendor ID supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt,
&data->usb_dev.product, def, &usb_dev->product, def,
_("no USB product ID supplied for '%s'"), _("no USB product ID supplied for '%s'"),
_("invalid USB product ID supplied for '%s'")) < 0) _("invalid USB product ID supplied for '%s'")) < 0)
goto out; goto out;
data->usb_dev.vendor_name = virXPathString("string(./vendor[1])", ctxt); usb_dev->vendor_name = virXPathString("string(./vendor[1])", ctxt);
data->usb_dev.product_name = virXPathString("string(./product[1])", ctxt); usb_dev->product_name = virXPathString("string(./product[1])", ctxt);
ret = 0; ret = 0;
out: out:
@ -1083,7 +1083,7 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt,
static int static int
virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt, virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr iommuGroupNode, xmlNodePtr iommuGroupNode,
virNodeDevCapDataPtr data) virNodeDevCapPCIDevPtr pci_dev)
{ {
xmlNodePtr origNode = ctxt->node; xmlNodePtr origNode = ctxt->node;
xmlNodePtr *addrNodes = NULL; xmlNodePtr *addrNodes = NULL;
@ -1101,7 +1101,7 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt,
goto cleanup; goto cleanup;
} }
if (virStrToLong_ui(numberStr, NULL, 10, if (virStrToLong_ui(numberStr, NULL, 10,
&data->pci_dev.iommuGroupNumber) < 0) { &pci_dev->iommuGroupNumber) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("invalid iommuGroup number attribute '%s'"), _("invalid iommuGroup number attribute '%s'"),
numberStr); numberStr);
@ -1121,8 +1121,8 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt,
pciAddr->bus = addr.bus; pciAddr->bus = addr.bus;
pciAddr->slot = addr.slot; pciAddr->slot = addr.slot;
pciAddr->function = addr.function; pciAddr->function = addr.function;
if (VIR_APPEND_ELEMENT(data->pci_dev.iommuGroupDevices, if (VIR_APPEND_ELEMENT(pci_dev->iommuGroupDevices,
data->pci_dev.nIommuGroupDevices, pci_dev->nIommuGroupDevices,
pciAddr) < 0) pciAddr) < 0)
goto cleanup; goto cleanup;
} }
@ -1222,7 +1222,7 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt,
static int static int
virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt, virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data) virNodeDevCapPCIDevPtr pci_dev)
{ {
char *maxFuncsStr = virXMLPropString(node, "maxCount"); char *maxFuncsStr = virXMLPropString(node, "maxCount");
char *type = virXMLPropString(node, "type"); char *type = virXMLPropString(node, "type");
@ -1241,7 +1241,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
if (STREQ(type, "phys_function")) { if (STREQ(type, "phys_function")) {
xmlNodePtr address = virXPathNode("./address[1]", ctxt); xmlNodePtr address = virXPathNode("./address[1]", ctxt);
if (VIR_ALLOC(data->pci_dev.physical_function) < 0) if (VIR_ALLOC(pci_dev->physical_function) < 0)
goto out; goto out;
if (!address) { if (!address) {
@ -1251,10 +1251,10 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
} }
if (virPCIDeviceAddressParseXML(address, if (virPCIDeviceAddressParseXML(address,
data->pci_dev.physical_function) < 0) pci_dev->physical_function) < 0)
goto out; goto out;
data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
} else if (STREQ(type, "virt_functions")) { } else if (STREQ(type, "virt_functions")) {
int naddresses; int naddresses;
@ -1263,13 +1263,13 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
if (maxFuncsStr && if (maxFuncsStr &&
virStrToLong_uip(maxFuncsStr, NULL, 10, virStrToLong_uip(maxFuncsStr, NULL, 10,
&data->pci_dev.max_virtual_functions) < 0) { &pci_dev->max_virtual_functions) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("Malformed 'maxCount' parameter")); _("Malformed 'maxCount' parameter"));
goto out; goto out;
} }
if (VIR_ALLOC_N(data->pci_dev.virtual_functions, naddresses) < 0) if (VIR_ALLOC_N(pci_dev->virtual_functions, naddresses) < 0)
goto out; goto out;
for (i = 0; i < naddresses; i++) { for (i = 0; i < naddresses; i++) {
@ -1283,18 +1283,18 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
goto out; goto out;
} }
if (VIR_APPEND_ELEMENT(data->pci_dev.virtual_functions, if (VIR_APPEND_ELEMENT(pci_dev->virtual_functions,
data->pci_dev.num_virtual_functions, pci_dev->num_virtual_functions,
addr) < 0) addr) < 0)
goto out; goto out;
} }
data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
} else { } else {
int hdrType = virPCIHeaderTypeFromString(type); int hdrType = virPCIHeaderTypeFromString(type);
if (hdrType > 0 && !data->pci_dev.hdrType) if (hdrType > 0 && !pci_dev->hdrType)
data->pci_dev.hdrType = hdrType; pci_dev->hdrType = hdrType;
} }
ret = 0; ret = 0;
@ -1311,7 +1311,7 @@ static int
virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt, virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data) virNodeDevCapPCIDevPtr pci_dev)
{ {
xmlNodePtr orignode, iommuGroupNode, pciExpress; xmlNodePtr orignode, iommuGroupNode, pciExpress;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
@ -1325,64 +1325,64 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt,
ctxt->node = node; ctxt->node = node;
if (virNodeDevCapsDefParseULong("number(./domain[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./domain[1])", ctxt,
&data->pci_dev.domain, def, &pci_dev->domain, def,
_("no PCI domain ID supplied for '%s'"), _("no PCI domain ID supplied for '%s'"),
_("invalid PCI domain ID supplied for '%s'")) < 0) _("invalid PCI domain ID supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt,
&data->pci_dev.bus, def, &pci_dev->bus, def,
_("no PCI bus ID supplied for '%s'"), _("no PCI bus ID supplied for '%s'"),
_("invalid PCI bus ID supplied for '%s'")) < 0) _("invalid PCI bus ID supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseULong("number(./slot[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./slot[1])", ctxt,
&data->pci_dev.slot, def, &pci_dev->slot, def,
_("no PCI slot ID supplied for '%s'"), _("no PCI slot ID supplied for '%s'"),
_("invalid PCI slot ID supplied for '%s'")) < 0) _("invalid PCI slot ID supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseULong("number(./function[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./function[1])", ctxt,
&data->pci_dev.function, def, &pci_dev->function, def,
_("no PCI function ID supplied for '%s'"), _("no PCI function ID supplied for '%s'"),
_("invalid PCI function ID supplied for '%s'")) < 0) _("invalid PCI function ID supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt, if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt,
&data->pci_dev.vendor, def, &pci_dev->vendor, def,
_("no PCI vendor ID supplied for '%s'"), _("no PCI vendor ID supplied for '%s'"),
_("invalid PCI vendor ID supplied for '%s'")) < 0) _("invalid PCI vendor ID supplied for '%s'")) < 0)
goto out; goto out;
if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt, if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt,
&data->pci_dev.product, def, &pci_dev->product, def,
_("no PCI product ID supplied for '%s'"), _("no PCI product ID supplied for '%s'"),
_("invalid PCI product ID supplied for '%s'")) < 0) _("invalid PCI product ID supplied for '%s'")) < 0)
goto out; goto out;
data->pci_dev.vendor_name = virXPathString("string(./vendor[1])", ctxt); pci_dev->vendor_name = virXPathString("string(./vendor[1])", ctxt);
data->pci_dev.product_name = virXPathString("string(./product[1])", ctxt); pci_dev->product_name = virXPathString("string(./product[1])", ctxt);
if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0)
goto out; goto out;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (virNodeDevPCICapabilityParseXML(ctxt, nodes[i], data) < 0) if (virNodeDevPCICapabilityParseXML(ctxt, nodes[i], pci_dev) < 0)
goto out; goto out;
} }
VIR_FREE(nodes); VIR_FREE(nodes);
if ((iommuGroupNode = virXPathNode("./iommuGroup[1]", ctxt))) { if ((iommuGroupNode = virXPathNode("./iommuGroup[1]", ctxt))) {
if (virNodeDevCapPCIDevIommuGroupParseXML(ctxt, iommuGroupNode, if (virNodeDevCapPCIDevIommuGroupParseXML(ctxt, iommuGroupNode,
data) < 0) { pci_dev) < 0) {
goto out; goto out;
} }
} }
/* The default value is -1 since zero is valid NUMA node number */ /* The default value is -1 since zero is valid NUMA node number */
data->pci_dev.numa_node = -1; pci_dev->numa_node = -1;
if (virNodeDevCapsDefParseIntOptional("number(./numa[1]/@node)", ctxt, if (virNodeDevCapsDefParseIntOptional("number(./numa[1]/@node)", ctxt,
&data->pci_dev.numa_node, def, &pci_dev->numa_node, def,
_("invalid NUMA node ID supplied for '%s'")) < 0) _("invalid NUMA node ID supplied for '%s'")) < 0)
goto out; goto out;
@ -1393,9 +1393,9 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt,
if (virPCIEDeviceInfoParseXML(ctxt, pciExpress, pci_express) < 0) if (virPCIEDeviceInfoParseXML(ctxt, pciExpress, pci_express) < 0)
goto out; goto out;
data->pci_dev.pci_express = pci_express; pci_dev->pci_express = pci_express;
pci_express = NULL; pci_express = NULL;
data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCIE; pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCIE;
} }
ret = 0; ret = 0;
@ -1412,8 +1412,10 @@ static int
virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt, virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDataPtr data) virNodeDevCapSystemPtr system)
{ {
virNodeDevCapSystemHardwarePtr hardware = &system->hardware;
virNodeDevCapSystemFirmwarePtr firmware = &system->firmware;
xmlNodePtr orignode; xmlNodePtr orignode;
int ret = -1; int ret = -1;
char *tmp; char *tmp;
@ -1421,11 +1423,11 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt,
orignode = ctxt->node; orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
data->system.product_name = virXPathString("string(./product[1])", ctxt); system->product_name = virXPathString("string(./product[1])", ctxt);
data->system.hardware.vendor_name = virXPathString("string(./hardware/vendor[1])", ctxt); hardware->vendor_name = virXPathString("string(./hardware/vendor[1])", ctxt);
data->system.hardware.version = virXPathString("string(./hardware/version[1])", ctxt); hardware->version = virXPathString("string(./hardware/version[1])", ctxt);
data->system.hardware.serial = virXPathString("string(./hardware/serial[1])", ctxt); hardware->serial = virXPathString("string(./hardware/serial[1])", ctxt);
tmp = virXPathString("string(./hardware/uuid[1])", ctxt); tmp = virXPathString("string(./hardware/uuid[1])", ctxt);
if (!tmp) { if (!tmp) {
@ -1434,7 +1436,7 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt,
goto out; goto out;
} }
if (virUUIDParse(tmp, data->system.hardware.uuid) < 0) { if (virUUIDParse(tmp, hardware->uuid) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("malformed uuid element for '%s'"), def->name); _("malformed uuid element for '%s'"), def->name);
VIR_FREE(tmp); VIR_FREE(tmp);
@ -1442,9 +1444,9 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt,
} }
VIR_FREE(tmp); VIR_FREE(tmp);
data->system.firmware.vendor_name = virXPathString("string(./firmware/vendor[1])", ctxt); firmware->vendor_name = virXPathString("string(./firmware/vendor[1])", ctxt);
data->system.firmware.version = virXPathString("string(./firmware/version[1])", ctxt); firmware->version = virXPathString("string(./firmware/version[1])", ctxt);
data->system.firmware.release_date = virXPathString("string(./firmware/release_date[1])", ctxt); firmware->release_date = virXPathString("string(./firmware/release_date[1])", ctxt);
ret = 0; ret = 0;
out: out:
@ -1485,37 +1487,40 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt,
switch (caps->data.type) { switch (caps->data.type) {
case VIR_NODE_DEV_CAP_SYSTEM: case VIR_NODE_DEV_CAP_SYSTEM:
ret = virNodeDevCapSystemParseXML(ctxt, def, node, &caps->data); ret = virNodeDevCapSystemParseXML(ctxt, def, node, &caps->data.system);
break; break;
case VIR_NODE_DEV_CAP_PCI_DEV: case VIR_NODE_DEV_CAP_PCI_DEV:
ret = virNodeDevCapPCIDevParseXML(ctxt, def, node, &caps->data); ret = virNodeDevCapPCIDevParseXML(ctxt, def, node, &caps->data.pci_dev);
break; break;
case VIR_NODE_DEV_CAP_USB_DEV: case VIR_NODE_DEV_CAP_USB_DEV:
ret = virNodeDevCapUSBDevParseXML(ctxt, def, node, &caps->data); ret = virNodeDevCapUSBDevParseXML(ctxt, def, node, &caps->data.usb_dev);
break; break;
case VIR_NODE_DEV_CAP_USB_INTERFACE: case VIR_NODE_DEV_CAP_USB_INTERFACE:
ret = virNodeDevCapUSBInterfaceParseXML(ctxt, def, node, &caps->data); ret = virNodeDevCapUSBInterfaceParseXML(ctxt, def, node,
&caps->data.usb_if);
break; break;
case VIR_NODE_DEV_CAP_NET: case VIR_NODE_DEV_CAP_NET:
ret = virNodeDevCapNetParseXML(ctxt, def, node, &caps->data); ret = virNodeDevCapNetParseXML(ctxt, def, node, &caps->data.net);
break; break;
case VIR_NODE_DEV_CAP_SCSI_HOST: case VIR_NODE_DEV_CAP_SCSI_HOST:
ret = virNodeDevCapSCSIHostParseXML(ctxt, def, node, ret = virNodeDevCapSCSIHostParseXML(ctxt, def, node,
&caps->data, &caps->data.scsi_host,
create, create,
virt_type); virt_type);
break; break;
case VIR_NODE_DEV_CAP_SCSI_TARGET: case VIR_NODE_DEV_CAP_SCSI_TARGET:
ret = virNodeDevCapSCSITargetParseXML(ctxt, def, node, &caps->data); ret = virNodeDevCapSCSITargetParseXML(ctxt, def, node,
&caps->data.scsi_target);
break; break;
case VIR_NODE_DEV_CAP_SCSI: case VIR_NODE_DEV_CAP_SCSI:
ret = virNodeDevCapSCSIParseXML(ctxt, def, node, &caps->data); ret = virNodeDevCapSCSIParseXML(ctxt, def, node, &caps->data.scsi);
break; break;
case VIR_NODE_DEV_CAP_STORAGE: case VIR_NODE_DEV_CAP_STORAGE:
ret = virNodeDevCapStorageParseXML(ctxt, def, node, &caps->data); ret = virNodeDevCapStorageParseXML(ctxt, def, node,
&caps->data.storage);
break; break;
case VIR_NODE_DEV_CAP_DRM: case VIR_NODE_DEV_CAP_DRM:
ret = virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data); ret = virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data.drm);
break; break;
case VIR_NODE_DEV_CAP_FC_HOST: case VIR_NODE_DEV_CAP_FC_HOST:
case VIR_NODE_DEV_CAP_VPORTS: case VIR_NODE_DEV_CAP_VPORTS:

View File

@ -54,7 +54,7 @@ static int update_caps(virNodeDeviceObjPtr dev)
while (cap) { while (cap) {
switch (cap->data.type) { switch (cap->data.type) {
case VIR_NODE_DEV_CAP_SCSI_HOST: case VIR_NODE_DEV_CAP_SCSI_HOST:
nodeDeviceSysfsGetSCSIHostCaps(&dev->def->caps->data); nodeDeviceSysfsGetSCSIHostCaps(&dev->def->caps->data.scsi_host);
break; break;
case VIR_NODE_DEV_CAP_NET: case VIR_NODE_DEV_CAP_NET:
if (virNetDevGetLinkInfo(cap->data.net.ifname, &cap->data.net.lnk) < 0) if (virNetDevGetLinkInfo(cap->data.net.ifname, &cap->data.net.lnk) < 0)
@ -65,7 +65,7 @@ static int update_caps(virNodeDeviceObjPtr dev)
break; break;
case VIR_NODE_DEV_CAP_PCI_DEV: case VIR_NODE_DEV_CAP_PCI_DEV:
if (nodeDeviceSysfsGetPCIRelatedDevCaps(dev->def->sysfs_path, if (nodeDeviceSysfsGetPCIRelatedDevCaps(dev->def->sysfs_path,
&dev->def->caps->data) < 0) &dev->def->caps->data.pci_dev) < 0)
return -1; return -1;
break; break;
@ -297,7 +297,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
while (cap) { while (cap) {
if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) { if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
nodeDeviceSysfsGetSCSIHostCaps(&cap->data); nodeDeviceSysfsGetSCSIHostCaps(&cap->data.scsi_host);
if (cap->data.scsi_host.flags & if (cap->data.scsi_host.flags &
VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
if (STREQ(cap->data.scsi_host.wwnn, wwnn) && if (STREQ(cap->data.scsi_host.wwnn, wwnn) &&

View File

@ -153,7 +153,7 @@ gather_pci_cap(LibHalContext *ctx, const char *udi,
ignore_value(virStrToLong_ui(p+1, &p, 16, &d->pci_dev.function)); ignore_value(virStrToLong_ui(p+1, &p, 16, &d->pci_dev.function));
} }
if (nodeDeviceSysfsGetPCIRelatedDevCaps(sysfs_path, d) < 0) { if (nodeDeviceSysfsGetPCIRelatedDevCaps(sysfs_path, &d->pci_dev) < 0) {
VIR_FREE(sysfs_path); VIR_FREE(sysfs_path);
return -1; return -1;
} }
@ -239,7 +239,7 @@ gather_scsi_host_cap(LibHalContext *ctx, const char *udi,
(void)get_int_prop(ctx, udi, "scsi_host.host", (int *)&d->scsi_host.host); (void)get_int_prop(ctx, udi, "scsi_host.host", (int *)&d->scsi_host.host);
retval = nodeDeviceSysfsGetSCSIHostCaps(d); retval = nodeDeviceSysfsGetSCSIHostCaps(&d->scsi_host);
if (retval == -1) if (retval == -1)
goto out; goto out;

View File

@ -44,65 +44,65 @@
VIR_LOG_INIT("node_device.node_device_linux_sysfs"); VIR_LOG_INIT("node_device.node_device_linux_sysfs");
int int
nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d) nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host)
{ {
char *tmp = NULL; char *tmp = NULL;
int ret = -1; int ret = -1;
if ((d->scsi_host.unique_id = if ((scsi_host->unique_id =
virSCSIHostGetUniqueId(NULL, d->scsi_host.host)) < 0) { virSCSIHostGetUniqueId(NULL, scsi_host->host)) < 0) {
VIR_DEBUG("Failed to read unique_id for host%d", d->scsi_host.host); VIR_DEBUG("Failed to read unique_id for host%d", scsi_host->host);
d->scsi_host.unique_id = -1; scsi_host->unique_id = -1;
} }
VIR_DEBUG("Checking if host%d is an FC HBA", d->scsi_host.host); VIR_DEBUG("Checking if host%d is an FC HBA", scsi_host->host);
if (virVHBAPathExists(NULL, d->scsi_host.host)) { if (virVHBAPathExists(NULL, scsi_host->host)) {
d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST; scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
if (!(tmp = virVHBAGetConfig(NULL, d->scsi_host.host, "port_name"))) { if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host, "port_name"))) {
VIR_WARN("Failed to read WWPN for host%d", d->scsi_host.host); VIR_WARN("Failed to read WWPN for host%d", scsi_host->host);
goto cleanup; goto cleanup;
} }
VIR_FREE(d->scsi_host.wwpn); VIR_FREE(scsi_host->wwpn);
VIR_STEAL_PTR(d->scsi_host.wwpn, tmp); VIR_STEAL_PTR(scsi_host->wwpn, tmp);
if (!(tmp = virVHBAGetConfig(NULL, d->scsi_host.host, "node_name"))) { if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host, "node_name"))) {
VIR_WARN("Failed to read WWNN for host%d", d->scsi_host.host); VIR_WARN("Failed to read WWNN for host%d", scsi_host->host);
goto cleanup; goto cleanup;
} }
VIR_FREE(d->scsi_host.wwnn); VIR_FREE(scsi_host->wwnn);
VIR_STEAL_PTR(d->scsi_host.wwnn, tmp); VIR_STEAL_PTR(scsi_host->wwnn, tmp);
if ((tmp = virVHBAGetConfig(NULL, d->scsi_host.host, "fabric_name"))) { if ((tmp = virVHBAGetConfig(NULL, scsi_host->host, "fabric_name"))) {
VIR_FREE(d->scsi_host.fabric_wwn); VIR_FREE(scsi_host->fabric_wwn);
VIR_STEAL_PTR(d->scsi_host.fabric_wwn, tmp); VIR_STEAL_PTR(scsi_host->fabric_wwn, tmp);
} }
} }
if (virVHBAIsVportCapable(NULL, d->scsi_host.host)) { if (virVHBAIsVportCapable(NULL, scsi_host->host)) {
d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
if (!(tmp = virVHBAGetConfig(NULL, d->scsi_host.host, if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
"max_npiv_vports"))) { "max_npiv_vports"))) {
VIR_WARN("Failed to read max_npiv_vports for host%d", VIR_WARN("Failed to read max_npiv_vports for host%d",
d->scsi_host.host); scsi_host->host);
goto cleanup; goto cleanup;
} }
if (virStrToLong_i(tmp, NULL, 10, &d->scsi_host.max_vports) < 0) { if (virStrToLong_i(tmp, NULL, 10, &scsi_host->max_vports) < 0) {
VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp); VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp);
goto cleanup; goto cleanup;
} }
if (!(tmp = virVHBAGetConfig(NULL, d->scsi_host.host, if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
"npiv_vports_inuse"))) { "npiv_vports_inuse"))) {
VIR_WARN("Failed to read npiv_vports_inuse for host%d", VIR_WARN("Failed to read npiv_vports_inuse for host%d",
d->scsi_host.host); scsi_host->host);
goto cleanup; goto cleanup;
} }
if (virStrToLong_i(tmp, NULL, 10, &d->scsi_host.vports) < 0) { if (virStrToLong_i(tmp, NULL, 10, &scsi_host->vports) < 0) {
VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tmp); VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tmp);
goto cleanup; goto cleanup;
} }
@ -112,12 +112,12 @@ nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d)
cleanup: cleanup:
if (ret < 0) { if (ret < 0) {
/* Clear the two flags in case of producing confusing XML output */ /* Clear the two flags in case of producing confusing XML output */
d->scsi_host.flags &= ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST | scsi_host->flags &= ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST |
VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS); VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS);
VIR_FREE(d->scsi_host.wwnn); VIR_FREE(scsi_host->wwnn);
VIR_FREE(d->scsi_host.wwpn); VIR_FREE(scsi_host->wwpn);
VIR_FREE(d->scsi_host.fabric_wwn); VIR_FREE(scsi_host->fabric_wwn);
} }
VIR_FREE(tmp); VIR_FREE(tmp);
return ret; return ret;
@ -126,37 +126,37 @@ nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d)
static int static int
nodeDeviceSysfsGetPCISRIOVCaps(const char *sysfsPath, nodeDeviceSysfsGetPCISRIOVCaps(const char *sysfsPath,
virNodeDevCapDataPtr data) virNodeDevCapPCIDevPtr pci_dev)
{ {
size_t i; size_t i;
int ret; int ret;
/* this could be a refresh, so clear out the old data */ /* this could be a refresh, so clear out the old data */
for (i = 0; i < data->pci_dev.num_virtual_functions; i++) for (i = 0; i < pci_dev->num_virtual_functions; i++)
VIR_FREE(data->pci_dev.virtual_functions[i]); VIR_FREE(pci_dev->virtual_functions[i]);
VIR_FREE(data->pci_dev.virtual_functions); VIR_FREE(pci_dev->virtual_functions);
data->pci_dev.num_virtual_functions = 0; pci_dev->num_virtual_functions = 0;
data->pci_dev.max_virtual_functions = 0; pci_dev->max_virtual_functions = 0;
data->pci_dev.flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; pci_dev->flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
data->pci_dev.flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; pci_dev->flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
ret = virPCIGetPhysicalFunction(sysfsPath, ret = virPCIGetPhysicalFunction(sysfsPath,
&data->pci_dev.physical_function); &pci_dev->physical_function);
if (ret < 0) if (ret < 0)
goto cleanup; goto cleanup;
if (data->pci_dev.physical_function) if (pci_dev->physical_function)
data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION; pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
ret = virPCIGetVirtualFunctions(sysfsPath, &data->pci_dev.virtual_functions, ret = virPCIGetVirtualFunctions(sysfsPath, &pci_dev->virtual_functions,
&data->pci_dev.num_virtual_functions, &pci_dev->num_virtual_functions,
&data->pci_dev.max_virtual_functions); &pci_dev->max_virtual_functions);
if (ret < 0) if (ret < 0)
goto cleanup; goto cleanup;
if (data->pci_dev.num_virtual_functions > 0 || if (pci_dev->num_virtual_functions > 0 ||
data->pci_dev.max_virtual_functions > 0) pci_dev->max_virtual_functions > 0)
data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION; pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
cleanup: cleanup:
return ret; return ret;
@ -164,23 +164,23 @@ nodeDeviceSysfsGetPCISRIOVCaps(const char *sysfsPath,
static int static int
nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapDataPtr data) nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapPCIDevPtr pci_dev)
{ {
size_t i; size_t i;
int tmpGroup, ret = -1; int tmpGroup, ret = -1;
virPCIDeviceAddress addr; virPCIDeviceAddress addr;
/* this could be a refresh, so clear out the old data */ /* this could be a refresh, so clear out the old data */
for (i = 0; i < data->pci_dev.nIommuGroupDevices; i++) for (i = 0; i < pci_dev->nIommuGroupDevices; i++)
VIR_FREE(data->pci_dev.iommuGroupDevices[i]); VIR_FREE(pci_dev->iommuGroupDevices[i]);
VIR_FREE(data->pci_dev.iommuGroupDevices); VIR_FREE(pci_dev->iommuGroupDevices);
data->pci_dev.nIommuGroupDevices = 0; pci_dev->nIommuGroupDevices = 0;
data->pci_dev.iommuGroupNumber = 0; pci_dev->iommuGroupNumber = 0;
addr.domain = data->pci_dev.domain; addr.domain = pci_dev->domain;
addr.bus = data->pci_dev.bus; addr.bus = pci_dev->bus;
addr.slot = data->pci_dev.slot; addr.slot = pci_dev->slot;
addr.function = data->pci_dev.function; addr.function = pci_dev->function;
tmpGroup = virPCIDeviceAddressGetIOMMUGroupNum(&addr); tmpGroup = virPCIDeviceAddressGetIOMMUGroupNum(&addr);
if (tmpGroup == -1) { if (tmpGroup == -1) {
/* error was already reported */ /* error was already reported */
@ -192,10 +192,10 @@ nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapDataPtr data)
goto cleanup; goto cleanup;
} }
if (tmpGroup >= 0) { if (tmpGroup >= 0) {
if (virPCIDeviceAddressGetIOMMUGroupAddresses(&addr, &data->pci_dev.iommuGroupDevices, if (virPCIDeviceAddressGetIOMMUGroupAddresses(&addr, &pci_dev->iommuGroupDevices,
&data->pci_dev.nIommuGroupDevices) < 0) &pci_dev->nIommuGroupDevices) < 0)
goto cleanup; goto cleanup;
data->pci_dev.iommuGroupNumber = tmpGroup; pci_dev->iommuGroupNumber = tmpGroup;
} }
ret = 0; ret = 0;
@ -212,11 +212,11 @@ nodeDeviceSysfsGetPCIIOMMUGroupCaps(virNodeDevCapDataPtr data)
*/ */
int int
nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath, nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath,
virNodeDevCapDataPtr data) virNodeDevCapPCIDevPtr pci_dev)
{ {
if (nodeDeviceSysfsGetPCISRIOVCaps(sysfsPath, data) < 0) if (nodeDeviceSysfsGetPCISRIOVCaps(sysfsPath, pci_dev) < 0)
return -1; return -1;
if (nodeDeviceSysfsGetPCIIOMMUGroupCaps(data) < 0) if (nodeDeviceSysfsGetPCIIOMMUGroupCaps(pci_dev) < 0)
return -1; return -1;
return 0; return 0;
} }
@ -225,14 +225,14 @@ nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath,
#else #else
int int
nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d ATTRIBUTE_UNUSED) nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host ATTRIBUTE_UNUSED)
{ {
return -1; return -1;
} }
int int
nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath ATTRIBUTE_UNUSED, nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath ATTRIBUTE_UNUSED,
virNodeDevCapDataPtr data ATTRIBUTE_UNUSED) virNodeDevCapPCIDevPtr pci_dev ATTRIBUTE_UNUSED)
{ {
return -1; return -1;
} }

View File

@ -25,8 +25,8 @@
# include "node_device_conf.h" # include "node_device_conf.h"
int nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d); int nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host);
int nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath, int nodeDeviceSysfsGetPCIRelatedDevCaps(const char *sysfsPath,
virNodeDevCapDataPtr data); virNodeDevCapPCIDevPtr pci_dev);
#endif /* __VIR_NODE_DEVICE_LINUX_SYSFS_H__ */ #endif /* __VIR_NODE_DEVICE_LINUX_SYSFS_H__ */

View File

@ -317,7 +317,7 @@ static int udevProcessPCI(struct udev_device *device,
virNodeDeviceDefPtr def) virNodeDeviceDefPtr def)
{ {
const char *syspath = NULL; const char *syspath = NULL;
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapPCIDevPtr pci_dev = &def->caps->data.pci_dev;
virPCIEDeviceInfoPtr pci_express = NULL; virPCIEDeviceInfoPtr pci_express = NULL;
virPCIDevicePtr pciDev = NULL; virPCIDevicePtr pciDev = NULL;
udevPrivate *priv = driver->privateData; udevPrivate *priv = driver->privateData;
@ -326,30 +326,30 @@ static int udevProcessPCI(struct udev_device *device,
syspath = udev_device_get_syspath(device); syspath = udev_device_get_syspath(device);
if (udevGetUintProperty(device, "PCI_CLASS", &data->pci_dev.class, 16) < 0) if (udevGetUintProperty(device, "PCI_CLASS", &pci_dev->class, 16) < 0)
goto cleanup; goto cleanup;
if ((p = strrchr(syspath, '/')) == NULL || if ((p = strrchr(syspath, '/')) == NULL ||
virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.domain) < 0 || p == NULL || virStrToLong_ui(p + 1, &p, 16, &pci_dev->domain) < 0 || p == NULL ||
virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.bus) < 0 || p == NULL || virStrToLong_ui(p + 1, &p, 16, &pci_dev->bus) < 0 || p == NULL ||
virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.slot) < 0 || p == NULL || virStrToLong_ui(p + 1, &p, 16, &pci_dev->slot) < 0 || p == NULL ||
virStrToLong_ui(p + 1, &p, 16, &data->pci_dev.function) < 0) { virStrToLong_ui(p + 1, &p, 16, &pci_dev->function) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse the PCI address from sysfs path: '%s'"), _("failed to parse the PCI address from sysfs path: '%s'"),
syspath); syspath);
goto cleanup; goto cleanup;
} }
if (udevGetUintSysfsAttr(device, "vendor", &data->pci_dev.vendor, 16) < 0) if (udevGetUintSysfsAttr(device, "vendor", &pci_dev->vendor, 16) < 0)
goto cleanup; goto cleanup;
if (udevGetUintSysfsAttr(device, "device", &data->pci_dev.product, 16) < 0) if (udevGetUintSysfsAttr(device, "device", &pci_dev->product, 16) < 0)
goto cleanup; goto cleanup;
if (udevTranslatePCIIds(data->pci_dev.vendor, if (udevTranslatePCIIds(pci_dev->vendor,
data->pci_dev.product, pci_dev->product,
&data->pci_dev.vendor_name, &pci_dev->vendor_name,
&data->pci_dev.product_name) != 0) { &pci_dev->product_name) != 0) {
goto cleanup; goto cleanup;
} }
@ -358,23 +358,24 @@ static int udevProcessPCI(struct udev_device *device,
/* The default value is -1, because it can't be 0 /* The default value is -1, because it can't be 0
* as zero is valid node number. */ * as zero is valid node number. */
data->pci_dev.numa_node = -1; pci_dev->numa_node = -1;
if (udevGetIntSysfsAttr(device, "numa_node", if (udevGetIntSysfsAttr(device, "numa_node",
&data->pci_dev.numa_node, 10) < 0) &pci_dev->numa_node, 10) < 0)
goto cleanup; goto cleanup;
if (nodeDeviceSysfsGetPCIRelatedDevCaps(syspath, data) < 0) if (nodeDeviceSysfsGetPCIRelatedDevCaps(syspath,
&def->caps->data.pci_dev) < 0)
goto cleanup; goto cleanup;
if (!(pciDev = virPCIDeviceNew(data->pci_dev.domain, if (!(pciDev = virPCIDeviceNew(pci_dev->domain,
data->pci_dev.bus, pci_dev->bus,
data->pci_dev.slot, pci_dev->slot,
data->pci_dev.function))) pci_dev->function)))
goto cleanup; goto cleanup;
/* We need to be root to read PCI device configs */ /* We need to be root to read PCI device configs */
if (priv->privileged) { if (priv->privileged) {
if (virPCIGetHeaderType(pciDev, &data->pci_dev.hdrType) < 0) if (virPCIGetHeaderType(pciDev, &pci_dev->hdrType) < 0)
goto cleanup; goto cleanup;
if (virPCIDeviceIsPCIExpress(pciDev) > 0) { if (virPCIDeviceIsPCIExpress(pciDev) > 0) {
@ -396,8 +397,8 @@ static int udevProcessPCI(struct udev_device *device,
pci_express->link_sta->port = -1; /* PCIe can't negotiate port. Yet :) */ pci_express->link_sta->port = -1; /* PCIe can't negotiate port. Yet :) */
} }
data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCIE; pci_dev->flags |= VIR_NODE_DEV_CAP_FLAG_PCIE;
data->pci_dev.pci_express = pci_express; pci_dev->pci_express = pci_express;
pci_express = NULL; pci_express = NULL;
} }
} }
@ -430,7 +431,7 @@ static int drmGetMinorType(int minor)
static int udevProcessDRMDevice(struct udev_device *device, static int udevProcessDRMDevice(struct udev_device *device,
virNodeDeviceDefPtr def) virNodeDeviceDefPtr def)
{ {
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapDRMPtr drm = &def->caps->data.drm;
int minor; int minor;
if (udevGenerateDeviceName(device, def, NULL) != 0) if (udevGenerateDeviceName(device, def, NULL) != 0)
@ -442,7 +443,7 @@ static int udevProcessDRMDevice(struct udev_device *device,
if ((minor = drmGetMinorType(minor)) == -1) if ((minor = drmGetMinorType(minor)) == -1)
return -1; return -1;
data->drm.type = minor; drm->type = minor;
return 0; return 0;
} }
@ -450,36 +451,36 @@ static int udevProcessDRMDevice(struct udev_device *device,
static int udevProcessUSBDevice(struct udev_device *device, static int udevProcessUSBDevice(struct udev_device *device,
virNodeDeviceDefPtr def) virNodeDeviceDefPtr def)
{ {
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapUSBDevPtr usb_dev = &def->caps->data.usb_dev;
if (udevGetUintProperty(device, "BUSNUM", &data->usb_dev.bus, 10) < 0) if (udevGetUintProperty(device, "BUSNUM", &usb_dev->bus, 10) < 0)
return -1; return -1;
if (udevGetUintProperty(device, "DEVNUM", &data->usb_dev.device, 10) < 0) if (udevGetUintProperty(device, "DEVNUM", &usb_dev->device, 10) < 0)
return -1; return -1;
if (udevGetUintProperty(device, "ID_VENDOR_ID", &data->usb_dev.vendor, 16) < 0) if (udevGetUintProperty(device, "ID_VENDOR_ID", &usb_dev->vendor, 16) < 0)
return -1; return -1;
if (udevGetStringProperty(device, if (udevGetStringProperty(device,
"ID_VENDOR_FROM_DATABASE", "ID_VENDOR_FROM_DATABASE",
&data->usb_dev.vendor_name) < 0) &usb_dev->vendor_name) < 0)
return -1; return -1;
if (!data->usb_dev.vendor_name && if (!usb_dev->vendor_name &&
udevGetStringSysfsAttr(device, "manufacturer", udevGetStringSysfsAttr(device, "manufacturer",
&data->usb_dev.vendor_name) < 0) &usb_dev->vendor_name) < 0)
return -1; return -1;
if (udevGetUintProperty(device, "ID_MODEL_ID", &data->usb_dev.product, 16) < 0) if (udevGetUintProperty(device, "ID_MODEL_ID", &usb_dev->product, 16) < 0)
return -1; return -1;
if (udevGetStringProperty(device, if (udevGetStringProperty(device,
"ID_MODEL_FROM_DATABASE", "ID_MODEL_FROM_DATABASE",
&data->usb_dev.product_name) < 0) &usb_dev->product_name) < 0)
return -1; return -1;
if (!data->usb_dev.product_name && if (!usb_dev->product_name &&
udevGetStringSysfsAttr(device, "product", udevGetStringSysfsAttr(device, "product",
&data->usb_dev.product_name) < 0) &usb_dev->product_name) < 0)
return -1; return -1;
if (udevGenerateDeviceName(device, def, NULL) != 0) if (udevGenerateDeviceName(device, def, NULL) != 0)
@ -492,22 +493,22 @@ static int udevProcessUSBDevice(struct udev_device *device,
static int udevProcessUSBInterface(struct udev_device *device, static int udevProcessUSBInterface(struct udev_device *device,
virNodeDeviceDefPtr def) virNodeDeviceDefPtr def)
{ {
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapUSBIfPtr usb_if = &def->caps->data.usb_if;
if (udevGetUintSysfsAttr(device, "bInterfaceNumber", if (udevGetUintSysfsAttr(device, "bInterfaceNumber",
&data->usb_if.number, 16) < 0) &usb_if->number, 16) < 0)
return -1; return -1;
if (udevGetUintSysfsAttr(device, "bInterfaceClass", if (udevGetUintSysfsAttr(device, "bInterfaceClass",
&data->usb_if._class, 16) < 0) &usb_if->_class, 16) < 0)
return -1; return -1;
if (udevGetUintSysfsAttr(device, "bInterfaceSubClass", if (udevGetUintSysfsAttr(device, "bInterfaceSubClass",
&data->usb_if.subclass, 16) < 0) &usb_if->subclass, 16) < 0)
return -1; return -1;
if (udevGetUintSysfsAttr(device, "bInterfaceProtocol", if (udevGetUintSysfsAttr(device, "bInterfaceProtocol",
&data->usb_if.protocol, 16) < 0) &usb_if->protocol, 16) < 0)
return -1; return -1;
if (udevGenerateDeviceName(device, def, NULL) != 0) if (udevGenerateDeviceName(device, def, NULL) != 0)
@ -521,33 +522,33 @@ static int udevProcessNetworkInterface(struct udev_device *device,
virNodeDeviceDefPtr def) virNodeDeviceDefPtr def)
{ {
const char *devtype = udev_device_get_devtype(device); const char *devtype = udev_device_get_devtype(device);
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapNetPtr net = &def->caps->data.net;
if (devtype && STREQ(devtype, "wlan")) { if (devtype && STREQ(devtype, "wlan")) {
data->net.subtype = VIR_NODE_DEV_CAP_NET_80211; net->subtype = VIR_NODE_DEV_CAP_NET_80211;
} else { } else {
data->net.subtype = VIR_NODE_DEV_CAP_NET_80203; net->subtype = VIR_NODE_DEV_CAP_NET_80203;
} }
if (udevGetStringProperty(device, if (udevGetStringProperty(device,
"INTERFACE", "INTERFACE",
&data->net.ifname) < 0) &net->ifname) < 0)
return -1; return -1;
if (udevGetStringSysfsAttr(device, "address", if (udevGetStringSysfsAttr(device, "address",
&data->net.address) < 0) &net->address) < 0)
return -1; return -1;
if (udevGetUintSysfsAttr(device, "addr_len", &data->net.address_len, 0) < 0) if (udevGetUintSysfsAttr(device, "addr_len", &net->address_len, 0) < 0)
return -1; return -1;
if (udevGenerateDeviceName(device, def, data->net.address) != 0) if (udevGenerateDeviceName(device, def, net->address) != 0)
return -1; return -1;
if (virNetDevGetLinkInfo(data->net.ifname, &data->net.lnk) < 0) if (virNetDevGetLinkInfo(net->ifname, &net->lnk) < 0)
return -1; return -1;
if (virNetDevGetFeatures(data->net.ifname, &data->net.features) < 0) if (virNetDevGetFeatures(net->ifname, &net->features) < 0)
return -1; return -1;
return 0; return 0;
@ -557,21 +558,21 @@ static int udevProcessNetworkInterface(struct udev_device *device,
static int udevProcessSCSIHost(struct udev_device *device ATTRIBUTE_UNUSED, static int udevProcessSCSIHost(struct udev_device *device ATTRIBUTE_UNUSED,
virNodeDeviceDefPtr def) virNodeDeviceDefPtr def)
{ {
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapSCSIHostPtr scsi_host = &def->caps->data.scsi_host;
char *filename = NULL; char *filename = NULL;
char *str; char *str;
filename = last_component(def->sysfs_path); filename = last_component(def->sysfs_path);
if (!(str = STRSKIP(filename, "host")) || if (!(str = STRSKIP(filename, "host")) ||
virStrToLong_ui(str, NULL, 0, &data->scsi_host.host) < 0) { virStrToLong_ui(str, NULL, 0, &scsi_host->host) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse SCSI host '%s'"), _("failed to parse SCSI host '%s'"),
filename); filename);
return -1; return -1;
} }
nodeDeviceSysfsGetSCSIHostCaps(&def->caps->data); nodeDeviceSysfsGetSCSIHostCaps(&def->caps->data.scsi_host);
if (udevGenerateDeviceName(device, def, NULL) != 0) if (udevGenerateDeviceName(device, def, NULL) != 0)
return -1; return -1;
@ -584,11 +585,11 @@ static int udevProcessSCSITarget(struct udev_device *device ATTRIBUTE_UNUSED,
virNodeDeviceDefPtr def) virNodeDeviceDefPtr def)
{ {
const char *sysname = NULL; const char *sysname = NULL;
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapSCSITargetPtr scsi_target = &def->caps->data.scsi_target;
sysname = udev_device_get_sysname(device); sysname = udev_device_get_sysname(device);
if (VIR_STRDUP(data->scsi_target.name, sysname) < 0) if (VIR_STRDUP(scsi_target->name, sysname) < 0)
return -1; return -1;
if (udevGenerateDeviceName(device, def, NULL) != 0) if (udevGenerateDeviceName(device, def, NULL) != 0)
@ -661,15 +662,15 @@ static int udevProcessSCSIDevice(struct udev_device *device ATTRIBUTE_UNUSED,
{ {
int ret = -1; int ret = -1;
unsigned int tmp = 0; unsigned int tmp = 0;
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapSCSIPtr scsi = &def->caps->data.scsi;
char *filename = NULL, *p = NULL; char *filename = NULL, *p = NULL;
filename = last_component(def->sysfs_path); filename = last_component(def->sysfs_path);
if (virStrToLong_ui(filename, &p, 10, &data->scsi.host) < 0 || p == NULL || if (virStrToLong_ui(filename, &p, 10, &scsi->host) < 0 || p == NULL ||
virStrToLong_ui(p + 1, &p, 10, &data->scsi.bus) < 0 || p == NULL || virStrToLong_ui(p + 1, &p, 10, &scsi->bus) < 0 || p == NULL ||
virStrToLong_ui(p + 1, &p, 10, &data->scsi.target) < 0 || p == NULL || virStrToLong_ui(p + 1, &p, 10, &scsi->target) < 0 || p == NULL ||
virStrToLong_ui(p + 1, &p, 10, &data->scsi.lun) < 0) { virStrToLong_ui(p + 1, &p, 10, &scsi->lun) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse the SCSI address from filename: '%s'"), _("failed to parse the SCSI address from filename: '%s'"),
filename); filename);
@ -680,7 +681,7 @@ static int udevProcessSCSIDevice(struct udev_device *device ATTRIBUTE_UNUSED,
if (udevGetUintSysfsAttr(device, "type", &tmp, 0) < 0) if (udevGetUintSysfsAttr(device, "type", &tmp, 0) < 0)
goto cleanup; goto cleanup;
if (udevGetSCSIType(def, tmp, &data->scsi.type) < 0) if (udevGetSCSIType(def, tmp, &scsi->type) < 0)
goto cleanup; goto cleanup;
} }
@ -702,17 +703,16 @@ static int udevProcessSCSIDevice(struct udev_device *device ATTRIBUTE_UNUSED,
static int udevProcessDisk(struct udev_device *device, static int udevProcessDisk(struct udev_device *device,
virNodeDeviceDefPtr def) virNodeDeviceDefPtr def)
{ {
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapStoragePtr storage = &def->caps->data.storage;
if (udevGetUint64SysfsAttr(device, "size", &data->storage.num_blocks) < 0) if (udevGetUint64SysfsAttr(device, "size", &storage->num_blocks) < 0)
return -1; return -1;
if (udevGetUint64SysfsAttr(device, "queue/logical_block_size", if (udevGetUint64SysfsAttr(device, "queue/logical_block_size",
&data->storage.logical_block_size) < 0) &storage->logical_block_size) < 0)
return -1; return -1;
data->storage.size = data->storage.num_blocks * storage->size = storage->num_blocks * storage->logical_block_size;
data->storage.logical_block_size;
return 0; return 0;
} }
@ -722,7 +722,7 @@ static int udevProcessRemoveableMedia(struct udev_device *device,
virNodeDeviceDefPtr def, virNodeDeviceDefPtr def,
int has_media) int has_media)
{ {
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapStoragePtr storage = &def->caps->data.storage;
int is_removable = 0; int is_removable = 0;
if (udevGetIntSysfsAttr(device, "removable", &is_removable, 0) < 0) if (udevGetIntSysfsAttr(device, "removable", &is_removable, 0) < 0)
@ -737,15 +737,15 @@ static int udevProcessRemoveableMedia(struct udev_device *device,
VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE; VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE;
if (udevGetStringProperty(device, "ID_FS_LABEL", if (udevGetStringProperty(device, "ID_FS_LABEL",
&data->storage.media_label) < 0) &storage->media_label) < 0)
return -1; return -1;
if (udevGetUint64SysfsAttr(device, "size", if (udevGetUint64SysfsAttr(device, "size",
&data->storage.num_blocks) < 0) &storage->num_blocks) < 0)
return -1; return -1;
if (udevGetUint64SysfsAttr(device, "queue/logical_block_size", if (udevGetUint64SysfsAttr(device, "queue/logical_block_size",
&data->storage.logical_block_size) < 0) &storage->logical_block_size) < 0)
return -1; return -1;
/* XXX This calculation is wrong for the qemu virtual cdrom /* XXX This calculation is wrong for the qemu virtual cdrom
@ -800,18 +800,17 @@ static int udevProcessFloppy(struct udev_device *device,
static int udevProcessSD(struct udev_device *device, static int udevProcessSD(struct udev_device *device,
virNodeDeviceDefPtr def) virNodeDeviceDefPtr def)
{ {
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapStoragePtr storage = &def->caps->data.storage;
if (udevGetUint64SysfsAttr(device, "size", if (udevGetUint64SysfsAttr(device, "size",
&data->storage.num_blocks) < 0) &storage->num_blocks) < 0)
return -1; return -1;
if (udevGetUint64SysfsAttr(device, "queue/logical_block_size", if (udevGetUint64SysfsAttr(device, "queue/logical_block_size",
&data->storage.logical_block_size) < 0) &storage->logical_block_size) < 0)
return -1; return -1;
data->storage.size = data->storage.num_blocks * storage->size = storage->num_blocks * storage->logical_block_size;
data->storage.logical_block_size;
return 0; return 0;
} }
@ -846,7 +845,7 @@ static int udevKludgeStorageType(virNodeDeviceDefPtr def)
static int udevProcessStorage(struct udev_device *device, static int udevProcessStorage(struct udev_device *device,
virNodeDeviceDefPtr def) virNodeDeviceDefPtr def)
{ {
virNodeDevCapDataPtr data = &def->caps->data; virNodeDevCapStoragePtr storage = &def->caps->data.storage;
int ret = -1; int ret = -1;
const char* devnode; const char* devnode;
@ -856,20 +855,20 @@ static int udevProcessStorage(struct udev_device *device,
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(data->storage.block, devnode) < 0) if (VIR_STRDUP(storage->block, devnode) < 0)
goto cleanup; goto cleanup;
if (udevGetStringProperty(device, "ID_BUS", &data->storage.bus) < 0) if (udevGetStringProperty(device, "ID_BUS", &storage->bus) < 0)
goto cleanup; goto cleanup;
if (udevGetStringProperty(device, "ID_SERIAL", &data->storage.serial) < 0) if (udevGetStringProperty(device, "ID_SERIAL", &storage->serial) < 0)
goto cleanup; goto cleanup;
if (udevGetStringSysfsAttr(device, "device/vendor", &data->storage.vendor) < 0) if (udevGetStringSysfsAttr(device, "device/vendor", &storage->vendor) < 0)
goto cleanup; goto cleanup;
if (def->caps->data.storage.vendor) if (def->caps->data.storage.vendor)
virTrimSpaces(def->caps->data.storage.vendor, NULL); virTrimSpaces(def->caps->data.storage.vendor, NULL);
if (udevGetStringSysfsAttr(device, "device/model", &data->storage.model) < 0) if (udevGetStringSysfsAttr(device, "device/model", &storage->model) < 0)
goto cleanup; goto cleanup;
if (def->caps->data.storage.model) if (def->caps->data.storage.model)
virTrimSpaces(def->caps->data.storage.model, NULL); virTrimSpaces(def->caps->data.storage.model, NULL);
@ -878,10 +877,10 @@ static int udevProcessStorage(struct udev_device *device,
* expected, so I don't see a problem with not having a property * expected, so I don't see a problem with not having a property
* for it. */ * for it. */
if (udevGetStringProperty(device, "ID_TYPE", &data->storage.drive_type) < 0) if (udevGetStringProperty(device, "ID_TYPE", &storage->drive_type) < 0)
goto cleanup; goto cleanup;
if (!data->storage.drive_type || if (!storage->drive_type ||
STREQ(def->caps->data.storage.drive_type, "generic")) { STREQ(def->caps->data.storage.drive_type, "generic")) {
int val = 0; int val = 0;
const char *str = NULL; const char *str = NULL;
@ -908,7 +907,7 @@ static int udevProcessStorage(struct udev_device *device,
} }
if (str) { if (str) {
if (VIR_STRDUP(data->storage.drive_type, str) < 0) if (VIR_STRDUP(storage->drive_type, str) < 0)
goto cleanup; goto cleanup;
} else { } else {
/* If udev doesn't have it, perhaps we can guess it. */ /* If udev doesn't have it, perhaps we can guess it. */
@ -931,7 +930,7 @@ static int udevProcessStorage(struct udev_device *device,
goto cleanup; goto cleanup;
} }
if (udevGenerateDeviceName(device, def, data->storage.serial) != 0) if (udevGenerateDeviceName(device, def, storage->serial) != 0)
goto cleanup; goto cleanup;
cleanup: cleanup:
@ -1421,10 +1420,12 @@ static void udevEventHandleCallback(int watch ATTRIBUTE_UNUSED,
/* DMI is intel-compatible specific */ /* DMI is intel-compatible specific */
#if defined(__x86_64__) || defined(__i386__) || defined(__amd64__) #if defined(__x86_64__) || defined(__i386__) || defined(__amd64__)
static void static void
udevGetDMIData(virNodeDevCapDataPtr data) udevGetDMIData(virNodeDevCapSystemPtr system)
{ {
struct udev *udev = NULL; struct udev *udev = NULL;
struct udev_device *device = NULL; struct udev_device *device = NULL;
virNodeDevCapSystemHardwarePtr hardware = &system->hardware;
virNodeDevCapSystemFirmwarePtr firmware = &system->firmware;
udev = udev_monitor_get_udev(DRV_STATE_UDEV_MONITOR(driver)); udev = udev_monitor_get_udev(DRV_STATE_UDEV_MONITOR(driver));
@ -1440,29 +1441,29 @@ udevGetDMIData(virNodeDevCapDataPtr data)
} }
if (udevGetStringSysfsAttr(device, "product_name", if (udevGetStringSysfsAttr(device, "product_name",
&data->system.product_name) < 0) &system->product_name) < 0)
goto cleanup; goto cleanup;
if (udevGetStringSysfsAttr(device, "sys_vendor", if (udevGetStringSysfsAttr(device, "sys_vendor",
&data->system.hardware.vendor_name) < 0) &hardware->vendor_name) < 0)
goto cleanup; goto cleanup;
if (udevGetStringSysfsAttr(device, "product_version", if (udevGetStringSysfsAttr(device, "product_version",
&data->system.hardware.version) < 0) &hardware->version) < 0)
goto cleanup; goto cleanup;
if (udevGetStringSysfsAttr(device, "product_serial", if (udevGetStringSysfsAttr(device, "product_serial",
&data->system.hardware.serial) < 0) &hardware->serial) < 0)
goto cleanup; goto cleanup;
if (virGetHostUUID(data->system.hardware.uuid)) if (virGetHostUUID(hardware->uuid))
goto cleanup; goto cleanup;
if (udevGetStringSysfsAttr(device, "bios_vendor", if (udevGetStringSysfsAttr(device, "bios_vendor",
&data->system.firmware.vendor_name) < 0) &firmware->vendor_name) < 0)
goto cleanup; goto cleanup;
if (udevGetStringSysfsAttr(device, "bios_version", if (udevGetStringSysfsAttr(device, "bios_version",
&data->system.firmware.version) < 0) &firmware->version) < 0)
goto cleanup; goto cleanup;
if (udevGetStringSysfsAttr(device, "bios_date", if (udevGetStringSysfsAttr(device, "bios_date",
&data->system.firmware.release_date) < 0) &firmware->release_date) < 0)
goto cleanup; goto cleanup;
cleanup: cleanup:
@ -1489,7 +1490,7 @@ static int udevSetupSystemDev(void)
goto cleanup; goto cleanup;
#if defined(__x86_64__) || defined(__i386__) || defined(__amd64__) #if defined(__x86_64__) || defined(__i386__) || defined(__amd64__)
udevGetDMIData(&def->caps->data); udevGetDMIData(&def->caps->data.system);
#endif #endif
dev = virNodeDeviceObjAssignDef(&driver->devs, def); dev = virNodeDeviceObjAssignDef(&driver->devs, def);