Currently cache setting of a block device cannot be changed without restarting a running VM. Following patchset is for enabling dynamic change of cache setting for block devices through qemu monitor and qmp. Code changes are based on patches from Christoph Hellwig and Prerna Saxena.
This patchset introduces a. monitor command 'block_set_hostcache' using which host pagecache setting for a block device can be changed dynamically while guest VM is running. b. 'hostcache' - a new option for setting host cache from qemu command -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 raw-posix is done for now. I am working on to extend the same for raw-win32 image files as well. Note: 'Hostcache and 'cache' options cannot be used simultaneously from commandline. v7: 1. Added structure BDRVReopenState to support safe reopening of image files. 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 | 119 ++++++++++++++++++++++++++++++++++++++------- qemu/block.h | 2 + qemu/block/raw-posix.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++ qemu/block/raw.c | 11 +++++++ qemu/block_int.h | 15 ++++++++++ qemu/blockdev.c | 39 +++++++++++++++++++++++++ qemu/blockdev.h | 2 + qemu/hmp-commands.hx | 14 +++++++++ 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 | 29 +++++++++++++++++++ 17 files changed, 306 insertions(+), 13 deletions(-)