From: Chunyan Liu <cyliu@suse.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH] qemu-img: set nocow flag to new file
Date: Thu, 14 Nov 2013 16:15:28 +0800 [thread overview]
Message-ID: <1384416928-3441-1-git-send-email-cyliu@suse.com> (raw)
Set NOCOW flag to newly created images to solve performance issues on btrfs.
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).
Signed-off-by: Chunyan Liu <cyliu@suse.com>
---
block/raw-posix.c | 6 ++++++
block/vdi.c | 7 +++++++
block/vmdk.c | 7 +++++++
include/qemu-common.h | 9 +++++++++
4 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index f6d48bb..4a3e9d0 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1072,6 +1072,12 @@ static int raw_create(const char *filename, QEMUOptionParameter *options,
result = -errno;
error_setg_errno(errp, -result, "Could not create file");
} else {
+#ifdef __linux__
+ /* set NOCOW flag to solve performance issue on fs like btrfs */
+ int attr;
+ attr = FS_NOCOW_FL;
+ ioctl(fd, FS_IOC_SETFLAGS, &attr);
+#endif
if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
result = -errno;
error_setg_errno(errp, -result, "Could not resize file");
diff --git a/block/vdi.c b/block/vdi.c
index b6ec002..dfaa905 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -686,6 +686,13 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options,
0644);
if (fd < 0) {
return -errno;
+ } else {
+#ifdef __linux__
+ /* set NOCOW flag to solve performance issue on fs like btrfs */
+ int attr;
+ attr = FS_NOCOW_FL;
+ ioctl(fd, FS_IOC_SETFLAGS, &attr);
+#endif
}
/* We need enough blocks to store the given disk size,
diff --git a/block/vmdk.c b/block/vmdk.c
index a7ebd0f..bd953bc 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1447,6 +1447,13 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
0644);
if (fd < 0) {
return -errno;
+ } else {
+#ifdef __linux__
+ /* set NOCOW flag to solve performance issue on fs like btrfs */
+ int attr;
+ attr = FS_NOCOW_FL;
+ ioctl(fd, FS_IOC_SETFLAGS, &attr);
+#endif
}
if (flat) {
ret = ftruncate(fd, filesize);
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 5054836..fe7dd9b 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -50,6 +50,15 @@
#include "sysemu/os-posix.h"
#endif
+#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
+
#ifndef O_LARGEFILE
#define O_LARGEFILE 0
#endif
--
1.6.0.2
next reply other threads:[~2013-11-14 8:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-14 8:15 Chunyan Liu [this message]
2013-11-14 9:17 ` [Qemu-devel] [PATCH] qemu-img: set nocow flag to new file Kevin Wolf
2013-11-14 14:23 ` Alex Bligh
2013-11-14 14:28 ` Alex Bligh
2013-11-15 4:05 ` Chunyan Liu
2013-11-15 12:26 ` Kevin Wolf
2013-11-14 9:44 ` Alex Bennée
2013-11-14 10:14 ` Kevin Wolf
2013-11-15 9:38 ` Stefan Hajnoczi
2013-11-18 4:54 ` Chunyan Liu
2013-11-18 9:57 ` Stefan Hajnoczi
2013-12-10 22:23 ` Alex Bennée
2013-12-11 8:29 ` Stefan Hajnoczi
2013-12-18 14:24 ` Daniel P. Berrange
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1384416928-3441-1-git-send-email-cyliu@suse.com \
--to=cyliu@suse.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).