mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
storagevol: add nocow to vol xml
Add 'nocow' to storage volume xml so that user can have an option to set NOCOW flag to the newly created volume. It's useful on btrfs file system to enhance performance. Btrfs has low performance when hosting VM images, even more when the guest in those VM are also using btrfs as file system. One way to mitigate this bad performance is to turn off COW attributes on VM files. Generally, there are two ways to turn off COW on btrfs: a) by mounting fs with nodatacow, then all newly created files will be NOCOW. b) per file. Add the NOCOW file attribute. It could only be done to empty or new files. This patch tries the second way, according to 'nocow' option, it could set NOCOW flag per file: for raw file images, handle 'nocow' in libvirt code; for non-raw file images, pass 'nocow=on' option to qemu-img, and let qemu-img to handle that (requires qemu-img version >= 2.1). Signed-off-by: Chunyan Liu <cyliu@suse.com>
This commit is contained in:
parent
607806f87f
commit
a9fd30e633
@ -385,6 +385,7 @@
|
|||||||
<label>virt_image_t</label>
|
<label>virt_image_t</label>
|
||||||
</permissions>
|
</permissions>
|
||||||
<compat>1.1</compat>
|
<compat>1.1</compat>
|
||||||
|
<nocow/>
|
||||||
<features>
|
<features>
|
||||||
<lazy_refcounts/>
|
<lazy_refcounts/>
|
||||||
</features>
|
</features>
|
||||||
@ -424,6 +425,12 @@
|
|||||||
1.1 is used. If omitted, qemu-img default is used.
|
1.1 is used. If omitted, qemu-img default is used.
|
||||||
<span class="since">Since 1.1.0</span>
|
<span class="since">Since 1.1.0</span>
|
||||||
</dd>
|
</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>
|
<dt><code>features</code></dt>
|
||||||
<dd>Format-specific features. Only used for <code>qcow2</code> now.
|
<dd>Format-specific features. Only used for <code>qcow2</code> now.
|
||||||
Valid sub-elements are:
|
Valid sub-elements are:
|
||||||
|
@ -137,6 +137,11 @@
|
|||||||
<optional>
|
<optional>
|
||||||
<ref name='compat'/>
|
<ref name='compat'/>
|
||||||
</optional>
|
</optional>
|
||||||
|
<optional>
|
||||||
|
<element name='nocow'>
|
||||||
|
<empty/>
|
||||||
|
</element>
|
||||||
|
</optional>
|
||||||
<optional>
|
<optional>
|
||||||
<ref name='fileFormatFeatures'/>
|
<ref name='fileFormatFeatures'/>
|
||||||
</optional>
|
</optional>
|
||||||
|
@ -1299,6 +1299,9 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
virStringFreeList(version);
|
virStringFreeList(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (virXPathNode("./target/nocow", ctxt))
|
||||||
|
ret->target.nocow = true;
|
||||||
|
|
||||||
if (options->featureFromString && virXPathNode("./target/features", ctxt)) {
|
if (options->featureFromString && virXPathNode("./target/features", ctxt)) {
|
||||||
if ((n = virXPathNodeSet("./target/features/*", ctxt, &nodes)) < 0)
|
if ((n = virXPathNodeSet("./target/features/*", ctxt, &nodes)) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -37,6 +37,9 @@
|
|||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
# include <sys/ioctl.h>
|
# include <sys/ioctl.h>
|
||||||
# include <linux/fs.h>
|
# include <linux/fs.h>
|
||||||
|
# ifndef FS_NOCOW_FL
|
||||||
|
# define FS_NOCOW_FL 0x00800000 /* Do not cow file */
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if WITH_SELINUX
|
#if WITH_SELINUX
|
||||||
@ -453,6 +456,21 @@ virStorageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
goto cleanup;
|
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)
|
if ((ret = createRawFile(fd, vol, inputvol)) < 0)
|
||||||
/* createRawFile already reported the exact error. */
|
/* createRawFile already reported the exact error. */
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -718,6 +736,7 @@ virStorageBackendCreateQemuImgOpts(char **opts,
|
|||||||
bool preallocate,
|
bool preallocate,
|
||||||
int format,
|
int format,
|
||||||
const char *compat,
|
const char *compat,
|
||||||
|
bool nocow,
|
||||||
virBitmapPtr features)
|
virBitmapPtr features)
|
||||||
{
|
{
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
@ -730,6 +749,8 @@ virStorageBackendCreateQemuImgOpts(char **opts,
|
|||||||
virBufferAddLit(&buf, "encryption=on,");
|
virBufferAddLit(&buf, "encryption=on,");
|
||||||
if (preallocate)
|
if (preallocate)
|
||||||
virBufferAddLit(&buf, "preallocation=metadata,");
|
virBufferAddLit(&buf, "preallocation=metadata,");
|
||||||
|
if (nocow)
|
||||||
|
virBufferAddLit(&buf, "nocow=on,");
|
||||||
|
|
||||||
if (compat)
|
if (compat)
|
||||||
virBufferAsprintf(&buf, "compat=%s,", compat);
|
virBufferAsprintf(&buf, "compat=%s,", compat);
|
||||||
@ -950,6 +971,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
|
|||||||
do_encryption, preallocate,
|
do_encryption, preallocate,
|
||||||
vol->target.format,
|
vol->target.format,
|
||||||
compat,
|
compat,
|
||||||
|
vol->target.nocow,
|
||||||
vol->target.features) < 0) {
|
vol->target.features) < 0) {
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -247,6 +247,7 @@ struct _virStorageSource {
|
|||||||
* pool-specific enum for storage volumes */
|
* pool-specific enum for storage volumes */
|
||||||
virBitmapPtr features;
|
virBitmapPtr features;
|
||||||
char *compat;
|
char *compat;
|
||||||
|
bool nocow;
|
||||||
|
|
||||||
virStoragePermsPtr perms;
|
virStoragePermsPtr perms;
|
||||||
virStorageTimestampsPtr timestamps;
|
virStorageTimestampsPtr timestamps;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user