From patchwork Thu Nov 7 08:08:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 289220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AB8FD2C00A2 for ; Thu, 7 Nov 2013 19:08:35 +1100 (EST) Received: from localhost ([::1]:38824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VeKdl-0001sZ-3L for incoming@patchwork.ozlabs.org; Thu, 07 Nov 2013 03:08:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VeKdS-0001rX-2a for qemu-devel@nongnu.org; Thu, 07 Nov 2013 03:08:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VeKdM-0006tg-2n for qemu-devel@nongnu.org; Thu, 07 Nov 2013 03:08:13 -0500 Received: from inet-orm.provo.novell.com ([137.65.248.124]:34291 helo=mail.novell.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VeKdL-0006qa-RB for qemu-devel@nongnu.org; Thu, 07 Nov 2013 03:08:08 -0500 Received: from localhost.localdomain ([147.2.207.54]) by mail.novell.com with ESMTP; Thu, 07 Nov 2013 01:07:40 -0700 From: Chunyan Liu To: qemu-devel@nongnu.org Date: Thu, 7 Nov 2013 16:08:29 +0800 Message-Id: <1383811709-32203-1-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 1.6.0.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 137.65.248.124 Cc: stefanha@gmail.com, Chunyan Liu Subject: [Qemu-devel] [PATCH] qemu-img create: set nocow flag by default X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 #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 = NULL; Error *local_err = NULL; bool quiet = false; + int fd, attr; for(;;) { c = 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 = qemu_open(filename, O_RDONLY|O_NONBLOCK); + if (fd >= 0) { + attr = FS_NOCOW_FL; + ioctl(fd, FS_IOC_SETFLAGS, &attr); + qemu_close(fd); + } + return 0; }