From: Anton Nefedov <anton.nefedov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, armbru@redhat.com,
jsnow@redhat.com, pbonzini@redhat.com, eblake@redhat.com,
den@virtuozzo.com, Anton Nefedov <anton.nefedov@virtuozzo.com>
Subject: [Qemu-devel] [PATCH 7/7] qapi: query-blockstat: add driver specific file-posix stats
Date: Mon, 20 Nov 2017 19:51:04 +0300 [thread overview]
Message-ID: <1511196664-85304-8-git-send-email-anton.nefedov@virtuozzo.com> (raw)
In-Reply-To: <1511196664-85304-1-git-send-email-anton.nefedov@virtuozzo.com>
A block driver can provide a callback to report driver-specific
statistics.
file-posix driver now reports discard statistics
Signed-off-by: Anton Nefedov <anton.nefedov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
qapi/block-core.json | 37 +++++++++++++++++++++++++++++++++++++
include/block/block.h | 1 +
include/block/block_int.h | 1 +
block.c | 9 +++++++++
block/file-posix.c | 21 +++++++++++++++++++++
block/qapi.c | 5 +++++
6 files changed, 74 insertions(+)
diff --git a/qapi/block-core.json b/qapi/block-core.json
index ba2705d..aefccf6 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -765,6 +765,40 @@
'timed_stats': ['BlockDeviceTimedStats'] } }
##
+# @BlockDriverStatsFile:
+#
+# File driver statistics
+#
+# @discard_nb_ok: The number of succeeded discard operations performed by
+# the driver.
+#
+# @discard_nb_failed: The number of failed discard operations performed by
+# the driver.
+#
+# @discard_bytes_ok: The number of bytes discarded by the driver.
+#
+# Since 2.12
+##
+{ 'struct': 'BlockDriverStatsFile',
+ 'data': {
+ 'discard_nb_ok': 'int',
+ 'discard_nb_failed': 'int',
+ 'discard_bytes_ok': 'int'
+ } }
+
+##
+# @BlockDriverStats:
+#
+# Statistics of a block driver (driver-specific)
+#
+# Since: 2.12
+##
+{ 'union': 'BlockDriverStats',
+ 'data': {
+ 'file': 'BlockDriverStatsFile'
+ } }
+
+##
# @BlockStats:
#
# Statistics of a virtual block device or a block backing device.
@@ -776,6 +810,8 @@
#
# @stats: A @BlockDeviceStats for the device.
#
+# @driver-stats: Optional driver-specific statistics. (Since 2.12)
+#
# @parent: This describes the file block device if it has one.
# Contains recursively the statistics of the underlying
# protocol (e.g. the host file for a qcow2 image). If there is
@@ -789,6 +825,7 @@
{ 'struct': 'BlockStats',
'data': {'*device': 'str', '*node-name': 'str',
'stats': 'BlockDeviceStats',
+ '*driver-stats': 'BlockDriverStats',
'*parent': 'BlockStats',
'*backing': 'BlockStats'} }
diff --git a/include/block/block.h b/include/block/block.h
index c05cac5..e6baead 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -473,6 +473,7 @@ const char *bdrv_get_device_or_node_name(const BlockDriverState *bs);
int bdrv_get_flags(BlockDriverState *bs);
int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs);
+BlockDriverStats *bdrv_get_driver_stats(BlockDriverState *bs);
void bdrv_round_to_clusters(BlockDriverState *bs,
int64_t offset, int64_t bytes,
int64_t *cluster_offset,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index a548277..a127861 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -269,6 +269,7 @@ struct BlockDriver {
Error **errp);
int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
ImageInfoSpecific *(*bdrv_get_specific_info)(BlockDriverState *bs);
+ BlockDriverStats *(*bdrv_get_stats)(BlockDriverState *bs);
int coroutine_fn (*bdrv_save_vmstate)(BlockDriverState *bs,
QEMUIOVector *qiov,
diff --git a/block.c b/block.c
index 6c8ef98..7e5822f 100644
--- a/block.c
+++ b/block.c
@@ -4016,6 +4016,15 @@ ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs)
return NULL;
}
+BlockDriverStats *bdrv_get_driver_stats(BlockDriverState *bs)
+{
+ BlockDriver *drv = bs->drv;
+ if (!drv || !drv->bdrv_get_stats) {
+ return NULL;
+ }
+ return drv->bdrv_get_stats(bs);
+}
+
void bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event)
{
if (!bs || !bs->drv || !bs->drv->bdrv_debug_event) {
diff --git a/block/file-posix.c b/block/file-posix.c
index 544ae58..3ab92e6 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2240,6 +2240,25 @@ static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return 0;
}
+static BlockDriverStats *raw_get_stats(BlockDriverState *bs)
+{
+ BDRVRawState *s = bs->opaque;
+ BlockDriverStats *stats = g_new(BlockDriverStats, 1);
+
+ *stats = (BlockDriverStats){
+ .type = BLOCK_DRIVER_STATS_KIND_FILE,
+ .u.file.data = g_new(BlockDriverStatsFile, 1),
+ };
+
+ *stats->u.file.data = (BlockDriverStatsFile){
+ .discard_nb_ok = s->stats.discard_nb_ok,
+ .discard_nb_failed = s->stats.discard_nb_failed,
+ .discard_bytes_ok = s->stats.discard_bytes_ok,
+ };
+
+ return stats;
+}
+
static QemuOptsList raw_create_opts = {
.name = "raw-create-opts",
.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
@@ -2312,6 +2331,7 @@ BlockDriver bdrv_file = {
.bdrv_get_info = raw_get_info,
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
+ .bdrv_get_stats = raw_get_stats,
.bdrv_check_perm = raw_check_perm,
.bdrv_set_perm = raw_set_perm,
.bdrv_abort_perm_update = raw_abort_perm_update,
@@ -2790,6 +2810,7 @@ static BlockDriver bdrv_host_device = {
.bdrv_get_info = raw_get_info,
.bdrv_get_allocated_file_size
= raw_get_allocated_file_size,
+ .bdrv_get_stats = raw_get_stats,
.bdrv_check_perm = raw_check_perm,
.bdrv_set_perm = raw_set_perm,
.bdrv_abort_perm_update = raw_abort_perm_update,
diff --git a/block/qapi.c b/block/qapi.c
index 6e110f2..4191e6c 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -489,6 +489,11 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
s->stats->wr_highest_offset = stat64_get(&bs->wr_highest_offset);
+ s->driver_stats = bdrv_get_driver_stats(bs);
+ if (s->driver_stats) {
+ s->has_driver_stats = true;
+ }
+
if (bs->file) {
s->has_parent = true;
s->parent = bdrv_query_bds_stats(bs->file->bs, blk_level);
--
2.7.4
next prev parent reply other threads:[~2017-11-20 16:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-20 16:50 [Qemu-devel] [PATCH 0/7] discard blockstats Anton Nefedov
2017-11-20 16:50 ` [Qemu-devel] [PATCH 1/7] qapi: add unmap to BlockDeviceStats Anton Nefedov
2017-12-05 15:09 ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2017-12-05 15:19 ` Eric Blake
2017-12-05 17:15 ` Anton Nefedov
2017-11-20 16:50 ` [Qemu-devel] [PATCH 2/7] ide: account UNMAP (TRIM) operations Anton Nefedov
2017-12-05 15:21 ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2017-12-05 17:14 ` Anton Nefedov
2017-12-06 22:09 ` John Snow
2017-11-20 16:51 ` [Qemu-devel] [PATCH 3/7] scsi: store unmap offset and nb_sectors in request struct Anton Nefedov
2017-12-11 15:12 ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2017-11-20 16:51 ` [Qemu-devel] [PATCH 4/7] scsi: move unmap error checking to the complete callback Anton Nefedov
2017-11-20 16:51 ` [Qemu-devel] [PATCH 5/7] scsi: account unmap operations Anton Nefedov
2017-11-20 16:51 ` [Qemu-devel] [PATCH 6/7] file-posix: account discard operations Anton Nefedov
2017-11-20 16:51 ` Anton Nefedov [this message]
2018-08-17 17:27 ` [Qemu-devel] [PATCH 0/7] discard blockstats Paolo Bonzini
2018-08-20 10:02 ` Anton Nefedov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1511196664-85304-8-git-send-email-anton.nefedov@virtuozzo.com \
--to=anton.nefedov@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=den@virtuozzo.com \
--cc=eblake@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).