forked from pool/libvirt
114 lines
4.0 KiB
Diff
114 lines
4.0 KiB
Diff
commit ccc0b45917fa76a77ff83f1ddfd30836c8c3805e
|
|
Author: Chunyan Liu <cyliu@suse.com>
|
|
Date: Wed May 7 12:45:40 2014 +0800
|
|
|
|
add nocow to vol xml
|
|
|
|
Updated patch. Rebase to git master.
|
|
|
|
Signed-off-by: Chunyan Liu <cyliu@suse.com>
|
|
|
|
Index: libvirt-1.2.4/docs/schemas/storagevol.rng
|
|
===================================================================
|
|
--- libvirt-1.2.4.orig/docs/schemas/storagevol.rng
|
|
+++ libvirt-1.2.4/docs/schemas/storagevol.rng
|
|
@@ -138,6 +138,11 @@
|
|
<ref name='compat'/>
|
|
</optional>
|
|
<optional>
|
|
+ <element name='nocow'>
|
|
+ <empty/>
|
|
+ </element>
|
|
+ </optional>
|
|
+ <optional>
|
|
<ref name='fileFormatFeatures'/>
|
|
</optional>
|
|
</interleave>
|
|
Index: libvirt-1.2.4/src/conf/storage_conf.c
|
|
===================================================================
|
|
--- libvirt-1.2.4.orig/src/conf/storage_conf.c
|
|
+++ libvirt-1.2.4/src/conf/storage_conf.c
|
|
@@ -1395,6 +1395,9 @@ virStorageVolDefParseXML(virStoragePoolD
|
|
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;
|
|
Index: libvirt-1.2.4/src/storage/storage_backend.c
|
|
===================================================================
|
|
--- libvirt-1.2.4.orig/src/storage/storage_backend.c
|
|
+++ libvirt-1.2.4/src/storage/storage_backend.c
|
|
@@ -37,6 +37,9 @@
|
|
#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
|
|
@@ -452,6 +455,21 @@ virStorageBackendCreateRaw(virConnectPtr
|
|
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;
|
|
@@ -717,6 +735,7 @@ virStorageBackendCreateQemuImgOpts(char
|
|
bool preallocate,
|
|
int format,
|
|
const char *compat,
|
|
+ bool nocow,
|
|
virBitmapPtr features)
|
|
{
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
@@ -729,6 +748,8 @@ virStorageBackendCreateQemuImgOpts(char
|
|
virBufferAddLit(&buf, "encryption=on,");
|
|
if (preallocate)
|
|
virBufferAddLit(&buf, "preallocation=metadata,");
|
|
+ if (nocow)
|
|
+ virBufferAddLit(&buf, "nocow=on,");
|
|
|
|
if (compat)
|
|
virBufferAsprintf(&buf, "compat=%s,", compat);
|
|
@@ -950,6 +971,7 @@ virStorageBackendCreateQemuImgCmd(virCon
|
|
do_encryption, preallocate,
|
|
vol->target.format,
|
|
compat,
|
|
+ vol->target.nocow,
|
|
vol->target.features) < 0) {
|
|
virCommandFree(cmd);
|
|
return NULL;
|
|
Index: libvirt-1.2.4/src/util/virstoragefile.h
|
|
===================================================================
|
|
--- libvirt-1.2.4.orig/src/util/virstoragefile.h
|
|
+++ libvirt-1.2.4/src/util/virstoragefile.h
|
|
@@ -228,6 +228,7 @@ struct _virStorageSource {
|
|
int format; /* enum virStorageFileFormat */
|
|
virBitmapPtr features;
|
|
char *compat;
|
|
+ bool nocow;
|
|
|
|
virStoragePermsPtr perms;
|
|
virStorageTimestampsPtr timestamps;
|