Skip to content

Commit

Permalink
block: pass OnOffAuto instead of bool to block_acct_setup()
Browse files Browse the repository at this point in the history
We would have one more place for block_acct_setup() calling, which should
not corrupt original value.

Signed-off-by: Denis V. Lunev <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[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]>
Message-Id: <[email protected]>
Reviewed-by: Kevin Wolf <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
Denis V. Lunev authored and kevmw committed Sep 30, 2022
1 parent 7f118b4 commit b2aaf35
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
22 changes: 18 additions & 4 deletions block/accounting.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 14 additions & 3 deletions blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,25 @@ 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)
{
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;
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions include/block/accounting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b2aaf35

Please sign in to comment.