From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg7GH-0006if-4C for qemu-devel@nongnu.org; Tue, 12 Nov 2013 01:15:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vg7GC-0002zB-2s for qemu-devel@nongnu.org; Tue, 12 Nov 2013 01:15:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:10092) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vg7GB-0002y2-Ob for qemu-devel@nongnu.org; Tue, 12 Nov 2013 01:15:36 -0500 Message-ID: <5281C77E.4080108@redhat.com> Date: Tue, 12 Nov 2013 14:15:26 +0800 From: Fam Zheng MIME-Version: 1.0 References: <1383811709-32203-1-git-send-email-cyliu@suse.com> In-Reply-To: <1383811709-32203-1-git-send-email-cyliu@suse.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] qemu-img create: set nocow flag by default List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Chunyan Liu , qemu-devel@nongnu.org Cc: stefanha@gmail.com On 2013=E5=B9=B411=E6=9C=8807=E6=97=A5 16:08, Chunyan Liu wrote: > Set NOCOW flag to newly created images to solve performance issues on b= trfs. > > Btrfs has terrible performance when hosting VM images, even more when t= he guest > in those VM are also using btrfs as file system. One way to mitigate th= is bad > performance is to turn off COW attributes on VM files (since having cop= y on > write for this kind of data is not useful). > > Signed-off-by: Chunyan Liu > --- > qemu-img.c | 15 +++++++++++++++ > 1 files changed, 15 insertions(+), 0 deletions(-) > > diff --git a/qemu-img.c b/qemu-img.c > index bf3fb4f..d43e8f1 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -34,11 +34,17 @@ > #include > #include > #include > +#include > +#include This should be in #ifdef to not break build on Windows. > #ifdef _WIN32 > #include > #endif > > +#ifndef FS_NOCOW_FL > +#define FS_NOCOW_FL 0x00800000 /* Do not cow file = */ > +#endif > + > typedef struct img_cmd_t { > const char *name; > int (*handler)(int argc, char **argv); > @@ -340,6 +346,7 @@ static int img_create(int argc, char **argv) > char *options =3D NULL; > Error *local_err =3D NULL; > bool quiet =3D false; > + int fd, attr; > > for(;;) { > c =3D getopt(argc, argv, "F:b:f:he6o:q"); > @@ -417,6 +424,14 @@ static int img_create(int argc, char **argv) > return 1; > } > > + /* set NOCOW by default to solve performance issue on btrfs */ > + fd =3D qemu_open(filename, O_RDONLY|O_NONBLOCK); > + if (fd >=3D 0) { > + attr =3D FS_NOCOW_FL; > + ioctl(fd, FS_IOC_SETFLAGS, &attr); > + qemu_close(fd); > + } > + > return 0; > } > > "man chattr" says: ... For btrfs, the 'C' flag should be set on new or empty files. If it=20 is set on a file which already has data blocks, it is undefined when the=20 blocks assigned to the file will be fully stable... But you are setting the attr after image creation, so what's the=20 difference here? just want to make sure this does what's expected. Thanks, Fam