<disk type='block' device='lun'>
<driver name='qemu' type='raw'/>
<source dev='/dev/sda'>
- <reservations enabled='yes' managed='no'>
+ <reservations managed='no'>
<source type='unix' path='/path/to/qemu-pr-helper' mode='client'/>
</reservations>
<target dev='sda' bus='scsi'/>
<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>
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;
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;
}
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");
}
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;
bool
virStoragePRDefIsEnabled(virStoragePRDefPtr prd)
{
- return prd && prd->enabled == VIR_TRISTATE_BOOL_YES;
+ return !!prd;
}