From 676531609382f7ff57ec614b9ea8f91a991aca9b Mon Sep 17 00:00:00 2001 From: Osier Yang Date: Sat, 4 May 2013 02:07:40 +0800 Subject: [PATCH] conf: Introduce sgio for hostdev "sgio" is only valid for scsi host device. --- docs/formatdomain.html.in | 7 +++- docs/schemas/domaincommon.rng | 8 +++++ src/conf/domain_conf.c | 34 +++++++++++++++--- src/conf/domain_conf.h | 1 + .../qemuxml2argv-hostdev-scsi-sgio.xml | 35 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 6 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-sgio.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 97dffc8b50..c6c0728a4f 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2414,7 +2414,12 @@ and virNodeDeviceReAttach (or virsh nodedev-reattach) after hot-unplug or stopping the guest. For SCSI device, user is responsible to make sure the device - is not used by host. + is not used by host. + The optional sgio (since 1.0.6) + attribute indicates whether the kernel will filter unprivileged + SG_IO commands for the disk, valid settings are "filtered" or + "unfiltered". Defaults to "filtered". +
source
The source element describes the device as seen from the host. The USB device can either be addressed by vendor / product id using the diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 548838f90d..8c7c1bcf01 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3234,6 +3234,14 @@ scsi + + + + filtered + unfiltered + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 640c798487..11978dbe2e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3790,6 +3790,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, { xmlNodePtr sourcenode; char *managed = NULL; + char *sgio = NULL; char *backendStr = NULL; int backend; int ret = -1; @@ -3804,6 +3805,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, def->managed = true; } + sgio = virXMLPropString(node, "sgio"); + /* @type is passed in from the caller rather than read from the * xml document, because it is specified in different places for * different kinds of defs - it is an attribute of @@ -3840,6 +3843,22 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, goto error; } + if (sgio) { + if (def->source.subsys.type != + VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("sgio is only supported for scsi host device")); + goto error; + } + + if ((def->source.subsys.u.scsi.sgio = + virDomainDeviceSGIOTypeFromString(sgio)) <= 0) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown sgio mode '%s'"), sgio); + goto error; + } + } + switch (def->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (virDomainHostdevSubsysPciDefParseXML(sourcenode, def, flags) < 0) @@ -3878,6 +3897,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, ret = 0; error: VIR_FREE(managed); + VIR_FREE(sgio); VIR_FREE(backendStr); return ret; } @@ -15439,11 +15459,17 @@ virDomainHostdevDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) - virBufferAsprintf(buf, " managed='%s'>\n", + if (def->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { + virBufferAsprintf(buf, " managed='%s'", def->managed ? "yes" : "no"); - else - virBufferAddLit(buf, ">\n"); + + if (def->source.subsys.type == + VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI && + def->source.subsys.u.scsi.sgio) + virBufferAsprintf(buf, " sgio='%s'", + virDomainDeviceSGIOTypeToString(def->source.subsys.u.scsi.sgio)); + } + virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 6); switch (def->mode) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ff79f587b5..f40bfc64d3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -423,6 +423,7 @@ struct _virDomainHostdevSubsys { unsigned bus; unsigned target; unsigned unit; + int sgio; /* enum virDomainDeviceSGIO */ } scsi; } u; }; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-sgio.xml b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-sgio.xml new file mode 100644 index 0000000000..21404eee07 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-scsi-sgio.xml @@ -0,0 +1,35 @@ + + QEMUGuest2 + c7a5fdbd-edaf-9466-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + + + + +
+ +
+ + + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index ba492d141f..fde6fa373c 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -295,6 +295,7 @@ mymain(void) DO_TEST("disk-copy_on_read"); DO_TEST("hostdev-scsi-shareable"); + DO_TEST("hostdev-scsi-sgio"); virObjectUnref(driver.caps); virObjectUnref(driver.xmlopt); -- GitLab