From patchwork Tue May 14 12:10:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 1099456 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="XkQA9k9O"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 453Gq42yMKz9sML for ; Tue, 14 May 2019 22:15:28 +1000 (AEST) Received: from localhost ([127.0.0.1]:47290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQWL8-0006cG-Cv for incoming@patchwork.ozlabs.org; Tue, 14 May 2019 08:15:26 -0400 Received: from eggs.gnu.org ([209.51.188.92]:32886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQWH3-0003cw-C3 for qemu-devel@nongnu.org; Tue, 14 May 2019 08:11:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQWH2-0002Gt-1L for qemu-devel@nongnu.org; Tue, 14 May 2019 08:11:13 -0400 Received: from mail-eopbgr10128.outbound.protection.outlook.com ([40.107.1.128]:12999 helo=EUR02-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hQWGu-00020g-9R; Tue, 14 May 2019 08:11:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K4YYf3PuR34VNjFvC7sGzLzq8045B+QePLtmcbZ/Udo=; b=XkQA9k9OUJ5Lfjmpoe7qJsd+5yqYubH9PGmGh24d/ISYoADXfhKJHf6O0OXgYM95AMsQsGuG9oamlgsM5zpyin1A1l6g0ilp5iIGQRlZP/sUFifVb2Mbb50r0QNoarGa0IPfwn/jA76+GS0LLUU6kynPeawcHBjO1Av9gkIv6i8= Received: from VI1PR08MB4078.eurprd08.prod.outlook.com (20.178.127.92) by VI1PR08MB4573.eurprd08.prod.outlook.com (20.178.126.206) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.16; Tue, 14 May 2019 12:10:50 +0000 Received: from VI1PR08MB4078.eurprd08.prod.outlook.com ([fe80::8ce8:ffb4:fe9:4900]) by VI1PR08MB4078.eurprd08.prod.outlook.com ([fe80::8ce8:ffb4:fe9:4900%3]) with mapi id 15.20.1878.024; Tue, 14 May 2019 12:10:50 +0000 From: Anton Nefedov To: "qemu-block@nongnu.org" Thread-Topic: [PATCH v7 9/9] qapi: query-blockstat: add driver specific file-posix stats Thread-Index: AQHVCk4SN315YgoU806PWwRT21zAmg== Date: Tue, 14 May 2019 12:10:50 +0000 Message-ID: <20190514121015.32190-10-anton.nefedov@virtuozzo.com> References: <20190514121015.32190-1-anton.nefedov@virtuozzo.com> In-Reply-To: <20190514121015.32190-1-anton.nefedov@virtuozzo.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1PR0701CA0057.eurprd07.prod.outlook.com (2603:10a6:3:9e::25) To VI1PR08MB4078.eurprd08.prod.outlook.com (2603:10a6:803:e5::28) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [185.231.240.5] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2fbdb9a2-8cd8-48cf-95a3-08d6d8653486 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328)(7193020); SRVR:VI1PR08MB4573; x-ms-traffictypediagnostic: VI1PR08MB4573: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:390; x-forefront-prvs: 0037FD6480 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39850400004)(136003)(376002)(346002)(396003)(366004)(199004)(189003)(386003)(6506007)(102836004)(305945005)(5640700003)(6436002)(66946007)(26005)(316002)(7736002)(6512007)(64756008)(66446008)(66556008)(107886003)(66476007)(73956011)(76176011)(11346002)(446003)(2906002)(6486002)(476003)(2616005)(3846002)(6916009)(25786009)(4326008)(2351001)(186003)(53936002)(6116002)(44832011)(486006)(86362001)(71190400001)(71200400001)(52116002)(50226002)(256004)(14444005)(66066001)(2501003)(1076003)(5660300002)(68736007)(8676002)(99286004)(14454004)(478600001)(36756003)(8936002)(81156014)(81166006)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR08MB4573; H:VI1PR08MB4078.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: JPXLvDrY8qgel2GrYy7mZdqxrVWC8NkonhTNwB3LDGxqylTY4QIHZI5wxJB33wWrik3G1wwg3toW7GTyKWN0LBL/+kLvDp2rKxM+nZIhR7y4uqchb+bTnLULkhjb+9nX6rYUe1HFxF/fFI/VkQjEH5Zh5pelnykSSpxW15KavAvp/MmkTjOEHx2GGBagLXUAKF+Uxff5NZu2yuIft10Ra+vDQviJFkIpqP8+BqtI3m23efrdcWI85aL5FZvlOGNj5JyBYXeG3zKCpJ7xT5l2r/E08CK7wdKcyM+GJwB6JYVqBElYEYqUknOpHE0+ST6UMzb+Bw6x2ul0UEckqYfdrCqfF1H1MgIAQMWq16m+GuBKDLs3jRoYb5Vbr+Je91pLURRVbiRKJPs233ADk2U/IOk8Ik9aT9SI49q4nj+ab6s= MIME-Version: 1.0 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2fbdb9a2-8cd8-48cf-95a3-08d6d8653486 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 May 2019 12:10:50.6337 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4573 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.1.128 Subject: [Qemu-devel] [PATCH v7 9/9] qapi: query-blockstat: add driver specific file-posix stats X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "kwolf@redhat.com" , Vladimir Sementsov-Ogievskiy , "berto@igalia.com" , Denis Lunev , "qemu-devel@nongnu.org" , "mreitz@redhat.com" , Anton Nefedov , "pbonzini@redhat.com" , "jsnow@redhat.com" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" A block driver can provide a callback to report driver-specific statistics. file-posix driver now reports discard statistics Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy Acked-by: Markus Armbruster --- qapi/block-core.json | 38 ++++++++++++++++++++++++++++++++++++++ include/block/block.h | 1 + include/block/block_int.h | 1 + block.c | 9 +++++++++ block/file-posix.c | 38 +++++++++++++++++++++++++++++++++++--- block/qapi.c | 5 +++++ 6 files changed, 89 insertions(+), 3 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 55194f84ce..368e09ae37 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -956,6 +956,41 @@ '*wr_latency_histogram': 'BlockLatencyHistogramInfo', '*flush_latency_histogram': 'BlockLatencyHistogramInfo' } } +## +# @BlockStatsSpecificFile: +# +# File driver statistics +# +# @discard-nb-ok: The number of successful 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: 4.1 +## +{ 'struct': 'BlockStatsSpecificFile', + 'data': { + 'discard-nb-ok': 'uint64', + 'discard-nb-failed': 'uint64', + 'discard-bytes-ok': 'uint64' } } + +## +# @BlockStatsSpecific: +# +# Block driver specific statistics +# +# Since: 4.1 +## +{ 'union': 'BlockStatsSpecific', + 'base': { 'driver': 'BlockdevDriver' }, + 'discriminator': 'driver', + 'data': { + 'file': 'BlockStatsSpecificFile', + 'host_device': 'BlockStatsSpecificFile' } } + ## # @BlockStats: # @@ -971,6 +1006,8 @@ # # @stats: A @BlockDeviceStats for the device. # +# @driver-specific: Optional driver-specific stats. (Since 4.1) +# # @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 @@ -984,6 +1021,7 @@ { 'struct': 'BlockStats', 'data': {'*device': 'str', '*qdev': 'str', '*node-name': 'str', 'stats': 'BlockDeviceStats', + '*driver-specific': 'BlockStatsSpecific', '*parent': 'BlockStats', '*backing': 'BlockStats'} } diff --git a/include/block/block.h b/include/block/block.h index 5e2b98b0ee..b182f0c7ae 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -490,6 +490,7 @@ int bdrv_get_flags(BlockDriverState *bs); int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi); ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs, Error **errp); +BlockStatsSpecific *bdrv_get_specific_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 94d45c9708..dc3bc97ea3 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -358,6 +358,7 @@ struct BlockDriver { int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi); ImageInfoSpecific *(*bdrv_get_specific_info)(BlockDriverState *bs, Error **errp); + BlockStatsSpecific *(*bdrv_get_specific_stats)(BlockDriverState *bs); int coroutine_fn (*bdrv_save_vmstate)(BlockDriverState *bs, QEMUIOVector *qiov, diff --git a/block.c b/block.c index 6999aad446..f68fb5aaec 100644 --- a/block.c +++ b/block.c @@ -4942,6 +4942,15 @@ ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs, return NULL; } +BlockStatsSpecific *bdrv_get_specific_stats(BlockDriverState *bs) +{ + BlockDriver *drv = bs->drv; + if (!drv || !drv->bdrv_get_specific_stats) { + return NULL; + } + return drv->bdrv_get_specific_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 76d54b3a85..a2f01cfe10 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -160,9 +160,9 @@ typedef struct BDRVRawState { bool drop_cache; bool check_cache_dropped; struct { - int64_t discard_nb_ok; - int64_t discard_nb_failed; - int64_t discard_bytes_ok; + uint64_t discard_nb_ok; + uint64_t discard_nb_failed; + uint64_t discard_bytes_ok; } stats; PRManager *pr_mgr; @@ -2723,6 +2723,36 @@ static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) return 0; } +static BlockStatsSpecificFile get_blockstats_specific_file(BlockDriverState *bs) +{ + BDRVRawState *s = bs->opaque; + return (BlockStatsSpecificFile) { + .discard_nb_ok = s->stats.discard_nb_ok, + .discard_nb_failed = s->stats.discard_nb_failed, + .discard_bytes_ok = s->stats.discard_bytes_ok, + }; +} + +static BlockStatsSpecific *raw_get_specific_stats(BlockDriverState *bs) +{ + BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1); + + stats->driver = BLOCKDEV_DRIVER_FILE; + stats->u.file = get_blockstats_specific_file(bs); + + return stats; +} + +static BlockStatsSpecific *hdev_get_specific_stats(BlockDriverState *bs) +{ + BlockStatsSpecific *stats = g_new(BlockStatsSpecific, 1); + + stats->driver = BLOCKDEV_DRIVER_HOST_DEVICE; + stats->u.host_device = get_blockstats_specific_file(bs); + + return stats; +} + static QemuOptsList raw_create_opts = { .name = "raw-create-opts", .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head), @@ -2922,6 +2952,7 @@ BlockDriver bdrv_file = { .bdrv_get_info = raw_get_info, .bdrv_get_allocated_file_size = raw_get_allocated_file_size, + .bdrv_get_specific_stats = raw_get_specific_stats, .bdrv_check_perm = raw_check_perm, .bdrv_set_perm = raw_set_perm, .bdrv_abort_perm_update = raw_abort_perm_update, @@ -3400,6 +3431,7 @@ static BlockDriver bdrv_host_device = { .bdrv_get_info = raw_get_info, .bdrv_get_allocated_file_size = raw_get_allocated_file_size, + .bdrv_get_specific_stats = hdev_get_specific_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 f9447a3297..3afcb9dc5c 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -537,6 +537,11 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs, s->stats->wr_highest_offset = stat64_get(&bs->wr_highest_offset); + s->driver_specific = bdrv_get_specific_stats(bs); + if (s->driver_specific) { + s->has_driver_specific = true; + } + if (bs->file) { s->has_parent = true; s->parent = bdrv_query_bds_stats(bs->file->bs, blk_level);