diff mbox

[RFC,v3,1/6] block: introduce prealloc_mode

Message ID c6cb3e837464999ec730242b62fddca670aeb39e.1387419339.git.hutao@cn.fujitsu.com
State New
Headers show

Commit Message

Hu Tao Dec. 19, 2013, 2:27 a.m. UTC
This patch prepares for the subsequent patches.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 block/qcow2.c         | 6 +++---
 include/block/block.h | 6 ++++++
 2 files changed, 9 insertions(+), 3 deletions(-)

Comments

Stefan Hajnoczi Dec. 20, 2013, 10:08 a.m. UTC | #1
On Thu, Dec 19, 2013 at 10:27:36AM +0800, Hu Tao wrote:
> diff --git a/include/block/block.h b/include/block/block.h
> index 36efaea..3732f25 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -527,4 +527,10 @@ int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag);
>  int bdrv_debug_resume(BlockDriverState *bs, const char *tag);
>  bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag);
>  
> +enum prealloc_mode {

Please follow modern QEMU coding style and use CamelCase: PreallocMode

It would be nice to use PreallocMode instead int for variables.
Eric Blake Dec. 20, 2013, 12:36 p.m. UTC | #2
On 12/18/2013 07:27 PM, Hu Tao wrote:
> This patch prepares for the subsequent patches.
> 
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
>  block/qcow2.c         | 6 +++---
>  include/block/block.h | 6 ++++++
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 

> +++ b/include/block/block.h
> @@ -527,4 +527,10 @@ int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag);
>  int bdrv_debug_resume(BlockDriverState *bs, const char *tag);
>  bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag);
>  
> +enum prealloc_mode {
> +    PREALLOC_OFF = 0,
> +    PREALLOC_METADATA,
> +    PREALLOC_FULL,
> +};

Why not make this a QAPI enum:

{ 'enum': 'PreallocMode', 'data': ['off', 'metadata', 'full'] }

After all, this is the sort of thing where we will eventually want to
select the prealloc mode of new files being created by online operations
such as snapshot creation.
diff mbox

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index f29aa88..32cb39f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1614,7 +1614,7 @@  static int qcow2_create(const char *filename, QEMUOptionParameter *options,
     uint64_t sectors = 0;
     int flags = 0;
     size_t cluster_size = DEFAULT_CLUSTER_SIZE;
-    int prealloc = 0;
+    int prealloc = PREALLOC_OFF;
     int version = 3;
     Error *local_err = NULL;
     int ret;
@@ -1635,9 +1635,9 @@  static int qcow2_create(const char *filename, QEMUOptionParameter *options,
             }
         } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
             if (!options->value.s || !strcmp(options->value.s, "off")) {
-                prealloc = 0;
+                prealloc = PREALLOC_OFF;
             } else if (!strcmp(options->value.s, "metadata")) {
-                prealloc = 1;
+                prealloc = PREALLOC_METADATA;
             } else {
                 error_setg(errp, "Invalid preallocation mode: '%s'",
                            options->value.s);
diff --git a/include/block/block.h b/include/block/block.h
index 36efaea..3732f25 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -527,4 +527,10 @@  int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag);
 int bdrv_debug_resume(BlockDriverState *bs, const char *tag);
 bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag);
 
+enum prealloc_mode {
+    PREALLOC_OFF = 0,
+    PREALLOC_METADATA,
+    PREALLOC_FULL,
+};
+
 #endif