block: add missed block_acct_setup with new block device init procedure
v3 cover block: add missed block_acct_setup with new block device init procedure
Commit 5f76a7aac156ca75680dad5df4a385fd0b58f6b1 is looking harmless from the first glance, but it has changed things a lot. 'libvirt' uses it to detect that it should follow new initialization way and this changes things considerably. With this procedure followed, blockdev_init() is not called anymore and thus block_acct_setup() helper is not called.
This means in particular that defaults for block accounting statistics are changed and account_invalid/account_failed are actually initialized as false instead of true originally.
This commit changes things to match original world. There are the following constraints:
* new default value in block_acct_init() is set to true
* block_acct_setup() inside blockdev_init() is called before blkconf_apply_backend_options()
* thus newly created option in block device properties has precedence if specified
Changes from v2:
* called bool_from_onoffauto(account_..., true) in the first patch to preserve original semantics before patch 2
Changes from v1:
* set account_invalid/account_failed to true by default
* pass OnOffAuto to block_acct_init() to handle double initialization (patch 1)
* changed properties on BLK device to OnOffAuto
PATCH v3 1/2 target/hppa: Fix proberi instruction emulation for linux-user
From: Helge Deller <[email protected]>
The proberi assembler instruction checks the read/write access rights for the page of a given address and shall return a value of 1 if the test succeeds and a value of 0 on failure in the target register.
But when run in linux-user mode, qemu currently simply returns the return code of page_check_range() which returns 0 on success and -1 on failure, which is the opposite of what proberi should return.
Fix it by checking the return code of page_check_range() and return the expected return value.
The easiest way to reproduce the issue is by running "/lib/ld.so.1 --version" in a chroot which fails without this patch. At startup of ld.so the __canonicalize_funcptr_for_compare() function is used to resolve the function address out of a function descriptor, which fails because proberi (due to the wrong return code) seems to indicate that the given address isn't accessible.
--- target/hppa/op_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/hppa/op_helper.c +1 -1
@@ -170,7 +170,7 @@ target_ureg HELPER(probe)(CPUHPPAState *env, target_ulong addr, uint32_t level, uint32_t want) {#ifdef CONFIG_USER_ONLY -return page_check_range (addr,1 , want); +return (page_check_range (addr,1 , want) ==0 ) ?1 :0 ;#else int prot, excp;hwaddr phys;
Signature · 1 line
2.32.0
Re: [PATCH 1/2] target/hppa: Fix proberi instruction emulation for linux-user
Thank you Denis,
Btw, this patch was already pulled by Richard...
Helge
Quoted 38 lines · Denis V. Lunev
From: Helge Deller <[email protected]>
The proberi assembler instruction checks the read/write access rights for the page of a given address and shall return a value of 1 if the test succeeds and a value of 0 on failure in the target register.
But when run in linux-user mode, qemu currently simply returns the return code of
page_check_range()which returns 0 on success and -1 on failure, which is the opposite of what proberi should return.Fix it by checking the return code of
page_check_range()and return the expected return value.The easiest way to reproduce the issue is by running "
/lib/ld.so.1--version" in a chroot which fails without this patch. At startup of ld.so the__canonicalize_funcptr_for_compare()function is used to resolve the function address out of a function descriptor, which fails because proberi (due to the wrong return code) seems to indicate that the given address isn't accessible.Signed-off-by Helge Deller <[email protected]>--- target/hppa/op_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/hppa/op_helper.c +1
-1@@ -170,7 +170,7 @@ target_ureg HELPER(probe)(CPUHPPAState *env, target_ulong addr, uint32_t level, uint32_t want) {#ifdef CONFIG_USER_ONLY -return page_check_range (addr,1 , want); +return (page_check_range (addr,1 , want) ==0 ) ?1 :0 ;#else int prot, excp;hwaddr phys;
PATCH v3 2/2 block: pass OnOffAuto instead of bool to block_acct_setup()
In reply to Denis V. LunevWe would have one more place for block_acct_setup() calling, which should not corrupt original value.
--- block/accounting.c | 26 +++++++++++-- blockdev.c | 17 +++++++-- hw/block/block.c | 2 + include/block/accounting.h | 6 +-- include/hw/block/block.h | 7 +++- qapi/misc.json | 9 +---- tests/qemu-iotests/172.out | 76 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 124 insertions(+), 19 deletions(-)
block/accounting.c +22 -4
@@ -38,13 +38,31 @@ void block_acct_init(BlockAcctStats *stats)if (qtest_enabled ()) { clock_type =QEMU_CLOCK_VIRTUAL ; } + stats->account_invalid = true; + stats->account_failed = true; } -void block_acct_setup (BlockAcctStats *stats,bool account_invalid, -bool account_failed) +static bool bool_from_onoffauto (OnOffAuto val,bool def) { - stats->account_invalid = account_invalid; - stats->account_failed = account_failed; +switch (val) { +case ON_OFF_AUTO_AUTO : +return def; +case ON_OFF_AUTO_ON : +return true; +case ON_OFF_AUTO_OFF : +return false; +default : +abort (); + } +} + +void block_acct_setup (BlockAcctStats *stats,enum OnOffAuto account_invalid, +enum OnOffAuto account_failed) +{ + stats->account_invalid =bool_from_onoffauto (account_invalid, + stats->account_invalid); + stats->account_failed =bool_from_onoffauto (account_failed, + stats->account_failed); }void block_acct_cleanup (BlockAcctStats *stats)
blockdev.c +14 -3
@@ -455,6 +455,17 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, } } +static OnOffAuto account_get_opt (QemuOpts *opts,const char *name) +{ +if (!qemu_opt_find (opts, name)) { +return ON_OFF_AUTO_AUTO ; + } +if (qemu_opt_get_bool (opts, name, true)) { +return ON_OFF_AUTO_ON ; + } +return ON_OFF_AUTO_OFF ; +} +/* Takes the ownership of bs_opts */ static BlockBackend *blockdev_init (const char *file,QDict *bs_opts,Error **errp)
@@ -462,7 +473,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,const char *buf;int bdrv_flags =0 ;int on_read_error, on_write_error; -bool account_invalid, account_failed; +OnOffAuto account_invalid, account_failed;bool writethrough, read_only;BlockBackend *blk;BlockDriverState *bs;
@@ -496,8 +507,8 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,/* extract parameters */ snapshot =qemu_opt_get_bool (opts,"snapshot" ,0 ); - account_invalid =qemu_opt_get_bool (opts,"stats-account-invalid" , true); - account_failed =qemu_opt_get_bool (opts,"stats-account-failed" , true); + account_invalid =account_get_opt (opts,"stats-account-invalid" ); + account_failed =account_get_opt (opts,"stats-account-failed" ); writethrough = !qemu_opt_get_bool (opts,BDRV_OPT_CACHE_WB , true);
hw/block/block.c +2 -0
@@ -205,6 +205,8 @@ bool blkconf_apply_backend_options(BlockConf *conf, bool readonly,blk_set_enable_write_cache (blk, wce);blk_set_on_error (blk, rerror, werror); +block_acct_setup (blk_get_stats (blk), conf->account_invalid, + conf->account_failed);return true; }
include/block/accounting.h +3 -3
@@ -27,7 +27,7 @@#include "qemu/timed-average.h" #include "qemu/thread.h" -#include "qapi/qapi-builtin-types.h" +#include "qapi/qapi-types-common.h" typedef struct BlockAcctTimedStats BlockAcctTimedStats ;typedef struct BlockAcctStats BlockAcctStats ;
@@ -100,8 +100,8 @@ typedef struct BlockAcctCookie { } BlockAcctCookie;void block_acct_init (BlockAcctStats *stats); -void block_acct_setup (BlockAcctStats *stats,bool account_invalid, -bool account_failed); +void block_acct_setup (BlockAcctStats *stats,enum OnOffAuto account_invalid, +enum OnOffAuto account_failed);void block_acct_cleanup (BlockAcctStats *stats);void block_acct_add_interval (BlockAcctStats *stats,unsigned interval_length); BlockAcctTimedStats *block_acct_interval_next(BlockAcctStats *stats,
include/hw/block/block.h +6 -1
@@ -31,6 +31,7 @@ typedef struct BlockConf {uint32_t lcyls, lheads, lsecs;OnOffAuto wce;bool share_rw; +OnOffAuto account_invalid, account_failed;BlockdevOnError rerror;BlockdevOnError werror; } BlockConf;
@@ -61,7 +62,11 @@ static inline unsigned int get_physical_block_exp(BlockConf *conf) _conf.discard_granularity, -1), \DEFINE_PROP_ON_OFF_AUTO ("write-cache" , _state, _conf.wce, \ON_OFF_AUTO_AUTO ), \ - DEFINE_PROP_BOOL("share-rw", _state, _conf.share_rw, false) +DEFINE_PROP_BOOL ("share-rw" , _state, _conf.share_rw, false), \ +DEFINE_PROP_ON_OFF_AUTO ("account-invalid" , _state, \ + _conf.account_invalid,ON_OFF_AUTO_AUTO ), \ +DEFINE_PROP_ON_OFF_AUTO ("account-failed" , _state, \ + _conf.account_failed, ON_OFF_AUTO_AUTO)#define DEFINE_BLOCK_PROPERTIES (_state, _conf) \ DEFINE_PROP_DRIVE("drive", _state, _conf.blk), \
qapi/misc.json +1 -8
@@ -210,12 +210,6 @@ # # @cpu-index: The CPU to use for commands that require an implicit CPU # -# Features: -# @savevm-monitor-nodes: If present, HMP command savevm only snapshots -# monitor-owned nodes if they have no parents. -# This allows the use of 'savevm' with -# -blockdev. (since 4.2) -# # Returns: the output of the command as a string # # Since: 0.14
@@ -243,8 +237,7 @@ ## { 'command': 'human-monitor-command', 'data': {'command-line': 'str', '*cpu-index': 'int'}, - 'returns': 'str', - 'features': [ 'savevm-monitor-nodes' ] } + 'returns': 'str' } ## # @getfd:
tests/qemu-iotests/172.out +76 -0
304 lines not on this page · raw message
Signature · 1 line
2.32.0
Quoted 27 lines · Denis V. Lunev
Commit
5f76a7aac156ca75680dad5df4a385fd0b58f6b1is looking harmless from the first glance, but it has changed things a lot. 'libvirt' uses it to detect that it should follow new initialization way and this changes things considerably. With this procedure followed,blockdev_init()is not called anymore and thusblock_acct_setup()helper is not called.This means in particular that defaults for block accounting statistics are changed and account_invalid/account_failed are actually initialized as false instead of true originally.
This commit changes things to match original world. There are the following constraints:
* new default value inblock_acct_init()is set to true
*block_acct_setup()insideblockdev_init()is called beforeblkconf_apply_backend_options()
* thus newly created option in block device properties has precedence if specifiedChanges from v2:
* calledbool_from_onoffauto(account_..., true)in the first patch to preserve original semantics before patch 2Changes from v1:
* set account_invalid/account_failed to true by default
* pass OnOffAuto toblock_acct_init()to handle double initialization (patch 1)
* changed properties on BLK device to OnOffAuto
Quoted 9 lines
Signed-off-by Denis V. Lunev <[email protected]>CC Peter Krempa <[email protected]>CC Markus Armbruster <[email protected]>CC John Snow <[email protected]>CC Kevin Wolf <[email protected]>CC Hanna Reitz <[email protected]>CC Vladimir Sementsov-Ogievskiy <[email protected]>
pls disregard, sorry