mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-17 21:26:13 -07: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
15
blockdev.c
15
blockdev.c
|
|
@ -321,18 +321,9 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
|
|||
}
|
||||
|
||||
if ((buf = qemu_opt_get(opts, "cache")) != NULL) {
|
||||
if (!strcmp(buf, "off") || !strcmp(buf, "none")) {
|
||||
bdrv_flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
|
||||
} else if (!strcmp(buf, "writeback")) {
|
||||
bdrv_flags |= BDRV_O_CACHE_WB;
|
||||
} else if (!strcmp(buf, "unsafe")) {
|
||||
bdrv_flags |= BDRV_O_CACHE_WB;
|
||||
bdrv_flags |= BDRV_O_NO_FLUSH;
|
||||
} else if (!strcmp(buf, "writethrough")) {
|
||||
/* this is the default */
|
||||
} else {
|
||||
error_report("invalid cache option");
|
||||
return NULL;
|
||||
if (bdrv_parse_cache_flags(buf, &bdrv_flags) != 0) {
|
||||
error_report("invalid cache option");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue