Skip to contentSkip to conversation

block: add missed block_acct_setup with new block device init procedure

PATCH Applied Denis V. Lunev 4 participants 7 messages Aug 24, 2022 – Sep 22, 2022 Block layer

lore
Share & tools
lore
#0 lore raw

v5 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 v4:
* removed hunk to QAPI which was used to test old initialization path
* added R-b: Vladimir

Changes from v3:
* fixed accidentally wrong submission. Contains changes which should be sent as v3

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

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]>
#1 lore raw

PATCH v5 1/2 block: pass OnOffAuto instead of bool to block_acct_setup()

We would have one more place for block_acct_setup() calling, which should not corrupt original value.

---
 block/accounting.c         | 22 ++++++++++++++++++----
 blockdev.c                 | 17 ++++++++++++++---
 include/block/accounting.h |  6 +++---
 3 files changed, 35 insertions(+), 10 deletions(-)
block/accounting.c +18 -4
index 2030851d79..6b300c5129 100644
@@ -40,11 +40,25 @@ void block_acct_init(BlockAcctStats *stats)
     }
 }
 
-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, true);
+    stats->account_failed = bool_from_onoffauto(account_failed, true);
 }
 
 void block_acct_cleanup(BlockAcctStats *stats)
blockdev.c +14 -3
index 9230888e34..392d9476e6 100644
@@ -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);
 
include/block/accounting.h +3 -3
index 878b4c3581..b9caad60d5 100644
@@ -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,
Signature · 1 line
2.32.0
#2 lore raw

PATCH v5 2/2 block: add missed block_acct_setup with new block device init procedure

In reply to Denis V. Lunev

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

---
 block/accounting.c         |  8 +++-
 hw/block/block.c           |  2 +
 include/hw/block/block.h   |  7 +++-
 tests/qemu-iotests/172.out | 76 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 90 insertions(+), 3 deletions(-)
block/accounting.c +6 -2
index 6b300c5129..2829745377 100644
@@ -38,6 +38,8 @@ void block_acct_init(BlockAcctStats *stats)
     if (qtest_enabled()) {
         clock_type = QEMU_CLOCK_VIRTUAL;
     }
+    stats->account_invalid = true;
+    stats->account_failed = true;
 }
 
 static bool bool_from_onoffauto(OnOffAuto val, bool def)
@@ -57,8 +59,10 @@ static bool bool_from_onoffauto(OnOffAuto val, bool def)
 void block_acct_setup(BlockAcctStats *stats, enum OnOffAuto account_invalid,
                       enum OnOffAuto account_failed)
 {
-    stats->account_invalid = bool_from_onoffauto(account_invalid, true);
-    stats->account_failed = bool_from_onoffauto(account_failed, true);
+    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)
hw/block/block.c +2 -0
index 04279166ee..f9c4fe6767 100644
@@ -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/hw/block/block.h +6 -1
index 5902c0440a..15fff66435 100644
@@ -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),                      \
tests/qemu-iotests/172.out +76 -0

304 lines not on this page · raw message

Signature · 1 line
2.32.0
#3 lore raw
In reply to Denis V. Lunev
Quoted 35 lines · Denis V. Lunev

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 v4:
* removed hunk to QAPI which was used to test old initialization path
* added R-b: Vladimir

Changes from v3:
* fixed accidentally wrong submission. Contains changes which should be sent as v3

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

Quoted 9 lines
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]>

ping

#4 lore raw
Quoted 45 lines · Denis V. Lunev
Quoted 35 lines · Denis V. Lunev

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 v4:
* removed hunk to QAPI which was used to test old initialization path
* added R-b: Vladimir

Changes from v3:
* fixed accidentally wrong submission. Contains changes which should be sent as v3

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

Quoted 9 lines
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]>
Quoted 1 line

ping

Can't find this series anymore. Care to resend?

#5 lore raw
In reply to Denis V. Lunev

Am 07.09.2022 um 19:25 hat Denis V. Lunev geschrieben:

Quoted 1 line

ping

I'll get to it (and quite a few other small series on the list that should be quick to review), but probably only after KVM Forum. So I'll have to ask you to be patient for a little longer.

Kevin

Applied
#6 lore raw
In reply to Denis V. Lunev

Am 24.08.2022 um 11:50 hat Denis V. Lunev geschrieben:

Quoted 10 lines

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.

Quoted 7 lines

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

Thanks, applied to the block branch.

Kevin