提交 42957661 编写于 作者: J John Ferlan

hostdev: Introduce virDomainHostdevSubsysSCSIHost

Split virDomainHostdevSubsysSCSI further. In preparation for having
either SCSI or iSCSI data, create a union in virDomainHostdevSubsysSCSI
to contain just a virDomainHostdevSubsysSCSIHost to describe the
'scsi_host' host device
上级 5805621c
......@@ -423,14 +423,16 @@ virDomainAuditHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev,
goto cleanup;
}
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
if (virAsprintfQuiet(&address, "%s:%d:%d:%d",
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit) < 0) {
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit) < 0) {
VIR_WARN("OOM while encoding audit message");
goto cleanup;
}
break;
}
default:
VIR_WARN("Unexpected hostdev type while encoding audit message: %d",
hostdev->source.subsys.type);
......
......@@ -1726,7 +1726,7 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
break;
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
VIR_FREE(def->source.subsys.u.scsi.adapter);
VIR_FREE(def->source.subsys.u.scsi.u.host.adapter);
break;
}
}
......@@ -4011,16 +4011,16 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr node,
}
static int
virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr node,
virDomainHostdevDefPtr def)
virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode,
virDomainHostdevSubsysSCSIPtr scsisrc)
{
int ret = -1;
bool got_address = false, got_adapter = false;
xmlNodePtr cur;
char *bus = NULL, *target = NULL, *unit = NULL;
virDomainHostdevSubsysSCSIPtr scsisrc = &def->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
cur = node->children;
cur = sourcenode->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
if (xmlStrEqual(cur->name, BAD_CAST "address")) {
......@@ -4040,19 +4040,20 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr node,
goto cleanup;
}
if (virStrToLong_ui(bus, NULL, 0, &scsisrc->bus) < 0) {
if (virStrToLong_ui(bus, NULL, 0, &scsihostsrc->bus) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse bus '%s'"), bus);
goto cleanup;
}
if (virStrToLong_ui(target, NULL, 0, &scsisrc->target) < 0) {
if (virStrToLong_ui(target, NULL, 0,
&scsihostsrc->target) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse target '%s'"), target);
goto cleanup;
}
if (virStrToLong_ui(unit, NULL, 0, &scsisrc->unit) < 0) {
if (virStrToLong_ui(unit, NULL, 0, &scsihostsrc->unit) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse unit '%s'"), unit);
goto cleanup;
......@@ -4066,7 +4067,7 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr node,
"for scsi hostdev source"));
goto cleanup;
}
if (!(scsisrc->adapter = virXMLPropString(cur, "name"))) {
if (!(scsihostsrc->adapter = virXMLPropString(cur, "name"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("'adapter' must be specified for scsi hostdev source"));
goto cleanup;
......@@ -4098,6 +4099,13 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr node,
return ret;
}
static int
virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode,
virDomainHostdevSubsysSCSIPtr scsisrc)
{
return virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsisrc);
}
/* Check if a drive type address $controller:0:0:$unit is already
* taken by a disk or not.
*/
......@@ -4336,7 +4344,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, def) < 0)
if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc) < 0)
goto error;
break;
......@@ -10231,17 +10239,18 @@ virDomainHostdevMatchSubsysPCI(virDomainHostdevDefPtr first,
}
static int
virDomainHostdevMatchSubsysSCSI(virDomainHostdevDefPtr first,
virDomainHostdevDefPtr second)
{
virDomainHostdevSubsysSCSIPtr first_scsisrc = &first->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIPtr second_scsisrc =
&second->source.subsys.u.scsi;
if (STREQ(first_scsisrc->adapter, second_scsisrc->adapter) &&
first_scsisrc->bus == second_scsisrc->bus &&
first_scsisrc->target == second_scsisrc->target &&
first_scsisrc->unit == second_scsisrc->unit)
virDomainHostdevMatchSubsysSCSIHost(virDomainHostdevDefPtr first,
virDomainHostdevDefPtr second)
{
virDomainHostdevSubsysSCSIHostPtr first_scsihostsrc =
&first->source.subsys.u.scsi.u.host;
virDomainHostdevSubsysSCSIHostPtr second_scsihostsrc =
&second->source.subsys.u.scsi.u.host;
if (STREQ(first_scsihostsrc->adapter, second_scsihostsrc->adapter) &&
first_scsihostsrc->bus == second_scsihostsrc->bus &&
first_scsihostsrc->target == second_scsihostsrc->target &&
first_scsihostsrc->unit == second_scsihostsrc->unit)
return 1;
return 0;
}
......@@ -10259,7 +10268,7 @@ virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
return virDomainHostdevMatchSubsysUSB(a, b);
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
return virDomainHostdevMatchSubsysSCSI(a, b);
return virDomainHostdevMatchSubsysSCSIHost(a, b);
}
return 0;
}
......@@ -15526,6 +15535,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
virDomainHostdevSubsysPCIPtr pcisrc = &def->source.subsys.u.pci;
virDomainHostdevSubsysSCSIPtr scsisrc = &def->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
pcisrc->backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) {
......@@ -15594,10 +15604,11 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
virBufferAsprintf(buf, "<adapter name='%s'/>\n",
scsisrc->adapter);
scsihostsrc->adapter);
virBufferAsprintf(buf, "<address %sbus='%d' target='%d' unit='%d'/>\n",
includeTypeInAddr ? "type='scsi' " : "",
scsisrc->bus, scsisrc->target, scsisrc->unit);
scsihostsrc->bus, scsihostsrc->target,
scsihostsrc->unit);
break;
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
......
......@@ -407,14 +407,22 @@ struct _virDomainHostdevSubsysPCI {
int backend; /* enum virDomainHostdevSubsysPCIBackendType */
};
typedef struct _virDomainHostdevSubsysSCSI virDomainHostdevSubsysSCSI;
typedef virDomainHostdevSubsysSCSI *virDomainHostdevSubsysSCSIPtr;
struct _virDomainHostdevSubsysSCSI {
typedef struct _virDomainHostdevSubsysSCSIHost virDomainHostdevSubsysSCSIHost;
typedef virDomainHostdevSubsysSCSIHost *virDomainHostdevSubsysSCSIHostPtr;
struct _virDomainHostdevSubsysSCSIHost {
char *adapter;
unsigned bus;
unsigned target;
unsigned unit;
};
typedef struct _virDomainHostdevSubsysSCSI virDomainHostdevSubsysSCSI;
typedef virDomainHostdevSubsysSCSI *virDomainHostdevSubsysSCSIPtr;
struct _virDomainHostdevSubsysSCSI {
int sgio; /* enum virDomainDeviceSGIO */
union {
virDomainHostdevSubsysSCSIHost host;
} u;
};
typedef struct _virDomainHostdevSubsys virDomainHostdevSubsys;
......
......@@ -306,10 +306,11 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
}
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
if ((scsi = virSCSIDeviceNew(NULL,
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit,
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit,
dev->readonly,
dev->shareable)) == NULL)
goto cleanup;
......@@ -318,6 +319,8 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
qemuSetupHostSCSIDeviceCgroup,
vm) < 0)
goto cleanup;
break;
}
default:
break;
......
......@@ -5131,11 +5131,14 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
char *sg = NULL;
sg = (callbacks->qemuGetSCSIDeviceSgName)(NULL,
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit);
scsihostsrc->adapter,
scsihostsrc->bus,
scsihostsrc->target,
scsihostsrc->unit);
if (!sg)
goto error;
......
......@@ -928,11 +928,12 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
goto cleanup;
} else {
virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
if (!(dev_name = virSCSIDeviceGetDevName(NULL,
scsisrc->adapter,
scsisrc->bus,
scsisrc->target,
scsisrc->unit)))
scsihostsrc->adapter,
scsihostsrc->bus,
scsihostsrc->target,
scsihostsrc->unit)))
goto cleanup;
if (virAsprintf(&dev_path, "/dev/%s", dev_name) < 0)
......@@ -1034,11 +1035,12 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
goto cleanup;
} else {
virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
if (!(dev_name = virSCSIDeviceGetDevName(NULL,
scsisrc->adapter,
scsisrc->bus,
scsisrc->target,
scsisrc->unit)))
scsihostsrc->adapter,
scsihostsrc->bus,
scsihostsrc->target,
scsihostsrc->unit)))
goto cleanup;
if (virAsprintf(&dev_path, "/dev/%s", dev_name) < 0)
......
......@@ -1574,10 +1574,11 @@ qemuDomainAttachHostSCSIDevice(virQEMUDriverPtr driver,
if (qemuPrepareHostdevSCSIDevices(driver, vm->def->name,
&hostdev, 1)) {
virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to prepare scsi hostdev: %s:%d:%d:%d"),
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit);
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit);
return -1;
}
......@@ -3393,12 +3394,14 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
usbsrc->vendor, usbsrc->product);
}
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
virReportError(VIR_ERR_OPERATION_FAILED,
_("host scsi device %s:%d:%d.%d not found"),
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit);
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit);
break;
}
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected hostdev type %d"), subsys->type);
......
......@@ -870,10 +870,11 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
virSCSIDevicePtr scsi =
virSCSIDeviceNew(NULL,
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit,
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit,
dev->readonly, dev->shareable);
if (!scsi)
......
......@@ -571,10 +571,11 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
virSCSIDevicePtr scsi =
virSCSIDeviceNew(NULL,
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit,
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit,
dev->readonly, dev->shareable);
if (!scsi)
......@@ -688,10 +689,11 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr mgr,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
virSCSIDevicePtr scsi =
virSCSIDeviceNew(NULL,
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit,
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit,
dev->readonly, dev->shareable);
if (!scsi)
......
......@@ -1367,10 +1367,11 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr def,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
virSCSIDevicePtr scsi =
virSCSIDeviceNew(NULL,
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit,
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit,
dev->readonly, dev->shareable);
if (!scsi)
......@@ -1554,10 +1555,11 @@ virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virSecurityManagerPtr mgr,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: {
virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
virSCSIDevicePtr scsi =
virSCSIDeviceNew(NULL,
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit,
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit,
dev->readonly, dev->shareable);
if (!scsi)
......
......@@ -938,17 +938,17 @@ virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr,
virObjectLock(mgr->activeSCSIHostdevs);
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevSubsysSCSIPtr scsisrc;
virDomainHostdevSubsysSCSIHostPtr scsihostsrc;
hostdev = hostdevs[i];
scsisrc = &hostdev->source.subsys.u.scsi;
scsihostsrc = &hostdev->source.subsys.u.scsi.u.host;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
continue;
if (!(scsi = virSCSIDeviceNew(NULL,
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit,
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit,
hostdev->readonly, hostdev->shareable)))
goto cleanup;
......@@ -1219,8 +1219,8 @@ virHostdevPrepareSCSIDevices(virHostdevManagerPtr hostdev_mgr,
/* Loop 1: build temporary list */
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
virDomainHostdevSubsysSCSIPtr scsisrc =
&hostdev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIHostPtr scsihostsrc =
&hostdev->source.subsys.u.scsi.u.host;
virSCSIDevicePtr scsi;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
......@@ -1234,8 +1234,8 @@ virHostdevPrepareSCSIDevices(virHostdevManagerPtr hostdev_mgr,
}
if (!(scsi = virSCSIDeviceNew(NULL,
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit,
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit,
hostdev->readonly, hostdev->shareable)))
goto cleanup;
......@@ -1381,8 +1381,8 @@ virHostdevReAttachSCSIDevices(virHostdevManagerPtr hostdev_mgr,
virObjectLock(hostdev_mgr->activeSCSIHostdevs);
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
virDomainHostdevSubsysSCSIPtr scsisrc =
&hostdev->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIHostPtr scsihostsrc =
&hostdev->source.subsys.u.scsi.u.host;
virSCSIDevicePtr scsi;
virSCSIDevicePtr tmp;
......@@ -1391,12 +1391,12 @@ virHostdevReAttachSCSIDevices(virHostdevManagerPtr hostdev_mgr,
continue;
if (!(scsi = virSCSIDeviceNew(NULL,
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit,
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit,
hostdev->readonly, hostdev->shareable))) {
VIR_WARN("Unable to reattach SCSI device %s:%d:%d:%d on domain %s",
scsisrc->adapter, scsisrc->bus, scsisrc->target,
scsisrc->unit, dom_name);
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit, dom_name);
continue;
}
......@@ -1406,15 +1406,15 @@ virHostdevReAttachSCSIDevices(virHostdevManagerPtr hostdev_mgr,
if (!(tmp = virSCSIDeviceListFind(hostdev_mgr->activeSCSIHostdevs, scsi))) {
VIR_WARN("Unable to find device %s:%d:%d:%d "
"in list of active SCSI devices",
scsisrc->adapter, scsisrc->bus,
scsisrc->target, scsisrc->unit);
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit);
virSCSIDeviceFree(scsi);
continue;
}
VIR_DEBUG("Removing %s:%d:%d:%d dom=%s from activeSCSIHostdevs",
scsisrc->adapter, scsisrc->bus, scsisrc->target,
scsisrc->unit, dom_name);
scsihostsrc->adapter, scsihostsrc->bus,
scsihostsrc->target, scsihostsrc->unit, dom_name);
virSCSIDeviceListDel(hostdev_mgr->activeSCSIHostdevs, tmp,
drv_name, dom_name);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册