提交 e72b3f0b 编写于 作者: P Peter Krempa

util: storage: Drop pointless 'enabled' form PR definition

Everything can be disabled by not using the parent element. There's no
need to store this explicitly. Additionally it does not add any value
since any configuration is dropped if enabled='no' is configured.

Drop the attribute and adjust the code accordingly.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
上级 1efda367
......@@ -2583,7 +2583,7 @@
&lt;disk type='block' device='lun'&gt;
&lt;driver name='qemu' type='raw'/&gt;
&lt;source dev='/dev/sda'&gt;
&lt;reservations enabled='yes' managed='no'&gt;
&lt;reservations managed='no'&gt;
&lt;source type='unix' path='/path/to/qemu-pr-helper' mode='client'/&gt;
&lt;/reservations&gt;
&lt;target dev='sda' bus='scsi'/&gt;
......@@ -2952,19 +2952,19 @@
<dd><span class="since">Since libvirt 4.4.0</span>, the
<code>reservations</code> can be a sub-element of the
<code>source</code> element for storage sources (QEMU driver only).
If present (and enabled) it enables persistent reservations for SCSI
If present it enables persistent reservations for SCSI
based disks. The element has one mandatory attribute
<code>enabled</code> with accepted values <code>yes</code> and
<code>no</code>. If the feature is enabled, then there's another
mandatory attribute <code>managed</code> (accepted values are the
same as for <code>enabled</code>) that enables or disables libvirt
spawning a helper process. When the PR is unmanaged, then hypervisor
acts as a client and path to server socket must be provided in child
element <code>source</code>, which currently accepts only the
following attributes: <code>type</code> with one value
<code>unix</code>, <code>path</code> with path the socket, and
<code>managed</code> with accepted values <code>yes</code> and
<code>no</code>. If <code>managed</code> is enabled libvirt prepares
and manages any resources needed. When the persistent reservations
are unmanaged, then the hypervisor acts as a client and the path to
the server socket must be provided in the child element
<code>source</code>, which currently accepts only the following
attributes:
<code>type</code> with one value <code>unix</code>,
<code>path</code> path to the socket, and
finally <code>mode</code> which accepts one value
<code>client</code> and specifies the role of hypervisor.
<code>client</code> specifying the role of hypervisor.
It's recommended to allow libvirt manage the persistent
reservations.
</dd>
......
......@@ -75,9 +75,6 @@
<define name='reservations'>
<element name='reservations'>
<attribute name='enabled'>
<ref name='virYesNo'/>
</attribute>
<optional>
<attribute name='managed'>
<ref name='virYesNo'/>
......
......@@ -1906,8 +1906,8 @@ virStoragePRDefFree(virStoragePRDefPtr prd)
virStoragePRDefPtr
virStoragePRDefParseXML(xmlXPathContextPtr ctxt)
{
virStoragePRDefPtr prd, ret = NULL;
char *enabled = NULL;
virStoragePRDefPtr prd;
virStoragePRDefPtr ret = NULL;
char *managed = NULL;
char *type = NULL;
char *path = NULL;
......@@ -1916,81 +1916,65 @@ virStoragePRDefParseXML(xmlXPathContextPtr ctxt)
if (VIR_ALLOC(prd) < 0)
return NULL;
if (!(enabled = virXPathString("string(./@enabled)", ctxt))) {
if (!(managed = virXPathString("string(./@managed)", ctxt))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing @enabled attribute for <reservations/>"));
_("missing @managed attribute for <reservations/>"));
goto cleanup;
}
if ((prd->enabled = virTristateBoolTypeFromString(enabled)) <= 0) {
if ((prd->managed = virTristateBoolTypeFromString(managed)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid value for 'enabled': %s"), enabled);
_("invalid value for 'managed': %s"), managed);
goto cleanup;
}
if (prd->enabled == VIR_TRISTATE_BOOL_YES) {
if (!(managed = virXPathString("string(./@managed)", ctxt))) {
if (prd->managed == VIR_TRISTATE_BOOL_NO) {
type = virXPathString("string(./source[1]/@type)", ctxt);
path = virXPathString("string(./source[1]/@path)", ctxt);
mode = virXPathString("string(./source[1]/@mode)", ctxt);
if (!type) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing @managed attribute for <reservations/>"));
_("missing connection type for <reservations/>"));
goto cleanup;
}
if ((prd->managed = virTristateBoolTypeFromString(managed)) <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("invalid value for 'managed': %s"), managed);
if (!path) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing path for <reservations/>"));
goto cleanup;
}
if (prd->managed == VIR_TRISTATE_BOOL_NO) {
type = virXPathString("string(./source[1]/@type)", ctxt);
path = virXPathString("string(./source[1]/@path)", ctxt);
mode = virXPathString("string(./source[1]/@mode)", ctxt);
if (!type) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing connection type for <reservations/>"));
goto cleanup;
}
if (!path) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing path for <reservations/>"));
goto cleanup;
}
if (!mode) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing connection mode for <reservations/>"));
goto cleanup;
}
if (STRNEQ(type, "unix")) {
virReportError(VIR_ERR_XML_ERROR,
_("unsupported connection type for <reservations/>: %s"),
type);
goto cleanup;
}
if (!mode) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing connection mode for <reservations/>"));
goto cleanup;
}
if (STRNEQ(mode, "client")) {
virReportError(VIR_ERR_XML_ERROR,
_("unsupported connection mode for <reservations/>: %s"),
mode);
goto cleanup;
}
if (STRNEQ(type, "unix")) {
virReportError(VIR_ERR_XML_ERROR,
_("unsupported connection type for <reservations/>: %s"),
type);
goto cleanup;
}
VIR_STEAL_PTR(prd->path, path);
if (STRNEQ(mode, "client")) {
virReportError(VIR_ERR_XML_ERROR,
_("unsupported connection mode for <reservations/>: %s"),
mode);
goto cleanup;
}
VIR_STEAL_PTR(prd->path, path);
}
ret = prd;
prd = NULL;
VIR_STEAL_PTR(ret, prd);
cleanup:
VIR_FREE(mode);
VIR_FREE(path);
VIR_FREE(type);
VIR_FREE(managed);
VIR_FREE(enabled);
virStoragePRDefFree(prd);
return ret;
}
......@@ -2000,22 +1984,16 @@ void
virStoragePRDefFormat(virBufferPtr buf,
virStoragePRDefPtr prd)
{
virBufferAsprintf(buf, "<reservations enabled='%s'",
virTristateBoolTypeToString(prd->enabled));
if (prd->enabled == VIR_TRISTATE_BOOL_YES) {
virBufferAsprintf(buf, " managed='%s'",
virTristateBoolTypeToString(prd->managed));
if (prd->managed == VIR_TRISTATE_BOOL_NO) {
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
virBufferAddLit(buf, "<source type='unix'");
virBufferEscapeString(buf, " path='%s'", prd->path);
virBufferAddLit(buf, " mode='client'/>\n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</reservations>\n");
} else {
virBufferAddLit(buf, "/>\n");
}
virBufferAsprintf(buf, "<reservations managed='%s'",
virTristateBoolTypeToString(prd->managed));
if (prd->managed == VIR_TRISTATE_BOOL_NO) {
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
virBufferAddLit(buf, "<source type='unix'");
virBufferEscapeString(buf, " path='%s'", prd->path);
virBufferAddLit(buf, " mode='client'/>\n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</reservations>\n");
} else {
virBufferAddLit(buf, "/>\n");
}
......@@ -2032,8 +2010,7 @@ virStoragePRDefIsEqual(virStoragePRDefPtr a,
if (!a || !b)
return false;
if (a->enabled != b->enabled ||
a->managed != b->managed ||
if (a->managed != b->managed ||
STRNEQ_NULLABLE(a->path, b->path))
return false;
......@@ -2044,7 +2021,7 @@ virStoragePRDefIsEqual(virStoragePRDefPtr a,
bool
virStoragePRDefIsEnabled(virStoragePRDefPtr prd)
{
return prd && prd->enabled == VIR_TRISTATE_BOOL_YES;
return !!prd;
}
......
......@@ -219,7 +219,6 @@ struct _virStorageAuthDef {
typedef struct _virStoragePRDef virStoragePRDef;
typedef virStoragePRDef *virStoragePRDefPtr;
struct _virStoragePRDef {
int enabled; /* enum virTristateBool */
int managed; /* enum virTristateBool */
char *path;
};
......
......@@ -17,7 +17,7 @@
<disk type='block' device='lun'>
<driver name='qemu' type='raw'/>
<source dev='/dev/HostVG/QEMUGuest1'>
<reservations enabled='yes' managed='yes'/>
<reservations managed='yes'/>
</source>
<target dev='sda' bus='scsi'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
......@@ -25,7 +25,7 @@
<disk type='block' device='lun'>
<driver name='qemu' type='raw'/>
<source dev='/dev/HostVG/QEMUGuest2'>
<reservations enabled='yes' managed='no'>
<reservations managed='no'>
<source type='unix' path='/path/to/qemu-pr-helper.sock' mode='client'/>
</reservations>
</source>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册