mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-11 03:24:58 -06:00
block: make 'stats-interval' an array of ints instead of a string
This is the natural JSON representation and prevents us from having to decode the list manually. Signed-off-by: Alberto Garcia <berto@igalia.com> Message-id: 0e3da8fa206f4ab534ae3ce6086e75fe84f1557e.1447665472.git.berto@igalia.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
0ed39f3df2
commit
40119effc5
3 changed files with 61 additions and 39 deletions
85
blockdev.c
85
blockdev.c
|
@ -300,6 +300,45 @@ static int parse_block_error_action(const char *buf, bool is_read, Error **errp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool parse_stats_intervals(BlockAcctStats *stats, QList *intervals,
|
||||||
|
Error **errp)
|
||||||
|
{
|
||||||
|
const QListEntry *entry;
|
||||||
|
for (entry = qlist_first(intervals); entry; entry = qlist_next(entry)) {
|
||||||
|
switch (qobject_type(entry->value)) {
|
||||||
|
|
||||||
|
case QTYPE_QSTRING: {
|
||||||
|
unsigned long long length;
|
||||||
|
const char *str = qstring_get_str(qobject_to_qstring(entry->value));
|
||||||
|
if (parse_uint_full(str, &length, 10) == 0 &&
|
||||||
|
length > 0 && length <= UINT_MAX) {
|
||||||
|
block_acct_add_interval(stats, (unsigned) length);
|
||||||
|
} else {
|
||||||
|
error_setg(errp, "Invalid interval length: %s", str);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case QTYPE_QINT: {
|
||||||
|
int64_t length = qint_get_int(qobject_to_qint(entry->value));
|
||||||
|
if (length > 0 && length <= UINT_MAX) {
|
||||||
|
block_acct_add_interval(stats, (unsigned) length);
|
||||||
|
} else {
|
||||||
|
error_setg(errp, "Invalid interval length: %" PRId64, length);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
error_setg(errp, "The specification of stats-intervals is invalid");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)
|
static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)
|
||||||
{
|
{
|
||||||
if (throttle_conflicting(cfg)) {
|
if (throttle_conflicting(cfg)) {
|
||||||
|
@ -442,13 +481,14 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
|
||||||
int bdrv_flags = 0;
|
int bdrv_flags = 0;
|
||||||
int on_read_error, on_write_error;
|
int on_read_error, on_write_error;
|
||||||
bool account_invalid, account_failed;
|
bool account_invalid, account_failed;
|
||||||
const char *stats_intervals;
|
|
||||||
BlockBackend *blk;
|
BlockBackend *blk;
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
ThrottleConfig cfg;
|
ThrottleConfig cfg;
|
||||||
int snapshot = 0;
|
int snapshot = 0;
|
||||||
Error *error = NULL;
|
Error *error = NULL;
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
|
QDict *interval_dict = NULL;
|
||||||
|
QList *interval_list = NULL;
|
||||||
const char *id;
|
const char *id;
|
||||||
bool has_driver_specific_opts;
|
bool has_driver_specific_opts;
|
||||||
BlockdevDetectZeroesOptions detect_zeroes =
|
BlockdevDetectZeroesOptions detect_zeroes =
|
||||||
|
@ -482,7 +522,14 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
|
||||||
account_invalid = qemu_opt_get_bool(opts, "stats-account-invalid", true);
|
account_invalid = qemu_opt_get_bool(opts, "stats-account-invalid", true);
|
||||||
account_failed = qemu_opt_get_bool(opts, "stats-account-failed", true);
|
account_failed = qemu_opt_get_bool(opts, "stats-account-failed", true);
|
||||||
|
|
||||||
stats_intervals = qemu_opt_get(opts, "stats-intervals");
|
qdict_extract_subqdict(bs_opts, &interval_dict, "stats-intervals.");
|
||||||
|
qdict_array_split(interval_dict, &interval_list);
|
||||||
|
|
||||||
|
if (qdict_size(interval_dict) != 0) {
|
||||||
|
error_setg(errp, "Invalid option stats-intervals.%s",
|
||||||
|
qdict_first(interval_dict)->key);
|
||||||
|
goto early_err;
|
||||||
|
}
|
||||||
|
|
||||||
extract_common_blockdev_options(opts, &bdrv_flags, &throttling_group, &cfg,
|
extract_common_blockdev_options(opts, &bdrv_flags, &throttling_group, &cfg,
|
||||||
&detect_zeroes, &error);
|
&detect_zeroes, &error);
|
||||||
|
@ -583,44 +630,25 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
|
||||||
|
|
||||||
block_acct_init(blk_get_stats(blk), account_invalid, account_failed);
|
block_acct_init(blk_get_stats(blk), account_invalid, account_failed);
|
||||||
|
|
||||||
if (stats_intervals) {
|
if (!parse_stats_intervals(blk_get_stats(blk), interval_list, errp)) {
|
||||||
char **intervals = g_strsplit(stats_intervals, ":", 0);
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
if (*stats_intervals == '\0') {
|
|
||||||
error_setg(&error, "stats-intervals can't have an empty value");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; !error && intervals[i] != NULL; i++) {
|
|
||||||
unsigned long long val;
|
|
||||||
if (parse_uint_full(intervals[i], &val, 10) == 0 &&
|
|
||||||
val > 0 && val <= UINT_MAX) {
|
|
||||||
block_acct_add_interval(blk_get_stats(blk), val);
|
|
||||||
} else {
|
|
||||||
error_setg(&error, "Invalid interval length: '%s'",
|
|
||||||
intervals[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_strfreev(intervals);
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
error_propagate(errp, error);
|
|
||||||
blk_unref(blk);
|
blk_unref(blk);
|
||||||
blk = NULL;
|
blk = NULL;
|
||||||
goto err_no_bs_opts;
|
goto err_no_bs_opts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
blk_set_on_error(blk, on_read_error, on_write_error);
|
blk_set_on_error(blk, on_read_error, on_write_error);
|
||||||
|
|
||||||
err_no_bs_opts:
|
err_no_bs_opts:
|
||||||
qemu_opts_del(opts);
|
qemu_opts_del(opts);
|
||||||
|
QDECREF(interval_dict);
|
||||||
|
QDECREF(interval_list);
|
||||||
return blk;
|
return blk;
|
||||||
|
|
||||||
early_err:
|
early_err:
|
||||||
qemu_opts_del(opts);
|
qemu_opts_del(opts);
|
||||||
|
QDECREF(interval_dict);
|
||||||
|
QDECREF(interval_list);
|
||||||
err_no_opts:
|
err_no_opts:
|
||||||
QDECREF(bs_opts);
|
QDECREF(bs_opts);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3948,11 +3976,6 @@ QemuOptsList qemu_common_drive_opts = {
|
||||||
.type = QEMU_OPT_BOOL,
|
.type = QEMU_OPT_BOOL,
|
||||||
.help = "whether to account for failed I/O operations "
|
.help = "whether to account for failed I/O operations "
|
||||||
"in the statistics",
|
"in the statistics",
|
||||||
},{
|
|
||||||
.name = "stats-intervals",
|
|
||||||
.type = QEMU_OPT_STRING,
|
|
||||||
.help = "colon-separated list of intervals "
|
|
||||||
"for collecting I/O statistics, in seconds",
|
|
||||||
},
|
},
|
||||||
{ /* end of list */ }
|
{ /* end of list */ }
|
||||||
},
|
},
|
||||||
|
|
|
@ -1531,9 +1531,8 @@
|
||||||
# @stats-account-failed: #optional whether to include failed
|
# @stats-account-failed: #optional whether to include failed
|
||||||
# operations when computing latency and last
|
# operations when computing latency and last
|
||||||
# access statistics (default: true) (Since 2.5)
|
# access statistics (default: true) (Since 2.5)
|
||||||
# @stats-intervals: #optional colon-separated list of intervals for
|
# @stats-intervals: #optional list of intervals for collecting I/O
|
||||||
# collecting I/O statistics, in seconds (default: none)
|
# statistics, in seconds (default: none) (Since 2.5)
|
||||||
# (Since 2.5)
|
|
||||||
# @detect-zeroes: #optional detect and optimize zero writes (Since 2.1)
|
# @detect-zeroes: #optional detect and optimize zero writes (Since 2.1)
|
||||||
# (default: off)
|
# (default: off)
|
||||||
#
|
#
|
||||||
|
@ -1551,7 +1550,7 @@
|
||||||
'*read-only': 'bool',
|
'*read-only': 'bool',
|
||||||
'*stats-account-invalid': 'bool',
|
'*stats-account-invalid': 'bool',
|
||||||
'*stats-account-failed': 'bool',
|
'*stats-account-failed': 'bool',
|
||||||
'*stats-intervals': 'str',
|
'*stats-intervals': ['int'],
|
||||||
'*detect-zeroes': 'BlockdevDetectZeroesOptions' } }
|
'*detect-zeroes': 'BlockdevDetectZeroesOptions' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
@ -69,7 +69,7 @@ sector = "%d"
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
drive_args = []
|
drive_args = []
|
||||||
drive_args.append("stats-intervals=%d" % interval_length)
|
drive_args.append("stats-intervals.0=%d" % interval_length)
|
||||||
drive_args.append("stats-account-invalid=%s" %
|
drive_args.append("stats-account-invalid=%s" %
|
||||||
(self.account_invalid and "on" or "off"))
|
(self.account_invalid and "on" or "off"))
|
||||||
drive_args.append("stats-account-failed=%s" %
|
drive_args.append("stats-account-failed=%s" %
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue