diff --git a/add-nocow-to-vol-xml.patch b/add-nocow-to-vol-xml.patch new file mode 100644 index 0000000..acbc9ab --- /dev/null +++ b/add-nocow-to-vol-xml.patch @@ -0,0 +1,103 @@ +Index: libvirt-1.2.3/docs/schemas/storagevol.rng +=================================================================== +--- libvirt-1.2.3.orig/docs/schemas/storagevol.rng ++++ libvirt-1.2.3/docs/schemas/storagevol.rng +@@ -139,6 +139,11 @@ + + + ++ ++ ++ ++ ++ + + + +Index: libvirt-1.2.3/src/conf/storage_conf.c +=================================================================== +--- libvirt-1.2.3.orig/src/conf/storage_conf.c ++++ libvirt-1.2.3/src/conf/storage_conf.c +@@ -1401,6 +1401,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.3/src/conf/storage_conf.h +=================================================================== +--- libvirt-1.2.3.orig/src/conf/storage_conf.h ++++ libvirt-1.2.3/src/conf/storage_conf.h +@@ -90,6 +90,7 @@ struct _virStorageVolTarget { + virStorageEncryptionPtr encryption; + virBitmapPtr features; + char *compat; ++ bool nocow; + }; + + typedef struct _virStorageVolDef virStorageVolDef; +Index: libvirt-1.2.3/src/storage/storage_backend.c +=================================================================== +--- libvirt-1.2.3.orig/src/storage/storage_backend.c ++++ libvirt-1.2.3/src/storage/storage_backend.c +@@ -37,6 +37,9 @@ + #ifdef __linux__ + # include + # include ++# ifndef FS_NOCOW_FL ++# define FS_NOCOW_FL 0x00800000 /* Do not cow file */ ++# endif + #endif + + #if WITH_SELINUX +@@ -449,6 +452,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; +@@ -712,6 +730,7 @@ virStorageBackendCreateQemuImgOpts(char + bool preallocate, + int format, + const char *compat, ++ bool nocow, + virBitmapPtr features) + { + virBuffer buf = VIR_BUFFER_INITIALIZER; +@@ -724,6 +743,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); +@@ -945,6 +966,7 @@ virStorageBackendCreateQemuImgCmd(virCon + do_encryption, preallocate, + vol->target.format, + compat, ++ vol->target.nocow, + vol->target.features) < 0) { + virCommandFree(cmd); + return NULL; diff --git a/libvirt.changes b/libvirt.changes index 260acb3..33ecba3 100644 --- a/libvirt.changes +++ b/libvirt.changes @@ -5,6 +5,12 @@ Tue Apr 8 09:44:50 MDT 2014 - jfehlig@suse.com 0e0c1a74-domid-fix.patch, 7a1452f5-libxl-empty-cdrom.patch bnc#872517 +------------------------------------------------------------------- +Mon Apr 7 14:34:59 CST 2014 - cyliu@suse.com + +- Fate#315125: add NOCOW flag + add-nocow-to-vol-xml.patch + ------------------------------------------------------------------- Wed Apr 2 13:38:50 UTC 2014 - cbosdonnat@suse.com diff --git a/libvirt.spec b/libvirt.spec index 2a9f861..7ca178b 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -434,6 +434,7 @@ Patch1: 7a1452f5-libxl-empty-cdrom.patch Patch100: xen-name-for-devid.patch Patch101: ia64-clone.patch Patch102: xen-pv-cdrom.patch +Patch103: add-nocow-to-vol-xml.patch # Our patches Patch200: libvirtd-defaults.patch Patch201: libvirtd-init-script.patch @@ -950,6 +951,7 @@ namespaces. %patch100 -p1 %patch101 -p1 %patch102 -p1 +%patch103 -p1 %patch200 -p1 %patch201 -p1 %patch202 -p1