From patchwork Thu May 20 09:32:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 53053 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 C3EAFB7D2D for ; Thu, 20 May 2010 19:35:25 +1000 (EST) Received: from localhost ([127.0.0.1]:39781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OF29y-0007GD-Sf for incoming@patchwork.ozlabs.org; Thu, 20 May 2010 05:35:22 -0400 Received: from [140.186.70.92] (port=47419 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OF271-0006LQ-As for qemu-devel@nongnu.org; Thu, 20 May 2010 05:32:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OF26w-0003N2-T4 for qemu-devel@nongnu.org; Thu, 20 May 2010 05:32:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51756) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OF26w-0003Mm-JW for qemu-devel@nongnu.org; Thu, 20 May 2010 05:32:14 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4K9WBJ7013416 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 20 May 2010 05:32:11 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4K9W62E012624; Thu, 20 May 2010 05:32:09 -0400 From: Jes.Sorensen@redhat.com To: aliguori@us.ibm.com Date: Thu, 20 May 2010 11:32:04 +0200 Message-Id: <1274347924-9188-2-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1274347924-9188-1-git-send-email-Jes.Sorensen@redhat.com> References: <1274347924-9188-1-git-send-email-Jes.Sorensen@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: hch@infradead.org, Jes Sorensen , qemu-devel@nongnu.org, crobinso@redhat.com Subject: [Qemu-devel] [PATCH] QEMU: Change default disk caching to nocache 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 From: Jes Sorensen Change default disk image caching to nocache (O_DIRECT). However in case it fails (ramfs, NFS etc.). fall back and retry with write-back. Signed-off-by: Jes Sorensen --- vl.c | 25 +++++++++++++++++++------ 1 files changed, 19 insertions(+), 6 deletions(-) diff --git a/vl.c b/vl.c index d77b47c..f3a7d63 100644 --- a/vl.c +++ b/vl.c @@ -787,7 +787,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, int max_devs; int index; int ro = 0; - int bdrv_flags = 0; + int bdrv_flags = BDRV_O_NOCACHE; int on_read_error, on_write_error; const char *devaddr; DriveInfo *dinfo; @@ -910,11 +910,11 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, if ((buf = qemu_opt_get(opts, "cache")) != NULL) { if (!strcmp(buf, "off") || !strcmp(buf, "none")) { - bdrv_flags |= BDRV_O_NOCACHE; + /* default */ } else if (!strcmp(buf, "writeback")) { bdrv_flags |= BDRV_O_CACHE_WB; } else if (!strcmp(buf, "writethrough")) { - /* this is the default */ + bdrv_flags &= ~BDRV_O_CACHE_MASK; } else { fprintf(stderr, "qemu: invalid cache option\n"); return NULL; @@ -1120,15 +1120,28 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, bdrv_flags |= ro ? 0 : BDRV_O_RDWR; if (bdrv_open(dinfo->bdrv, file, bdrv_flags, drv) < 0) { - fprintf(stderr, "qemu: could not open disk image %s: %s\n", - file, strerror(errno)); - return NULL; + if (bdrv_flags & BDRV_O_NOCACHE) { + fprintf(stderr, "qemu: failed to open disk image %s as " + "nocache (O_DIRECT) retrying as write-back\n", file); + bdrv_flags &= BDRV_O_NOCACHE; + bdrv_flags |= BDRV_O_CACHE_WB; + if (bdrv_open(dinfo->bdrv, file, bdrv_flags, drv) < 0) + goto error_open; + } else { + goto error_open; + } } if (bdrv_key_required(dinfo->bdrv)) autostart = 0; *fatal_error = 0; return dinfo; + +error_open: + fprintf(stderr, "qemu: could not open disk image %s: %s\n", + file, strerror(errno)); + return NULL; + } static int drive_init_func(QemuOpts *opts, void *opaque)