Skip to contentSkip to conversation

Qemu: Host pagecache setting from cmdline and monitor

PATCH In review Supriya Kannery 6 participants 44 messages Nov 11, 2011 – Jan 19, 2012 Block layer

lore
Share & tools
lore
#0 lore raw

v9 cover Qemu: Host pagecache setting from cmdline and monitor

Following patchset is for enabling dynamic change of host pagecache setting of block devices through qemu monitor.

This patchset introduces
a. monitor command 'block_set_hostcache' using which host
pagecache setting for a block device can be changed dynamically.
b. a new option for setting host cache from qemu
commandline option -drive "hostcache=on/off".
c. BDRVReopenState, a generic structure which can be
extended by each of the block drivers to reopen respective image files.
Extension of this structure for drivers raw-posix is done here.
Note: 'hostcache and 'cache' options when used together, cache=xx will override hostcache=yy.

v9:
1. Rebased patchset to use qapi interfaces
2. Approach of extending BDRVReopenState changed
to use container_of()

v8:
1. Mandate implementation of all three reopen
related functions by block drivers.
2. If 'cache=xx' and 'hostcache=yy' specified
in cmdline, 'cache=' overrides 'hostcache='.

v7:
1. Added structure BDRVReopenState to support safe reopening of image files.
2. Implemented reopen functions for raw-posix driver

v6:
1. "block_set_hostcache" to replace "block_set" command

v5:
1. Defined qerror class for incorrect command syntax.
2. Changed error_report() calls to qerror_report()

v4:
Added 'hostcache' option to '-drive' commandline option.

v3:
1. Command "block_set" for changing various block params
2. Enhanced info-block to display hostcache setting
3. Added qmp interfaces for setting and querying hostcache

v2:
1. Support of dynamic cache change only for hostcache.
2. Monitor command "hostcache_get" added to display cache setting
3. Backed off the changes for display of cache setting in "info block"

v1:
Dynamic cache change through monitor

New block command added:
"block_set_hostcache"
-- Sets hostcache parameter for block device while guest is running.

Usage:
block_set_hostcache <device> <option>
<device> = block device
<option> = on/off

New 'hostcache' option added to -drive:
-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n"

        ....

" [,readonly=on|off][,hostcache=on|off]\n"

 qemu/block.c           |  111 +++++++++++++++++++++++++++++++++++++++++++++---- 
 qemu/block.h           |    5 +  
 qemu/block/raw-posix.c |   72 ++++++++++++++++++++++++++++++++
 qemu/block/raw.c       |   23 +++++++++-
 qemu/block_int.h       |   13 +++++
 qemu/blockdev.c        |   33 ++++++++++++++
 qemu/blockdev.h        |    2
 qemu/hmp-commands.hx   |   14 ++++++
 qemu/hmp.c             |    2
 qemu/qapi-schema.json  |    4 +
 qemu/qapi-types.h      |    1
 qemu/qemu-common.h     |    1
 qemu/qemu-config.c     |    4 +
 qemu/qemu-options.hx   |    2
 qemu/qerror.c          |    8 +++
 qemu/qerror.h          |    6 ++
 qemu/qmp-commands.hx   |   27 ++++++++++++
 20 files changed, 315 insertions(+), 13 deletions(-)

~
~
~
~
~
~
~
~
~
~
"txt" 13L, 574C

#1 lore raw

PATCH v9 1/6 Qemu: Enhance "info block" to display host cache setting

Enhance "info block" to display hostcache setting for each block device.

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

Enhanced to display "hostcache" setting:
(qemu) info block
ide0-hd0: removable=0 hostcache=1 file=../rhel6-32.raw ro=0 drv=raw encrypted=0

---
 block.c         |   20 ++++++++++++++++----
 qmp-commands.hx |    2 ++
 2 files changed, 18 insertions(+), 4 deletions(-)
qapi-schema.json +3 -1
Index: qemu/qapi-schema.json
===================================================================
@@ -409,6 +409,8 @@
 # @locked: True if the guest has locked this device from having its media
 #          removed
 #
+# @hostcache: True if host pagecache is enabled.
+#
 # @tray_open: #optional True if the device has a tray and it is open
 #             (only present if removable is true)
 #
@@ -422,7 +424,7 @@
 ##
 { 'type': 'BlockInfo',
   'data': {'device': 'str', 'type': 'str', 'removable': 'bool',
-           'locked': 'bool', '*inserted': 'BlockDeviceInfo',
+           'locked': 'bool','hostcache': 'bool', '*inserted': 'BlockDeviceInfo',
            '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus'} }
 
 ##
qapi-types.h +1 -0
Index: qemu/qapi-types.h
===================================================================
@@ -383,6 +383,7 @@ struct BlockInfo
 {
     char * device;
     char * type;
+    bool hostcache;
     bool removable;
     bool locked;
     bool has_inserted;
block.c +1 -0
Index: qemu/block.c
===================================================================
@@ -1839,6 +1839,7 @@ BlockInfoList *qmp_query_block(Error **e
         info->value->device = g_strdup(bs->device_name);
         info->value->type = g_strdup("unknown");
         info->value->locked = bdrv_dev_is_medium_locked(bs);
+        info->value->hostcache = !(bs->open_flags & BDRV_O_NOCACHE);
         info->value->removable = bdrv_dev_has_removable_media(bs);
 
         if (bdrv_dev_has_removable_media(bs)) {
hmp.c +2 -0
Index: qemu/hmp.c
===================================================================
@@ -199,6 +199,8 @@ void hmp_info_block(Monitor *mon)
             monitor_printf(mon, " tray-open=%d", info->value->tray_open);
         }
 
+        monitor_printf(mon, " hostcache=%d", info->value->hostcache);
+
         if (info->value->has_io_status) {
             monitor_printf(mon, " io-status=%s",
                            BlockDeviceIoStatus_lookup[info->value->io_status]);
#2 lore raw

Re: [Qemu-devel] [v9 Patch 1/6 - updated]Qemu: Enhance "info block" to display host cache setting

Quoted 17 lines · Supriya Kannery

Enhance "info block" to display hostcache setting for each block device.

##
Index: qemu/qapi-types.h
===================================================================

qapi-types.h +1 -0
@@ -383,6 +383,7 @@ struct BlockInfo
  {
      char * device;
      char * type;
+    bool hostcache;
      bool removable;
      bool locked;
      bool has_inserted;
Quoted 1 line

Index: qemu/block.c

hostcache gets added to qapi-types.h from
the change done in qapi-schema.json. Hence
above change has to be ignored. Pls find
updated patch.

*********************************************************************
Enhance "info block" to display hostcache setting for each block device.

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

Enhanced to display "hostcache" setting:
(qemu) info block
ide0-hd0: removable=0 hostcache=1 file=../rhel6-32.raw ro=0 drv=raw encrypted=0

---
 block.c         |   20 ++++++++++++++++----
 qmp-commands.hx |    2 ++
 2 files changed, 18 insertions(+), 4 deletions(-)
qapi-schema.json +3 -1
Index: qemu/qapi-schema.json
===================================================================
@@ -409,6 +409,8 @@
 # @locked: True if the guest has locked this device from having its media
 #          removed
 #
+# @hostcache: True if host pagecache is enabled.
+#
 # @tray_open: #optional True if the device has a tray and it is open
 #             (only present if removable is true)
 #
@@ -422,7 +424,7 @@
 ##
 { 'type': 'BlockInfo',
   'data': {'device': 'str', 'type': 'str', 'removable': 'bool',
-           'locked': 'bool', '*inserted': 'BlockDeviceInfo',
+           'locked': 'bool','hostcache': 'bool', '*inserted': 'BlockDeviceInfo',
            '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus'} }
 
 ##
block.c +1 -0
Index: qemu/block.c
===================================================================
@@ -1839,6 +1839,7 @@ BlockInfoList *qmp_query_block(Error **e
         info->value->device = g_strdup(bs->device_name);
         info->value->type = g_strdup("unknown");
         info->value->locked = bdrv_dev_is_medium_locked(bs);
+        info->value->hostcache = !(bs->open_flags & BDRV_O_NOCACHE);
         info->value->removable = bdrv_dev_has_removable_media(bs);
 
         if (bdrv_dev_has_removable_media(bs)) {
hmp.c +2 -0
Index: qemu/hmp.c
===================================================================
@@ -199,6 +199,8 @@ void hmp_info_block(Monitor *mon)
             monitor_printf(mon, " tray-open=%d", info->value->tray_open);
         }
 
+        monitor_printf(mon, " hostcache=%d", info->value->hostcache);
+
         if (info->value->has_io_status) {
             monitor_printf(mon, " io-status=%s",
 

BlockDeviceIoStatus_lookup[info->value->io_status]);

#3 lore raw

Re: [Qemu-devel] [v9 Patch 1/6 - updated]Qemu: Enhance "info block" to display host cache setting

Quoted 16 lines · On Fri, 11 Nov 2011 15:39:29 +0530 Supriya Kannery…
Quoted 15 lines · Supriya Kannery

Enhance "info block" to display hostcache setting for each block device.

##
Index: qemu/qapi-types.h
===================================================================

qapi-types.h +1 -0
@@ -383,6 +383,7 @@ struct BlockInfo
  {
      char * device;
      char * type;
+    bool hostcache;
      bool removable;
Quoted 8 lines
Quoted 3 lines
qapi-types.h +0 -0
      bool locked;
      bool has_inserted;

Index: qemu/block.c

hostcache gets added to qapi-types.h from
the change done in qapi-schema.json. Hence
above change has to be ignored. Pls find
updated patch.

git am says this patch is corrupted. Otherwise the QAPI changes look ok to me.

Quoted 73 lines

*********************************************************************
Enhance "info block" to display hostcache setting for each block device.

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

Enhanced to display "hostcache" setting:
(qemu) info block
ide0-hd0: removable=0 hostcache=1 file=../rhel6-32.raw ro=0 drv=raw encrypted=0

---
  block.c         |   20 ++++++++++++++++----
  qmp-commands.hx |    2 ++
  2 files changed, 18 insertions(+), 4 deletions(-)

Index: qemu/qapi-schema.json
===================================================================

qapi-schema.json +3 -1
@@ -409,6 +409,8 @@
  # @locked: True if the guest has locked this device from having its media
  #          removed
  #
+# @hostcache: True if host pagecache is enabled.
+#
  # @tray_open: #optional True if the device has a tray and it is open
  #             (only present if removable is true)
  #
@@ -422,7 +424,7 @@
  ##
  { 'type': 'BlockInfo',
    'data': {'device': 'str', 'type': 'str', 'removable': 'bool',
-           'locked': 'bool', '*inserted': 'BlockDeviceInfo',
+           'locked': 'bool','hostcache': 'bool', '*inserted': 
 'BlockDeviceInfo',
             '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus'} }
 

##
Index: qemu/block.c
===================================================================

block.c +1 -0
@@ -1839,6 +1839,7 @@ BlockInfoList *qmp_query_block(Error **e
          info->value->device = g_strdup(bs->device_name);
          info->value->type = g_strdup("unknown");
          info->value->locked = bdrv_dev_is_medium_locked(bs);
+        info->value->hostcache = !(bs->open_flags & BDRV_O_NOCACHE);
          info->value->removable = bdrv_dev_has_removable_media(bs);
 
          if (bdrv_dev_has_removable_media(bs)) {

Index: qemu/hmp.c
===================================================================

hmp.c +2 -0
@@ -199,6 +199,8 @@ void hmp_info_block(Monitor *mon)
              monitor_printf(mon, " tray-open=%d", info->value->tray_open);
          }
 
+        monitor_printf(mon, " hostcache=%d", info->value->hostcache);
+
          if (info->value->has_io_status) {
              monitor_printf(mon, " io-status=%s",
 

BlockDeviceIoStatus_lookup[info->value->io_status]);

#4 lore raw

Re: [Qemu-devel] [v9 Patch 1/6 - updated]Qemu: Enhance "info block" to display host cache setting

Quoted 11 lines · Luiz Capitulino
Quoted 6 lines · On Fri, 11 Nov 2011 15:39:29 +0530 Supriya Kannery…

On 11/11/2011 12:17 PM, Supriya Kannery wrote:
hostcache gets added to qapi-types.h from
the change done in qapi-schema.json. Hence
above change has to be ignored. Pls find
updated patch.

Quoted 4 lines

git am says this patch is corrupted. Otherwise the QAPI changes look ok to me.

ok, will recheck with git am while sending updated patchset.

- thanks, Supriya

#5 lore raw

PATCH v9 2/6 Qemu: Error classes for file reopen and data sync failure

In reply to Supriya Kannery

New error classes defined for file reopen failure and data sync error

---
 qerror.c |    8 ++++++++
 qerror.h |    6 ++++++
 2 files changed, 14 insertions(+)
qerror.c +8 -0
Index: qemu/qerror.c
===================================================================
@@ -97,6 +97,14 @@ static const QErrorStringTable qerror_ta
         .desc      = "Device '%(device)' is not removable",
     },
     {
+        .error_fmt = QERR_DATA_SYNC_FAILED,
+        .desc      = "Syncing of data failed for device '%(device)'",
+    },
+    {
+        .error_fmt = QERR_REOPEN_FILE_FAILED,
+        .desc      = "Could not reopen '%(filename)'",
+    },
+    {
         .error_fmt = QERR_DEVICE_NO_BUS,
         .desc      = "Device '%(device)' has no child bus",
     },
qerror.h +6 -0
Index: qemu/qerror.h
===================================================================
@@ -87,6 +87,9 @@ QError *qobject_to_qerror(const QObject 
 #define QERR_DEVICE_NOT_FOUND \
     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
 
+#define QERR_DATA_SYNC_FAILED \
+    "{ 'class': 'DataSyncFailed', 'data': { 'device': %s } }"
+
 #define QERR_DEVICE_NOT_REMOVABLE \
     "{ 'class': 'DeviceNotRemovable', 'data': { 'device': %s } }"
 
@@ -144,6 +147,9 @@ QError *qobject_to_qerror(const QObject 
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_REOPEN_FILE_FAILED \
+    "{ 'class': 'ReopenFileFailed', 'data': { 'filename': %s } }"
+
 #define QERR_PROPERTY_NOT_FOUND \
     "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }"
 
#6 lore raw

Re: [Qemu-devel] [v9 Patch 2/6]Qemu: Error classes for file reopen and data sync failure

Quoted 15 lines · On Fri, 11 Nov 2011 12:17:35 +0530 Supriya Kannery…

New error classes defined for file reopen failure and data sync error

---
 qerror.c |    8 ++++++++
 qerror.h |    6 ++++++
 2 files changed, 14 insertions(+)

Index: qemu/qerror.c
===================================================================

qerror.c static const QErrorStringTable qerror_ta · line 106

Quoted 10 lines
qerror.c +7 -0
@@ -97,6 +97,14 @@ static const QErrorStringTable qerror_ta
         .desc      = "Device '%(device)' is not removable",
     },
     {
+        .error_fmt = QERR_DATA_SYNC_FAILED,
+        .desc      = "Syncing of data failed for device '%(device)'",
+    },
+    {
+        .error_fmt = QERR_REOPEN_FILE_FAILED,
+        .desc      = "Could not reopen '%(filename)'",
+    },

Is this really needed? I think you could use QERR_OPEN_FILE_FAILED.

Quoted 29 lines
qerror.c +1 -0
+    {
         .error_fmt = QERR_DEVICE_NO_BUS,
         .desc      = "Device '%(device)' has no child bus",
     },

Index: qemu/qerror.h
===================================================================

qerror.h +6 -0
@@ -87,6 +87,9 @@ QError *qobject_to_qerror(const QObject 
 #define QERR_DEVICE_NOT_FOUND \
     "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
 
+#define QERR_DATA_SYNC_FAILED \
+    "{ 'class': 'DataSyncFailed', 'data': { 'device': %s } }"
+
 #define QERR_DEVICE_NOT_REMOVABLE \
     "{ 'class': 'DeviceNotRemovable', 'data': { 'device': %s } }"
 
@@ -144,6 +147,9 @@ QError *qobject_to_qerror(const QObject 
 #define QERR_OPEN_FILE_FAILED \
     "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_REOPEN_FILE_FAILED \
+    "{ 'class': 'ReopenFileFailed', 'data': { 'filename': %s } }"
+
 #define QERR_PROPERTY_NOT_FOUND \
     "{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }"
 
#7 lore raw

Re: [Qemu-devel] [v9 Patch 2/6]Qemu: Error classes for file reopen and data sync failure

Quoted 24 lines · Luiz Capitulino
Quoted 20 lines · On Fri, 11 Nov 2011 12:17:35 +0530 Supriya Kannery…

New error classes defined for file reopen failure and data sync error

---
 qerror.c |    8 ++++++++
 qerror.h |    6 ++++++
 2 files changed, 14 insertions(+)

Index: qemu/qerror.c
===================================================================

qerror.c +2 -0
@@ -97,6 +97,14 @@ static const QErrorStringTable qerror_ta
         .desc      = "Device '%(device)' is not removable",
     },
     {
+        .error_fmt = QERR_DATA_SYNC_FAILED,
+        .desc      = "Syncing of data failed for device '%(device)'",
Quoted 10 lines

qerror.c static const QErrorStringTable qerror_ta

Quoted 6 lines
qerror.c +5 -0
+    },
+    {
+        .error_fmt = QERR_REOPEN_FILE_FAILED,
+        .desc      = "Could not reopen '%(filename)'",
+    },
 

Is this really needed? I think you could use QERR_OPEN_FILE_FAILED.

This could confuse the user, as to what was tried on an already opened file by qemu. So I feel, QERR_REOPEN_FILE_FAILED can bring in better clarity to the message passed to the user.

- thanks Supriya

#8 lore raw

Re: [Qemu-devel] [v9 Patch 2/6]Qemu: Error classes for file reopen and data sync failure

Quoted 36 lines · On Fri, 18 Nov 2011 14:59:40 +0530 supriya kannery <[email protected]> wrote:
Quoted 24 lines · Luiz Capitulino
Quoted 20 lines · On Fri, 11 Nov 2011 12:17:35 +0530 Supriya Kannery…

New error classes defined for file reopen failure and data sync error

---
 qerror.c |    8 ++++++++
 qerror.h |    6 ++++++
 2 files changed, 14 insertions(+)

Index: qemu/qerror.c
===================================================================

qerror.c +2 -0
@@ -97,6 +97,14 @@ static const QErrorStringTable qerror_ta
         .desc      = "Device '%(device)' is not removable",
     },
     {
+        .error_fmt = QERR_DATA_SYNC_FAILED,
+        .desc      = "Syncing of data failed for device '%(device)'",
Quoted 10 lines

qerror.c static const QErrorStringTable qerror_ta

Quoted 6 lines
qerror.c +5 -0
+    },
+    {
+        .error_fmt = QERR_REOPEN_FILE_FAILED,
+        .desc      = "Could not reopen '%(filename)'",
+    },
 

Is this really needed? I think you could use QERR_OPEN_FILE_FAILED.

Quoted 3 lines

This could confuse the user, as to what was tried on an already opened file by qemu. So I feel, QERR_REOPEN_FILE_FAILED can bring in better clarity to the message passed to the user.

I think it's the contrary.

First, the fact that we reopen the image is an implementation detail. If we do it differently in the future than the error won't fit anymore.

Second, what did really fail when REOPEN_FILE_FAILED is triggered? Flushing the buffers? Closing the image? Opening it with different flags? All these operations are part of the "reopen" algorithm.

On the other hand, if you see a OPEN_FILE_FAILED then there's only one single operation that might have failed. Also, OPEN_FILE_FAILED is widely well known as some version of it exists in any operating system.

#9 lore raw

PATCH v9 3/6 Qemu: Cmd "block_set_hostcache" for dynamic cache change

In reply to Supriya Kannery

New command "block_set_hostcache" added for dynamically changing host pagecache setting of a block device.

Usage:
block_set_hostcache <device> <option>
<device> = block device
<option> = on/off

Example:
(qemu) block_set_hostcache ide0-hd0 off

---
 block.c         |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 block.h         |    2 ++
 blockdev.c      |   26 ++++++++++++++++++++++++++
 blockdev.h      |    2 ++
 hmp-commands.hx |   14 ++++++++++++++
 qmp-commands.hx |   27 +++++++++++++++++++++++++++
 6 files changed, 125 insertions(+)
block.c +55 -0
Index: qemu/block.c
===================================================================
@@ -696,6 +696,35 @@ unlink_and_fail:
     return ret;
 }
 
+int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
+{
+    BlockDriver *drv = bs->drv;
+    int ret = 0, open_flags;
+
+    /* Quiesce IO for the given block device */
+    qemu_aio_flush();
+    ret = bdrv_flush(bs);
+    if (ret != 0) {
+        qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
+        return ret;
+    }
+    open_flags = bs->open_flags;
+    bdrv_close(bs);
+
+    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
+    if (ret < 0) {
+        /* Reopen failed. Try to open with original flags */
+        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+        if (ret < 0) {
+            /* Reopen failed with orig and modified flags */
+            abort();
+        }
+    }
+
+    return ret;
+}
+
 void bdrv_close(BlockDriverState *bs)
 {
     if (bs->drv) {
@@ -733,6 +762,32 @@ void bdrv_close_all(void)
     }
 }
 
+int bdrv_change_hostcache(BlockDriverState *bs, bool enable_host_cache)
+{
+    int bdrv_flags = bs->open_flags;
+
+    /* set hostcache flags (without changing WCE/flush bits) */
+    if (enable_host_cache) {
+        bdrv_flags &= ~BDRV_O_NOCACHE;
+    } else {
+        bdrv_flags |= BDRV_O_NOCACHE;
+    }
+
+    /* If no change in flags, no need to reopen */
+    if (bdrv_flags == bs->open_flags) {
+        return 0;
+    }
+
+    if (bdrv_is_inserted(bs)) {
+        /* Reopen file with changed set of flags */
+        return bdrv_reopen(bs, bdrv_flags);
+    } else {
+        /* Save hostcache change for future use */
+        bs->open_flags = bdrv_flags;
+        return 0;
+    }
+}
+
 /* make a BlockDriverState anonymous by removing from bdrv_state list.
    Also, NULL terminate the device_name to prevent double remove */
 void bdrv_make_anon(BlockDriverState *bs)
block.h +2 -0
Index: qemu/block.h
===================================================================
@@ -104,6 +104,7 @@ int bdrv_parse_cache_flags(const char *m
 int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
 int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
               BlockDriver *drv);
+int bdrv_reopen(BlockDriverState *bs, int bdrv_flags);
 void bdrv_close(BlockDriverState *bs);
 int bdrv_attach_dev(BlockDriverState *bs, void *dev);
 void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev);
@@ -138,6 +139,7 @@ void bdrv_commit_all(void);
 int bdrv_change_backing_file(BlockDriverState *bs,
     const char *backing_file, const char *backing_fmt);
 void bdrv_register(BlockDriver *bdrv);
+int bdrv_change_hostcache(BlockDriverState *bs, bool enable_host_cache);
 
 
 typedef struct BdrvCheckResult {
blockdev.c +26 -0
Index: qemu/blockdev.c
===================================================================
@@ -776,3 +776,29 @@ int do_block_resize(Monitor *mon, const 
 
     return 0;
 }
+
+
+/*
+ * Change host page cache setting while guest is running.
+*/
+int do_block_set_hostcache(Monitor *mon, const QDict *qdict,
+                           QObject **ret_data)
+{
+    BlockDriverState *bs = NULL;
+    int enable;
+    const char *device;
+
+    /* Validate device */
+    device = qdict_get_str(qdict, "device");
+    bs = bdrv_find(device);
+    if (!bs) {
+        qerror_report(QERR_DEVICE_NOT_FOUND, device);
+        return -1;
+    }
+
+    /* Read hostcache setting */
+    enable = qdict_get_bool(qdict, "option");
+    return bdrv_change_hostcache(bs, enable);
+
+}
+
blockdev.h +2 -0
Index: qemu/blockdev.h
===================================================================
@@ -65,5 +65,7 @@ int do_change_block(Monitor *mon, const 
 int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int do_block_set_hostcache(Monitor *mon, const QDict *qdict,
+                           QObject **ret_data);
 
 #endif
hmp-commands.hx +14 -0
Index: qemu/hmp-commands.hx
===================================================================
@@ -70,6 +70,20 @@ but should be used with extreme caution.
 resizes image files, it can not resize block devices like LVM volumes.
 ETEXI
 
+    {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",
+        .params     = "device on|off",
+        .help       = "Change setting of host pagecache",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set_hostcache,
+    },
+STEXI
+@item block_set_hostcache @var{device} @var{setting}
+@findex block_set_hostcache
+Change host pagecache setting of a block device while guest is running.
+ETEXI
+
 
     {
         .name       = "eject",
qmp-commands.hx +27 -0
Index: qemu/qmp-commands.hx
===================================================================
@@ -716,7 +716,34 @@ Example:
 
 EQMP
 
+
     {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",
+        .params     = "device on|off",
+        .help       = "Change setting of host pagecache (true|false)",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set_hostcache,
+    },
+
+SQMP
+block_set_hostcache
+-------------------
+
+Change host pagecache setting of a block device (on|off)
+
+Arguments:
+
+- "device": the device's ID, must be unique (json-string)
+- "option": hostcache setting (json-bool)
+
+Example:
+-> { "execute": "block_set_hostcache", "arguments": { "device": "ide0-hd0", "option": false } }
+<- { "return": {} }
+
+EQMP
+
+	{
         .name       = "balloon",
         .args_type  = "value:M",
         .params     = "target",
#10 lore raw

Re: [Qemu-devel] [v9 Patch 3/6]Qemu: Cmd "block_set_hostcache" for dynamic cache change

Quoted 10 lines · Supriya Kannery

+    {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",
+        .params     = "device on|off",
+        .help       = "Change setting of host pagecache",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set_hostcache,
+    },
+STEXI
+@item block_set_hostcache @var{device} @var{setting}

@var{option}

Quoted 15 lines

+@findex block_set_hostcache

hmp-commands.hx +3 -0
+Change host pagecache setting of a block device while guest is running.
+ETEXI
+

    {
        .name       = "eject",
Index: qemu/qmp-commands.hx
===================================================================

qmp-commands.hx +0 -0
@@ -716,7 +716,34 @@ Example:
 

 EQMP

Quoted 6 lines

+
    {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",
+        .params     = "device on|off",
+        .help       = "Change setting of host pagecache (true|false)",

It would be more consistent to use "on|off" instead of "true|false". Or eliminate it entirely by saying "Enable or disable host pagecache usage".

Stefan

#11 lore raw

Re: [Qemu-devel] [v9 Patch 3/6]Qemu: Cmd "block_set_hostcache" for dynamic cache change

Quoted 13 lines · Stefan Hajnoczi

hmp-commands.hx but should be used with extreme caution. · line 82

Quoted 10 lines · Supriya Kannery
hmp-commands.hx +10 -0
+    {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",
+        .params     = "device on|off",
+        .help       = "Change setting of host pagecache",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set_hostcache,
+    },
+STEXI
+@item block_set_hostcache @var{device} @var{setting}
Quoted 1 line

@var{option}

Will send updated patch

Quoted 27 lines
Quoted 13 lines

+@findex block_set_hostcache

hmp-commands.hx +3 -0
+Change host pagecache setting of a block device while guest is running.
+ETEXI
+
 
     {
         .name       = "eject",

Index: qemu/qmp-commands.hx
===================================================================

qmp-commands.hx Example: · line 724

Quoted 9 lines
qmp-commands.hx +5 -0
@@ -716,7 +716,34 @@ Example:
 
  EQMP
 
+
     {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",
+        .params     = "device on|off",
+        .help       = "Change setting of host pagecache (true|false)",

It would be more consistent to use "on|off" instead of "true|false". Or eliminate it entirely by saying "Enable or disable host pagecache usage".

Quoted 2 lines

Stefan

Followed similar way how set_link is done.
Specified 'true/false' in brackets as 'on' or 'off' are not accepted as bool parameter in qmp prompt.

#12 lore raw

Re: [Qemu-devel] [v9 Patch 3/6]Qemu: Cmd "block_set_hostcache" for dynamic cache change

Quoted 45 lines · On Thu, 17 Nov 2011 11:15:06 +0530 Supriya Kannery…
Quoted 13 lines · Stefan Hajnoczi

hmp-commands.hx but should be used with extreme caution. · line 82

Quoted 10 lines · Supriya Kannery
hmp-commands.hx +10 -0
+    {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",
+        .params     = "device on|off",
+        .help       = "Change setting of host pagecache",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set_hostcache,
+    },
+STEXI
+@item block_set_hostcache @var{device} @var{setting}
Quoted 1 line

@var{option}

Will send updated patch

Quoted 27 lines
Quoted 13 lines

+@findex block_set_hostcache

hmp-commands.hx +3 -0
+Change host pagecache setting of a block device while guest is running.
+ETEXI
+
 
     {
         .name       = "eject",

Index: qemu/qmp-commands.hx
===================================================================

qmp-commands.hx Example: · line 724

Quoted 9 lines
qmp-commands.hx +5 -0
@@ -716,7 +716,34 @@ Example:
 
  EQMP
 
+
     {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",
+        .params     = "device on|off",
+        .help       = "Change setting of host pagecache (true|false)",

It would be more consistent to use "on|off" instead of "true|false". Or eliminate it entirely by saying "Enable or disable host pagecache usage".

Quoted 6 lines
Quoted 2 lines

Stefan

Followed similar way how set_link is done.
Specified 'true/false' in brackets as 'on' or 'off' are not accepted as bool parameter in qmp prompt.

on/off is used in HMP, while true/false is used in QMP.

#13 lore raw

Re: [Qemu-devel] [v9 Patch 3/6]Qemu: Cmd "block_set_hostcache" for dynamic cache change

In reply to Supriya Kannery
Quoted 48 lines · On Fri, 11 Nov 2011 12:17:48 +0530 Supriya Kannery…

New command "block_set_hostcache" added for dynamically changing host pagecache setting of a block device.

Usage:
block_set_hostcache <device> <option>
<device> = block device
<option> = on/off

Example:
(qemu) block_set_hostcache ide0-hd0 off

---
 block.c         |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 block.h         |    2 ++
 blockdev.c      |   26 ++++++++++++++++++++++++++
 blockdev.h      |    2 ++
 hmp-commands.hx |   14 ++++++++++++++
 qmp-commands.hx |   27 +++++++++++++++++++++++++++
 6 files changed, 125 insertions(+)

Index: qemu/block.c
===================================================================

block.c +18 -0
@@ -696,6 +696,35 @@ unlink_and_fail:
     return ret;
 }
 
+int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
+{
+    BlockDriver *drv = bs->drv;
+    int ret = 0, open_flags;
+
+    /* Quiesce IO for the given block device */
+    qemu_aio_flush();
+    ret = bdrv_flush(bs);
+    if (ret != 0) {
+        qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
+        return ret;
+    }
+    open_flags = bs->open_flags;
+    bdrv_close(bs);
+
+    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
+    if (ret < 0) {
+        /* Reopen failed. Try to open with original flags */

block.c unlink_and_fail: · line 726

Quoted 10 lines
block.c +10 -0
+        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+        if (ret < 0) {
+            /* Reopen failed with orig and modified flags */
+            abort();
+        }
+    }
+
+    return ret;
+}

In this thread:

http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01271.html

Juan uses a similar method (well, at least it looks similar to me) to fix a problem with migration. However, it was said that that method can cause problems with -snapshot and encrypted images.

Won't we have the same sort of problems with this series?

Quoted 22 lines
block.c +15 -0
+
 void bdrv_close(BlockDriverState *bs)
 {
     if (bs->drv) {
@@ -733,6 +762,32 @@ void bdrv_close_all(void)
     }
 }
 
+int bdrv_change_hostcache(BlockDriverState *bs, bool enable_host_cache)
+{
+    int bdrv_flags = bs->open_flags;
+
+    /* set hostcache flags (without changing WCE/flush bits) */
+    if (enable_host_cache) {
+        bdrv_flags &= ~BDRV_O_NOCACHE;
+    } else {
+        bdrv_flags |= BDRV_O_NOCACHE;
+    }
+
+    /* If no change in flags, no need to reopen */
+    if (bdrv_flags == bs->open_flags) {
+        return 0;

block.c void bdrv_close_all(void) · line 788

Quoted 10 lines
block.c +10 -0
+    }
+
+    if (bdrv_is_inserted(bs)) {
+        /* Reopen file with changed set of flags */
+        return bdrv_reopen(bs, bdrv_flags);
+    } else {
+        /* Save hostcache change for future use */
+        bs->open_flags = bdrv_flags;
+        return 0;
+    }

I'm wondering if the simplest (and best) thing to do here is to fail if the drive is not inserted. Just wondering, not exactly asking you to change it. But it should at least be clearly documented if you keep it.

Quoted 48 lines
block.c +2 -0
+}
+
 /* make a BlockDriverState anonymous by removing from bdrv_state list.
    Also, NULL terminate the device_name to prevent double remove */
 void bdrv_make_anon(BlockDriverState *bs)

Index: qemu/block.h
===================================================================

block.h +2 -0
@@ -104,6 +104,7 @@ int bdrv_parse_cache_flags(const char *m
 int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
 int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
               BlockDriver *drv);
+int bdrv_reopen(BlockDriverState *bs, int bdrv_flags);
 void bdrv_close(BlockDriverState *bs);
 int bdrv_attach_dev(BlockDriverState *bs, void *dev);
 void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev);
@@ -138,6 +139,7 @@ void bdrv_commit_all(void);
 int bdrv_change_backing_file(BlockDriverState *bs,
     const char *backing_file, const char *backing_fmt);
 void bdrv_register(BlockDriver *bdrv);
+int bdrv_change_hostcache(BlockDriverState *bs, bool enable_host_cache);
 
 
 typedef struct BdrvCheckResult {

Index: qemu/blockdev.c
===================================================================

blockdev.c +15 -0
@@ -776,3 +776,29 @@ int do_block_resize(Monitor *mon, const 
 
     return 0;
 }
+
+
+/*
+ * Change host page cache setting while guest is running.
+*/
+int do_block_set_hostcache(Monitor *mon, const QDict *qdict,
+                           QObject **ret_data)
+{
+    BlockDriverState *bs = NULL;
+    int enable;
+    const char *device;
+
+    /* Validate device */
+    device = qdict_get_str(qdict, "device");
+    bs = bdrv_find(device);

blockdev.c int do_block_resize(Monitor *mon, const · line 803

Quoted 10 lines
blockdev.c +10 -0
+    if (!bs) {
+        qerror_report(QERR_DEVICE_NOT_FOUND, device);
+        return -1;
+    }
+
+    /* Read hostcache setting */
+    enable = qdict_get_bool(qdict, "option");
+    return bdrv_change_hostcache(bs, enable);
+
+}

This is not using the QAPI.

Quoted 18 lines
blockdev.c +1 -0
+

Index: qemu/blockdev.h
===================================================================

blockdev.h +2 -0
@@ -65,5 +65,7 @@ int do_change_block(Monitor *mon, const 
 int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int do_block_set_hostcache(Monitor *mon, const QDict *qdict,
+                           QObject **ret_data);
 
 #endif

Index: qemu/hmp-commands.hx
===================================================================

hmp-commands.hx but should be used with extreme caution. · line 75

Quoted 6 lines
hmp-commands.hx +3 -0
@@ -70,6 +70,20 @@ but should be used with extreme caution.
 resizes image files, it can not resize block devices like LVM volumes.
 ETEXI
 
+    {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",

"option" is not good enough. I'd call it "enable" or "disable".

Quoted 54 lines
hmp-commands.hx +11 -0
+        .params     = "device on|off",
+        .help       = "Change setting of host pagecache",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set_hostcache,
+    },
+STEXI
+@item block_set_hostcache @var{device} @var{setting}
+@findex block_set_hostcache
+Change host pagecache setting of a block device while guest is running.
+ETEXI
+
 
     {
         .name       = "eject",

Index: qemu/qmp-commands.hx
===================================================================

qmp-commands.hx +27 -0
@@ -716,7 +716,34 @@ Example:
 
 EQMP
 
+
     {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",
+        .params     = "device on|off",
+        .help       = "Change setting of host pagecache (true|false)",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set_hostcache,
+    },
+
+SQMP
+block_set_hostcache
+-------------------
+
+Change host pagecache setting of a block device (on|off)
+
+Arguments:
+
+- "device": the device's ID, must be unique (json-string)
+- "option": hostcache setting (json-bool)
+
+Example:
+-> { "execute": "block_set_hostcache", "arguments": { "device": "ide0-hd0", "option": false } }
+<- { "return": {} }
+
+EQMP
+
+	{
         .name       = "balloon",
         .args_type  = "value:M",
         .params     = "target",
#14 lore raw

Re: [Qemu-devel] [v9 Patch 3/6]Qemu: Cmd "block_set_hostcache" for dynamic cache change

Quoted 22 lines · Luiz Capitulino
Quoted 5 lines · On Fri, 11 Nov 2011 12:17:48 +0530 Supriya Kannery…
block.c +4 -0
+
+    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
+    if (ret < 0) {
+        /* Reopen failed. Try to open with original flags */

block.c unlink_and_fail: · line 726

Quoted 10 lines
block.c +10 -0
+        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+        if (ret < 0) {
+            /* Reopen failed with orig and modified flags */
+            abort();
+        }
+    }
+
+    return ret;
+}

In this thread:

Quoted 10 lines

http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg01271.html

Juan uses a similar method (well, at least it looks similar to me) to fix a problem with migration. However, it was said that that method can cause problems with -snapshot and encrypted images.

Won't we have the same sort of problems with this series?

Thanks! for this link. Yes, this series also need to look at such issues. Will go through the discussions and see what needs to be looked at.

Quoted 10 lines

block.c void bdrv_close_all(void) · line 788

Quoted 9 lines
block.c +8 -0
+    if (bdrv_is_inserted(bs)) {
+        /* Reopen file with changed set of flags */
+        return bdrv_reopen(bs, bdrv_flags);
+    } else {
+        /* Save hostcache change for future use */
+        bs->open_flags = bdrv_flags;
+        return 0;
+    }
Quoted 5 lines

I'm wondering if the simplest (and best) thing to do here is to fail if the drive is not inserted. Just wondering, not exactly asking you to change it. But it should at least be clearly documented if you keep it.

I initially started the patchset with returning error message on detecting uninserted drive. But later thought that, user should be given the flexibility of changing hostcache setting irrespective of whether drive is full or not. To what I understand, hostcache setting is independent of what user puts in to the drive.

Need to make these saved status flags used when opening a newly inserted device.

Quoted 9 lines

blockdev.c int do_block_resize(Monitor *mon, const · line 803

Quoted 6 lines
blockdev.c +5 -0
+    /* Read hostcache setting */
+    enable = qdict_get_bool(qdict, "option");
+    return bdrv_change_hostcache(bs, enable);
+
+}

This is not using the QAPI.

will change to use QAPI.

Quoted 22 lines
Quoted 22 lines

+
Index: qemu/blockdev.h
===================================================================

blockdev.h +2 -0
@@ -65,5 +65,7 @@ int do_change_block(Monitor *mon, const 
 int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_snapshot_blkdev(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_block_resize(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int do_block_set_hostcache(Monitor *mon, const QDict *qdict,
+                           QObject **ret_data);
 
 #endif

Index: qemu/hmp-commands.hx
===================================================================

hmp-commands.hx +0 -0
@@ -70,6 +70,20 @@ but should be used with extreme caution.
 resizes image files, it can not resize block devices like LVM volumes.
 ETEXI
 
Quoted 8 lines

hmp-commands.hx but should be used with extreme caution. · line 87

Quoted 4 lines
hmp-commands.hx +3 -0
+    {
+        .name       = "block_set_hostcache",
+        .args_type  = "device:B,option:b",
 

"option" is not good enough. I'd call it "enable" or "disable".

ok

#15 lore raw

PATCH v9 4/6 Qemu: Add commandline -drive option 'hostcache'

In reply to Supriya Kannery

qemu command option 'hostcache' added to -drive for block devices. While starting a VM from qemu commandline, this option can be used for setting host cache usage for block data access.

---
 blockdev.c      |   13 +++++++++++++
 qemu-config.c   |    4 ++++
 qemu-options.hx |    2 +-
 3 files changed, 18 insertions(+), 1 deletion(-)
blockdev.c +7 -0
Index: qemu/blockdev.c
===================================================================
@@ -237,6 +237,7 @@ DriveInfo *drive_init(QemuOpts *opts, in
     DriveInfo *dinfo;
     int snapshot = 0;
     int ret;
+    int hostcache = 0;
 
     translation = BIOS_ATA_TRANSLATION_AUTO;
     media = MEDIA_DISK;
@@ -324,6 +325,12 @@ DriveInfo *drive_init(QemuOpts *opts, in
             error_report("invalid cache option");
             return NULL;
         }
+    } else {
+        if ((hostcache = qemu_opt_get_bool(opts, "hostcache", -1)) != -1) {
+            if (!hostcache) {
+                bdrv_flags |= BDRV_O_NOCACHE;
+            }
+        }
     }
 
 #ifdef CONFIG_LINUX_AIO
qemu-options.hx +1 -1
Index: qemu/qemu-options.hx
===================================================================
@@ -135,7 +135,7 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive,
     "       [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
     "       [,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n"
     "       [,serial=s][,addr=A][,id=name][,aio=threads|native]\n"
-    "       [,readonly=on|off]\n"
+    "       [,readonly=on|off][,hostcache=on|off]\n"
     "                use 'file' as a drive image\n", QEMU_ARCH_ALL)
 STEXI
 @item -drive @var{option}[,@var{option}[,@var{option}[,...]]]
qemu-config.c +4 -0
Index: qemu/qemu-config.c
===================================================================
@@ -85,6 +85,10 @@ static QemuOptsList qemu_drive_opts = {
             .name = "readonly",
             .type = QEMU_OPT_BOOL,
             .help = "open drive file as read-only",
+        },{
+            .name = "hostcache",
+            .type = QEMU_OPT_BOOL,
+            .help = "set or reset hostcache (on/off)"
         },
         { /* end of list */ }
     },
#16 lore raw

Re: [Qemu-devel] [v9 Patch 4/6]Qemu: Add commandline -drive option 'hostcache'

Quoted 1 line · Supriya Kannery

+        if ((hostcache = qemu_opt_get_bool(opts, "hostcache", -1)) != -1) {

This does not work. qemu_opt_get_bool() takes a bool default argument and returns a bool. (bool)-1 == true. But (int)true == 1 and you cannot expect it to ever equal -1.

Try this:

if (qemu_opt_get(opts, "hostcache") &&

    !qemu_opt_get_bool(opts, "hostcache", false)) {
    bdrv_flags |= BDRV_O_NOCACHE;
}

Stefan

#17 lore raw

Re: [Qemu-devel] [v9 Patch 4/6]Qemu: Add commandline -drive option 'hostcache'

Quoted 8 lines · Stefan Hajnoczi
Quoted 1 line · Supriya Kannery

+ if ((hostcache = qemu_opt_get_bool(opts, "hostcache", -1)) != -1) {

This does not work. qemu_opt_get_bool() takes a bool default argument and returns a bool. (bool)-1 == true. But (int)true == 1 and you cannot expect it to ever equal -1.

Quoted 9 lines

Try this:

if (qemu_opt_get(opts, "hostcache")&&

     !qemu_opt_get_bool(opts, "hostcache", false)) {
     bdrv_flags |= BDRV_O_NOCACHE;
}

Stefan

Thanks! for pointing this.
Does the following look ok?

 if ((hostcache = qemu_opt_get_bool(opts, "hostcache", 1) == 0) {
     bdrv_flags |= BDRV_O_NOCACHE;

}

If either "hostcache" is not at all specified or it is specified as "on", qemu_opt_get_bool will return 1, which can be ignored as bdrv_flags is initialized to 0.

#18 lore raw

Re: [Qemu-devel] [v9 Patch 4/6]Qemu: Add commandline -drive option 'hostcache'

Quoted 25 lines · Supriya Kannery
Quoted 11 lines · Stefan Hajnoczi
Quoted 3 lines · Supriya Kannery

+        if ((hostcache = qemu_opt_get_bool(opts, "hostcache", -1)) != -1) {

This does not work.  qemu_opt_get_bool() takes a bool default argument and returns a bool.  (bool)-1 == true.  But (int)true == 1 and you cannot expect it to ever equal -1.

Quoted 9 lines

Try this:

if (qemu_opt_get(opts, "hostcache")&& !qemu_opt_get_bool(opts, "hostcache", false)) { bdrv_flags |= BDRV_O_NOCACHE;
}

Stefan

Thanks! for pointing this.
Does the following look ok?

Quoted 7 lines

 if ((hostcache = qemu_opt_get_bool(opts, "hostcache", 1) == 0) { bdrv_flags |= BDRV_O_NOCACHE;
 }

If either "hostcache" is not at all specified or it is specified as "on", qemu_opt_get_bool will return 1, which can be ignored as bdrv_flags is initialized to 0.

It depends on the overall way this should work. I think this captures all the cases:

1. cache= and hostcache= may not be used together.
2. cache= sets bdrv_flags.
3. hostcache= may |= BDRV_O_NOCACHE.
4. No option defaults to cache=writethrough (bdrv_flags &= ~BDRV_O_CACHE_MASK).

The code you posted will work although I find it a bit weird how it also includes case #4. IMO it's cleanest to just do case #3 by testing whether or not the hostcache= option is set.

BTW, is there a check for case #1 in your patch series. I thought I saw one earlier but now I can't find it.

Stefan

#19 lore raw

Re: [Qemu-devel] [v9 Patch 4/6]Qemu: Add commandline -drive option 'hostcache'

Quoted 45 lines · Stefan Hajnoczi
Quoted 25 lines · Supriya Kannery
Quoted 10 lines · Stefan Hajnoczi
Quoted 3 lines · Supriya Kannery

+ if ((hostcache = qemu_opt_get_bool(opts, "hostcache", -1)) !=
-1) {

This does not work. qemu_opt_get_bool() takes a bool default argument and returns a bool. (bool)-1 == true. But (int)true == 1 and you cannot expect it to ever equal -1.

Quoted 10 lines

Try this:

if (qemu_opt_get(opts, "hostcache")&&

    !qemu_opt_get_bool(opts, "hostcache", false)) {
    bdrv_flags |= BDRV_O_NOCACHE;
}

Stefan

Thanks! for pointing this.
Does the following look ok?

Quoted 8 lines
 if ((hostcache = qemu_opt_get_bool(opts, "hostcache", 1) == 0) {
    bdrv_flags |= BDRV_O_NOCACHE;

}

If either "hostcache" is not at all specified or it is specified as "on", qemu_opt_get_bool will return 1, which can be ignored as bdrv_flags is initialized to 0.

It depends on the overall way this should work. I think this captures all the cases:

1. cache= and hostcache= may not be used together.
2. cache= sets bdrv_flags.
3. hostcache= may |= BDRV_O_NOCACHE.
4. No option defaults to cache=writethrough (bdrv_flags &= ~BDRV_O_CACHE_MASK).

Quoted 7 lines

The code you posted will work although I find it a bit weird how it also includes case #4. IMO it's cleanest to just do case #3 by testing whether or not the hostcache= option is set.

BTW, is there a check for case #1 in your patch series. I thought I saw one earlier but now I can't find it.

Following is what I tried to accomplish:

1. cache= and hostcache= may be used together. Cache= will override hostcache= if specified together This condition can be retained till cache-xx can be completely replaced by combinations of separate cmdline options defined for setting hostcache, flush, and WCE
[I think I can change the current implementation to have Cache=xx ORed with hostcache=yy if
they are specified together instead of just ignoring hostcache= ]
2. If only cache= specified sets bdrv_flags.
3. If only hostcache= specified, bdrv_flags |= BDRV_O_NOCACHE
4. No option defaults to cache=writethrough (bdrv_flags &= ~BDRV_O_CACHE_MASK).

So the check I had earlier for case #1 in your list, I changed that to allow both the options to co-exist.

-thanks, Supriya

Quoted 3 lines

Stefan

#20 lore raw

Re: [Qemu-devel] [v9 Patch 4/6]Qemu: Add commandline -drive option 'hostcache'

Quoted 63 lines · supriya kannery
Quoted 52 lines · Stefan Hajnoczi
Quoted 30 lines · Supriya Kannery
Quoted 13 lines · Stefan Hajnoczi
Quoted 4 lines · Supriya Kannery

+        if ((hostcache = qemu_opt_get_bool(opts, "hostcache", -1)) != -1) {

This does not work.  qemu_opt_get_bool() takes a bool default argument and returns a bool.  (bool)-1 == true.  But (int)true == 1 and you cannot expect it to ever equal -1.

Quoted 10 lines

Try this:

if (qemu_opt_get(opts, "hostcache")&& !qemu_opt_get_bool(opts, "hostcache", false)) { bdrv_flags |= BDRV_O_NOCACHE;
}

Stefan

Thanks! for pointing this.
Does the following look ok?

Quoted 8 lines

 if ((hostcache = qemu_opt_get_bool(opts, "hostcache", 1) == 0) { bdrv_flags |= BDRV_O_NOCACHE;
 }

If either "hostcache" is not at all specified or it is specified as "on", qemu_opt_get_bool will return 1, which can be ignored as bdrv_flags is initialized to 0.

It depends on the overall way this should work.  I think this captures all the cases:

1. cache= and hostcache= may not be used together.
2. cache= sets bdrv_flags.
3. hostcache= may |= BDRV_O_NOCACHE.
4. No option defaults to cache=writethrough (bdrv_flags &= ~BDRV_O_CACHE_MASK).

Quoted 7 lines

The code you posted will work although I find it a bit weird how it also includes case #4.  IMO it's cleanest to just do case #3 by testing whether or not the hostcache= option is set.

BTW, is there a check for case #1 in your patch series.  I thought I saw one earlier but now I can't find it.

Following is what I tried to accomplish:

Quoted 8 lines

1. cache= and hostcache= may be used together. Cache= will override hostcache= if specified together
 This condition can be retained till cache-xx can be completely replaced by combinations of separate   cmdline options defined for setting hostcache, flush, and WCE
 [I think I can change the current implementation to have Cache=xx ORed with hostcache=yy if     they are specified together instead of just ignoring hostcache= ]

Okay, I can see that line of reasoning but then hostcache= does not provide much value on the command-line. Perhaps it's better to drop this patch and not merge a new -drive option until the guest-visible write cache enable support is also merged?

The interesting feature that this series adds is changing of hostcache at run-time.

Stefan

#21 lore raw

Re: [Qemu-devel] [v9 Patch 4/6]Qemu: Add commandline -drive option 'hostcache'

Quoted 75 lines · Stefan Hajnoczi
Quoted 63 lines · supriya kannery
Quoted 51 lines · Stefan Hajnoczi
Quoted 29 lines · Supriya Kannery
Quoted 12 lines · Stefan Hajnoczi
Quoted 4 lines · Supriya Kannery

+ if ((hostcache = qemu_opt_get_bool(opts, "hostcache", -1)) !=
-1) {

This does not work. qemu_opt_get_bool() takes a bool default argument and returns a bool. (bool)-1 == true. But (int)true == 1 and you cannot expect it to ever equal -1.

Quoted 11 lines

Try this:

if (qemu_opt_get(opts, "hostcache")&&

   !qemu_opt_get_bool(opts, "hostcache", false)) {
   bdrv_flags |= BDRV_O_NOCACHE;
}

Stefan

Thanks! for pointing this.
Does the following look ok?

Quoted 9 lines
 if ((hostcache = qemu_opt_get_bool(opts, "hostcache", 1) == 0) {
   bdrv_flags |= BDRV_O_NOCACHE;

}

If either "hostcache" is not at all specified or it is specified as "on", qemu_opt_get_bool will return 1, which can be ignored as bdrv_flags is initialized to 0.

It depends on the overall way this should work. I think this captures all the cases:

1. cache= and hostcache= may not be used together.
2. cache= sets bdrv_flags.
3. hostcache= may |= BDRV_O_NOCACHE.
4. No option defaults to cache=writethrough (bdrv_flags &= ~BDRV_O_CACHE_MASK).

Quoted 8 lines

The code you posted will work although I find it a bit weird how it also includes case #4. IMO it's cleanest to just do case #3 by testing whether or not the hostcache= option is set.

BTW, is there a check for case #1 in your patch series. I thought I saw one earlier but now I can't find it.

Following is what I tried to accomplish:

Quoted 9 lines

1. cache= and hostcache= may be used together. Cache= will override hostcache= if specified together
This condition can be retained till cache-xx can be completely replaced by
combinations of separate cmdline options defined for setting hostcache,
flush, and WCE
[I think I can change the current implementation to have Cache=xx ORed with
hostcache=yy if they are specified together instead of just ignoring
hostcache= ]

Quoted 6 lines

Okay, I can see that line of reasoning but then hostcache= does not provide much value on the command-line. Perhaps it's better to drop this patch and not merge a new -drive option until the guest-visible write cache enable support is also merged?

Let us have the implementation for hostcache= as command line option, with the condition that if both cache= and hostcache= are specified together, then depending upon enable/disable value specified for hostcache, corresponding bit in cache flags can be set/reset. That way, there is a value add on specifying hostcache in cmdline as well as user will be able to control hostcache value from cmdline itself.

Quoted 5 lines

The interesting feature that this series adds is changing of hostcache at run-time.

Yes.. will resume with dynamic hostcache change part to make it usable by qemu

- thanks, Supriya

Quoted 3 lines

Stefan

#22 lore raw

Re: [Qemu-devel] [v9 Patch 4/6]Qemu: Add commandline -drive option 'hostcache'

Am 22.11.2011 09:10, schrieb supriya kannery:

Quoted 9 lines

Let us have the implementation for hostcache= as command line option, with the condition that if both cache= and hostcache= are specified together, then depending upon enable/disable value specified for hostcache, corresponding
bit in cache flags can be set/reset. That way, there is a value add on specifying
hostcache in cmdline as well as user will be able to control hostcache value from cmdline
itself.

The additional thing this would introduce is cache=unsafe hostcache=off. Probably not the most common thing to have, but why not allow it now.

Kevin

#23 lore raw

Re: [Qemu-devel] [v9 Patch 4/6]Qemu: Add commandline -drive option 'hostcache'

Quoted 11 lines · Kevin Wolf

Am 22.11.2011 09:10, schrieb supriya kannery:

Quoted 9 lines

Let us have the implementation for hostcache= as command line option, with the condition that if both cache= and hostcache= are specified together, then depending upon enable/disable value specified for hostcache, corresponding
bit in cache flags can be set/reset. That way, there is a value add on specifying
hostcache in cmdline as well as user will be able to control hostcache value from cmdline
itself.

Quoted 2 lines

The additional thing this would introduce is cache=unsafe hostcache=off. Probably not the most common thing to have, but why not allow it now.

QEMU's command-line is hairy enough already. I don't think this option is helpful until we can replace cache= completely.

This is a subjective issue though so if you want to take this option, Kevin, then please do.

Stefan

#24 lore raw

Re: [Qemu-devel] [v9 Patch 4/6]Qemu: Add commandline -drive option 'hostcache'

Am 22.11.2011 12:17, schrieb Stefan Hajnoczi:

Quoted 12 lines · Kevin Wolf
Quoted 11 lines

Am 22.11.2011 09:10, schrieb supriya kannery:

Quoted 9 lines

Let us have the implementation for hostcache= as command line option, with the condition that if both cache= and hostcache= are specified together, then depending upon enable/disable value specified for hostcache, corresponding
bit in cache flags can be set/reset. That way, there is a value add on specifying
hostcache in cmdline as well as user will be able to control hostcache value from cmdline
itself.

Quoted 8 lines
Quoted 2 lines

The additional thing this would introduce is cache=unsafe hostcache=off. Probably not the most common thing to have, but why not allow it now.

QEMU's command-line is hairy enough already. I don't think this option is helpful until we can replace cache= completely.

This is a subjective issue though so if you want to take this option, Kevin, then please do.

In fact, I think I suggested removing it in an earlier version of the series because I felt the same. I didn't have a strong enough opinion on it to really insist on it, though. Discuss it with Supriya and I'll be happy with whatever you decide.

Kevin

#25 lore raw

PATCH v9 5/6 Qemu: Framework for reopening images safely

In reply to Supriya Kannery

Struct BDRVReopenState along with three reopen related functions introduced for handling reopen state of images safely. This can be extended by each of the block drivers to reopen respective image files.

block.c +46 -9
Index: qemu/block.c
===================================================================
@@ -696,10 +696,33 @@ unlink_and_fail:
     return ret;
 }
 
+int bdrv_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs, int flags)
+{
+     BlockDriver *drv = bs->drv;
+
+     return drv->bdrv_reopen_prepare(bs, prs, flags);
+}
+
+void bdrv_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs, int flags)
+{
+    BlockDriver *drv = bs->drv;
+
+    drv->bdrv_reopen_commit(bs, rs, flags);
+    bs->open_flags = flags;
+}
+
+void bdrv_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs)
+{
+    BlockDriver *drv = bs->drv;
+
+    drv->bdrv_reopen_abort(bs, rs);
+}
+
 int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
 {
     BlockDriver *drv = bs->drv;
     int ret = 0, open_flags;
+    BDRVReopenState *reopen_state = NULL;
 
     /* Quiesce IO for the given block device */
     qemu_aio_flush();
@@ -708,17 +731,31 @@ int bdrv_reopen(BlockDriverState *bs, in
         qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
         return ret;
     }
-    open_flags = bs->open_flags;
-    bdrv_close(bs);
 
-    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
-    if (ret < 0) {
-        /* Reopen failed. Try to open with original flags */
-        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
-        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+    /* Use driver specific reopen() if available */
+    if (drv->bdrv_reopen_prepare) {
+        ret = bdrv_reopen_prepare(bs, &reopen_state, bdrv_flags);
+         if (ret < 0) {
+            bdrv_reopen_abort(bs, reopen_state);
+            qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+            return ret;
+        }
+
+        bdrv_reopen_commit(bs, reopen_state, bdrv_flags);
+
+    } else {
+       open_flags = bs->open_flags;
+       bdrv_close(bs);
+
+       ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
         if (ret < 0) {
-            /* Reopen failed with orig and modified flags */
-            abort();
+            /* Reopen failed. Try to open with original flags */
+            qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+            ret = bdrv_open(bs, bs->filename, open_flags, drv);
+            if (ret < 0) {
+                /* Reopen failed with orig and modified flags */
+                bs->drv = NULL;
+            }
         }
     }
 
block_int.h +13 -0
Index: qemu/block_int.h
===================================================================
@@ -56,6 +56,14 @@ struct BlockDriver {
     int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
     int (*bdrv_probe_device)(const char *filename);
     int (*bdrv_open)(BlockDriverState *bs, int flags);
+
+    /* For handling image reopen for split or non-split files */
+    int (*bdrv_reopen_prepare)(BlockDriverState *bs,
+                               BDRVReopenState **prs,
+                               int flags);
+    void (*bdrv_reopen_commit)(BlockDriverState *bs, BDRVReopenState *rs,
+                               int flags);
+    void (*bdrv_reopen_abort)(BlockDriverState *bs, BDRVReopenState *rs);
     int (*bdrv_file_open)(BlockDriverState *bs, const char *filename, int flags);
     int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
                      uint8_t *buf, int nb_sectors);
@@ -213,6 +221,11 @@ struct BlockDriverState {
     void *private;
 };
 
+struct BDRVReopenState {
+    BlockDriverState *bs;
+    int reopen_flags;
+};
+
 struct BlockDriverAIOCB {
     AIOPool *pool;
     BlockDriverState *bs;
qemu-common.h +1 -0
Index: qemu/qemu-common.h
===================================================================
@@ -203,6 +203,7 @@ typedef struct NICInfo NICInfo;
 typedef struct HCIInfo HCIInfo;
 typedef struct AudioState AudioState;
 typedef struct BlockDriverState BlockDriverState;
+typedef struct BDRVReopenState BDRVReopenState;
 typedef struct DriveInfo DriveInfo;
 typedef struct DisplayState DisplayState;
 typedef struct DisplayChangeListener DisplayChangeListener;
block.h +3 -0
Index: qemu/block.h
===================================================================
@@ -105,6 +105,9 @@ int bdrv_file_open(BlockDriverState **pb
 int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
               BlockDriver *drv);
 int bdrv_reopen(BlockDriverState *bs, int bdrv_flags);
+int bdrv_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs, int flags);
+void bdrv_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs,  int flags);
+void bdrv_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs);
 void bdrv_close(BlockDriverState *bs);
 int bdrv_attach_dev(BlockDriverState *bs, void *dev);
 void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev);
#26 lore raw

Re: [Qemu-devel] [v9 Patch 5/6]Qemu: Framework for reopening images safely

Quoted 4 lines · On Fri, 11 Nov 2011 12:18:18 +0530 Supriya Kannery…

Struct BDRVReopenState along with three reopen related functions introduced for handling reopen state of images safely. This can be extended by each of the block drivers to reopen respective image files.

Shouldn't this patch come before the one introducing the QMP command?

Quoted 140 lines

Index: qemu/block.c
===================================================================

block.c +46 -9
@@ -696,10 +696,33 @@ unlink_and_fail:
     return ret;
 }
 
+int bdrv_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs, int flags)
+{
+     BlockDriver *drv = bs->drv;
+
+     return drv->bdrv_reopen_prepare(bs, prs, flags);
+}
+
+void bdrv_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs, int flags)
+{
+    BlockDriver *drv = bs->drv;
+
+    drv->bdrv_reopen_commit(bs, rs, flags);
+    bs->open_flags = flags;
+}
+
+void bdrv_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs)
+{
+    BlockDriver *drv = bs->drv;
+
+    drv->bdrv_reopen_abort(bs, rs);
+}
+
 int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
 {
     BlockDriver *drv = bs->drv;
     int ret = 0, open_flags;
+    BDRVReopenState *reopen_state = NULL;
 
     /* Quiesce IO for the given block device */
     qemu_aio_flush();
@@ -708,17 +731,31 @@ int bdrv_reopen(BlockDriverState *bs, in
         qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
         return ret;
     }
-    open_flags = bs->open_flags;
-    bdrv_close(bs);
 
-    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
-    if (ret < 0) {
-        /* Reopen failed. Try to open with original flags */
-        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
-        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+    /* Use driver specific reopen() if available */
+    if (drv->bdrv_reopen_prepare) {
+        ret = bdrv_reopen_prepare(bs, &reopen_state, bdrv_flags);
+         if (ret < 0) {
+            bdrv_reopen_abort(bs, reopen_state);
+            qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+            return ret;
+        }
+
+        bdrv_reopen_commit(bs, reopen_state, bdrv_flags);
+
+    } else {
+       open_flags = bs->open_flags;
+       bdrv_close(bs);
+
+       ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
         if (ret < 0) {
-            /* Reopen failed with orig and modified flags */
-            abort();
+            /* Reopen failed. Try to open with original flags */
+            qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+            ret = bdrv_open(bs, bs->filename, open_flags, drv);
+            if (ret < 0) {
+                /* Reopen failed with orig and modified flags */
+                bs->drv = NULL;
+            }
         }
     }
 

Index: qemu/block_int.h
===================================================================

block_int.h +13 -0
@@ -56,6 +56,14 @@ struct BlockDriver {
     int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
     int (*bdrv_probe_device)(const char *filename);
     int (*bdrv_open)(BlockDriverState *bs, int flags);
+
+    /* For handling image reopen for split or non-split files */
+    int (*bdrv_reopen_prepare)(BlockDriverState *bs,
+                               BDRVReopenState **prs,
+                               int flags);
+    void (*bdrv_reopen_commit)(BlockDriverState *bs, BDRVReopenState *rs,
+                               int flags);
+    void (*bdrv_reopen_abort)(BlockDriverState *bs, BDRVReopenState *rs);
     int (*bdrv_file_open)(BlockDriverState *bs, const char *filename, int flags);
     int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
                      uint8_t *buf, int nb_sectors);
@@ -213,6 +221,11 @@ struct BlockDriverState {
     void *private;
 };
 
+struct BDRVReopenState {
+    BlockDriverState *bs;
+    int reopen_flags;
+};
+
 struct BlockDriverAIOCB {
     AIOPool *pool;
     BlockDriverState *bs;

Index: qemu/qemu-common.h
===================================================================

qemu-common.h +1 -0
@@ -203,6 +203,7 @@ typedef struct NICInfo NICInfo;
 typedef struct HCIInfo HCIInfo;
 typedef struct AudioState AudioState;
 typedef struct BlockDriverState BlockDriverState;
+typedef struct BDRVReopenState BDRVReopenState;
 typedef struct DriveInfo DriveInfo;
 typedef struct DisplayState DisplayState;
 typedef struct DisplayChangeListener DisplayChangeListener;

Index: qemu/block.h
===================================================================

block.h +3 -0
@@ -105,6 +105,9 @@ int bdrv_file_open(BlockDriverState **pb
 int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
               BlockDriver *drv);
 int bdrv_reopen(BlockDriverState *bs, int bdrv_flags);
+int bdrv_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs, int flags);
+void bdrv_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs,  int flags);
+void bdrv_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs);
 void bdrv_close(BlockDriverState *bs);
 int bdrv_attach_dev(BlockDriverState *bs, void *dev);
 void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev);
#27 lore raw

Re: [Qemu-devel] [v9 Patch 5/6]Qemu: Framework for reopening images safely

In reply to Supriya Kannery
Quoted 4 lines · Supriya Kannery
block.c +0 -0
@@ -708,17 +731,31 @@ int bdrv_reopen(BlockDriverState *bs, in
         qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
         return ret;
     }

block.c int bdrv_reopen(BlockDriverState *bs, in · line 736

Quoted 10 lines
block.c +2 -7
-    open_flags = bs->open_flags;
-    bdrv_close(bs);
 
-    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
-    if (ret < 0) {
-        /* Reopen failed. Try to open with original flags */
-        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
-        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+    /* Use driver specific reopen() if available */
+    if (drv->bdrv_reopen_prepare) {

This seems weird to me because we're saying a driver may have drv->bdrv_reopen_prepare == NULL but the public bdrv_reopen_prepare() function doesn't check and return -ENOTSUP.

This check can be moved into bdrv_reopen_prepare(). We can test for the -ENOTSUP return value here instead.

Review int bdrv_reopen(BlockDriverState *bs, in · line 738

Quoted 2 lines
(quoted diff) +2 -0
+        ret = bdrv_reopen_prepare(bs, &reopen_state, bdrv_flags);
+         if (ret < 0) {

Indentation is off here.

Stefan

#28 lore raw

Re: [Qemu-devel] [v9 Patch 5/6]Qemu: Framework for reopening images safely

Quoted 10 lines · Stefan Hajnoczi
Quoted 7 lines · Supriya Kannery
block.c +0 -2
@@ -708,17 +731,31 @@ int bdrv_reopen(BlockDriverState *bs, in
        qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
        return ret;
    }
-    open_flags = bs->open_flags;
-    bdrv_close(bs);
 
Quoted 13 lines

block.c int bdrv_reopen(BlockDriverState *bs, in · line 761

Quoted 8 lines
block.c +2 -5
-    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
-    if (ret < 0) {
-        /* Reopen failed. Try to open with original flags */
-        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
-        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+    /* Use driver specific reopen() if available */
+    if (drv->bdrv_reopen_prepare) {
 

This seems weird to me because we're saying a driver may have drv->bdrv_reopen_prepare == NULL but the public bdrv_reopen_prepare() function doesn't check and return -ENOTSUP.

If drv->bdrv_reopen_prepare == NULL , then we are not calling the publick bdrv_reopen_prepare at all. Unless we later call public bdrv_reopen_prepare from elsewhere without checking drv->bdrv_reopen_prepare, a check for -ENOTSUP inside the public one is not needed right?

Also, we are handling reopening for even those drivers which don't have its own bdrv_reopen_prepare defined, by taking the "else" control path. So condition for reporting "ENOTSUP" shouldn't come up as of now. Please let me know your thoughts.

Quoted 10 lines

This check can be moved into bdrv_reopen_prepare(). We can test for the -ENOTSUP return value here instead.

block.c int bdrv_reopen(BlockDriverState *bs, in · line 761

Quoted 3 lines
block.c +2 -0
+        ret = bdrv_reopen_prepare(bs, &reopen_state, bdrv_flags);
+         if (ret < 0) {
 

Indentation is off here.

sure..will take care in next version.

Quoted 3 lines

Stefan

#29 lore raw

Re: [Qemu-devel] [v9 Patch 5/6]Qemu: Framework for reopening images safely

Quoted 33 lines · supriya kannery
Quoted 12 lines · Stefan Hajnoczi
Quoted 8 lines · Supriya Kannery
block.c +0 -2
@@ -708,17 +731,31 @@ int bdrv_reopen(BlockDriverState *bs, in
        qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
        return ret;
    }
-    open_flags = bs->open_flags;
-    bdrv_close(bs);
 
Quoted 13 lines

block.c int bdrv_reopen(BlockDriverState *bs, in · line 761

Quoted 8 lines
block.c +2 -5
-    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
-    if (ret < 0) {
-        /* Reopen failed. Try to open with original flags */
-        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
-        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+    /* Use driver specific reopen() if available */
+    if (drv->bdrv_reopen_prepare) {
 

This seems weird to me because we're saying a driver may have drv->bdrv_reopen_prepare == NULL but the public bdrv_reopen_prepare() function doesn't check and return -ENOTSUP.

If drv->bdrv_reopen_prepare == NULL , then we are not calling the publick bdrv_reopen_prepare at all. Unless we later call  public bdrv_reopen_prepare
from elsewhere without checking drv->bdrv_reopen_prepare,  a check for -ENOTSUP inside the public one is not needed right?

Quoted 4 lines

Also, we are handling reopening for even those drivers which don't have its own bdrv_reopen_prepare defined, by taking the "else" control path. So condition for reporting "ENOTSUP" shouldn't come up as of now. Please let me know your thoughts.

How does VMDK implement its prepare/commit/abort? It needs to use the "public" bdrv_reopen_prepare() function on its image files.

BTW I think the bdrv_reopen_*() functions should go in block_int.h and not block.h. They are visible to the block layer but not public to the rest of QEMU, which must use the bdrv_reopen() interface only.

I think what's really missing is a way to tie this all together. You have posted raw format and raw-posix protocol patches. But we need to cover image formats, where VMDK is the multi-file special case and qcow2/qed/etc are simpler but also need to be supported.

Right now anything but raw-posix is still closing and reopening. By adding support for image formats I think you'll find the right way to structure this code.

Stefan

#30 lore raw

Re: [Qemu-devel] [v9 Patch 5/6]Qemu: Framework for reopening images safely

Quoted 35 lines · Stefan Hajnoczi
Quoted 33 lines · supriya kannery
Quoted 11 lines · Stefan Hajnoczi
Quoted 7 lines · Supriya Kannery
block.c +0 -2
@@ -708,17 +731,31 @@ int bdrv_reopen(BlockDriverState *bs, in
       qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
       return ret;
   }
-    open_flags = bs->open_flags;
-    bdrv_close(bs);
 
Quoted 14 lines

block.c int bdrv_reopen(BlockDriverState *bs, in

Quoted 9 lines
block.c +2 -5
-    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
-    if (ret < 0) {
-        /* Reopen failed. Try to open with original flags */
-        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
-        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+    /* Use driver specific reopen() if available */
+    if (drv->bdrv_reopen_prepare) {
 
 

This seems weird to me because we're saying a driver may have drv->bdrv_reopen_prepare == NULL but the public bdrv_reopen_prepare() function doesn't check and return -ENOTSUP.

If drv->bdrv_reopen_prepare == NULL , then we are not calling the publick bdrv_reopen_prepare at all. Unless we later call public bdrv_reopen_prepare
from elsewhere without checking drv->bdrv_reopen_prepare, a check for -ENOTSUP inside the public one is not needed right?

Quoted 9 lines
Quoted 5 lines

Also, we are handling reopening for even those drivers which don't have its own bdrv_reopen_prepare defined, by taking the "else" control path. So condition for reporting "ENOTSUP" shouldn't come up as of now. Please let me know your thoughts.

How does VMDK implement its prepare/commit/abort? It needs to use the "public" bdrv_reopen_prepare() function on its image files.

bdrv_reopen() is the public interface which gets called by any of the image formats. So VMDK or any image format has to call bdrv_reopen which decides to call driver specific prepare/commit/abort or simply close and reopen the file.

Quoted 4 lines

BTW I think the bdrv_reopen_*() functions should go in block_int.h and not block.h. They are visible to the block layer but not public to the rest of QEMU, which must use the bdrv_reopen() interface only.

Quoted 10 lines

I think what's really missing is a way to tie this all together. You have posted raw format and raw-posix protocol patches. But we need to cover image formats, where VMDK is the multi-file special case and qcow2/qed/etc are simpler but also need to be supported.

Right now anything but raw-posix is still closing and reopening. By adding support for image formats I think you'll find the right way to structure this code.

Since only bdrv_reopen() is public, it is declared in block.h and structure of code done in similar way how bdrv_open() is done.

The else part in bdrv_reopen() will handle reopen requests for images other than raw for now (simply close and reopen).

-thanks, Supriya

Quoted 3 lines

Stefan

#31 lore raw

Re: [Qemu-devel] [v9 Patch 5/6]Qemu: Framework for reopening images safely

Am 22.11.2011 11:24, schrieb supriya kannery:

Quoted 42 lines
Quoted 41 lines · Stefan Hajnoczi
Quoted 38 lines · supriya kannery
Quoted 11 lines · Stefan Hajnoczi
Quoted 7 lines · Supriya Kannery
block.c +0 -2
@@ -708,17 +731,31 @@ int bdrv_reopen(BlockDriverState *bs, in
       qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
       return ret;
   }
-    open_flags = bs->open_flags;
-    bdrv_close(bs);
 
Quoted 14 lines

block.c int bdrv_reopen(BlockDriverState *bs, in

Quoted 9 lines
block.c +2 -5
-    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
-    if (ret < 0) {
-        /* Reopen failed. Try to open with original flags */
-        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
-        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+    /* Use driver specific reopen() if available */
+    if (drv->bdrv_reopen_prepare) {
 
 

This seems weird to me because we're saying a driver may have drv->bdrv_reopen_prepare == NULL but the public bdrv_reopen_prepare() function doesn't check and return -ENOTSUP.

If drv->bdrv_reopen_prepare == NULL , then we are not calling the publick bdrv_reopen_prepare at all. Unless we later call public bdrv_reopen_prepare
from elsewhere without checking drv->bdrv_reopen_prepare, a check for -ENOTSUP inside the public one is not needed right?

Also, we are handling reopening for even those drivers which don't have its own bdrv_reopen_prepare defined, by taking the "else" control path. So condition for reporting "ENOTSUP" shouldn't come up as of now. Please let me know your thoughts.

Quoted 8 lines
Quoted 3 lines

How does VMDK implement its prepare/commit/abort? It needs to use the "public" bdrv_reopen_prepare() function on its image files.

bdrv_reopen() is the public interface which gets called by any of the image formats.
So VMDK or any image format has to call bdrv_reopen which decides to call driver specific prepare/commit/abort or simply close and reopen the file.

No, that doesn't work. In order to get all-or-nothing semantics, you need to explicitly prepare all child images and only when you know the results of all preparations, you can decide whether to commit or abort all.

Kevin

#32 lore raw

Re: [Qemu-devel] [v9 Patch 5/6]Qemu: Framework for reopening images safely

Quoted 54 lines · Kevin Wolf

Am 22.11.2011 11:24, schrieb supriya kannery:

Quoted 52 lines
Quoted 50 lines · Stefan Hajnoczi
Quoted 37 lines · supriya kannery
Quoted 12 lines · Stefan Hajnoczi
Quoted 7 lines · Supriya Kannery
block.c +0 -2
@@ -708,17 +731,31 @@ int bdrv_reopen(BlockDriverState *bs, in
       qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
       return ret;
   }
-    open_flags = bs->open_flags;
-    bdrv_close(bs);
 
Quoted 16 lines

block.c int bdrv_reopen(BlockDriverState *bs, in

Quoted 10 lines
block.c +2 -5
-    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
-    if (ret < 0) {
-        /* Reopen failed. Try to open with original flags */
-        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
-        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+    /* Use driver specific reopen() if available */
+    if (drv->bdrv_reopen_prepare) {
 
 
 

This seems weird to me because we're saying a driver may have drv->bdrv_reopen_prepare == NULL but the public bdrv_reopen_prepare() function doesn't check and return -ENOTSUP.

If drv->bdrv_reopen_prepare == NULL , then we are not calling the publick bdrv_reopen_prepare at all. Unless we later call public bdrv_reopen_prepare
from elsewhere without checking drv->bdrv_reopen_prepare, a check for -ENOTSUP inside the public one is not needed right?

Quoted 6 lines

Also, we are handling reopening for even those drivers which don't have its own bdrv_reopen_prepare defined, by taking the "else" control path. So condition for reporting "ENOTSUP" shouldn't come up as of now. Please let me know your thoughts.

How does VMDK implement its prepare/commit/abort? It needs to use the "public" bdrv_reopen_prepare() function on its image files.

Quoted 9 lines
Quoted 4 lines

bdrv_reopen() is the public interface which gets called by any of the image formats. So VMDK or any image format has to call bdrv_reopen which decides to call driver specific prepare/commit/abort or simply close and reopen the file.

No, that doesn't work. In order to get all-or-nothing semantics, you need to explicitly prepare all child images and only when you know the results of all preparations, you can decide whether to commit or abort all.

bdrv_reopen_prepare/commit/abort will be implemented specific to VMDK in vmdk.c. Then for vmdk, drv->bdrv_reopen_prepare() will handle preparing child images and return success to bdrv_reopen () only if all of them get prepared successfully. The prepare/commit/abort concept we took up considering vmdk's special case of multiple files.

So it is bdrv_reopen() which is public and called by hostcache change request for any of the image formats. It then routes the processing to respective prepare/commit/abort implemented by the drivers, including VMDK. In cases where drivers don't have their own implementation, default route is taken which is simply closing and opening the file.

- thanks, Supriya

Quoted 3 lines

Kevin

#33 lore raw

Re: [Qemu-devel] [v9 Patch 5/6]Qemu: Framework for reopening images safely

Quoted 79 lines · supriya kannery
Quoted 64 lines · Kevin Wolf

Am 22.11.2011 11:24, schrieb supriya kannery:

Quoted 51 lines
Quoted 48 lines · Stefan Hajnoczi
Quoted 43 lines · supriya kannery
Quoted 13 lines · Stefan Hajnoczi
Quoted 8 lines · Supriya Kannery
(quoted diff) +0 -2
@@ -708,17 +731,31 @@ int bdrv_reopen(BlockDriverState *bs, in
       qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
       return ret;
   }
-    open_flags = bs->open_flags;
-    bdrv_close(bs);
 
Quoted 15 lines

Review int bdrv_reopen(BlockDriverState *bs, in · line 738

Quoted 9 lines
(quoted diff) +2 -5
-    ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
-    if (ret < 0) {
-        /* Reopen failed. Try to open with original flags */
-        qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
-        ret = bdrv_open(bs, bs->filename, open_flags, drv);
+    /* Use driver specific reopen() if available */
+    if (drv->bdrv_reopen_prepare) {
 
 

This seems weird to me because we're saying a driver may have drv->bdrv_reopen_prepare == NULL but the public bdrv_reopen_prepare() function doesn't check and return -ENOTSUP.

If drv->bdrv_reopen_prepare == NULL , then we are not calling the publick bdrv_reopen_prepare at all. Unless we later call  public bdrv_reopen_prepare
from elsewhere without checking drv->bdrv_reopen_prepare,  a check for -ENOTSUP inside the public one is not needed right?

Also, we are handling reopening for even those drivers which don't have its own bdrv_reopen_prepare defined, by taking the "else" control path. So condition for reporting "ENOTSUP" shouldn't come up as of now. Please let me know your thoughts.

Quoted 9 lines
Quoted 3 lines

How does VMDK implement its prepare/commit/abort?  It needs to use the "public" bdrv_reopen_prepare() function on its image files.

bdrv_reopen() is the public interface which gets called by any of the image formats.
So VMDK or any image format has to call bdrv_reopen which decides to call driver specific prepare/commit/abort or simply close and reopen the file.

Quoted 5 lines

No, that doesn't work. In order to get all-or-nothing semantics, you need to explicitly prepare all child images and only when you know the results of all preparations, you can decide whether to commit or abort all.

bdrv_reopen_prepare/commit/abort will be implemented specific to VMDK in vmdk.c. Then for vmdk,
drv->bdrv_reopen_prepare() will handle  preparing child images and return success to bdrv_reopen ()
only if all of them get prepared successfully.  The prepare/commit/abort concept we took up considering
vmdk's special case of multiple files.

Quoted 7 lines

So it is bdrv_reopen() which is public and called by hostcache change request for any of the image formats.
It then routes the processing to respective prepare/commit/abort implemented by the drivers, including VMDK.
In cases where drivers don't have their own implementation, default route is taken which is simply
closing and opening the file.

VMDK must call bdrv_reopen_prepare()/bdrv_reopen_commit()/bdrv_reopen_abort() on its child images in order to support aborting when there is a failure half-way through. If it used bdrv_reopen() on its child images then it could not roll back later when there is a failure on the next child.

My bigger picture comment was that safe reopen support for raw-posix is great but we should be able to take advantage of that for image formats. I'd rather see all image formats except VMDK have safe reopen in this series than only raw-posix and vmdk. How about the generic prepare/commit/abort implementation that Kevin suggested in a previous thread - something that qcow2, qed, etc can use in order to get the safe reopen ability?

(If we don't get safe reopen support for qcow2, qed, etc then dynamic hostcache changing will take the unsafe reopen path in some of the common usecases with image file.)

Stefan

#34 lore raw

Re: [Qemu-devel] [v9 Patch 5/6]Qemu: Framework for reopening images safely

Quoted 39 lines · Stefan Hajnoczi
Quoted 30 lines · supriya kannery
Quoted 15 lines · Kevin Wolf

Am 22.11.2011 11:24, schrieb supriya kannery:

Quoted 11 lines
Quoted 5 lines

How does VMDK implement its prepare/commit/abort? It needs to use the "public" bdrv_reopen_prepare() function on its image files.

bdrv_reopen() is the public interface which gets called by any of the image formats.
So VMDK or any image format has to call bdrv_reopen which decides to call driver specific prepare/commit/abort or simply close and reopen the file.

Quoted 5 lines

No, that doesn't work. In order to get all-or-nothing semantics, you need to explicitly prepare all child images and only when you know the results of all preparations, you can decide whether to commit or abort all.

bdrv_reopen_prepare/commit/abort will be implemented specific to VMDK in vmdk.c. Then for vmdk,
drv->bdrv_reopen_prepare() will handle preparing child images and return success to bdrv_reopen ()
only if all of them get prepared successfully. The prepare/commit/abort concept we took up considering
vmdk's special case of multiple files.

Quoted 7 lines

So it is bdrv_reopen() which is public and called by hostcache change request for any of the image formats.
It then routes the processing to respective prepare/commit/abort implemented by the drivers, including VMDK.
In cases where drivers don't have their own implementation, default route is taken which is simply
closing and opening the file.

Quoted 6 lines

VMDK must call bdrv_reopen_prepare()/bdrv_reopen_commit()/bdrv_reopen_abort() on its child images in order to support aborting when there is a failure half-way through. If it used bdrv_reopen() on its child images then it could not roll back later when there is a failure on the next child.

I got both your's and Kevin's point now, after looking into vmdk.c code
related to extents.
My initial understanding was bdrv_reopen_prepare() implemented inside vmdk.c can be called for handling reopening of multiple child
images. But observing how vmdk_open() is implemented for child images, I should follow that method. So will make bdrv_reopen_prepare()/commit/abort in block.c to be used by vmdk as well as other required image formats (like how raw.c is using them).

- thanks, Supriya

#35 lore raw

PATCH v9 6/6 Qemu: raw posix implementation of reopen functions

In reply to Supriya Kannery

raw-posix driver changes for bdrv_reopen_xx functions to safely reopen image files. Reopening of image files while changing hostcache dynamically is handled here.

block/raw.c +21 -2
Index: qemu/block/raw.c
===================================================================
@@ -9,6 +9,23 @@ static int raw_open(BlockDriverState *bs
     return 0;
 }
 
+static int raw_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs,
+                              int flags)
+{
+    return bdrv_reopen_prepare(bs->file, prs, flags);
+}
+
+static void raw_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs,
+                              int flags)
+{
+    bdrv_reopen_commit(bs->file, rs, flags);
+}
+
+static void raw_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs)
+{
+    bdrv_reopen_abort(bs->file, rs);
+}
+
 static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
                                      int nb_sectors, QEMUIOVector *qiov)
 {
@@ -107,10 +124,12 @@ static BlockDriver bdrv_raw = {
 
     /* It's really 0, but we need to make g_malloc() happy */
     .instance_size      = 1,
-
     .bdrv_open          = raw_open,
+    .bdrv_reopen_prepare
+                        = raw_reopen_prepare,
+    .bdrv_reopen_commit = raw_reopen_commit,
+    .bdrv_reopen_abort  = raw_reopen_abort,
     .bdrv_close         = raw_close,
-
     .bdrv_co_readv      = raw_co_readv,
     .bdrv_co_writev     = raw_co_writev,
     .bdrv_co_flush      = raw_co_flush,
block/raw-posix.c +72 -0

90 lines not on this page · raw message

#36 lore raw

Re: [Qemu-devel] [v9 Patch 6/6]Qemu: raw posix implementation of reopen functions

Quoted 9 lines · Supriya Kannery
block/raw-posix.c +9 -0
+static int raw_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs,
+                              int flags)
+{
+    BDRVRawReopenState *raw_rs = g_malloc0(sizeof(BDRVRawReopenState));
+    BDRVRawState *s = bs->opaque;
+    int ret = 0;
+
+    raw_rs->reopen_state.reopen_flags = s->open_flags;
+    raw_rs->reopen_state.bs = bs;

block/raw-posix.c static int raw_open(BlockDriverState *bs · line 305

Quoted 10 lines
block/raw-posix.c +10 -0
+    raw_rs->reopen_fd = -1;
+    *prs = &(raw_rs->reopen_state);
+
+    /* Flags that can be set using fcntl */
+    int fcntl_flags = BDRV_O_NOCACHE;
+
+    if ((bs->open_flags & ~fcntl_flags) == (flags & ~fcntl_flags)) {
+        raw_rs->reopen_fd = dup(s->fd);
+        if (raw_rs->reopen_fd <= 0) {
+            return -1;

return -errno;

Quoted 7 lines

+        }
+        if ((flags & BDRV_O_NOCACHE)) {
+            raw_rs->reopen_state.reopen_flags |= O_DIRECT;
+        } else {
+            raw_rs->reopen_state.reopen_flags &= ~O_DIRECT;
+        }
+        ret = fcntl_setfl(raw_rs->reopen_fd, raw_rs->reopen_state.reopen_flags);

I wonder if this works on Solaris, FreeBSD, etc?

Perhaps there needs to be a fallback to the missing "else" case below...

Quoted 4 lines

+    } else {
+
+        /* TBD: Handle O_DSYNC and other flags. For now return error */
+        ret = -1;

...and this needs to be implemented.

Quoted 3 lines

+    }
+    return ret;
+}

Stefan

#37 lore raw

Re: [Qemu-devel] [v9 Patch 6/6]Qemu: raw posix implementation of reopen functions

Quoted 36 lines · Stefan Hajnoczi
Quoted 10 lines · Supriya Kannery
block/raw-posix.c +9 -0
+static int raw_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs,
+                              int flags)
+{
+    BDRVRawReopenState *raw_rs = g_malloc0(sizeof(BDRVRawReopenState));
+    BDRVRawState *s = bs->opaque;
+    int ret = 0;
+
+    raw_rs->reopen_state.reopen_flags = s->open_flags;
+    raw_rs->reopen_state.bs = bs;

block/raw-posix.c static int raw_open(BlockDriverState *bs · line 305

Quoted 10 lines
block/raw-posix.c +10 -0
+    raw_rs->reopen_fd = -1;
+    *prs = &(raw_rs->reopen_state);
+
+    /* Flags that can be set using fcntl */
+    int fcntl_flags = BDRV_O_NOCACHE;
+
+    if ((bs->open_flags & ~fcntl_flags) == (flags & ~fcntl_flags)) {
+        raw_rs->reopen_fd = dup(s->fd);
+        if (raw_rs->reopen_fd <= 0) {
+            return -1;

return -errno;

block/raw-posix.c static int raw_open(BlockDriverState *bs · line 312

Quoted 8 lines
block/raw-posix.c +7 -0
+        }
+        if ((flags & BDRV_O_NOCACHE)) {
+            raw_rs->reopen_state.reopen_flags |= O_DIRECT;
+        } else {
+            raw_rs->reopen_state.reopen_flags &= ~O_DIRECT;
+        }
+        ret = fcntl_setfl(raw_rs->reopen_fd, raw_rs->reopen_state.reopen_flags);
Quoted 5 lines

I wonder if this works on Solaris, FreeBSD, etc?

Perhaps there needs to be a fallback to the missing "else" case below...

ok. Will look into whether this will work on Solaris, FreeBSD etc..

Quoted 9 lines

block/raw-posix.c static int raw_open(BlockDriverState *bs · line 316

Quoted 5 lines
block/raw-posix.c +4 -0
+    } else {
+
+        /* TBD: Handle O_DSYNC and other flags. For now return error */
+        ret = -1;

...and this needs to be implemented.

ok

Quoted 8 lines

block/raw-posix.c static int raw_open(BlockDriverState *bs · line 319

Quoted 4 lines
block/raw-posix.c +3 -0
+    }
+    return ret;
+}

Stefan

#38 lore raw

Re: [Qemu-devel] [v9 Patch 6/6]Qemu: raw posix implementation of reopen functions

Quoted 14 lines · supriya kannery
Quoted 13 lines · Stefan Hajnoczi
Quoted 9 lines · Supriya Kannery
block/raw-posix.c +7 -0
+        }
+        if ((flags & BDRV_O_NOCACHE)) {
+            raw_rs->reopen_state.reopen_flags |= O_DIRECT;
+        } else {
+            raw_rs->reopen_state.reopen_flags &= ~O_DIRECT;
+        }
+        ret = fcntl_setfl(raw_rs->reopen_fd, 

raw_rs->reopen_state.reopen_flags);

Quoted 8 lines
Quoted 5 lines

I wonder if this works on Solaris, FreeBSD, etc?

Perhaps there needs to be a fallback to the missing "else" case below...

ok. Will look into whether this will work on Solaris, FreeBSD etc..

This should work for all non-win Oses.
I have tested only in x86.

#ifndef _WIN32
/* Sets a specific flag */
int fcntl_setfl(int fd, int flag)
{
int flags;

   flags = fcntl(fd, F_GETFL);

- thanks, Supriya

#39 lore raw

Re: [Qemu-devel] [v9 Patch 6/6]Qemu: raw posix implementation of reopen functions

Quoted 30 lines · supriya kannery
Quoted 17 lines · supriya kannery
Quoted 15 lines · Stefan Hajnoczi
Quoted 10 lines · Supriya Kannery

+        }
+        if ((flags & BDRV_O_NOCACHE)) {
+            raw_rs->reopen_state.reopen_flags |= O_DIRECT;
+        } else {
+            raw_rs->reopen_state.reopen_flags &= ~O_DIRECT;
+        }
+        ret = fcntl_setfl(raw_rs->reopen_fd, raw_rs->reopen_state.reopen_flags);

Quoted 8 lines
Quoted 5 lines

I wonder if this works on Solaris, FreeBSD, etc?

Perhaps there needs to be a fallback to the missing "else" case below...

ok. Will look into whether this will work on Solaris, FreeBSD etc..

This should work for all non-win Oses.
I have tested only in x86.

Quoted 7 lines

#ifndef _WIN32
/* Sets a specific flag */
int fcntl_setfl(int fd, int flag)
{
  int flags;

  flags = fcntl(fd, F_GETFL);

Are you sure POSIX guarantees that O_DIRECT can be changed with F_SETFL? I didn't find any statement in the specification. It is possible that this code compiles but does not actually work on non-Linux OSes. Did you run tests?

Stefan

#40 lore raw

Re: [Qemu-devel] [v9 Patch 6/6]Qemu: raw posix implementation of reopen functions

Quoted 4 lines · Stefan Hajnoczi

Are you sure POSIX guarantees that O_DIRECT can be changed with F_SETFL? I didn't find any statement in the specification. It is possible that this code compiles but does not actually work on non-Linux OSes. Did you run tests?

O_DIRECT is a non-posix extention, and semantics of it will differ greatly between the operating systems implementing it.

#41 lore raw

Re: [Qemu-devel] [v9 Patch 6/6]Qemu: raw posix implementation of reopen functions

In reply to Stefan Hajnoczi
Quoted 38 lines · Stefan Hajnoczi
Quoted 36 lines · supriya kannery
Quoted 16 lines · supriya kannery
Quoted 14 lines · Stefan Hajnoczi
Quoted 10 lines · Supriya Kannery
block/raw-posix.c +7 -0
+        }
+        if ((flags & BDRV_O_NOCACHE)) {
+            raw_rs->reopen_state.reopen_flags |= O_DIRECT;
+        } else {
+            raw_rs->reopen_state.reopen_flags &= ~O_DIRECT;
+        }
+        ret = fcntl_setfl(raw_rs->reopen_fd,

raw_rs->reopen_state.reopen_flags);

Quoted 9 lines
Quoted 6 lines

I wonder if this works on Solaris, FreeBSD, etc?

Perhaps there needs to be a fallback to the missing "else" case below...

ok. Will look into whether this will work on Solaris, FreeBSD etc..

This should work for all non-win Oses.
I have tested only in x86.

#ifndef _WIN32
/* Sets a specific flag */
int fcntl_setfl(int fd, int flag)
{
int flags;

Quoted 8 lines
Quoted 2 lines
  flags = fcntl(fd, F_GETFL);

Are you sure POSIX guarantees that O_DIRECT can be changed with F_SETFL? I didn't find any statement in the specification. It is possible that this code compiles but does not actually work on non-Linux OSes. Did you run tests?

I don't have FreeBSD and Solaris systems to use.
Referred the following man page links to verify that O_DIRECT in these OSes can be changed using fcntl.
http://fuse4bsd.creo.hu/localcgi/man-cgi.cgi?fcntl+2
http://man-wiki.net/index.php/2:fcntl
If anybody with these systems can confirm, that would be very helpful.

-thanks, Supriya

Quoted 3 lines

Stefan

#42 lore raw

Re: [Qemu-devel] [v9 Patch 6/6]Qemu: raw posix implementation of reopen functions

Quoted 58 lines · supriya kannery
Quoted 48 lines · Stefan Hajnoczi
Quoted 44 lines · supriya kannery
Quoted 22 lines · supriya kannery
Quoted 19 lines · Stefan Hajnoczi
Quoted 11 lines · Supriya Kannery

+        }
+        if ((flags & BDRV_O_NOCACHE)) {
+            raw_rs->reopen_state.reopen_flags |= O_DIRECT;
+        } else {
+            raw_rs->reopen_state.reopen_flags &= ~O_DIRECT;
+        }
+        ret = fcntl_setfl(raw_rs->reopen_fd, raw_rs->reopen_state.reopen_flags);

I wonder if this works on Solaris, FreeBSD, etc?

Quoted 9 lines
Quoted 5 lines

Perhaps there needs to be a fallback to the missing "else" case below...

ok. Will look into whether this will work on Solaris, FreeBSD etc..

This should work for all non-win Oses.
I have tested only in x86.

#ifndef _WIN32
/* Sets a specific flag */
int fcntl_setfl(int fd, int flag)
{
 int flags;

Quoted 8 lines
Quoted 2 lines

 flags = fcntl(fd, F_GETFL);

Are you sure POSIX guarantees that O_DIRECT can be changed with F_SETFL?  I didn't find any statement in the specification.  It is possible that this code compiles but does not actually work on non-Linux OSes.  Did you run tests?

Quoted 6 lines

I don't have FreeBSD and Solaris systems to use.
Referred the following man page links to verify that O_DIRECT in these OSes can be changed using fcntl.
http://fuse4bsd.creo.hu/localcgi/man-cgi.cgi?fcntl+2
http://man-wiki.net/index.php/2:fcntl
If anybody with these systems can confirm, that would be very helpful.

Cool, thanks for sharing. The safest would be to do a F_GETFL afterwards and fall back to unsafe reopen if it didn't work.

Stefan

#43 lore raw
In reply to Supriya Kannery

Am 11.11.2011 07:47, schrieb Supriya Kannery:

Quoted 4 lines

Following patchset is for enabling dynamic change of host pagecache setting of block devices through qemu monitor.

Quoted 13 lines

This patchset introduces
a. monitor command 'block_set_hostcache' using which host
pagecache setting for a block device can be changed dynamically.
b. a new option for setting host cache from qemu
commandline option -drive "hostcache=on/off".
c. BDRVReopenState, a generic structure which can be
extended by each of the block drivers to reopen respective image files.
Extension of this structure for drivers raw-posix is done here.
Note: 'hostcache and 'cache' options when used together, cache=xx will override hostcache=yy.

Are you going to submit a v10 of the series? It would be great to have this functionality in qemu 1.1.

Kevin