Add <features> and <compat> elements to volume target XML.
<compat> is a string which for qcow2 represents the QEMU version
it should be compatible with. Valid values are 0.10 and 1.1.
1.1 is implicit if the <features> element is present, otherwise
qemu-img default is used. 0.10 can be specified to explicitly
create older images after the qemu-img default changes.
<features> contains optional features, so far
<lazy_refcounts/> is available, which enables caching of reference
counters, improving performance for snapshots.
<mode>0744</mode>
<label>virt_image_t</label>
</permissions>
+ <compat>1.1</compat>
+ <features>
+ <lazy_refcounts/>
+ </features>
</target></pre>
<dl>
contains the MAC (eg SELinux) label string.
<span class="since">Since 0.4.1</span>
</dd>
+ <dt><code>compat</code></dt>
+ <dd>Specify compatibility level. So far, this is only used for
+ <code>type='qcow2'</code> volumes. Valid values are <code>0.10</code>
+ and <code>1.1</code> so far, specifying QEMU version the images should
+ be compatible with. If the <code>feature</code> element is present,
+ 1.1 is used. If omitted, qemu-img default is used.
+ <span class="since">Since 1.0.7</span>
+ </dd>
+ <dt><code>features</code></dt>
+ <dd>Format-specific features. Only used for <code>qcow2</code> now.
+ Valid sub-elements are:
+ <ul>
+ <li><code><lazy_refcounts/></code> - allow delayed reference
+ counter updates. <span class="since">Since 1.0.7</span></li>
+ </ul>
+ </dd>
</dl>
<h3><a name="StorageVolBacking">Backing store elements</a></h3>
nwfilter.rng \
secret.rng \
storageencryption.rng \
+ storagefilefeatures.rng \
storagepool.rng \
storagevol.rng
--- /dev/null
+<?xml version="1.0"?>
+<!-- A Relax NG schema for the libvirt volume features XML format -->
+<grammar xmlns="http://relaxng.org/ns/structure/1.0"
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+
+ <define name='compat'>
+ <element name='compat'>
+ <data type='string'>
+ <param name='pattern'>[0-9]+\.[0-9]+</param>
+ </data>
+ </element>
+ </define>
+ <define name='fileFormatFeatures'>
+ <element name='features'>
+ <interleave>
+ <optional>
+ <element name='lazy_refcounts'>
+ <empty/>
+ </element>
+ </optional>
+ </interleave>
+ </element>
+ </define>
+</grammar>
</start>
<include href='storageencryption.rng'/>
+ <include href='storagefilefeatures.rng'/>
<define name='vol'>
<optional>
<ref name='encryption'/>
</optional>
+ <optional>
+ <ref name='compat'/>
+ </optional>
+ <optional>
+ <ref name='fileFormatFeatures'/>
+ </optional>
</element>
</define>
%{_datadir}/libvirt/schemas/nwfilter.rng
%{_datadir}/libvirt/schemas/secret.rng
%{_datadir}/libvirt/schemas/storageencryption.rng
+%{_datadir}/libvirt/schemas/storagefilefeatures.rng
%{_datadir}/libvirt/schemas/storagepool.rng
%{_datadir}/libvirt/schemas/storagevol.rng
%{mingw32_datadir}/libvirt/schemas/nwfilter.rng
%{mingw32_datadir}/libvirt/schemas/secret.rng
%{mingw32_datadir}/libvirt/schemas/storageencryption.rng
+%{mingw32_datadir}/libvirt/schemas/storagefilefeatures.rng
%{mingw32_datadir}/libvirt/schemas/storagepool.rng
%{mingw32_datadir}/libvirt/schemas/storagevol.rng
%dir %{mingw32_datadir}/libvirt/api/
%{mingw64_datadir}/libvirt/schemas/nwfilter.rng
%{mingw64_datadir}/libvirt/schemas/secret.rng
%{mingw64_datadir}/libvirt/schemas/storageencryption.rng
+%{mingw64_datadir}/libvirt/schemas/storagefilefeatures.rng
%{mingw64_datadir}/libvirt/schemas/storagepool.rng
%{mingw64_datadir}/libvirt/schemas/storagevol.rng
%dir %{mingw64_datadir}/libvirt/api/
typedef const char *(*virStorageVolFormatToString)(int format);
typedef int (*virStorageVolFormatFromString)(const char *format);
+typedef const char *(*virStorageVolFeatureToString)(int feature);
+typedef int (*virStorageVolFeatureFromString)(const char *feature);
typedef const char *(*virStoragePoolFormatToString)(int format);
typedef int (*virStoragePoolFormatFromString)(const char *format);
int defaultFormat;
virStorageVolFormatToString formatToString;
virStorageVolFormatFromString formatFromString;
+ virStorageVolFeatureToString featureToString;
+ virStorageVolFeatureFromString featureFromString;
};
/* Flags to indicate mandatory components in the pool source */
.defaultFormat = VIR_STORAGE_FILE_RAW,
.formatFromString = virStorageVolumeFormatFromString,
.formatToString = virStorageFileFormatTypeToString,
+ .featureFromString = virStorageFileFeatureTypeFromString,
+ .featureToString = virStorageFileFeatureTypeToString,
},
},
{.poolType = VIR_STORAGE_POOL_FS,
.defaultFormat = VIR_STORAGE_FILE_RAW,
.formatFromString = virStorageVolumeFormatFromString,
.formatToString = virStorageFileFormatTypeToString,
+ .featureFromString = virStorageFileFeatureTypeFromString,
+ .featureToString = virStorageFileFeatureTypeToString,
},
},
{.poolType = VIR_STORAGE_POOL_NETFS,
.defaultFormat = VIR_STORAGE_FILE_RAW,
.formatFromString = virStorageVolumeFormatFromString,
.formatToString = virStorageFileFormatTypeToString,
+ .featureFromString = virStorageFileFeatureTypeFromString,
+ .featureToString = virStorageFileFeatureTypeToString,
},
},
{.poolType = VIR_STORAGE_POOL_ISCSI,
}
VIR_FREE(def->source.extents);
+ VIR_FREE(def->target.compat);
+ virBitmapFree(def->target.features);
VIR_FREE(def->target.path);
VIR_FREE(def->target.perms.label);
VIR_FREE(def->target.timestamps);
char *capacity = NULL;
char *unit = NULL;
xmlNodePtr node;
+ xmlNodePtr *nodes = NULL;
+ int i, n;
options = virStorageVolOptionsForPoolType(pool->type);
if (options == NULL)
VIR_FREE(format);
}
+ ret->target.compat = virXPathString("string(./target/compat)", ctxt);
+ if (ret->target.compat) {
+ char **version = virStringSplit(ret->target.compat, ".", 2);
+ unsigned int result;
+
+ if (!version || !version[1] ||
+ virStrToLong_ui(version[0], NULL, 10, &result) < 0 ||
+ virStrToLong_ui(version[1], NULL, 10, &result) < 0) {
+ virStringFreeList(version);
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("forbidden characters in 'compat' attribute"));
+ goto error;
+ }
+ virStringFreeList(version);
+ }
+
+ if (options->featureFromString && virXPathNode("./target/features", ctxt)) {
+ if ((n = virXPathNodeSet("./target/features/*", ctxt, &nodes)) < 0)
+ goto error;
+
+ if (!ret->target.compat && VIR_STRDUP(ret->target.compat, "1.1") < 0)
+ goto error;
+
+ if (!(ret->target.features = virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST)))
+ goto no_memory;
+
+ for (i = 0; i < n; i++) {
+ int f = options->featureFromString((const char*)nodes[i]->name);
+
+ if (f < 0) {
+ virReportError(VIR_ERR_XML_ERROR, _("unsupported feature %s"),
+ (const char*)nodes[i]->name);
+ goto error;
+ }
+ ignore_value(virBitmapSetBit(ret->target.features, f));
+ }
+ VIR_FREE(nodes);
+ }
+
if (virStorageDefParsePerms(ctxt, &ret->backingStore.perms,
"./backingStore/permissions",
DEFAULT_VOL_PERM_MODE) < 0)
goto error;
cleanup:
+ VIR_FREE(nodes);
VIR_FREE(allocation);
VIR_FREE(capacity);
VIR_FREE(unit);
return ret;
+no_memory:
+ virReportOOMError();
error:
virStorageVolDefFree(ret);
ret = NULL;
virBufferAdjustIndent(buf, -4);
}
+ virBufferEscapeString(buf, " <compat>%s</compat>\n", def->compat);
+
+ if (options->featureToString && def->features) {
+ int i;
+ bool b;
+ bool empty = virBitmapIsAllClear(def->features);
+
+ if (empty)
+ virBufferAddLit(buf, " <features/>\n");
+ else
+ virBufferAddLit(buf, " <features>\n");
+
+ for (i = 0; i < VIR_STORAGE_FILE_FEATURE_LAST; i++) {
+ ignore_value(virBitmapGetBit(def->features, i, &b));
+ if (b)
+ virBufferAsprintf(buf, " <%s/>\n",
+ options->featureToString(i));
+ }
+ if (!empty)
+ virBufferAddLit(buf, " </features>\n");
+ }
+
virBufferAsprintf(buf, " </%s>\n", type);
return 0;
# include "internal.h"
# include "storage_encryption_conf.h"
+# include "virbitmap.h"
# include "virthread.h"
# include <libxml/tree.h>
virStoragePerms perms;
virStorageTimestampsPtr timestamps;
int type; /* only used by disk backend for partition type */
-
- /* only used in vol->target, not in vol->backingstore. */
+ /* The next three are currently only used in vol->target,
+ * not in vol->backingStore. */
virStorageEncryptionPtr encryption;
+ virBitmapPtr features;
+ char *compat;
};
typedef struct _virStorageVolDef virStorageVolDef;
# util/virstoragefile.h
virStorageFileChainLookup;
+virStorageFileFeatureTypeFromString;
+virStorageFileFeatureTypeToString;
virStorageFileFormatTypeFromString;
virStorageFileFormatTypeToString;
virStorageFileFreeMetadata;
*/
}
+ virBitmapFree(target->features);
+ target->features = meta->features;
+ meta->features = NULL;
+
+ if (meta->compat) {
+ VIR_FREE(target->compat);
+ target->compat = meta->compat;
+ meta->compat = NULL;
+ }
+
virStorageFileFreeMetadata(meta);
return ret;
--- /dev/null
+<volume>
+ <name>OtherDemo.img</name>
+ <key>/var/lib/libvirt/images/OtherDemo.img</key>
+ <source>
+ </source>
+ <capacity unit="G">5</capacity>
+ <allocation>294912</allocation>
+ <target>
+ <path>/var/lib/libvirt/images/OtherDemo.img</path>
+ <format type='qcow2'/>
+ <permissions>
+ <mode>0644</mode>
+ <owner>0</owner>
+ <group>0</group>
+ <label>unconfined_u:object_r:virt_image_t:s0</label>
+ </permissions>
+ <encryption format='qcow'>
+ <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
+ </encryption>
+ <features/>
+ </target>
+ <backingStore>
+ <path>/var/lib/libvirt/images/BaseDemo.img</path>
+ <format type='raw'/>
+ <permissions>
+ <mode>0644</mode>
+ <owner>0</owner>
+ <group>0</group>
+ <label>unconfined_u:object_r:virt_image_t:s0</label>
+ </permissions>
+ </backingStore>
+</volume>
--- /dev/null
+<volume>
+ <name>OtherDemo.img</name>
+ <key>/var/lib/libvirt/images/OtherDemo.img</key>
+ <source>
+ </source>
+ <capacity unit="G">5</capacity>
+ <allocation>294912</allocation>
+ <target>
+ <path>/var/lib/libvirt/images/OtherDemo.img</path>
+ <format type='qcow2'/>
+ <permissions>
+ <mode>0644</mode>
+ <owner>0</owner>
+ <group>0</group>
+ <label>unconfined_u:object_r:virt_image_t:s0</label>
+ </permissions>
+ <encryption format='qcow'>
+ <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
+ </encryption>
+ <compat>1.1</compat>
+ <features>
+ <lazy_refcounts/>
+ </features>
+ </target>
+ <backingStore>
+ <path>/var/lib/libvirt/images/BaseDemo.img</path>
+ <format type='raw'/>
+ <permissions>
+ <mode>0644</mode>
+ <owner>0</owner>
+ <group>0</group>
+ <label>unconfined_u:object_r:virt_image_t:s0</label>
+ </permissions>
+ </backingStore>
+</volume>
--- /dev/null
+<volume>
+ <name>OtherDemo.img</name>
+ <key>(null)</key>
+ <source>
+ </source>
+ <capacity unit='bytes'>5368709120</capacity>
+ <allocation unit='bytes'>294912</allocation>
+ <target>
+ <path>/var/lib/libvirt/images/OtherDemo.img</path>
+ <format type='qcow2'/>
+ <permissions>
+ <mode>0644</mode>
+ <owner>0</owner>
+ <group>0</group>
+ <label>unconfined_u:object_r:virt_image_t:s0</label>
+ </permissions>
+ <encryption format='qcow'>
+ <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
+ </encryption>
+ <compat>1.1</compat>
+ <features/>
+ </target>
+ <backingStore>
+ <path>/var/lib/libvirt/images/BaseDemo.img</path>
+ <format type='raw'/>
+ <permissions>
+ <mode>0644</mode>
+ <owner>0</owner>
+ <group>0</group>
+ <label>unconfined_u:object_r:virt_image_t:s0</label>
+ </permissions>
+ </backingStore>
+</volume>
--- /dev/null
+<volume>
+ <name>OtherDemo.img</name>
+ <key>(null)</key>
+ <source>
+ </source>
+ <capacity unit='bytes'>5368709120</capacity>
+ <allocation unit='bytes'>294912</allocation>
+ <target>
+ <path>/var/lib/libvirt/images/OtherDemo.img</path>
+ <format type='qcow2'/>
+ <permissions>
+ <mode>0644</mode>
+ <owner>0</owner>
+ <group>0</group>
+ <label>unconfined_u:object_r:virt_image_t:s0</label>
+ </permissions>
+ <encryption format='qcow'>
+ <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
+ </encryption>
+ <compat>1.1</compat>
+ <features>
+ <lazy_refcounts/>
+ </features>
+ </target>
+ <backingStore>
+ <path>/var/lib/libvirt/images/BaseDemo.img</path>
+ <format type='raw'/>
+ <permissions>
+ <mode>0644</mode>
+ <owner>0</owner>
+ <group>0</group>
+ <label>unconfined_u:object_r:virt_image_t:s0</label>
+ </permissions>
+ </backingStore>
+</volume>
DO_TEST("pool-dir", "vol-file");
DO_TEST("pool-dir", "vol-file-backing");
DO_TEST("pool-dir", "vol-qcow2");
+ DO_TEST("pool-dir", "vol-qcow2-1.1");
+ DO_TEST("pool-dir", "vol-qcow2-lazy");
DO_TEST("pool-disk", "vol-partition");
DO_TEST("pool-logical", "vol-logical");
DO_TEST("pool-logical", "vol-logical-backing");