From 272619412292783795658af730cf3d349e28a37d Mon Sep 17 00:00:00 2001 From: Kevin Wolf <kwolf@redhat.com> Date: Thu, 2 Sep 2010 13:05:53 -0300 Subject: [PATCH 1/2] Add cache=unsafe parameter to -drive RH-Author: Kevin Wolf <kwolf@redhat.com> Message-id: <1283432754-8775-2-git-send-email-kwolf@redhat.com> Patchwork-id: 11723 O-Subject: [RHEL-5.5.z KVM PATCH 1/2] Add cache=unsafe parameter to -drive Bugzilla: 629574 RH-Acked-by: Don Dutile <ddutile@redhat.com> RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com> From: Alexander Graf <agraf@suse.de> Bugzilla: 629574 Upstream commit: 016f5cf6ff465411733878a17c8f8febb7668321 This is half of the upstream commit to add cache=unsafe. The bdrv_aio_flush part is completely left out, so we will still flush for these (the reason is that we have no ACB pools in RHEL 5 and we would need them to use the right bdrv_aio_cancel implementation even with fake flushes). However, what we're really interested in are metadata flushes in qcow2 and those are synchronous anyway. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- qemu/block.c | 4 ++++ qemu/block.h | 4 +++- qemu/vl.c | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- qemu/block.c | 4 ++++ qemu/block.h | 4 +++- qemu/vl.c | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/qemu/block.c b/qemu/block.c index 585204e..3e2eb2f 100644 --- a/qemu/block.c +++ b/qemu/block.c @@ -1241,6 +1241,10 @@ const char *bdrv_get_device_name(BlockDriverState *bs) void bdrv_flush(BlockDriverState *bs) { + if (bs->open_flags & BDRV_O_NO_FLUSH) { + return; + } + if (bs->drv->bdrv_flush) bs->drv->bdrv_flush(bs); if (bs->backing_hd) diff --git a/qemu/block.h b/qemu/block.h index e571be6..e561df3 100644 --- a/qemu/block.h +++ b/qemu/block.h @@ -48,8 +48,10 @@ typedef struct QEMUSnapshotInfo { #define BDRV_O_CACHE_WB 0x0040 /* use write-back caching */ #define BDRV_O_CACHE_DEF 0x0080 /* use default caching */ #define BDRV_O_NO_BACKING 0x0100 /* don't open the backing file */ +#define BDRV_O_NO_FLUSH 0x0200 /* disable flushing on this disk */ -#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_CACHE_DEF) +#define BDRV_O_CACHE_MASK \ + (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_CACHE_DEF | BDRV_O_NO_FLUSH) void bdrv_info(void); void bdrv_info_stats(void); diff --git a/qemu/vl.c b/qemu/vl.c index 621c027..e50ce1c 100644 --- a/qemu/vl.c +++ b/qemu/vl.c @@ -2538,6 +2538,8 @@ int drive_init(struct drive_opt *arg, int snapshot, cache = 1; else if (!strcmp(buf, "writeback")) cache = 2; + else if (!strcmp(buf, "unsafe")) + cache = 4; else { fprintf(stderr, "qemu: invalid cache option\n"); return -1; @@ -2707,6 +2709,8 @@ int drive_init(struct drive_opt *arg, int snapshot, bdrv_flags |= BDRV_O_CACHE_WB; else if (cache == 3) /* not specified */ bdrv_flags |= BDRV_O_CACHE_DEF; + else if (cache == 4) /* unsafe */ + bdrv_flags |= BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH; drives_table[drives_table_idx].drv = drv; drives_table[drives_table_idx].bdrv_flags = bdrv_flags; @@ -4204,7 +4208,7 @@ static void help(int exitcode) "-cdrom file use 'file' as IDE cdrom image (cdrom is ide1 master)\n" "-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n" " [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n" - " [,cache=writethrough|writeback|none][,format=f][,serial=s]\n" + " [,cache=writethrough|writeback|none|unsafe][,format=f][,serial=s]\n" " [,boot=on|off]\n" " use 'file' as a drive image\n" "-mtdblock file use 'file' as on-board Flash memory image\n" -- 1.6.5.5