mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
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>
This commit is contained in:
parent
12888904fe
commit
c3993cdca3
4 changed files with 32 additions and 36 deletions
25
block.c
25
block.c
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue