<label>virt_image_t</label>
</permissions>
<compat>1.1</compat>
+ <nocow/>
<features>
<lazy_refcounts/>
</features>
1.1 is used. If omitted, qemu-img default is used.
<span class="since">Since 1.1.0</span>
</dd>
+ <dt><code>nocow</code></dt>
+ <dd>Turn off COW of the newly created volume. So far, this is only valid
+ for a file image in btrfs file system. It will improve performance when
+ the file image is used in VM. To create non-raw file images, it
+ requires QEMU version since 2.1. <span class="since">Since 1.2.7</span>
+ </dd>
<dt><code>features</code></dt>
<dd>Format-specific features. Only used for <code>qcow2</code> now.
Valid sub-elements are:
virStringFreeList(version);
}
+ if (virXPathNode("./target/nocow", ctxt))
+ ret->target.nocow = true;
+
if (options->featureFromString && virXPathNode("./target/features", ctxt)) {
if ((n = virXPathNodeSet("./target/features/*", ctxt, &nodes)) < 0)
goto error;
#ifdef __linux__
# include <sys/ioctl.h>
# include <linux/fs.h>
+# ifndef FS_NOCOW_FL
+# define FS_NOCOW_FL 0x00800000 /* Do not cow file */
+# endif
#endif
#if WITH_SELINUX
goto cleanup;
}
+ if (vol->target.nocow) {
+#ifdef __linux__
+ int attr;
+
+ /* Set NOCOW flag. This is an optimisation for btrfs.
+ * The FS_IOC_SETFLAGS ioctl return value will be ignored since any
+ * failure of this operation should not block the left work.
+ */
+ if (ioctl(fd, FS_IOC_GETFLAGS, &attr) == 0) {
+ attr |= FS_NOCOW_FL;
+ ioctl(fd, FS_IOC_SETFLAGS, &attr);
+ }
+#endif
+ }
+
if ((ret = createRawFile(fd, vol, inputvol)) < 0)
/* createRawFile already reported the exact error. */
ret = -1;
bool preallocate,
int format,
const char *compat,
+ bool nocow,
virBitmapPtr features)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(&buf, "encryption=on,");
if (preallocate)
virBufferAddLit(&buf, "preallocation=metadata,");
+ if (nocow)
+ virBufferAddLit(&buf, "nocow=on,");
if (compat)
virBufferAsprintf(&buf, "compat=%s,", compat);
do_encryption, preallocate,
vol->target.format,
compat,
+ vol->target.nocow,
vol->target.features) < 0) {
virCommandFree(cmd);
return NULL;