From patchwork Mon May 10 21:51:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 52238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 921C6B7D77 for ; Tue, 11 May 2010 07:54:14 +1000 (EST) Received: from localhost ([127.0.0.1]:53997 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OBavO-00058v-1S for incoming@patchwork.ozlabs.org; Mon, 10 May 2010 17:54:06 -0400 Received: from [140.186.70.92] (port=41548 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OBat2-0004OG-JW for qemu-devel@nongnu.org; Mon, 10 May 2010 17:51:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OBat0-0005jn-AV for qemu-devel@nongnu.org; Mon, 10 May 2010 17:51:40 -0400 Received: from cantor2.suse.de ([195.135.220.15]:38838 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OBat0-0005jS-1O for qemu-devel@nongnu.org; Mon, 10 May 2010 17:51:38 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id 75479890B6; Mon, 10 May 2010 23:51:37 +0200 (CEST) From: Alexander Graf To: qemu-devel@nongnu.org Date: Mon, 10 May 2010 23:51:50 +0200 Message-Id: <1273528310-7051-3-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1273528310-7051-2-git-send-email-agraf@suse.de> References: <1273528310-7051-1-git-send-email-agraf@suse.de> <1273528310-7051-2-git-send-email-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: kwolf@redhat.com, hch@lst.de Subject: [Qemu-devel] [PATCH 2/2] Add flush=off parameter to -drive X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Usually the guest can tell the host to flush data to disk. In some cases we don't want to flush though, but try to keep everything in cache. So let's add a new parameter to -drive that allows us to set the flushing behavior to "on" or "off", defaulting to enabling the guest to flush. Signed-off-by: Alexander Graf --- block/raw-posix.c | 13 +++++++++++++ qemu-config.c | 3 +++ qemu-options.hx | 3 +++ vl.c | 3 +++ 4 files changed, 22 insertions(+), 0 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 7541ed2..2510b1b 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -106,6 +106,7 @@ typedef struct BDRVRawState { int fd; int type; int open_flags; + int bdrv_flags; #if defined(__linux__) /* linux floppy specific */ int64_t fd_open_time; @@ -133,6 +134,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, BDRVRawState *s = bs->opaque; int fd, ret; + s->bdrv_flags = bdrv_flags; s->open_flags = open_flags | O_BINARY; s->open_flags &= ~O_ACCMODE; if (bdrv_flags & BDRV_O_RDWR) { @@ -555,6 +557,11 @@ static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs, if (fd_open(bs) < 0) return NULL; + /* Don't flush? */ + if (s->bdrv_flags & BDRV_O_NOFLUSH) { + return bdrv_aio_noop_em(bs, cb, opaque); + } + return paio_submit(bs, s->fd, 0, NULL, 0, cb, opaque, QEMU_AIO_FLUSH); } @@ -726,6 +733,12 @@ static int raw_create(const char *filename, QEMUOptionParameter *options) static void raw_flush(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; + + /* No flush means no flush */ + if (s->bdrv_flags & BDRV_O_NOFLUSH) { + return; + } + qemu_fdatasync(s->fd); } diff --git a/qemu-config.c b/qemu-config.c index d500885..c358add 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -79,6 +79,9 @@ QemuOptsList qemu_drive_opts = { },{ .name = "readonly", .type = QEMU_OPT_BOOL, + },{ + .name = "flush", + .type = QEMU_OPT_BOOL, }, { /* end if list */ } }, diff --git a/qemu-options.hx b/qemu-options.hx index 12f6b51..69ae8de 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -120,6 +120,7 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive, " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n" " [,cache=writethrough|writeback|none][,format=f][,serial=s]\n" " [,addr=A][,id=name][,aio=threads|native][,readonly=on|off]\n" + " [,flush=on|off]\n" " use 'file' as a drive image\n", QEMU_ARCH_ALL) STEXI @item -drive @var{option}[,@var{option}[,@var{option}[,...]]] @@ -151,6 +152,8 @@ These options have the same definition as they have in @option{-hdachs}. @var{cache} is "none", "writeback", or "writethrough" and controls how the host cache is used to access block data. @item aio=@var{aio} @var{aio} is "threads", or "native" and selects between pthread based disk I/O and native Linux AIO. +@item flush=@var{flush} +@var{flush} is "on" (default), or "off" and select whether the guest can trigger a host flush @item format=@var{format} Specify which disk @var{format} will be used rather than detecting the format. Can be used to specifiy format=raw to avoid interpreting diff --git a/vl.c b/vl.c index 85bcc84..a7ca2c3 100644 --- a/vl.c +++ b/vl.c @@ -787,6 +787,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, int max_devs; int index; int ro = 0; + int flush = 1; int bdrv_flags = 0; int on_read_error, on_write_error; const char *devaddr; @@ -819,6 +820,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, snapshot = qemu_opt_get_bool(opts, "snapshot", 0); ro = qemu_opt_get_bool(opts, "readonly", 0); + flush = qemu_opt_get_bool(opts, "flush", 1); file = qemu_opt_get(opts, "file"); serial = qemu_opt_get(opts, "serial"); @@ -1118,6 +1120,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, } bdrv_flags |= ro ? 0 : BDRV_O_RDWR; + bdrv_flags |= flush ? 0 : BDRV_O_NOFLUSH; if (bdrv_open(dinfo->bdrv, file, bdrv_flags, drv) < 0) { fprintf(stderr, "qemu: could not open disk image %s: %s\n",