2008-11-21 12:20:45 +00:00
|
|
|
/*
|
|
|
|
* node_device_conf.c: config handling for node devices
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Virtual Iron Software, Inc.
|
|
|
|
* Copyright (C) 2008 David F. Lively
|
|
|
|
*
|
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-11-21 12:20:45 +00:00
|
|
|
*
|
|
|
|
* Author: David F. Lively <dlively@virtualiron.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2009-02-24 14:55:45 +00:00
|
|
|
#include "datatypes.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2008-11-21 12:20:45 +00:00
|
|
|
|
|
|
|
#include "node_device_conf.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-13 18:13:21 +00:00
|
|
|
#include "virxml.h"
|
2012-12-13 17:44:57 +00:00
|
|
|
#include "virutil.h"
|
2012-12-04 12:04:07 +00:00
|
|
|
#include "virbuffer.h"
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2012-02-10 04:51:47 +00:00
|
|
|
#include "virrandom.h"
|
2008-11-21 12:20:45 +00:00
|
|
|
|
2009-01-29 12:10:32 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NODEDEV
|
2008-11-21 12:20:45 +00:00
|
|
|
|
|
|
|
VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST,
|
|
|
|
"system",
|
|
|
|
"pci",
|
|
|
|
"usb_device",
|
|
|
|
"usb",
|
|
|
|
"net",
|
|
|
|
"scsi_host",
|
2009-11-12 22:03:47 +00:00
|
|
|
"scsi_target",
|
2008-11-21 12:20:45 +00:00
|
|
|
"scsi",
|
2008-12-17 21:09:44 +00:00
|
|
|
"storage")
|
2008-11-21 12:20:45 +00:00
|
|
|
|
|
|
|
VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST,
|
|
|
|
"80203",
|
2008-12-17 21:09:44 +00:00
|
|
|
"80211")
|
2008-11-21 12:20:45 +00:00
|
|
|
|
2009-06-02 15:12:53 +00:00
|
|
|
VIR_ENUM_IMPL(virNodeDevHBACap, VIR_NODE_DEV_CAP_HBA_LAST,
|
|
|
|
"fc_host",
|
|
|
|
"vport_ops")
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapsDefParseString(const char *xpath,
|
2009-06-02 15:12:53 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
2012-02-10 04:51:47 +00:00
|
|
|
char **string)
|
2009-06-02 15:12:53 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
2012-02-10 04:51:47 +00:00
|
|
|
if (!(s = virXPathString(xpath, ctxt)))
|
2009-06-02 15:12:53 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
*string = s;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-01 18:53:43 +00:00
|
|
|
int virNodeDeviceHasCap(const virNodeDeviceObjPtr dev, const char *cap)
|
|
|
|
{
|
|
|
|
virNodeDevCapsDefPtr caps = dev->def->caps;
|
|
|
|
while (caps) {
|
|
|
|
if (STREQ(cap, virNodeDevCapTypeToString(caps->type)))
|
|
|
|
return 1;
|
|
|
|
caps = caps->next;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-06-02 15:12:53 +00:00
|
|
|
|
2009-11-12 21:48:24 +00:00
|
|
|
|
|
|
|
virNodeDeviceObjPtr
|
|
|
|
virNodeDeviceFindBySysfsPath(const virNodeDeviceObjListPtr devs,
|
|
|
|
const char *sysfs_path)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < devs->count; i++) {
|
|
|
|
virNodeDeviceObjLock(devs->objs[i]);
|
|
|
|
if ((devs->objs[i]->def->sysfs_path != NULL) &&
|
|
|
|
(STREQ(devs->objs[i]->def->sysfs_path, sysfs_path))) {
|
|
|
|
return devs->objs[i];
|
|
|
|
}
|
|
|
|
virNodeDeviceObjUnlock(devs->objs[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-21 12:20:45 +00:00
|
|
|
virNodeDeviceObjPtr virNodeDeviceFindByName(const virNodeDeviceObjListPtr devs,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2008-12-04 22:00:14 +00:00
|
|
|
for (i = 0; i < devs->count; i++) {
|
|
|
|
virNodeDeviceObjLock(devs->objs[i]);
|
2008-11-21 12:20:45 +00:00
|
|
|
if (STREQ(devs->objs[i]->def->name, name))
|
|
|
|
return devs->objs[i];
|
2008-12-04 22:00:14 +00:00
|
|
|
virNodeDeviceObjUnlock(devs->objs[i]);
|
|
|
|
}
|
2008-11-21 12:20:45 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void virNodeDeviceDefFree(virNodeDeviceDefPtr def)
|
|
|
|
{
|
|
|
|
virNodeDevCapsDefPtr caps;
|
|
|
|
|
|
|
|
if (!def)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VIR_FREE(def->name);
|
|
|
|
VIR_FREE(def->parent);
|
2009-06-12 13:12:55 +00:00
|
|
|
VIR_FREE(def->driver);
|
2009-11-12 21:48:24 +00:00
|
|
|
VIR_FREE(def->sysfs_path);
|
|
|
|
VIR_FREE(def->parent_sysfs_path);
|
2008-11-21 12:20:45 +00:00
|
|
|
|
|
|
|
caps = def->caps;
|
|
|
|
while (caps) {
|
|
|
|
virNodeDevCapsDefPtr next = caps->next;
|
|
|
|
virNodeDevCapsDefFree(caps);
|
|
|
|
caps = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
void virNodeDeviceObjFree(virNodeDeviceObjPtr dev)
|
|
|
|
{
|
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
virNodeDeviceDefFree(dev->def);
|
|
|
|
if (dev->privateFree)
|
|
|
|
(*dev->privateFree)(dev->privateData);
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexDestroy(&dev->lock);
|
|
|
|
|
2008-11-21 12:20:45 +00:00
|
|
|
VIR_FREE(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0 ; i < devs->count ; i++)
|
|
|
|
virNodeDeviceObjFree(devs->objs[i]);
|
|
|
|
VIR_FREE(devs->objs);
|
|
|
|
devs->count = 0;
|
|
|
|
}
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDeviceObjPtr virNodeDeviceAssignDef(virNodeDeviceObjListPtr devs,
|
2008-11-21 12:20:45 +00:00
|
|
|
const virNodeDeviceDefPtr def)
|
|
|
|
{
|
|
|
|
virNodeDeviceObjPtr device;
|
|
|
|
|
|
|
|
if ((device = virNodeDeviceFindByName(devs, def->name))) {
|
|
|
|
virNodeDeviceDefFree(device->def);
|
|
|
|
device->def = def;
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC(device) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-11-21 12:20:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-01-15 19:56:05 +00:00
|
|
|
if (virMutexInit(&device->lock) < 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("cannot initialize mutex"));
|
2009-01-15 19:56:05 +00:00
|
|
|
VIR_FREE(device);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-12-04 22:00:14 +00:00
|
|
|
virNodeDeviceObjLock(device);
|
2008-11-21 12:20:45 +00:00
|
|
|
device->def = def;
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(devs->objs, devs->count+1) < 0) {
|
|
|
|
device->def = NULL;
|
2009-01-15 19:56:05 +00:00
|
|
|
virNodeDeviceObjUnlock(device);
|
2008-11-21 12:20:45 +00:00
|
|
|
virNodeDeviceObjFree(device);
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-11-21 12:20:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
devs->objs[devs->count++] = device;
|
|
|
|
|
|
|
|
return device;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs,
|
|
|
|
const virNodeDeviceObjPtr dev)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2008-12-04 22:00:14 +00:00
|
|
|
virNodeDeviceObjUnlock(dev);
|
|
|
|
|
2008-11-21 12:20:45 +00:00
|
|
|
for (i = 0; i < devs->count; i++) {
|
2008-12-04 22:00:14 +00:00
|
|
|
virNodeDeviceObjLock(dev);
|
2008-11-21 12:20:45 +00:00
|
|
|
if (devs->objs[i] == dev) {
|
2008-12-04 22:00:14 +00:00
|
|
|
virNodeDeviceObjUnlock(dev);
|
2008-11-21 12:20:45 +00:00
|
|
|
virNodeDeviceObjFree(devs->objs[i]);
|
|
|
|
|
|
|
|
if (i < (devs->count - 1))
|
|
|
|
memmove(devs->objs + i, devs->objs + i + 1,
|
|
|
|
sizeof(*(devs->objs)) * (devs->count - (i + 1)));
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(devs->objs, devs->count - 1) < 0) {
|
|
|
|
; /* Failure to reduce memory allocation isn't fatal */
|
|
|
|
}
|
|
|
|
devs->count--;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2008-12-04 22:00:14 +00:00
|
|
|
virNodeDeviceObjUnlock(dev);
|
2008-11-21 12:20:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
char *virNodeDeviceDefFormat(const virNodeDeviceDefPtr def)
|
2008-11-21 12:20:45 +00:00
|
|
|
{
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2009-09-03 11:38:57 +00:00
|
|
|
virNodeDevCapsDefPtr caps;
|
2009-12-14 13:44:12 +00:00
|
|
|
unsigned int i = 0;
|
2008-11-21 12:20:45 +00:00
|
|
|
|
|
|
|
virBufferAddLit(&buf, "<device>\n");
|
|
|
|
virBufferEscapeString(&buf, " <name>%s</name>\n", def->name);
|
2009-11-12 21:48:24 +00:00
|
|
|
if (def->parent) {
|
2008-11-21 12:20:45 +00:00
|
|
|
virBufferEscapeString(&buf, " <parent>%s</parent>\n", def->parent);
|
2009-11-12 21:48:24 +00:00
|
|
|
}
|
2009-06-12 13:12:55 +00:00
|
|
|
if (def->driver) {
|
|
|
|
virBufferAddLit(&buf, " <driver>\n");
|
|
|
|
virBufferEscapeString(&buf, " <name>%s</name>\n", def->driver);
|
|
|
|
virBufferAddLit(&buf, " </driver>\n");
|
|
|
|
}
|
2008-11-21 12:20:45 +00:00
|
|
|
|
|
|
|
for (caps = def->caps; caps; caps = caps->next) {
|
|
|
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
|
|
union _virNodeDevCapData *data = &caps->data;
|
|
|
|
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <capability type='%s'>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
virNodeDevCapTypeToString(caps->type));
|
|
|
|
switch (caps->type) {
|
|
|
|
case VIR_NODE_DEV_CAP_SYSTEM:
|
|
|
|
if (data->system.product_name)
|
|
|
|
virBufferEscapeString(&buf, " <product>%s</product>\n",
|
|
|
|
data->system.product_name);
|
|
|
|
virBufferAddLit(&buf, " <hardware>\n");
|
|
|
|
if (data->system.hardware.vendor_name)
|
|
|
|
virBufferEscapeString(&buf, " <vendor>%s</vendor>\n",
|
|
|
|
data->system.hardware.vendor_name);
|
|
|
|
if (data->system.hardware.version)
|
|
|
|
virBufferEscapeString(&buf, " <version>%s</version>\n",
|
|
|
|
data->system.hardware.version);
|
|
|
|
if (data->system.hardware.serial)
|
|
|
|
virBufferEscapeString(&buf, " <serial>%s</serial>\n",
|
|
|
|
data->system.hardware.serial);
|
|
|
|
virUUIDFormat(data->system.hardware.uuid, uuidstr);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <uuid>%s</uuid>\n", uuidstr);
|
2008-11-21 12:20:45 +00:00
|
|
|
virBufferAddLit(&buf, " </hardware>\n");
|
|
|
|
virBufferAddLit(&buf, " <firmware>\n");
|
|
|
|
if (data->system.firmware.vendor_name)
|
|
|
|
virBufferEscapeString(&buf, " <vendor>%s</vendor>\n",
|
|
|
|
data->system.firmware.vendor_name);
|
|
|
|
if (data->system.firmware.version)
|
|
|
|
virBufferEscapeString(&buf, " <version>%s</version>\n",
|
|
|
|
data->system.firmware.version);
|
|
|
|
if (data->system.firmware.release_date)
|
|
|
|
virBufferEscapeString(&buf,
|
|
|
|
" <release_date>%s</release_date>\n",
|
|
|
|
data->system.firmware.release_date);
|
|
|
|
virBufferAddLit(&buf, " </firmware>\n");
|
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_PCI_DEV:
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <domain>%d</domain>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->pci_dev.domain);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <bus>%d</bus>\n", data->pci_dev.bus);
|
|
|
|
virBufferAsprintf(&buf, " <slot>%d</slot>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->pci_dev.slot);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <function>%d</function>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->pci_dev.function);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <product id='0x%04x'",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->pci_dev.product);
|
|
|
|
if (data->pci_dev.product_name)
|
|
|
|
virBufferEscapeString(&buf, ">%s</product>\n",
|
|
|
|
data->pci_dev.product_name);
|
|
|
|
else
|
|
|
|
virBufferAddLit(&buf, " />\n");
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <vendor id='0x%04x'",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->pci_dev.vendor);
|
|
|
|
if (data->pci_dev.vendor_name)
|
|
|
|
virBufferEscapeString(&buf, ">%s</vendor>\n",
|
|
|
|
data->pci_dev.vendor_name);
|
|
|
|
else
|
|
|
|
virBufferAddLit(&buf, " />\n");
|
2009-12-14 13:44:12 +00:00
|
|
|
if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION) {
|
|
|
|
virBufferAddLit(&buf, " <capability type='phys_function'>\n");
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf,
|
2009-12-14 13:44:12 +00:00
|
|
|
" <address domain='0x%.4x' bus='0x%.2x' "
|
|
|
|
"slot='0x%.2x' function='0x%.1x'/>\n",
|
|
|
|
data->pci_dev.physical_function->domain,
|
|
|
|
data->pci_dev.physical_function->bus,
|
|
|
|
data->pci_dev.physical_function->slot,
|
|
|
|
data->pci_dev.physical_function->function);
|
|
|
|
virBufferAddLit(&buf, " </capability>\n");
|
|
|
|
}
|
|
|
|
if (data->pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION) {
|
|
|
|
virBufferAddLit(&buf, " <capability type='virt_functions'>\n");
|
|
|
|
for (i = 0 ; i < data->pci_dev.num_virtual_functions ; i++) {
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf,
|
2009-12-14 13:44:12 +00:00
|
|
|
" <address domain='0x%.4x' bus='0x%.2x' "
|
|
|
|
"slot='0x%.2x' function='0x%.1x'/>\n",
|
|
|
|
data->pci_dev.virtual_functions[i]->domain,
|
|
|
|
data->pci_dev.virtual_functions[i]->bus,
|
|
|
|
data->pci_dev.virtual_functions[i]->slot,
|
|
|
|
data->pci_dev.virtual_functions[i]->function);
|
|
|
|
}
|
|
|
|
virBufferAddLit(&buf, " </capability>\n");
|
|
|
|
}
|
2008-11-21 12:20:45 +00:00
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_USB_DEV:
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <bus>%d</bus>\n", data->usb_dev.bus);
|
|
|
|
virBufferAsprintf(&buf, " <device>%d</device>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->usb_dev.device);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <product id='0x%04x'",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->usb_dev.product);
|
|
|
|
if (data->usb_dev.product_name)
|
|
|
|
virBufferEscapeString(&buf, ">%s</product>\n",
|
|
|
|
data->usb_dev.product_name);
|
|
|
|
else
|
|
|
|
virBufferAddLit(&buf, " />\n");
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <vendor id='0x%04x'",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->usb_dev.vendor);
|
|
|
|
if (data->usb_dev.vendor_name)
|
|
|
|
virBufferEscapeString(&buf, ">%s</vendor>\n",
|
|
|
|
data->usb_dev.vendor_name);
|
|
|
|
else
|
|
|
|
virBufferAddLit(&buf, " />\n");
|
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_USB_INTERFACE:
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <number>%d</number>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->usb_if.number);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <class>%d</class>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->usb_if._class);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <subclass>%d</subclass>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->usb_if.subclass);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <protocol>%d</protocol>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->usb_if.protocol);
|
|
|
|
if (data->usb_if.description)
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf,
|
|
|
|
" <description>%s</description>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->usb_if.description);
|
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_NET:
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <interface>%s</interface>\n",
|
2008-11-25 10:37:02 +00:00
|
|
|
data->net.ifname);
|
2008-11-21 12:20:45 +00:00
|
|
|
if (data->net.address)
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <address>%s</address>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->net.address);
|
|
|
|
if (data->net.subtype != VIR_NODE_DEV_CAP_NET_LAST) {
|
|
|
|
const char *subtyp =
|
|
|
|
virNodeDevNetCapTypeToString(data->net.subtype);
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <capability type='%s'/>\n",
|
|
|
|
subtyp);
|
2008-11-21 12:20:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_SCSI_HOST:
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <host>%d</host>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->scsi_host.host);
|
2009-06-02 15:12:53 +00:00
|
|
|
if (data->scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
|
|
|
|
virBufferAddLit(&buf, " <capability type='fc_host'>\n");
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <wwnn>%s</wwnn>\n",
|
|
|
|
data->scsi_host.wwnn);
|
|
|
|
virBufferEscapeString(&buf, " <wwpn>%s</wwpn>\n",
|
|
|
|
data->scsi_host.wwpn);
|
2011-12-06 12:09:03 +00:00
|
|
|
virBufferEscapeString(&buf, " <fabric_wwn>%s</fabric_wwn>\n",
|
|
|
|
data->scsi_host.fabric_wwn);
|
2009-06-02 15:12:53 +00:00
|
|
|
virBufferAddLit(&buf, " </capability>\n");
|
|
|
|
}
|
|
|
|
if (data->scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) {
|
|
|
|
virBufferAddLit(&buf, " <capability type='vport_ops' />\n");
|
|
|
|
}
|
|
|
|
|
2008-11-21 12:20:45 +00:00
|
|
|
break;
|
2009-11-12 22:03:47 +00:00
|
|
|
|
|
|
|
case VIR_NODE_DEV_CAP_SCSI_TARGET:
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <target>%s</target>\n",
|
|
|
|
data->scsi_target.name);
|
2009-11-12 22:03:47 +00:00
|
|
|
break;
|
|
|
|
|
2008-11-21 12:20:45 +00:00
|
|
|
case VIR_NODE_DEV_CAP_SCSI:
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <host>%d</host>\n", data->scsi.host);
|
|
|
|
virBufferAsprintf(&buf, " <bus>%d</bus>\n", data->scsi.bus);
|
|
|
|
virBufferAsprintf(&buf, " <target>%d</target>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->scsi.target);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <lun>%d</lun>\n", data->scsi.lun);
|
2008-11-21 12:20:45 +00:00
|
|
|
if (data->scsi.type)
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <type>%s</type>\n",
|
|
|
|
data->scsi.type);
|
2008-11-21 12:20:45 +00:00
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_STORAGE:
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <block>%s</block>\n",
|
2008-11-21 12:46:39 +00:00
|
|
|
data->storage.block);
|
2008-11-21 12:20:45 +00:00
|
|
|
if (data->storage.bus)
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <bus>%s</bus>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->storage.bus);
|
|
|
|
if (data->storage.drive_type)
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <drive_type>%s</drive_type>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->storage.drive_type);
|
|
|
|
if (data->storage.model)
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <model>%s</model>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->storage.model);
|
|
|
|
if (data->storage.vendor)
|
2010-02-08 17:03:43 +00:00
|
|
|
virBufferEscapeString(&buf, " <vendor>%s</vendor>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->storage.vendor);
|
2009-06-11 14:25:19 +00:00
|
|
|
if (data->storage.serial)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <serial>%s</serial>\n",
|
2009-06-11 14:25:19 +00:00
|
|
|
data->storage.serial);
|
2008-11-21 12:20:45 +00:00
|
|
|
if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE) {
|
|
|
|
int avl = data->storage.flags &
|
|
|
|
VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE;
|
|
|
|
virBufferAddLit(&buf, " <capability type='removable'>\n");
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf,
|
2008-11-21 12:20:45 +00:00
|
|
|
" <media_available>%d"
|
|
|
|
"</media_available>\n", avl ? 1 : 0);
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <media_size>%llu</media_size>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->storage.removable_media_size);
|
2009-12-14 13:58:23 +00:00
|
|
|
if (data->storage.media_label)
|
|
|
|
virBufferEscapeString(&buf,
|
|
|
|
" <media_label>%s</media_label>\n",
|
|
|
|
data->storage.media_label);
|
|
|
|
|
2009-11-12 21:39:40 +00:00
|
|
|
if (data->storage.logical_block_size > 0)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <logical_block_size>%llu"
|
2009-11-12 21:39:40 +00:00
|
|
|
"</logical_block_size>\n",
|
|
|
|
data->storage.logical_block_size);
|
|
|
|
if (data->storage.num_blocks > 0)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf,
|
2009-11-12 21:39:40 +00:00
|
|
|
" <num_blocks>%llu</num_blocks>\n",
|
|
|
|
data->storage.num_blocks);
|
2008-11-21 12:20:45 +00:00
|
|
|
virBufferAddLit(&buf, " </capability>\n");
|
|
|
|
} else {
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <size>%llu</size>\n",
|
2008-11-21 12:20:45 +00:00
|
|
|
data->storage.size);
|
2009-11-12 21:39:40 +00:00
|
|
|
if (data->storage.logical_block_size > 0)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, " <logical_block_size>%llu"
|
2009-11-12 21:39:40 +00:00
|
|
|
"</logical_block_size>\n",
|
|
|
|
data->storage.logical_block_size);
|
|
|
|
if (data->storage.num_blocks > 0)
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf,
|
2009-11-12 21:39:40 +00:00
|
|
|
" <num_blocks>%llu</num_blocks>\n",
|
|
|
|
data->storage.num_blocks);
|
2008-11-21 12:20:45 +00:00
|
|
|
}
|
|
|
|
if (data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE)
|
|
|
|
virBufferAddLit(&buf,
|
|
|
|
" <capability type='hotpluggable' />\n");
|
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_LAST:
|
|
|
|
/* ignore special LAST value */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buf, " </capability>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
virBufferAddLit(&buf, "</device>\n");
|
|
|
|
|
|
|
|
if (virBufferError(&buf))
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
|
|
|
|
no_memory:
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-12-09 23:00:50 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
2008-11-21 12:20:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-24 14:55:45 +00:00
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapsDefParseULong(const char *xpath,
|
2009-02-24 14:55:45 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
unsigned *value,
|
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
const char *missing_error_fmt,
|
|
|
|
const char *invalid_error_fmt)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long val;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathULong(xpath, ctxt, &val);
|
2009-02-24 14:55:45 +00:00
|
|
|
if (ret < 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
ret == -1 ? missing_error_fmt : invalid_error_fmt,
|
|
|
|
def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapsDefParseULongLong(const char *xpath,
|
2009-02-24 14:55:45 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
unsigned long long *value,
|
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
const char *missing_error_fmt,
|
|
|
|
const char *invalid_error_fmt)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long long val;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathULongLong(xpath, ctxt, &val);
|
2009-02-24 14:55:45 +00:00
|
|
|
if (ret < 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
ret == -1 ? missing_error_fmt : invalid_error_fmt,
|
|
|
|
def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
xmlNodePtr node,
|
|
|
|
union _virNodeDevCapData *data)
|
|
|
|
{
|
|
|
|
xmlNodePtr orignode, *nodes = NULL;
|
|
|
|
int i, n, ret = -1;
|
|
|
|
unsigned long long val;
|
|
|
|
|
|
|
|
orignode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->storage.block = virXPathString("string(./block[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
if (!data->storage.block) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("no block device path supplied for '%s'"),
|
|
|
|
def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->storage.bus = virXPathString("string(./bus[1])", ctxt);
|
|
|
|
data->storage.drive_type = virXPathString("string(./drive_type[1])", ctxt);
|
|
|
|
data->storage.model = virXPathString("string(./model[1])", ctxt);
|
|
|
|
data->storage.vendor = virXPathString("string(./vendor[1])", ctxt);
|
|
|
|
data->storage.serial = virXPathString("string(./serial[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) {
|
2009-02-24 14:55:45 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < n ; i++) {
|
|
|
|
char *type = virXMLPropString(nodes[i], "type");
|
|
|
|
|
|
|
|
if (!type) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("missing storage capability type for '%s'"),
|
|
|
|
def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ(type, "hotpluggable"))
|
|
|
|
data->storage.flags |= VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE;
|
|
|
|
else if (STREQ(type, "removable")) {
|
|
|
|
xmlNodePtr orignode2;
|
|
|
|
|
|
|
|
data->storage.flags |= VIR_NODE_DEV_CAP_STORAGE_REMOVABLE;
|
|
|
|
|
|
|
|
orignode2 = ctxt->node;
|
|
|
|
ctxt->node = nodes[i];
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
if (virXPathBoolean("count(./media_available[. = '1']) > 0", ctxt))
|
2009-02-24 14:55:45 +00:00
|
|
|
data->storage.flags |= VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->storage.media_label = virXPathString("string(./media_label[1])", ctxt);
|
2009-12-14 13:58:23 +00:00
|
|
|
|
2009-02-24 14:55:45 +00:00
|
|
|
val = 0;
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def,
|
2009-02-24 14:55:45 +00:00
|
|
|
_("no removable media size supplied for '%s'"),
|
|
|
|
_("invalid removable media size supplied for '%s'")) < 0) {
|
|
|
|
ctxt->node = orignode2;
|
|
|
|
VIR_FREE(type);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
data->storage.removable_media_size = val;
|
|
|
|
|
|
|
|
ctxt->node = orignode2;
|
|
|
|
} else {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unknown storage capability type '%s' for '%s'"),
|
|
|
|
type, def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
VIR_FREE(type);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(data->storage.flags & VIR_NODE_DEV_CAP_STORAGE_REMOVABLE)) {
|
|
|
|
val = 0;
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULongLong("number(./size[1])", ctxt, &val, def,
|
2009-02-24 14:55:45 +00:00
|
|
|
_("no size supplied for '%s'"),
|
|
|
|
_("invalid size supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
data->storage.size = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
ctxt->node = orignode;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapScsiParseXML(xmlXPathContextPtr ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
xmlNodePtr node,
|
|
|
|
union _virNodeDevCapData *data)
|
|
|
|
{
|
|
|
|
xmlNodePtr orignode;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
orignode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->scsi.host, def,
|
|
|
|
_("no SCSI host ID supplied for '%s'"),
|
|
|
|
_("invalid SCSI host ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->scsi.bus, def,
|
|
|
|
_("no SCSI bus ID supplied for '%s'"),
|
|
|
|
_("invalid SCSI bus ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./target[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->scsi.target, def,
|
|
|
|
_("no SCSI target ID supplied for '%s'"),
|
|
|
|
_("invalid SCSI target ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./lun[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->scsi.lun, def,
|
|
|
|
_("no SCSI LUN ID supplied for '%s'"),
|
|
|
|
_("invalid SCSI LUN ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->scsi.type = virXPathString("string(./type[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
ctxt->node = orignode;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-11-12 22:03:47 +00:00
|
|
|
|
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapScsiTargetParseXML(xmlXPathContextPtr ctxt,
|
2009-11-12 22:03:47 +00:00
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
xmlNodePtr node,
|
|
|
|
union _virNodeDevCapData *data)
|
|
|
|
{
|
|
|
|
xmlNodePtr orignode;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
orignode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->scsi_target.name = virXPathString("string(./name[1])", ctxt);
|
2009-11-12 22:03:47 +00:00
|
|
|
if (!data->scsi_target.name) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("no target name supplied for '%s'"),
|
|
|
|
def->name);
|
2009-11-12 22:03:47 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
ctxt->node = orignode;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-24 14:55:45 +00:00
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapScsiHostParseXML(xmlXPathContextPtr ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
xmlNodePtr node,
|
2009-06-02 15:12:53 +00:00
|
|
|
union _virNodeDevCapData *data,
|
2012-02-10 04:51:47 +00:00
|
|
|
int create,
|
|
|
|
const char *virt_type)
|
2009-02-24 14:55:45 +00:00
|
|
|
{
|
2009-06-02 15:12:53 +00:00
|
|
|
xmlNodePtr orignode, *nodes = NULL;
|
|
|
|
int ret = -1, n = 0, i;
|
|
|
|
char *type = NULL;
|
2009-02-24 14:55:45 +00:00
|
|
|
|
|
|
|
orignode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2009-06-02 15:12:53 +00:00
|
|
|
if (create == EXISTING_DEVICE &&
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapsDefParseULong("number(./host[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->scsi_host.host, def,
|
|
|
|
_("no SCSI host ID supplied for '%s'"),
|
2009-06-02 15:12:53 +00:00
|
|
|
_("invalid SCSI host ID supplied for '%s'")) < 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) {
|
2009-02-24 14:55:45 +00:00
|
|
|
goto out;
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < n ; i++) {
|
|
|
|
type = virXMLPropString(nodes[i], "type");
|
|
|
|
|
|
|
|
if (!type) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("missing SCSI host capability type for '%s'"),
|
|
|
|
def->name);
|
2009-06-02 15:12:53 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ(type, "vport_ops")) {
|
|
|
|
|
|
|
|
data->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
|
|
|
|
|
|
|
|
} else if (STREQ(type, "fc_host")) {
|
|
|
|
|
|
|
|
xmlNodePtr orignode2;
|
|
|
|
|
|
|
|
data->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
|
|
|
|
|
|
|
|
orignode2 = ctxt->node;
|
|
|
|
ctxt->node = nodes[i];
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseString("string(./wwnn[1])",
|
2009-06-02 15:12:53 +00:00
|
|
|
ctxt,
|
2012-02-10 04:51:47 +00:00
|
|
|
&data->scsi_host.wwnn) < 0) {
|
|
|
|
if (virRandomGenerateWWN(&data->scsi_host.wwnn, virt_type) < 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("no WWNN supplied for '%s', and "
|
|
|
|
"auto-generation failed"),
|
|
|
|
def->name);
|
2012-02-10 04:51:47 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseString("string(./wwpn[1])",
|
2009-06-02 15:12:53 +00:00
|
|
|
ctxt,
|
2012-02-10 04:51:47 +00:00
|
|
|
&data->scsi_host.wwpn) < 0) {
|
|
|
|
if (virRandomGenerateWWN(&data->scsi_host.wwpn, virt_type) < 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("no WWPN supplied for '%s', and "
|
|
|
|
"auto-generation failed"),
|
|
|
|
def->name);
|
2012-02-10 04:51:47 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2009-06-02 15:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctxt->node = orignode2;
|
|
|
|
|
|
|
|
} else {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unknown SCSI host capability type '%s' for '%s'"),
|
|
|
|
type, def->name);
|
2009-06-02 15:12:53 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(type);
|
|
|
|
}
|
2009-02-24 14:55:45 +00:00
|
|
|
|
|
|
|
ret = 0;
|
2009-06-02 15:12:53 +00:00
|
|
|
|
2009-02-24 14:55:45 +00:00
|
|
|
out:
|
2009-06-02 15:12:53 +00:00
|
|
|
VIR_FREE(type);
|
2009-02-24 14:55:45 +00:00
|
|
|
ctxt->node = orignode;
|
2010-02-15 18:54:45 +00:00
|
|
|
VIR_FREE(nodes);
|
2009-02-24 14:55:45 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:12:53 +00:00
|
|
|
|
2009-02-24 14:55:45 +00:00
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
xmlNodePtr node,
|
|
|
|
union _virNodeDevCapData *data)
|
|
|
|
{
|
|
|
|
xmlNodePtr orignode;
|
|
|
|
int ret = -1;
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
orignode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->net.ifname = virXPathString("string(./interface[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
if (!data->net.ifname) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("no network interface supplied for '%s'"),
|
|
|
|
def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->net.address = virXPathString("string(./address[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
|
|
|
data->net.subtype = VIR_NODE_DEV_CAP_NET_LAST;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./capability/@type)", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
if (tmp) {
|
|
|
|
int val = virNodeDevNetCapTypeFromString(tmp);
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
if (val < 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("invalid network type supplied for '%s'"),
|
|
|
|
def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
data->net.subtype = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
ctxt->node = orignode;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapUsbInterfaceParseXML(xmlXPathContextPtr ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
xmlNodePtr node,
|
|
|
|
union _virNodeDevCapData *data)
|
|
|
|
{
|
|
|
|
xmlNodePtr orignode;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
orignode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./number[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->usb_if.number, def,
|
|
|
|
_("no USB interface number supplied for '%s'"),
|
|
|
|
_("invalid USB interface number supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./class[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->usb_if._class, def,
|
|
|
|
_("no USB interface class supplied for '%s'"),
|
|
|
|
_("invalid USB interface class supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./subclass[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->usb_if.subclass, def,
|
|
|
|
_("no USB interface subclass supplied for '%s'"),
|
|
|
|
_("invalid USB interface subclass supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./protocol[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->usb_if.protocol, def,
|
|
|
|
_("no USB interface protocol supplied for '%s'"),
|
|
|
|
_("invalid USB interface protocol supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->usb_if.description = virXPathString("string(./description[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
ctxt->node = orignode;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapsDefParseHexId(const char *xpath,
|
2009-02-24 14:55:45 +00:00
|
|
|
xmlXPathContextPtr ctxt,
|
|
|
|
unsigned *value,
|
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
const char *missing_error_fmt,
|
|
|
|
const char *invalid_error_fmt)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long val;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
ret = virXPathULongHex(xpath, ctxt, &val);
|
2009-02-24 14:55:45 +00:00
|
|
|
if (ret < 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
ret == -1 ? missing_error_fmt : invalid_error_fmt,
|
|
|
|
def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = val;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapUsbDevParseXML(xmlXPathContextPtr ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
xmlNodePtr node,
|
|
|
|
union _virNodeDevCapData *data)
|
|
|
|
{
|
|
|
|
xmlNodePtr orignode;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
orignode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->usb_dev.bus, def,
|
|
|
|
_("no USB bus number supplied for '%s'"),
|
|
|
|
_("invalid USB bus number supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./device[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->usb_dev.device, def,
|
|
|
|
_("no USB device number supplied for '%s'"),
|
|
|
|
_("invalid USB device number supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->usb_dev.vendor, def,
|
|
|
|
_("no USB vendor ID supplied for '%s'"),
|
|
|
|
_("invalid USB vendor ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->usb_dev.product, def,
|
|
|
|
_("no USB product ID supplied for '%s'"),
|
|
|
|
_("invalid USB product ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->usb_dev.vendor_name = virXPathString("string(./vendor[1])", ctxt);
|
|
|
|
data->usb_dev.product_name = virXPathString("string(./product[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
ctxt->node = orignode;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapPciDevParseXML(xmlXPathContextPtr ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
xmlNodePtr node,
|
|
|
|
union _virNodeDevCapData *data)
|
|
|
|
{
|
|
|
|
xmlNodePtr orignode;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
orignode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./domain[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->pci_dev.domain, def,
|
|
|
|
_("no PCI domain ID supplied for '%s'"),
|
|
|
|
_("invalid PCI domain ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->pci_dev.bus, def,
|
|
|
|
_("no PCI bus ID supplied for '%s'"),
|
|
|
|
_("invalid PCI bus ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./slot[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->pci_dev.slot, def,
|
|
|
|
_("no PCI slot ID supplied for '%s'"),
|
|
|
|
_("invalid PCI slot ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseULong("number(./function[1])", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->pci_dev.function, def,
|
|
|
|
_("no PCI function ID supplied for '%s'"),
|
|
|
|
_("invalid PCI function ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseHexId("string(./vendor[1]/@id)", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->pci_dev.vendor, def,
|
|
|
|
_("no PCI vendor ID supplied for '%s'"),
|
|
|
|
_("invalid PCI vendor ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-10 10:40:18 +00:00
|
|
|
if (virNodeDevCapsDefParseHexId("string(./product[1]/@id)", ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
&data->pci_dev.product, def,
|
|
|
|
_("no PCI product ID supplied for '%s'"),
|
|
|
|
_("invalid PCI product ID supplied for '%s'")) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->pci_dev.vendor_name = virXPathString("string(./vendor[1])", ctxt);
|
|
|
|
data->pci_dev.product_name = virXPathString("string(./product[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
ctxt->node = orignode;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
virNodeDeviceDefPtr def,
|
|
|
|
xmlNodePtr node,
|
|
|
|
union _virNodeDevCapData *data)
|
|
|
|
{
|
|
|
|
xmlNodePtr orignode;
|
|
|
|
int ret = -1;
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
orignode = ctxt->node;
|
|
|
|
ctxt->node = node;
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->system.product_name = virXPathString("string(./product[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->system.hardware.vendor_name = virXPathString("string(./hardware/vendor[1])", ctxt);
|
|
|
|
data->system.hardware.version = virXPathString("string(./hardware/version[1])", ctxt);
|
|
|
|
data->system.hardware.serial = virXPathString("string(./hardware/serial[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
tmp = virXPathString("string(./hardware/uuid[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
if (!tmp) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("no system UUID supplied for '%s'"), def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virUUIDParse(tmp, data->system.hardware.uuid) < 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("malformed uuid element for '%s'"), def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
VIR_FREE(tmp);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
|
2010-02-04 21:52:34 +00:00
|
|
|
data->system.firmware.vendor_name = virXPathString("string(./firmware/vendor[1])", ctxt);
|
|
|
|
data->system.firmware.version = virXPathString("string(./firmware/version[1])", ctxt);
|
|
|
|
data->system.firmware.release_date = virXPathString("string(./firmware/release_date[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
ctxt->node = orignode;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virNodeDevCapsDefPtr
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt,
|
2009-02-24 14:55:45 +00:00
|
|
|
virNodeDeviceDefPtr def,
|
2009-06-02 15:12:53 +00:00
|
|
|
xmlNodePtr node,
|
2012-02-10 04:51:47 +00:00
|
|
|
int create,
|
|
|
|
const char *virt_type)
|
2009-02-24 14:55:45 +00:00
|
|
|
{
|
|
|
|
virNodeDevCapsDefPtr caps;
|
|
|
|
char *tmp;
|
|
|
|
int val, ret;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(caps) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-02-24 14:55:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = virXMLPropString(node, "type");
|
|
|
|
if (!tmp) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("missing capability type"));
|
2009-02-24 14:55:45 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((val = virNodeDevCapTypeFromString(tmp)) < 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unknown capability type '%s'"), tmp);
|
2009-02-24 14:55:45 +00:00
|
|
|
VIR_FREE(tmp);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
caps->type = val;
|
|
|
|
VIR_FREE(tmp);
|
|
|
|
|
|
|
|
switch (caps->type) {
|
|
|
|
case VIR_NODE_DEV_CAP_SYSTEM:
|
2010-02-10 10:40:18 +00:00
|
|
|
ret = virNodeDevCapSystemParseXML(ctxt, def, node, &caps->data);
|
2009-02-24 14:55:45 +00:00
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_PCI_DEV:
|
2010-02-10 10:40:18 +00:00
|
|
|
ret = virNodeDevCapPciDevParseXML(ctxt, def, node, &caps->data);
|
2009-02-24 14:55:45 +00:00
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_USB_DEV:
|
2010-02-10 10:40:18 +00:00
|
|
|
ret = virNodeDevCapUsbDevParseXML(ctxt, def, node, &caps->data);
|
2009-02-24 14:55:45 +00:00
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_USB_INTERFACE:
|
2010-02-10 10:40:18 +00:00
|
|
|
ret = virNodeDevCapUsbInterfaceParseXML(ctxt, def, node, &caps->data);
|
2009-02-24 14:55:45 +00:00
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_NET:
|
2010-02-10 10:40:18 +00:00
|
|
|
ret = virNodeDevCapNetParseXML(ctxt, def, node, &caps->data);
|
2009-02-24 14:55:45 +00:00
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_SCSI_HOST:
|
2012-02-10 04:51:47 +00:00
|
|
|
ret = virNodeDevCapScsiHostParseXML(ctxt, def, node,
|
|
|
|
&caps->data,
|
|
|
|
create,
|
|
|
|
virt_type);
|
2009-02-24 14:55:45 +00:00
|
|
|
break;
|
2009-11-12 22:03:47 +00:00
|
|
|
case VIR_NODE_DEV_CAP_SCSI_TARGET:
|
2010-02-10 10:40:18 +00:00
|
|
|
ret = virNodeDevCapScsiTargetParseXML(ctxt, def, node, &caps->data);
|
2009-11-12 22:03:47 +00:00
|
|
|
break;
|
2009-02-24 14:55:45 +00:00
|
|
|
case VIR_NODE_DEV_CAP_SCSI:
|
2010-02-10 10:40:18 +00:00
|
|
|
ret = virNodeDevCapScsiParseXML(ctxt, def, node, &caps->data);
|
2009-02-24 14:55:45 +00:00
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_STORAGE:
|
2010-02-10 10:40:18 +00:00
|
|
|
ret = virNodeDevCapStorageParseXML(ctxt, def, node, &caps->data);
|
2009-02-24 14:55:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unknown capability type '%d' for '%s'"),
|
|
|
|
caps->type, def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
goto error;
|
|
|
|
return caps;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virNodeDevCapsDefFree(caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virNodeDeviceDefPtr
|
2012-02-10 04:51:47 +00:00
|
|
|
virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
|
|
|
|
int create,
|
|
|
|
const char *virt_type)
|
2009-02-24 14:55:45 +00:00
|
|
|
{
|
|
|
|
virNodeDeviceDefPtr def;
|
|
|
|
virNodeDevCapsDefPtr *next_cap;
|
|
|
|
xmlNodePtr *nodes;
|
|
|
|
int n, i;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(def) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-02-24 14:55:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract device name */
|
2009-06-02 15:12:53 +00:00
|
|
|
if (create == EXISTING_DEVICE) {
|
2010-02-04 21:52:34 +00:00
|
|
|
def->name = virXPathString("string(./name[1])", ctxt);
|
2009-11-08 21:08:54 +00:00
|
|
|
|
|
|
|
if (!def->name) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_NO_NAME, NULL);
|
2009-11-08 21:08:54 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2009-06-02 15:12:53 +00:00
|
|
|
} else {
|
|
|
|
def->name = strdup("new device");
|
|
|
|
|
2009-11-08 21:08:54 +00:00
|
|
|
if (!def->name) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-11-08 21:08:54 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2009-02-24 14:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract device parent, if any */
|
2010-02-04 21:52:34 +00:00
|
|
|
def->parent = virXPathString("string(./parent[1])", ctxt);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
|
|
|
/* Parse device capabilities */
|
|
|
|
nodes = NULL;
|
2011-05-12 19:45:22 +00:00
|
|
|
if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == 0) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("no device capabilities for '%s'"),
|
|
|
|
def->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
next_cap = &def->caps;
|
|
|
|
for (i = 0 ; i < n ; i++) {
|
2012-02-10 04:51:47 +00:00
|
|
|
*next_cap = virNodeDevCapsDefParseXML(ctxt, def,
|
|
|
|
nodes[i],
|
|
|
|
create,
|
|
|
|
virt_type);
|
2009-02-24 14:55:45 +00:00
|
|
|
if (!*next_cap) {
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
next_cap = &(*next_cap)->next;
|
|
|
|
}
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
|
|
|
|
return def;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virNodeDeviceDefFree(def);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-02 14:03:55 +00:00
|
|
|
virNodeDeviceDefPtr
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDeviceDefParseNode(xmlDocPtr xml,
|
2009-10-02 14:03:55 +00:00
|
|
|
xmlNodePtr root,
|
2012-02-10 04:51:47 +00:00
|
|
|
int create,
|
|
|
|
const char *virt_type)
|
2009-02-24 14:55:45 +00:00
|
|
|
{
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
virNodeDeviceDefPtr def = NULL;
|
|
|
|
|
|
|
|
if (!xmlStrEqual(root->name, BAD_CAST "device")) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR,
|
|
|
|
_("unexpected root element <%s> "
|
|
|
|
"expecting <device>"),
|
|
|
|
root->name);
|
2009-02-24 14:55:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt = xmlXPathNewContext(xml);
|
|
|
|
if (ctxt == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-02-24 14:55:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxt->node = root;
|
2012-02-10 04:51:47 +00:00
|
|
|
def = virNodeDeviceDefParseXML(ctxt, create, virt_type);
|
2009-02-24 14:55:45 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2009-10-02 14:03:55 +00:00
|
|
|
static virNodeDeviceDefPtr
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDeviceDefParse(const char *str,
|
2009-10-02 14:03:55 +00:00
|
|
|
const char *filename,
|
2012-02-10 04:51:47 +00:00
|
|
|
int create,
|
|
|
|
const char *virt_type)
|
2009-02-24 14:55:45 +00:00
|
|
|
{
|
2010-02-24 20:53:16 +00:00
|
|
|
xmlDocPtr xml;
|
2009-02-24 14:55:45 +00:00
|
|
|
virNodeDeviceDefPtr def = NULL;
|
|
|
|
|
2011-09-14 14:17:57 +00:00
|
|
|
if ((xml = virXMLParse(filename, str, _("(node_device_definition)")))) {
|
2012-02-10 04:51:47 +00:00
|
|
|
def = virNodeDeviceDefParseNode(xml, xmlDocGetRootElement(xml),
|
|
|
|
create, virt_type);
|
2010-02-24 20:53:16 +00:00
|
|
|
xmlFreeDoc(xml);
|
2009-10-02 14:03:55 +00:00
|
|
|
}
|
|
|
|
|
2009-02-24 14:55:45 +00:00
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2009-10-02 14:03:55 +00:00
|
|
|
virNodeDeviceDefPtr
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDeviceDefParseString(const char *str,
|
2012-02-10 04:51:47 +00:00
|
|
|
int create,
|
|
|
|
const char *virt_type)
|
2009-10-02 14:03:55 +00:00
|
|
|
{
|
2012-02-10 04:51:47 +00:00
|
|
|
return virNodeDeviceDefParse(str, NULL, create, virt_type);
|
2009-10-02 14:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virNodeDeviceDefPtr
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDeviceDefParseFile(const char *filename,
|
2012-02-10 04:51:47 +00:00
|
|
|
int create,
|
|
|
|
const char *virt_type)
|
2009-10-02 14:03:55 +00:00
|
|
|
{
|
2012-02-10 04:51:47 +00:00
|
|
|
return virNodeDeviceDefParse(NULL, filename, create, virt_type);
|
2009-10-02 14:03:55 +00:00
|
|
|
}
|
|
|
|
|
2009-10-14 19:47:10 +00:00
|
|
|
/*
|
|
|
|
* Return fc_host dev's WWNN and WWPN
|
|
|
|
*/
|
|
|
|
int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDeviceGetWWNs(virNodeDeviceDefPtr def,
|
2009-10-14 19:47:10 +00:00
|
|
|
char **wwnn,
|
|
|
|
char **wwpn)
|
|
|
|
{
|
|
|
|
virNodeDevCapsDefPtr cap = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
cap = def->caps;
|
|
|
|
while (cap != NULL) {
|
|
|
|
if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST &&
|
|
|
|
cap->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
|
|
|
|
*wwnn = strdup(cap->data.scsi_host.wwnn);
|
|
|
|
*wwpn = strdup(cap->data.scsi_host.wwpn);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cap = cap->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cap == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Device is not a fibre channel HBA"));
|
2009-10-14 19:47:10 +00:00
|
|
|
ret = -1;
|
2009-10-21 20:27:09 +00:00
|
|
|
} else if (*wwnn == NULL || *wwpn == NULL) {
|
2009-10-14 19:47:10 +00:00
|
|
|
/* Free the other one, if allocated... */
|
2010-08-17 15:49:12 +00:00
|
|
|
VIR_FREE(*wwnn);
|
|
|
|
VIR_FREE(*wwpn);
|
2009-10-14 19:47:10 +00:00
|
|
|
ret = -1;
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-10-14 19:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the NPIV dev's parent device name
|
|
|
|
*/
|
|
|
|
int
|
2010-02-10 10:40:18 +00:00
|
|
|
virNodeDeviceGetParentHost(const virNodeDeviceObjListPtr devs,
|
2009-10-14 19:47:10 +00:00
|
|
|
const char *dev_name,
|
|
|
|
const char *parent_name,
|
|
|
|
int *parent_host)
|
|
|
|
{
|
|
|
|
virNodeDeviceObjPtr parent = NULL;
|
|
|
|
virNodeDevCapsDefPtr cap = NULL;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
parent = virNodeDeviceFindByName(devs, parent_name);
|
|
|
|
if (parent == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Could not find parent device for '%s'"),
|
|
|
|
dev_name);
|
2009-10-14 19:47:10 +00:00
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
cap = parent->def->caps;
|
|
|
|
while (cap != NULL) {
|
|
|
|
if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST &&
|
|
|
|
(cap->data.scsi_host.flags &
|
|
|
|
VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)) {
|
|
|
|
*parent_host = cap->data.scsi_host.host;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cap = cap->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cap == NULL) {
|
2012-07-18 10:50:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Parent device %s is not capable "
|
|
|
|
"of vport operations"),
|
|
|
|
parent->def->name);
|
2009-10-14 19:47:10 +00:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virNodeDeviceObjUnlock(parent);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
2009-10-02 14:03:55 +00:00
|
|
|
|
2008-11-21 12:20:45 +00:00
|
|
|
void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
|
|
|
|
{
|
2009-12-14 13:44:12 +00:00
|
|
|
int i = 0;
|
2008-11-21 12:20:45 +00:00
|
|
|
union _virNodeDevCapData *data = &caps->data;
|
|
|
|
|
|
|
|
switch (caps->type) {
|
|
|
|
case VIR_NODE_DEV_CAP_SYSTEM:
|
|
|
|
VIR_FREE(data->system.product_name);
|
|
|
|
VIR_FREE(data->system.hardware.vendor_name);
|
|
|
|
VIR_FREE(data->system.hardware.version);
|
|
|
|
VIR_FREE(data->system.hardware.serial);
|
|
|
|
VIR_FREE(data->system.firmware.vendor_name);
|
|
|
|
VIR_FREE(data->system.firmware.version);
|
|
|
|
VIR_FREE(data->system.firmware.release_date);
|
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_PCI_DEV:
|
|
|
|
VIR_FREE(data->pci_dev.product_name);
|
|
|
|
VIR_FREE(data->pci_dev.vendor_name);
|
2009-12-14 13:44:12 +00:00
|
|
|
VIR_FREE(data->pci_dev.physical_function);
|
|
|
|
for (i = 0 ; i < data->pci_dev.num_virtual_functions ; i++) {
|
|
|
|
VIR_FREE(data->pci_dev.virtual_functions[i]);
|
|
|
|
}
|
2008-11-21 12:20:45 +00:00
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_USB_DEV:
|
|
|
|
VIR_FREE(data->usb_dev.product_name);
|
|
|
|
VIR_FREE(data->usb_dev.vendor_name);
|
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_USB_INTERFACE:
|
|
|
|
VIR_FREE(data->usb_if.description);
|
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_NET:
|
2008-11-25 10:37:02 +00:00
|
|
|
VIR_FREE(data->net.ifname);
|
2008-11-21 12:20:45 +00:00
|
|
|
VIR_FREE(data->net.address);
|
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_SCSI_HOST:
|
2009-06-25 14:51:21 +00:00
|
|
|
VIR_FREE(data->scsi_host.wwnn);
|
|
|
|
VIR_FREE(data->scsi_host.wwpn);
|
2011-12-06 12:09:03 +00:00
|
|
|
VIR_FREE(data->scsi_host.fabric_wwn);
|
2008-11-21 12:20:45 +00:00
|
|
|
break;
|
2009-11-12 22:03:47 +00:00
|
|
|
case VIR_NODE_DEV_CAP_SCSI_TARGET:
|
|
|
|
VIR_FREE(data->scsi_target.name);
|
|
|
|
break;
|
2008-11-21 12:20:45 +00:00
|
|
|
case VIR_NODE_DEV_CAP_SCSI:
|
|
|
|
VIR_FREE(data->scsi.type);
|
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_STORAGE:
|
2008-11-21 12:46:39 +00:00
|
|
|
VIR_FREE(data->storage.block);
|
2008-11-21 12:20:45 +00:00
|
|
|
VIR_FREE(data->storage.bus);
|
|
|
|
VIR_FREE(data->storage.drive_type);
|
|
|
|
VIR_FREE(data->storage.model);
|
|
|
|
VIR_FREE(data->storage.vendor);
|
2009-06-11 14:25:19 +00:00
|
|
|
VIR_FREE(data->storage.serial);
|
2009-12-14 13:58:23 +00:00
|
|
|
VIR_FREE(data->storage.media_label);
|
2008-11-21 12:20:45 +00:00
|
|
|
break;
|
|
|
|
case VIR_NODE_DEV_CAP_LAST:
|
|
|
|
/* This case is here to shutup the compiler */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(caps);
|
|
|
|
}
|
|
|
|
|
2008-12-04 20:53:20 +00:00
|
|
|
|
2008-12-04 22:00:14 +00:00
|
|
|
void virNodeDeviceObjLock(virNodeDeviceObjPtr obj)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexLock(&obj->lock);
|
2008-12-04 22:00:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj)
|
|
|
|
{
|
2009-01-15 19:56:05 +00:00
|
|
|
virMutexUnlock(&obj->lock);
|
2008-12-04 20:53:20 +00:00
|
|
|
}
|
2012-09-05 05:34:09 +00:00
|
|
|
|
|
|
|
static bool
|
|
|
|
virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj,
|
|
|
|
int type)
|
|
|
|
{
|
|
|
|
virNodeDevCapsDefPtr cap = NULL;
|
|
|
|
|
|
|
|
for (cap = devobj->def->caps; cap; cap = cap->next) {
|
|
|
|
if (type == cap->type)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MATCH(FLAG) (flags & (FLAG))
|
|
|
|
static bool
|
|
|
|
virNodeDeviceMatch(virNodeDeviceObjPtr devobj,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
/* filter by cap type */
|
|
|
|
if (MATCH(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP)) {
|
|
|
|
if (!((MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM) &&
|
|
|
|
virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_SYSTEM)) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV) &&
|
|
|
|
virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_PCI_DEV)) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV) &&
|
|
|
|
virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_USB_DEV)) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE) &&
|
|
|
|
virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_USB_INTERFACE)) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET) &&
|
|
|
|
virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_NET)) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST) &&
|
|
|
|
virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_SCSI_HOST)) ||
|
|
|
|
(MATCH(VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET) &&
|
|
|
|
virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_SCSI_TARGET)) ||
|
|
|
|
(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))))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#undef MATCH
|
|
|
|
|
|
|
|
int
|
|
|
|
virNodeDeviceList(virConnectPtr conn,
|
|
|
|
virNodeDeviceObjList devobjs,
|
|
|
|
virNodeDevicePtr **devices,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virNodeDevicePtr *tmp_devices = NULL;
|
|
|
|
virNodeDevicePtr device = NULL;
|
|
|
|
int ndevices = 0;
|
|
|
|
int ret = -1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (devices) {
|
|
|
|
if (VIR_ALLOC_N(tmp_devices, devobjs.count + 1) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < devobjs.count; i++) {
|
|
|
|
virNodeDeviceObjPtr devobj = devobjs.objs[i];
|
|
|
|
virNodeDeviceObjLock(devobj);
|
|
|
|
if (virNodeDeviceMatch(devobj, flags)) {
|
|
|
|
if (devices) {
|
|
|
|
if (!(device = virGetNodeDevice(conn,
|
|
|
|
devobj->def->name))) {
|
|
|
|
virNodeDeviceObjUnlock(devobj);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
tmp_devices[ndevices] = device;
|
|
|
|
}
|
|
|
|
ndevices++;
|
|
|
|
}
|
|
|
|
virNodeDeviceObjUnlock(devobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp_devices) {
|
|
|
|
/* trim the array to the final size */
|
|
|
|
ignore_value(VIR_REALLOC_N(tmp_devices, ndevices + 1));
|
|
|
|
*devices = tmp_devices;
|
|
|
|
tmp_devices = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ndevices;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (tmp_devices) {
|
|
|
|
for (i = 0; i < ndevices; i++) {
|
|
|
|
if (tmp_devices[i])
|
|
|
|
virNodeDeviceFree(tmp_devices[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(tmp_devices);
|
|
|
|
return ret;
|
|
|
|
}
|