diff options
author | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2011-08-04 12:26:51 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2011-08-23 14:15:17 +0200 |
commit | 409e851823b4d13be16c88a54d6280a495ad4f7b (patch) | |
tree | fd31efb3149956a7fd09de821851b52ce2e20580 /block.c | |
parent | b23888cecaec1ed2ec1408e8db52cc208002539f (diff) | |
download | qemu-409e851823b4d13be16c88a54d6280a495ad4f7b.tar.gz qemu-409e851823b4d13be16c88a54d6280a495ad4f7b.tar.bz2 qemu-409e851823b4d13be16c88a54d6280a495ad4f7b.zip |
block: parse cache mode flags in a single place
This patch introduces bdrv_parse_cache_flags() which sets open flags
given a cache mode. Previously this was duplicated in blockdev.c and
qemu-img.c.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -437,6 +437,31 @@ static int refresh_total_sectors(BlockDriverState *bs, int64_t hint) return 0; } +/** + * Set open flags for a given cache mode + * + * Return 0 on success, -1 if the cache mode was invalid. + */ +int bdrv_parse_cache_flags(const char *mode, int *flags) +{ + *flags &= ~BDRV_O_CACHE_MASK; + + if (!strcmp(mode, "off") || !strcmp(mode, "none")) { + *flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; + } else if (!strcmp(mode, "writeback")) { + *flags |= BDRV_O_CACHE_WB; + } else if (!strcmp(mode, "unsafe")) { + *flags |= BDRV_O_CACHE_WB; + *flags |= BDRV_O_NO_FLUSH; + } else if (!strcmp(mode, "writethrough")) { + /* this is the default */ + } else { + return -1; + } + + return 0; +} + /* * Common part for opening disk images and files */ |