From: Jes.Sorensen@redhat.com
To: aliguori@us.ibm.com
Cc: hch@infradead.org, Jes Sorensen <Jes.Sorensen@redhat.com>,
qemu-devel@nongnu.org, crobinso@redhat.com
Subject: [Qemu-devel] [PATCH] QEMU: Change default disk caching to nocache
Date: Thu, 20 May 2010 11:32:04 +0200 [thread overview]
Message-ID: <1274347924-9188-2-git-send-email-Jes.Sorensen@redhat.com> (raw)
In-Reply-To: <1274347924-9188-1-git-send-email-Jes.Sorensen@redhat.com>
From: Jes Sorensen <Jes.Sorensen@redhat.com>
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 <Jes.Sorensen@redhat.com>
---
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)
--
1.6.5.2
next prev parent reply other threads:[~2010-05-20 9:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-20 9:32 [Qemu-devel] [PATCH] QEMU: change default disk cache behavior Jes.Sorensen
2010-05-20 9:32 ` Jes.Sorensen [this message]
2010-05-20 15:24 ` [Qemu-devel] Re: [PATCH] QEMU: Change default disk caching to nocache Paolo Bonzini
2010-05-20 18:56 ` Anthony Liguori
2010-05-20 12:30 ` [Qemu-devel] [PATCH] QEMU: change default disk cache behavior Anthony Liguori
2010-05-20 13:36 ` Jes Sorensen
2010-05-20 13:40 ` Anthony Liguori
2010-05-20 13:49 ` Jes Sorensen
2010-05-20 14:05 ` Stefan Hajnoczi
2010-05-20 18:58 ` Anthony Liguori
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=1274347924-9188-2-git-send-email-Jes.Sorensen@redhat.com \
--to=jes.sorensen@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=crobinso@redhat.com \
--cc=hch@infradead.org \
--cc=qemu-devel@nongnu.org \
/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).