* [PATCH] vhd-util create: add -C|nocow option
@ 2013-11-21 7:46 Chunyan Liu
2013-11-21 9:39 ` Ian Campbell
0 siblings, 1 reply; 10+ messages in thread
From: Chunyan Liu @ 2013-11-21 7:46 UTC (permalink / raw)
To: xen-devel; +Cc: ian.jackson
Add '-C' (nocow) option to vhd-util create.
Btrfs has terrible 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 (since having copy on
write for this kind of data is not useful). According to 'chattr' manpage, NOCOW
could be set to new or empty file only on btrfs, so add a option here so that
users could have a chance to set NOCOW to a vhd image.
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
tools/blktap2/include/libvhd.h | 1 +
tools/blktap2/vhd/lib/libvhd.c | 24 ++++++++++++++++++++++++
tools/blktap2/vhd/lib/vhd-util-create.c | 8 ++++++--
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/tools/blktap2/include/libvhd.h b/tools/blktap2/include/libvhd.h
index 8e854e4..fd0ca75 100644
--- a/tools/blktap2/include/libvhd.h
+++ b/tools/blktap2/include/libvhd.h
@@ -87,6 +87,7 @@
#define VHD_OPEN_IGNORE_DISABLED 0x00010
#define VHD_FLAG_CREAT_PARENT_RAW 0x00001
+#define VHD_FLAG_CREAT_NOCOW 0x00002
#define vhd_flag_set(word, flag) ((word) |= (flag))
#define vhd_flag_clear(word, flag) ((word) &= ~(flag))
diff --git a/tools/blktap2/vhd/lib/libvhd.c b/tools/blktap2/vhd/lib/libvhd.c
index 95eb5d6..12a9667 100644
--- a/tools/blktap2/vhd/lib/libvhd.c
+++ b/tools/blktap2/vhd/lib/libvhd.c
@@ -41,6 +41,14 @@
#include "libvhd.h"
#include "relative-path.h"
+#ifdef __linux__
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+#ifndef FS_NOCOW_FL
+#define FS_NOCOW_FL 0x00800000 /* Do not cow file */
+#endif
+#endif
+
/* VHD uses an epoch of 12:00AM, Jan 1, 2000. This is the Unix timestamp for
* the start of the VHD epoch. */
#define VHD_EPOCH_START 946684800
@@ -2829,6 +2837,7 @@ __vhd_create(const char *name, const char *parent, uint64_t bytes, int type,
vhd_footer_t *footer;
vhd_header_t *header;
uint64_t size, blks;
+ int attr;
switch (type) {
case HD_TYPE_DIFF:
@@ -2855,6 +2864,21 @@ __vhd_create(const char *name, const char *parent, uint64_t bytes, int type,
if (ctx.fd == -1)
return -errno;
+ if (flags & VHD_FLAG_CREAT_NOCOW) {
+ flags &= ~VHD_FLAG_CREAT_NOCOW;
+#ifdef __linux__
+ /* Set NOCOW flag to solve performance issue on fs like btrfs.
+ * This is an optimisation. The FS_IOC_SETFLAGS ioctl return value will
+ * be ignored since any failure of this operation should not block the
+ * left work.
+ */
+ if (ioctl(ctx.fd, FS_IOC_GETFLAGS, &attr) == 0) {
+ attr |= FS_NOCOW_FL;
+ ioctl(ctx.fd, FS_IOC_SETFLAGS, &attr);
+ }
+#endif
+ }
+
ctx.file = strdup(name);
if (!ctx.file) {
err = -ENOMEM;
diff --git a/tools/blktap2/vhd/lib/vhd-util-create.c b/tools/blktap2/vhd/lib/vhd-util-create.c
index a9bdf05..be632f8 100644
--- a/tools/blktap2/vhd/lib/vhd-util-create.c
+++ b/tools/blktap2/vhd/lib/vhd-util-create.c
@@ -49,7 +49,7 @@ vhd_util_create(int argc, char **argv)
goto usage;
optind = 0;
- while ((c = getopt(argc, argv, "n:s:rh")) != -1) {
+ while ((c = getopt(argc, argv, "n:s:rCh")) != -1) {
switch (c) {
case 'n':
name = optarg;
@@ -61,6 +61,10 @@ vhd_util_create(int argc, char **argv)
case 'r':
sparse = 0;
break;
+ case 'C':
+ /* NOCOW: this will remove COW for file on btrfs */
+ flags |= VHD_FLAG_CREAT_NOCOW;
+ break;
case 'h':
default:
goto usage;
@@ -75,6 +79,6 @@ vhd_util_create(int argc, char **argv)
flags);
usage:
- printf("options: <-n name> <-s size (MB)> [-r reserve] [-h help]\n");
+ printf("options: <-n name> <-s size (MB)> [-r reserve] [-C nocow] [-h help]\n");
return -EINVAL;
}
--
1.6.0.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] vhd-util create: add -C|nocow option
2013-11-21 7:46 [PATCH] vhd-util create: add -C|nocow option Chunyan Liu
@ 2013-11-21 9:39 ` Ian Campbell
2013-11-21 14:41 ` Ian Jackson
0 siblings, 1 reply; 10+ messages in thread
From: Ian Campbell @ 2013-11-21 9:39 UTC (permalink / raw)
To: Chunyan Liu; +Cc: xen-devel, ian.jackson
On Thu, 2013-11-21 at 15:46 +0800, Chunyan Liu wrote:
> Add '-C' (nocow) option to vhd-util create.
>
> Btrfs has terrible 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 (since having copy on
> write for this kind of data is not useful). According to 'chattr' manpage, NOCOW
> could be set to new or empty file only on btrfs, so add a option here so that
> users could have a chance to set NOCOW to a vhd image.
Is there not some btrfs (or generic) utility which could be used to do
this after image creation rather than trying to build it in to every
utility which creates an image file?
Ian.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] vhd-util create: add -C|nocow option
2013-11-21 9:39 ` Ian Campbell
@ 2013-11-21 14:41 ` Ian Jackson
2013-11-21 14:51 ` Ian Campbell
2013-11-22 0:57 ` Jim Fehlig
0 siblings, 2 replies; 10+ messages in thread
From: Ian Jackson @ 2013-11-21 14:41 UTC (permalink / raw)
To: Ian Campbell; +Cc: xen-devel, Chunyan Liu
Ian Campbell writes ("Re: [Xen-devel] [PATCH] vhd-util create: add -C|nocow option"):
> On Thu, 2013-11-21 at 15:46 +0800, Chunyan Liu wrote:
> > Add '-C' (nocow) option to vhd-util create.
> >
> > Btrfs has terrible 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 (since having copy on
> > write for this kind of data is not useful). According to 'chattr' manpage, NOCOW
> > could be set to new or empty file only on btrfs, so add a option here so that
> > users could have a chance to set NOCOW to a vhd image.
>
> Is there not some btrfs (or generic) utility which could be used to do
> this after image creation rather than trying to build it in to every
> utility which creates an image file?
This may seem like a daft question, but why do we even have a vhd
utility in our tree ? Is there not some vhd tools package that this
should be in ?
Ian.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] vhd-util create: add -C|nocow option
2013-11-21 14:41 ` Ian Jackson
@ 2013-11-21 14:51 ` Ian Campbell
2013-11-21 14:59 ` Ian Jackson
2013-11-22 0:57 ` Jim Fehlig
1 sibling, 1 reply; 10+ messages in thread
From: Ian Campbell @ 2013-11-21 14:51 UTC (permalink / raw)
To: Ian Jackson; +Cc: xen-devel, Chunyan Liu
On Thu, 2013-11-21 at 14:41 +0000, Ian Jackson wrote:
> Ian Campbell writes ("Re: [Xen-devel] [PATCH] vhd-util create: add -C|nocow option"):
> > On Thu, 2013-11-21 at 15:46 +0800, Chunyan Liu wrote:
> > > Add '-C' (nocow) option to vhd-util create.
> > >
> > > Btrfs has terrible 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 (since having copy on
> > > write for this kind of data is not useful). According to 'chattr' manpage, NOCOW
> > > could be set to new or empty file only on btrfs, so add a option here so that
> > > users could have a chance to set NOCOW to a vhd image.
> >
> > Is there not some btrfs (or generic) utility which could be used to do
> > this after image creation rather than trying to build it in to every
> > utility which creates an image file?
>
> This may seem like a daft question, but why do we even have a vhd
> utility in our tree ? Is there not some vhd tools package that this
> should be in ?
vhd was originally a microsoft thing and I think most OSS projects
adopted it in an ad-hoc and independent manner.
Most virt solutions have their own tools (e.g. qemu-img and virtualbox's
thing) for these things.
I agree that it seems silly though I'm not proposing to start a separate
project ;-)
Ian.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] vhd-util create: add -C|nocow option
2013-11-21 14:51 ` Ian Campbell
@ 2013-11-21 14:59 ` Ian Jackson
2013-11-21 15:01 ` Ian Campbell
0 siblings, 1 reply; 10+ messages in thread
From: Ian Jackson @ 2013-11-21 14:59 UTC (permalink / raw)
To: Ian Campbell; +Cc: xen-devel, Chunyan Liu
Ian Campbell writes ("Re: [Xen-devel] [PATCH] vhd-util create: add -C|nocow option"):
> On Thu, 2013-11-21 at 14:41 +0000, Ian Jackson wrote:
> > This may seem like a daft question, but why do we even have a vhd
> > utility in our tree ? Is there not some vhd tools package that this
> > should be in ?
>
> vhd was originally a microsoft thing and I think most OSS projects
> adopted it in an ad-hoc and independent manner.
>
> Most virt solutions have their own tools (e.g. qemu-img and virtualbox's
> thing) for these things.
>
> I agree that it seems silly though I'm not proposing to start a separate
> project ;-)
On that basis we should probably take this patch...
Ian.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] vhd-util create: add -C|nocow option
2013-11-21 14:59 ` Ian Jackson
@ 2013-11-21 15:01 ` Ian Campbell
0 siblings, 0 replies; 10+ messages in thread
From: Ian Campbell @ 2013-11-21 15:01 UTC (permalink / raw)
To: Ian Jackson; +Cc: xen-devel, Chunyan Liu
On Thu, 2013-11-21 at 14:59 +0000, Ian Jackson wrote:
> Ian Campbell writes ("Re: [Xen-devel] [PATCH] vhd-util create: add -C|nocow option"):
> > On Thu, 2013-11-21 at 14:41 +0000, Ian Jackson wrote:
> > > This may seem like a daft question, but why do we even have a vhd
> > > utility in our tree ? Is there not some vhd tools package that this
> > > should be in ?
> >
> > vhd was originally a microsoft thing and I think most OSS projects
> > adopted it in an ad-hoc and independent manner.
> >
> > Most virt solutions have their own tools (e.g. qemu-img and virtualbox's
> > thing) for these things.
> >
> > I agree that it seems silly though I'm not proposing to start a separate
> > project ;-)
>
> On that basis we should probably take this patch...
I'm not sure it follows that because we have vhd-utils in tree we should
also start incorporating btrfs-utils.
Ian.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] vhd-util create: add -C|nocow option
2013-11-21 14:41 ` Ian Jackson
2013-11-21 14:51 ` Ian Campbell
@ 2013-11-22 0:57 ` Jim Fehlig
2013-11-22 3:42 ` Chunyan Liu
1 sibling, 1 reply; 10+ messages in thread
From: Jim Fehlig @ 2013-11-22 0:57 UTC (permalink / raw)
To: Ian Jackson; +Cc: xen-devel, Ian Campbell, Chunyan Liu
Ian Jackson wrote:
> Ian Campbell writes ("Re: [Xen-devel] [PATCH] vhd-util create: add -C|nocow option"):
>
>> On Thu, 2013-11-21 at 15:46 +0800, Chunyan Liu wrote:
>>
>>> Add '-C' (nocow) option to vhd-util create.
>>>
>>> Btrfs has terrible 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 (since having copy on
>>> write for this kind of data is not useful). According to 'chattr' manpage, NOCOW
>>> could be set to new or empty file only on btrfs, so add a option here so that
>>> users could have a chance to set NOCOW to a vhd image.
>>>
>> Is there not some btrfs (or generic) utility which could be used to do
>> this after image creation rather than trying to build it in to every
>> utility which creates an image file?
>>
>
> This may seem like a daft question, but why do we even have a vhd
> utility in our tree ? Is there not some vhd tools package that this
> should be in ?
>
Newer qemu-img supports vhd and vhdx right? Is there even a need for
this tool at all anymore?
Regards,
Jim
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] vhd-util create: add -C|nocow option
2013-11-22 0:57 ` Jim Fehlig
@ 2013-11-22 3:42 ` Chunyan Liu
2013-11-22 16:09 ` Jim Fehlig
0 siblings, 1 reply; 10+ messages in thread
From: Chunyan Liu @ 2013-11-22 3:42 UTC (permalink / raw)
To: Jim Fehlig; +Cc: xen-devel@lists.xensource.com, Ian Jackson, Ian Campbell
[-- Attachment #1.1: Type: text/plain, Size: 1367 bytes --]
2013/11/22 Jim Fehlig <jfehlig@suse.com>
> Ian Jackson wrote:
> > Ian Campbell writes ("Re: [Xen-devel] [PATCH] vhd-util create: add
> -C|nocow option"):
> >
> >> On Thu, 2013-11-21 at 15:46 +0800, Chunyan Liu wrote:
> >>
> >>> Add '-C' (nocow) option to vhd-util create.
> >>>
> >>> Btrfs has terrible 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 (since having
> copy on
> >>> write for this kind of data is not useful). According to 'chattr'
> manpage, NOCOW
> >>> could be set to new or empty file only on btrfs, so add a option here
> so that
> >>> users could have a chance to set NOCOW to a vhd image.
> >>>
> >> Is there not some btrfs (or generic) utility which could be used to do
> >> this after image creation rather than trying to build it in to every
> >> utility which creates an image file?
> >>
> >
> > This may seem like a daft question, but why do we even have a vhd
> > utility in our tree ? Is there not some vhd tools package that this
> > should be in ?
> >
>
> Newer qemu-img supports vhd and vhdx right? Is there even a need for
> this tool at all anymore?
>
>
'qemu-img create' doesn't support creating vhd/vhdx format images. Only
open/probe supported.
> Regards,
> Jim
>
[-- Attachment #1.2: Type: text/html, Size: 2138 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] vhd-util create: add -C|nocow option
2013-11-22 3:42 ` Chunyan Liu
@ 2013-11-22 16:09 ` Jim Fehlig
0 siblings, 0 replies; 10+ messages in thread
From: Jim Fehlig @ 2013-11-22 16:09 UTC (permalink / raw)
To: Chunyan Liu; +Cc: xen-devel@lists.xensource.com, Ian Jackson, Ian Campbell
Chunyan Liu wrote:
>
>
>
> 2013/11/22 Jim Fehlig <jfehlig@suse.com <mailto:jfehlig@suse.com>>
>
> Ian Jackson wrote:
> > Ian Campbell writes ("Re: [Xen-devel] [PATCH] vhd-util create:
> add -C|nocow option"):
> >
> >> On Thu, 2013-11-21 at 15:46 +0800, Chunyan Liu wrote:
> >>
> >>> Add '-C' (nocow) option to vhd-util create.
> >>>
> >>> Btrfs has terrible 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 (since
> having copy on
> >>> write for this kind of data is not useful). According to
> 'chattr' manpage, NOCOW
> >>> could be set to new or empty file only on btrfs, so add a
> option here so that
> >>> users could have a chance to set NOCOW to a vhd image.
> >>>
> >> Is there not some btrfs (or generic) utility which could be
> used to do
> >> this after image creation rather than trying to build it in to
> every
> >> utility which creates an image file?
> >>
> >
> > This may seem like a daft question, but why do we even have a vhd
> > utility in our tree ? Is there not some vhd tools package that this
> > should be in ?
> >
>
> Newer qemu-img supports vhd and vhdx right? Is there even a need for
> this tool at all anymore?
>
>
> 'qemu-img create' doesn't support creating vhd/vhdx format images.
> Only open/probe supported.
Ah, I didn't know that. Is it possible to merge vhd-util with
qemu-img? You could then support nocow with something like 'qemu-img
create -f vhd -o nocow, ...'.
But I tend to agree with Ian that supporting backing store-specific
features should be higher in the stack. E.g. a libvirt filesystem
storage pool of type btrfs could support such features when creating
volumes from the pool.
Regards,
Jim
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] vhd-util create: add -C|nocow option
@ 2013-11-21 7:48 Chunyan Liu
0 siblings, 0 replies; 10+ messages in thread
From: Chunyan Liu @ 2013-11-21 7:48 UTC (permalink / raw)
To: xen-devel; +Cc: ian.jackson
Add '-C' (nocow) option to vhd-util create.
Btrfs has terrible 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 (since having copy on
write for this kind of data is not useful). According to 'chattr' manpage, NOCOW
could be set to new or empty file only on btrfs, so add a option here so that
users could have a chance to set NOCOW to a vhd image.
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
tools/blktap2/include/libvhd.h | 1 +
tools/blktap2/vhd/lib/libvhd.c | 24 ++++++++++++++++++++++++
tools/blktap2/vhd/lib/vhd-util-create.c | 8 ++++++--
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/tools/blktap2/include/libvhd.h b/tools/blktap2/include/libvhd.h
index 8e854e4..fd0ca75 100644
--- a/tools/blktap2/include/libvhd.h
+++ b/tools/blktap2/include/libvhd.h
@@ -87,6 +87,7 @@
#define VHD_OPEN_IGNORE_DISABLED 0x00010
#define VHD_FLAG_CREAT_PARENT_RAW 0x00001
+#define VHD_FLAG_CREAT_NOCOW 0x00002
#define vhd_flag_set(word, flag) ((word) |= (flag))
#define vhd_flag_clear(word, flag) ((word) &= ~(flag))
diff --git a/tools/blktap2/vhd/lib/libvhd.c b/tools/blktap2/vhd/lib/libvhd.c
index 95eb5d6..12a9667 100644
--- a/tools/blktap2/vhd/lib/libvhd.c
+++ b/tools/blktap2/vhd/lib/libvhd.c
@@ -41,6 +41,14 @@
#include "libvhd.h"
#include "relative-path.h"
+#ifdef __linux__
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+#ifndef FS_NOCOW_FL
+#define FS_NOCOW_FL 0x00800000 /* Do not cow file */
+#endif
+#endif
+
/* VHD uses an epoch of 12:00AM, Jan 1, 2000. This is the Unix timestamp for
* the start of the VHD epoch. */
#define VHD_EPOCH_START 946684800
@@ -2829,6 +2837,7 @@ __vhd_create(const char *name, const char *parent, uint64_t bytes, int type,
vhd_footer_t *footer;
vhd_header_t *header;
uint64_t size, blks;
+ int attr;
switch (type) {
case HD_TYPE_DIFF:
@@ -2855,6 +2864,21 @@ __vhd_create(const char *name, const char *parent, uint64_t bytes, int type,
if (ctx.fd == -1)
return -errno;
+ if (flags & VHD_FLAG_CREAT_NOCOW) {
+ flags &= ~VHD_FLAG_CREAT_NOCOW;
+#ifdef __linux__
+ /* Set NOCOW flag to solve performance issue on fs like btrfs.
+ * This is an optimisation. The FS_IOC_SETFLAGS ioctl return value will
+ * be ignored since any failure of this operation should not block the
+ * left work.
+ */
+ if (ioctl(ctx.fd, FS_IOC_GETFLAGS, &attr) == 0) {
+ attr |= FS_NOCOW_FL;
+ ioctl(ctx.fd, FS_IOC_SETFLAGS, &attr);
+ }
+#endif
+ }
+
ctx.file = strdup(name);
if (!ctx.file) {
err = -ENOMEM;
diff --git a/tools/blktap2/vhd/lib/vhd-util-create.c b/tools/blktap2/vhd/lib/vhd-util-create.c
index a9bdf05..be632f8 100644
--- a/tools/blktap2/vhd/lib/vhd-util-create.c
+++ b/tools/blktap2/vhd/lib/vhd-util-create.c
@@ -49,7 +49,7 @@ vhd_util_create(int argc, char **argv)
goto usage;
optind = 0;
- while ((c = getopt(argc, argv, "n:s:rh")) != -1) {
+ while ((c = getopt(argc, argv, "n:s:rCh")) != -1) {
switch (c) {
case 'n':
name = optarg;
@@ -61,6 +61,10 @@ vhd_util_create(int argc, char **argv)
case 'r':
sparse = 0;
break;
+ case 'C':
+ /* NOCOW: this will remove COW for file on btrfs */
+ flags |= VHD_FLAG_CREAT_NOCOW;
+ break;
case 'h':
default:
goto usage;
@@ -75,6 +79,6 @@ vhd_util_create(int argc, char **argv)
flags);
usage:
- printf("options: <-n name> <-s size (MB)> [-r reserve] [-h help]\n");
+ printf("options: <-n name> <-s size (MB)> [-r reserve] [-C nocow] [-h help]\n");
return -EINVAL;
}
--
1.6.0.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-11-22 16:09 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-21 7:46 [PATCH] vhd-util create: add -C|nocow option Chunyan Liu
2013-11-21 9:39 ` Ian Campbell
2013-11-21 14:41 ` Ian Jackson
2013-11-21 14:51 ` Ian Campbell
2013-11-21 14:59 ` Ian Jackson
2013-11-21 15:01 ` Ian Campbell
2013-11-22 0:57 ` Jim Fehlig
2013-11-22 3:42 ` Chunyan Liu
2013-11-22 16:09 ` Jim Fehlig
-- strict thread matches above, loose matches on Subject: below --
2013-11-21 7:48 Chunyan Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).