Patchwork [RFC,1/3] Qemu: Enhance "info block" to display cache setting

login
register
mail settings
Submitter Supriya Kannery
Date May 16, 2011, 6:10 p.m.
Message ID <20110516181037.7142.76146.sendpatchset@skannery>
Download mbox | patch
Permalink /patch/95794/
State New
Headers show

Comments

Supriya Kannery - May 16, 2011, 6:10 p.m.
Enhance "info block" to display cache setting

Example:
(qemu) info block
ide0-hd0: type=hd removable=0 file=../rhel6-32.qcow2 ro=0 drv=qcow2 
encrypted=0

Enhanced to include "cache" setting:
(qemu) info block
ide0-hd0: type=hd removable=0 cache=none file=../rhel6-32.qcow2 ro=0 
drv=qcow2 encrypted=0

Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>
Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>

---
 block.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
Kevin Wolf - May 17, 2011, 8:39 a.m.
Am 16.05.2011 20:10, schrieb Supriya Kannery:
> Enhance "info block" to display cache setting
> 
> Example:
> (qemu) info block
> ide0-hd0: type=hd removable=0 file=../rhel6-32.qcow2 ro=0 drv=qcow2 
> encrypted=0
> 
> Enhanced to include "cache" setting:
> (qemu) info block
> ide0-hd0: type=hd removable=0 cache=none file=../rhel6-32.qcow2 ro=0 
> drv=qcow2 encrypted=0
> 
> Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>
> Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
> 
> ---
>  block.c |   18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> Index: qemu/block.c
> ===================================================================
> --- qemu.orig/block.c
> +++ qemu/block.c
> @@ -1713,6 +1713,19 @@ static void bdrv_print_dict(QObject *obj
>          monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, "locked"));
>      }
>  
> +    if (qdict_haskey(bs_dict, "open_flags")) {
> +        int open_flags = qdict_get_int(bs_dict, "open_flags");
> +        if (open_flags & BDRV_O_NOCACHE) {
> +            monitor_printf(mon, " cache=none");
> +        } else if (open_flags & BDRV_O_CACHE_WB) {
> +            if (open_flags & BDRV_O_NO_FLUSH)
> +                monitor_printf(mon, " cache=unsafe");
> +            else
> +                monitor_printf(mon, " cache=writeback");
> +        } else
> +            monitor_printf(mon, " cache=writethrough");
> +    }
> +
>      if (qdict_haskey(bs_dict, "inserted")) {
>          QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
>  
> @@ -1762,9 +1775,10 @@ void bdrv_info(Monitor *mon, QObject **r
>          }
>  
>          bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': %s, "
> -                                    "'removable': %i, 'locked': %i }",
> +                                    "'removable': %i, 'locked': %i, "
> +                                    "'open_flags': %d }",
>                                      bs->device_name, type, bs->removable,
> -                                    bs->locked);
> +                                    bs->locked, bs->open_flags);
>  
>          if (bs->drv) {
>              QObject *obj;

bs->open_flags is a purely internal thing and its meaning is not
guaranteed to be stable. Exposing it to the user is wrong.

Kevin
supriya kannery - May 17, 2011, 9 a.m.
Kevin Wolf wrote:
> Am 16.05.2011 20:10, schrieb Supriya Kannery:
>   
>> Enhance "info block" to display cache setting
>>
>> Example:
>> (qemu) info block
>> ide0-hd0: type=hd removable=0 file=../rhel6-32.qcow2 ro=0 drv=qcow2 
>> encrypted=0
>>
>> Enhanced to include "cache" setting:
>> (qemu) info block
>> ide0-hd0: type=hd removable=0 cache=none file=../rhel6-32.qcow2 ro=0 
>> drv=qcow2 encrypted=0
>>
>>     

>>  
>>          bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': %s, "
>> -                                    "'removable': %i, 'locked': %i }",
>> +                                    "'removable': %i, 'locked': %i, "
>> +                                    "'open_flags': %d }",
>>                                      bs->device_name, type, bs->removable,
>> -                                    bs->locked);
>> +                                    bs->locked, bs->open_flags);
>>  
>>          if (bs->drv) {
>>              QObject *obj;
>>     
>
> bs->open_flags is a purely internal thing and its meaning is not
> guaranteed to be stable. Exposing it to the user is wrong.
>
>   
ok. Pls suggest what could a better approach to expose the cache setting.
> Kevin
>
>

Patch

Index: qemu/block.c
===================================================================
--- qemu.orig/block.c
+++ qemu/block.c
@@ -1713,6 +1713,19 @@  static void bdrv_print_dict(QObject *obj
         monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, "locked"));
     }
 
+    if (qdict_haskey(bs_dict, "open_flags")) {
+        int open_flags = qdict_get_int(bs_dict, "open_flags");
+        if (open_flags & BDRV_O_NOCACHE) {
+            monitor_printf(mon, " cache=none");
+        } else if (open_flags & BDRV_O_CACHE_WB) {
+            if (open_flags & BDRV_O_NO_FLUSH)
+                monitor_printf(mon, " cache=unsafe");
+            else
+                monitor_printf(mon, " cache=writeback");
+        } else
+            monitor_printf(mon, " cache=writethrough");
+    }
+
     if (qdict_haskey(bs_dict, "inserted")) {
         QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
 
@@ -1762,9 +1775,10 @@  void bdrv_info(Monitor *mon, QObject **r
         }
 
         bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': %s, "
-                                    "'removable': %i, 'locked': %i }",
+                                    "'removable': %i, 'locked': %i, "
+                                    "'open_flags': %d }",
                                     bs->device_name, type, bs->removable,
-                                    bs->locked);
+                                    bs->locked, bs->open_flags);
 
         if (bs->drv) {
             QObject *obj;