From: Federico Simoncelli <fsimonce@redhat.com>
To: kvm@vger.kernel.org
Cc: Federico Simoncelli <fsimonce@redhat.com>
Subject: [PATCH] qemu-img: Add nocache command line option
Date: Tue, 14 Jun 2011 08:09:42 -0400 [thread overview]
Message-ID: <1308053382-9771-1-git-send-email-fsimonce@redhat.com> (raw)
qemu-img currently writes images using writeback and filling up
the cache buffers which are then flushed by the kernel preventing
other processes from accessing the storage.
This is particularly bad in cluster environments where time-based
algorithms might be in place and accessing the storage within
certain timeouts is critical.
This patch adds the option to use nocache when other solutions
(eg: cgroups) are not available.
Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
---
qemu-img.c | 33 ++++++++++++++++++++++++---------
1 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 4f162d1..c10e4a6 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -78,6 +78,7 @@ static void help(void)
" rebasing in this case (useful for renaming the backing file)\n"
" '-h' with or without a command shows this help and lists the supported formats\n"
" '-p' show progress of command (only certain commands)\n"
+ " '-t' use write-through (no cache), valid with: convert, commit and rebase\n"
"\n"
"Parameters to snapshot subcommand:\n"
" 'snapshot' is the name of the snapshot to create, apply or delete\n"
@@ -441,13 +442,14 @@ static int img_check(int argc, char **argv)
static int img_commit(int argc, char **argv)
{
- int c, ret;
+ int c, ret, flags;
const char *filename, *fmt;
BlockDriverState *bs;
fmt = NULL;
+ flags = BDRV_O_FLAGS | BDRV_O_RDWR;
for(;;) {
- c = getopt(argc, argv, "f:h");
+ c = getopt(argc, argv, "f:ht");
if (c == -1) {
break;
}
@@ -459,6 +461,10 @@ static int img_commit(int argc, char **argv)
case 'f':
fmt = optarg;
break;
+ case 't':
+ flags &= ~BDRV_O_CACHE_WB;
+ flags |= BDRV_O_NOCACHE;
+ break;
}
}
if (optind >= argc) {
@@ -466,7 +472,7 @@ static int img_commit(int argc, char **argv)
}
filename = argv[optind++];
- bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
+ bs = bdrv_new_open(filename, fmt, flags);
if (!bs) {
return 1;
}
@@ -591,7 +597,7 @@ static int compare_sectors(const uint8_t *buf1, const uint8_t *buf2, int n,
static int img_convert(int argc, char **argv)
{
int c, ret = 0, n, n1, bs_n, bs_i, compress, cluster_size, cluster_sectors;
- int progress = 0;
+ int progress = 0, flags;
const char *fmt, *out_fmt, *out_baseimg, *out_filename;
BlockDriver *drv, *proto_drv;
BlockDriverState **bs = NULL, *out_bs = NULL;
@@ -610,8 +616,9 @@ static int img_convert(int argc, char **argv)
out_fmt = "raw";
out_baseimg = NULL;
compress = 0;
+ flags = BDRV_O_FLAGS | BDRV_O_RDWR | BDRV_O_NO_FLUSH;
for(;;) {
- c = getopt(argc, argv, "f:O:B:s:hce6o:p");
+ c = getopt(argc, argv, "f:O:B:s:hce6o:pt");
if (c == -1) {
break;
}
@@ -649,6 +656,10 @@ static int img_convert(int argc, char **argv)
case 'p':
progress = 1;
break;
+ case 't':
+ flags &= ~BDRV_O_CACHE_WB;
+ flags |= BDRV_O_NOCACHE;
+ break;
}
}
@@ -779,8 +790,7 @@ static int img_convert(int argc, char **argv)
goto out;
}
- out_bs = bdrv_new_open(out_filename, out_fmt,
- BDRV_O_FLAGS | BDRV_O_RDWR | BDRV_O_NO_FLUSH);
+ out_bs = bdrv_new_open(out_filename, out_fmt, flags);
if (!out_bs) {
ret = -1;
goto out;
@@ -1234,9 +1244,10 @@ static int img_rebase(int argc, char **argv)
fmt = NULL;
out_baseimg = NULL;
out_basefmt = NULL;
+ flags = BDRV_O_FLAGS | BDRV_O_RDWR;
for(;;) {
- c = getopt(argc, argv, "uhf:F:b:p");
+ c = getopt(argc, argv, "uhf:F:b:pt");
if (c == -1) {
break;
}
@@ -1256,10 +1267,15 @@ static int img_rebase(int argc, char **argv)
break;
case 'u':
unsafe = 1;
+ flags |= BDRV_O_NO_BACKING;
break;
case 'p':
progress = 1;
break;
+ case 't':
+ flags &= ~BDRV_O_CACHE_WB;
+ flags |= BDRV_O_NOCACHE;
+ break;
}
}
@@ -1277,7 +1293,6 @@ static int img_rebase(int argc, char **argv)
* Ignore the old backing file for unsafe rebase in case we want to correct
* the reference to a renamed or moved backing file.
*/
- flags = BDRV_O_FLAGS | BDRV_O_RDWR | (unsafe ? BDRV_O_NO_BACKING : 0);
bs = bdrv_new_open(filename, fmt, flags);
if (!bs) {
return 1;
--
1.7.1
next reply other threads:[~2011-06-14 12:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-14 12:09 Federico Simoncelli [this message]
2011-06-14 13:13 ` [PATCH] qemu-img: Add nocache command line option Avi Kivity
2011-06-15 10:50 ` Kevin Wolf
2011-06-15 11:17 ` Federico Simoncelli
2011-06-15 11:45 ` Kevin Wolf
2011-06-15 12:15 ` Federico Simoncelli
2011-06-15 12:26 ` Kevin Wolf
2011-06-15 13:46 ` [PATCH] qemu-img: Add cache " Federico Simoncelli
2011-06-15 13:51 ` [PATCHv2] " Federico Simoncelli
2011-06-16 11:58 ` [PATCHv3] " Federico Simoncelli
2011-06-16 14:28 ` [Qemu-devel] [PATCH] " Christoph Hellwig
2011-06-16 14:43 ` Kevin Wolf
2011-06-20 14:47 ` Kevin Wolf
2011-06-20 16:48 ` [PATCHv4] " Federico Simoncelli
2011-06-29 9:48 ` Kevin Wolf
2011-06-16 14:44 ` [Qemu-devel] [PATCH] " Federico Simoncelli
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=1308053382-9771-1-git-send-email-fsimonce@redhat.com \
--to=fsimonce@redhat.com \
--cc=kvm@vger.kernel.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