diff mbox

[v2,01/20] block: Add bdrv_parse_cache_mode()

Message ID 1459258257-17767-2-git-send-email-kwolf@redhat.com
State New
Headers show

Commit Message

Kevin Wolf March 29, 2016, 1:30 p.m. UTC
It's like bdrv_parse_cache_flags(), except that writethrough mode isn't
included in the flags, but returned as a separate bool.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 block.c               | 17 +++++++++++++++++
 include/block/block.h |  1 +
 2 files changed, 18 insertions(+)
diff mbox

Patch

diff --git a/block.c b/block.c
index 58acfda..33dc46c 100644
--- a/block.c
+++ b/block.c
@@ -666,6 +666,23 @@  int bdrv_parse_cache_flags(const char *mode, int *flags)
     return 0;
 }
 
+int bdrv_parse_cache_mode(const char *mode, int *flags, bool *writethrough)
+{
+    int ret = bdrv_parse_cache_flags(mode, flags);
+    if (ret < 0) {
+        return ret;
+    }
+
+    if (*flags & BDRV_O_CACHE_WB) {
+        *flags &= ~BDRV_O_CACHE_WB;
+        *writethrough = false;
+    } else {
+        *writethrough = true;
+    }
+
+    return 0;
+}
+
 /*
  * Returns the options and flags that a temporary snapshot should get, based on
  * the originally requested flags (the originally requested image will have
diff --git a/include/block/block.h b/include/block/block.h
index 26ad002..8d9bf2f 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -208,6 +208,7 @@  void bdrv_replace_in_backing_chain(BlockDriverState *old,
                                    BlockDriverState *new);
 
 int bdrv_parse_cache_flags(const char *mode, int *flags);
+int bdrv_parse_cache_mode(const char *mode, int *flags, bool *writethrough);
 int bdrv_parse_discard_flags(const char *mode, int *flags);
 BdrvChild *bdrv_open_child(const char *filename,
                            QDict *options, const char *bdref_key,