From patchwork Thu May 16 14:33:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10946747 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1BCC814DB for ; Thu, 16 May 2019 14:38:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C0E42883F for ; Thu, 16 May 2019 14:38:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F36C728AC2; Thu, 16 May 2019 14:38:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 97C662883F for ; Thu, 16 May 2019 14:38:36 +0000 (UTC) Received: from localhost ([127.0.0.1]:59196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHWl-0003ir-UT for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 May 2019 10:38:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHRs-00080n-Tr for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRHRr-0004KV-Ix for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:32 -0400 Received: from relay.sw.ru ([185.231.240.75]:39664) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRHRm-0004DO-TS; Thu, 16 May 2019 10:33:27 -0400 Received: from [172.16.25.154] (helo=xantnef-ws.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hRHRl-0007Lk-9V; Thu, 16 May 2019 17:33:25 +0300 From: Anton Nefedov To: qemu-block@nongnu.org Date: Thu, 16 May 2019 17:33:06 +0300 Message-Id: <20190516143314.81302-2-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> References: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v8 1/9] qapi: group BlockDeviceStats fields 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, vsementsov@virtuozzo.com, berto@igalia.com, den@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, Anton Nefedov , pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Make the stat fields definition slightly more readable. Also reorder total_time_ns stats read-write-flush as done elsewhere. Cosmetic change only. Signed-off-by: Anton Nefedov Reviewed-by: Alberto Garcia Reviewed-by: Vladimir Sementsov-Ogievskiy --- qapi/block-core.json | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 7ccbfff9d0..754d07f1fb 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -863,12 +863,12 @@ # @flush_operations: The number of cache flush operations performed by the # device (since 0.15.0) # -# @flush_total_time_ns: Total time spend on cache flushes in nano-seconds -# (since 0.15.0). +# @rd_total_time_ns: Total time spent on reads in nanoseconds (since 0.15.0). # -# @wr_total_time_ns: Total time spend on writes in nano-seconds (since 0.15.0). +# @wr_total_time_ns: Total time spent on writes in nanoseconds (since 0.15.0). # -# @rd_total_time_ns: Total_time_spend on reads in nano-seconds (since 0.15.0). +# @flush_total_time_ns: Total time spent on cache flushes in nanoseconds +# (since 0.15.0). # # @wr_highest_offset: The offset after the greatest byte written to the # device. The intended use of this information is for @@ -921,14 +921,18 @@ # Since: 0.14.0 ## { 'struct': 'BlockDeviceStats', - 'data': {'rd_bytes': 'int', 'wr_bytes': 'int', 'rd_operations': 'int', - 'wr_operations': 'int', 'flush_operations': 'int', - 'flush_total_time_ns': 'int', 'wr_total_time_ns': 'int', - 'rd_total_time_ns': 'int', 'wr_highest_offset': 'int', - 'rd_merged': 'int', 'wr_merged': 'int', '*idle_time_ns': 'int', + 'data': {'rd_bytes': 'int', 'wr_bytes': 'int', + 'rd_operations': 'int', 'wr_operations': 'int', + 'flush_operations': 'int', + 'rd_total_time_ns': 'int', 'wr_total_time_ns': 'int', + 'flush_total_time_ns': 'int', + 'wr_highest_offset': 'int', + 'rd_merged': 'int', 'wr_merged': 'int', + '*idle_time_ns': 'int', 'failed_rd_operations': 'int', 'failed_wr_operations': 'int', - 'failed_flush_operations': 'int', 'invalid_rd_operations': 'int', - 'invalid_wr_operations': 'int', 'invalid_flush_operations': 'int', + 'failed_flush_operations': 'int', + 'invalid_rd_operations': 'int', 'invalid_wr_operations': 'int', + 'invalid_flush_operations': 'int', 'account_invalid': 'bool', 'account_failed': 'bool', 'timed_stats': ['BlockDeviceTimedStats'], '*rd_latency_histogram': 'BlockLatencyHistogramInfo', From patchwork Thu May 16 14:33:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10946753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5AE36924 for ; Thu, 16 May 2019 14:40:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48E4E28D3F for ; Thu, 16 May 2019 14:40:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4617F28D78; Thu, 16 May 2019 14:40:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6B52328D5E for ; Thu, 16 May 2019 14:40:55 +0000 (UTC) Received: from localhost ([127.0.0.1]:59256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHZ0-0005ZP-CE for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 May 2019 10:40:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHRt-00081V-GU for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRHRr-0004Jx-EU for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:33 -0400 Received: from relay.sw.ru ([185.231.240.75]:39668) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRHRm-0004DN-VK; Thu, 16 May 2019 10:33:27 -0400 Received: from [172.16.25.154] (helo=xantnef-ws.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hRHRl-0007Lk-CE; Thu, 16 May 2019 17:33:25 +0300 From: Anton Nefedov To: qemu-block@nongnu.org Date: Thu, 16 May 2019 17:33:07 +0300 Message-Id: <20190516143314.81302-3-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> References: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v8 2/9] qapi: add unmap to BlockDeviceStats 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, vsementsov@virtuozzo.com, berto@igalia.com, den@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, Anton Nefedov , pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake --- qapi/block-core.json | 29 +++++++++++++++++++++++------ include/block/accounting.h | 1 + block/qapi.c | 6 ++++++ tests/qemu-iotests/227.out | 18 ++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 754d07f1fb..55194f84ce 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -856,6 +856,8 @@ # # @wr_bytes: The number of bytes written by the device. # +# @unmap_bytes: The number of bytes unmapped by the device (Since 4.1) +# # @rd_operations: The number of read operations performed by the device. # # @wr_operations: The number of write operations performed by the device. @@ -863,6 +865,9 @@ # @flush_operations: The number of cache flush operations performed by the # device (since 0.15.0) # +# @unmap_operations: The number of unmap operations performed by the device +# (Since 4.1) +# # @rd_total_time_ns: Total time spent on reads in nanoseconds (since 0.15.0). # # @wr_total_time_ns: Total time spent on writes in nanoseconds (since 0.15.0). @@ -870,6 +875,9 @@ # @flush_total_time_ns: Total time spent on cache flushes in nanoseconds # (since 0.15.0). # +# @unmap_total_time_ns: Total time spent on unmap operations in nanoseconds +# (Since 4.1) +# # @wr_highest_offset: The offset after the greatest byte written to the # device. The intended use of this information is for # growable sparse files (like qcow2) that are used on top @@ -881,6 +889,9 @@ # @wr_merged: Number of write requests that have been merged into another # request (Since 2.3). # +# @unmap_merged: Number of unmap requests that have been merged into another +# request (Since 4.1) +# # @idle_time_ns: Time since the last I/O operation, in # nanoseconds. If the field is absent it means that # there haven't been any operations yet (Since 2.5). @@ -894,6 +905,9 @@ # @failed_flush_operations: The number of failed flush operations # performed by the device (Since 2.5) # +# @failed_unmap_operations: The number of failed unmap operations performed +# by the device (Since 4.1) +# # @invalid_rd_operations: The number of invalid read operations # performed by the device (Since 2.5) # @@ -903,6 +917,9 @@ # @invalid_flush_operations: The number of invalid flush operations # performed by the device (Since 2.5) # +# @invalid_unmap_operations: The number of invalid unmap operations performed +# by the device (Since 4.1) +# # @account_invalid: Whether invalid operations are included in the # last access statistics (Since 2.5) # @@ -921,18 +938,18 @@ # Since: 0.14.0 ## { 'struct': 'BlockDeviceStats', - 'data': {'rd_bytes': 'int', 'wr_bytes': 'int', + 'data': {'rd_bytes': 'int', 'wr_bytes': 'int', 'unmap_bytes' : 'int', 'rd_operations': 'int', 'wr_operations': 'int', - 'flush_operations': 'int', + 'flush_operations': 'int', 'unmap_operations': 'int', 'rd_total_time_ns': 'int', 'wr_total_time_ns': 'int', - 'flush_total_time_ns': 'int', + 'flush_total_time_ns': 'int', 'unmap_total_time_ns': 'int', 'wr_highest_offset': 'int', - 'rd_merged': 'int', 'wr_merged': 'int', + 'rd_merged': 'int', 'wr_merged': 'int', 'unmap_merged': 'int', '*idle_time_ns': 'int', 'failed_rd_operations': 'int', 'failed_wr_operations': 'int', - 'failed_flush_operations': 'int', + 'failed_flush_operations': 'int', 'failed_unmap_operations': 'int', 'invalid_rd_operations': 'int', 'invalid_wr_operations': 'int', - 'invalid_flush_operations': 'int', + 'invalid_flush_operations': 'int', 'invalid_unmap_operations': 'int', 'account_invalid': 'bool', 'account_failed': 'bool', 'timed_stats': ['BlockDeviceTimedStats'], '*rd_latency_histogram': 'BlockLatencyHistogramInfo', diff --git a/include/block/accounting.h b/include/block/accounting.h index d1f67b10dd..ba8b04d572 100644 --- a/include/block/accounting.h +++ b/include/block/accounting.h @@ -36,6 +36,7 @@ enum BlockAcctType { BLOCK_ACCT_READ, BLOCK_ACCT_WRITE, BLOCK_ACCT_FLUSH, + BLOCK_ACCT_UNMAP, BLOCK_MAX_IOTYPE, }; diff --git a/block/qapi.c b/block/qapi.c index 0c13c86f4e..f9447a3297 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -434,24 +434,30 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk) ds->rd_bytes = stats->nr_bytes[BLOCK_ACCT_READ]; ds->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE]; + ds->unmap_bytes = stats->nr_bytes[BLOCK_ACCT_UNMAP]; ds->rd_operations = stats->nr_ops[BLOCK_ACCT_READ]; ds->wr_operations = stats->nr_ops[BLOCK_ACCT_WRITE]; + ds->unmap_operations = stats->nr_ops[BLOCK_ACCT_UNMAP]; ds->failed_rd_operations = stats->failed_ops[BLOCK_ACCT_READ]; ds->failed_wr_operations = stats->failed_ops[BLOCK_ACCT_WRITE]; ds->failed_flush_operations = stats->failed_ops[BLOCK_ACCT_FLUSH]; + ds->failed_unmap_operations = stats->failed_ops[BLOCK_ACCT_UNMAP]; ds->invalid_rd_operations = stats->invalid_ops[BLOCK_ACCT_READ]; ds->invalid_wr_operations = stats->invalid_ops[BLOCK_ACCT_WRITE]; ds->invalid_flush_operations = stats->invalid_ops[BLOCK_ACCT_FLUSH]; + ds->invalid_unmap_operations = stats->invalid_ops[BLOCK_ACCT_UNMAP]; ds->rd_merged = stats->merged[BLOCK_ACCT_READ]; ds->wr_merged = stats->merged[BLOCK_ACCT_WRITE]; + ds->unmap_merged = stats->merged[BLOCK_ACCT_UNMAP]; ds->flush_operations = stats->nr_ops[BLOCK_ACCT_FLUSH]; ds->wr_total_time_ns = stats->total_time_ns[BLOCK_ACCT_WRITE]; ds->rd_total_time_ns = stats->total_time_ns[BLOCK_ACCT_READ]; ds->flush_total_time_ns = stats->total_time_ns[BLOCK_ACCT_FLUSH]; + ds->unmap_total_time_ns = stats->total_time_ns[BLOCK_ACCT_UNMAP]; ds->has_idle_time_ns = stats->last_access_time_ns > 0; if (ds->has_idle_time_ns) { diff --git a/tests/qemu-iotests/227.out b/tests/qemu-iotests/227.out index e77efaf4cf..e9ab4d21f9 100644 --- a/tests/qemu-iotests/227.out +++ b/tests/qemu-iotests/227.out @@ -15,6 +15,8 @@ Testing: -drive driver=null-co,if=virtio { "device": "virtio0", "stats": { + "unmap_operations": 0, + "unmap_merged": 0, "flush_total_time_ns": 0, "wr_highest_offset": 0, "wr_total_time_ns": 0, @@ -24,13 +26,17 @@ Testing: -drive driver=null-co,if=virtio "wr_bytes": 0, "timed_stats": [ ], + "failed_unmap_operations": 0, "failed_flush_operations": 0, "account_invalid": true, "rd_total_time_ns": 0, + "invalid_unmap_operations": 0, "flush_operations": 0, "wr_operations": 0, + "unmap_bytes": 0, "rd_merged": 0, "rd_bytes": 0, + "unmap_total_time_ns": 0, "invalid_flush_operations": 0, "account_failed": true, "rd_operations": 0, @@ -74,6 +80,8 @@ Testing: -drive driver=null-co,if=none { "device": "none0", "stats": { + "unmap_operations": 0, + "unmap_merged": 0, "flush_total_time_ns": 0, "wr_highest_offset": 0, "wr_total_time_ns": 0, @@ -83,13 +91,17 @@ Testing: -drive driver=null-co,if=none "wr_bytes": 0, "timed_stats": [ ], + "failed_unmap_operations": 0, "failed_flush_operations": 0, "account_invalid": true, "rd_total_time_ns": 0, + "invalid_unmap_operations": 0, "flush_operations": 0, "wr_operations": 0, + "unmap_bytes": 0, "rd_merged": 0, "rd_bytes": 0, + "unmap_total_time_ns": 0, "invalid_flush_operations": 0, "account_failed": true, "rd_operations": 0, @@ -163,6 +175,8 @@ Testing: -blockdev driver=null-co,node-name=null -device virtio-blk,drive=null,i { "device": "", "stats": { + "unmap_operations": 0, + "unmap_merged": 0, "flush_total_time_ns": 0, "wr_highest_offset": 0, "wr_total_time_ns": 0, @@ -172,13 +186,17 @@ Testing: -blockdev driver=null-co,node-name=null -device virtio-blk,drive=null,i "wr_bytes": 0, "timed_stats": [ ], + "failed_unmap_operations": 0, "failed_flush_operations": 0, "account_invalid": false, "rd_total_time_ns": 0, + "invalid_unmap_operations": 0, "flush_operations": 0, "wr_operations": 0, + "unmap_bytes": 0, "rd_merged": 0, "rd_bytes": 0, + "unmap_total_time_ns": 0, "invalid_flush_operations": 0, "account_failed": false, "rd_operations": 0, From patchwork Thu May 16 14:33:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10946749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA3A614DB for ; Thu, 16 May 2019 14:38:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D94EE2883F for ; Thu, 16 May 2019 14:38:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD0E928A94; Thu, 16 May 2019 14:38:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A41A528A6E for ; Thu, 16 May 2019 14:38:36 +0000 (UTC) Received: from localhost ([127.0.0.1]:59194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHWl-0003iR-Pp for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 May 2019 10:38:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHRs-00080l-S8 for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRHRr-0004KO-GN for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:32 -0400 Received: from relay.sw.ru ([185.231.240.75]:39672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRHRm-0004DP-Ur; Thu, 16 May 2019 10:33:27 -0400 Received: from [172.16.25.154] (helo=xantnef-ws.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hRHRl-0007Lk-Ff; Thu, 16 May 2019 17:33:25 +0300 From: Anton Nefedov To: qemu-block@nongnu.org Date: Thu, 16 May 2019 17:33:08 +0300 Message-Id: <20190516143314.81302-4-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> References: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v8 3/9] block: add empty account cookie type 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, vsementsov@virtuozzo.com, berto@igalia.com, den@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, Anton Nefedov , pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This adds some protection from accounting uninitialized cookie. That is, block_acct_failed/done without previous block_acct_start; in that case, cookie probably holds values from previous operation. (Note: it might also be uninitialized holding garbage value and there is still "< BLOCK_MAX_IOTYPE" assertion for that. So block_acct_failed/done without previous block_acct_start should be used with caution.) Currently this is particularly useful in ide code where it's hard to keep track whether the request started accounting or not. For example, trim requests do the accounting separately. Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/accounting.h | 1 + block/accounting.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/block/accounting.h b/include/block/accounting.h index ba8b04d572..878b4c3581 100644 --- a/include/block/accounting.h +++ b/include/block/accounting.h @@ -33,6 +33,7 @@ typedef struct BlockAcctTimedStats BlockAcctTimedStats; typedef struct BlockAcctStats BlockAcctStats; enum BlockAcctType { + BLOCK_ACCT_NONE = 0, BLOCK_ACCT_READ, BLOCK_ACCT_WRITE, BLOCK_ACCT_FLUSH, diff --git a/block/accounting.c b/block/accounting.c index 70a3d9a426..8d41c8a83a 100644 --- a/block/accounting.c +++ b/block/accounting.c @@ -195,6 +195,10 @@ static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie, assert(cookie->type < BLOCK_MAX_IOTYPE); + if (cookie->type == BLOCK_ACCT_NONE) { + return; + } + qemu_mutex_lock(&stats->lock); if (failed) { @@ -217,6 +221,8 @@ static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *cookie, } qemu_mutex_unlock(&stats->lock); + + cookie->type = BLOCK_ACCT_NONE; } void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie) From patchwork Thu May 16 14:33:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10946743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 454D36C5 for ; Thu, 16 May 2019 14:35:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36CA528CFB for ; Thu, 16 May 2019 14:35:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 353A328CFF; Thu, 16 May 2019 14:35:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E309728CFB for ; Thu, 16 May 2019 14:35:46 +0000 (UTC) Received: from localhost ([127.0.0.1]:59165 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHU2-0001LD-61 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 May 2019 10:35:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHRs-000806-HH for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRHRr-0004KH-H6 for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:32 -0400 Received: from relay.sw.ru ([185.231.240.75]:39674) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRHRm-0004DZ-VL; Thu, 16 May 2019 10:33:27 -0400 Received: from [172.16.25.154] (helo=xantnef-ws.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hRHRl-0007Lk-M2; Thu, 16 May 2019 17:33:25 +0300 From: Anton Nefedov To: qemu-block@nongnu.org Date: Thu, 16 May 2019 17:33:09 +0300 Message-Id: <20190516143314.81302-5-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> References: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v8 4/9] ide: account UNMAP (TRIM) operations 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, vsementsov@virtuozzo.com, berto@igalia.com, den@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, Anton Nefedov , pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy --- hw/ide/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/ide/core.c b/hw/ide/core.c index 6afadf894f..3a7ac93777 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -441,6 +441,14 @@ static void ide_issue_trim_cb(void *opaque, int ret) TrimAIOCB *iocb = opaque; IDEState *s = iocb->s; + if (iocb->i >= 0) { + if (ret >= 0) { + block_acct_done(blk_get_stats(s->blk), &s->acct); + } else { + block_acct_failed(blk_get_stats(s->blk), &s->acct); + } + } + if (ret >= 0) { while (iocb->j < iocb->qiov->niov) { int j = iocb->j; @@ -458,10 +466,14 @@ static void ide_issue_trim_cb(void *opaque, int ret) } if (!ide_sect_range_ok(s, sector, count)) { + block_acct_invalid(blk_get_stats(s->blk), BLOCK_ACCT_UNMAP); iocb->ret = -EINVAL; goto done; } + block_acct_start(blk_get_stats(s->blk), &s->acct, + count << BDRV_SECTOR_BITS, BLOCK_ACCT_UNMAP); + /* Got an entry! Submit and exit. */ iocb->aiocb = blk_aio_pdiscard(s->blk, sector << BDRV_SECTOR_BITS, From patchwork Thu May 16 14:33:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10946751 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E02E314DB for ; Thu, 16 May 2019 14:40:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD04A28D5F for ; Thu, 16 May 2019 14:40:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CABE828D74; Thu, 16 May 2019 14:40:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6B60028D5F for ; Thu, 16 May 2019 14:40:55 +0000 (UTC) Received: from localhost ([127.0.0.1]:59254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHZ0-0005ZK-DX for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 May 2019 10:40:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHRs-00080E-Jr for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRHRr-0004K1-F6 for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:32 -0400 Received: from relay.sw.ru ([185.231.240.75]:39684) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRHRn-0004Dy-BV; Thu, 16 May 2019 10:33:27 -0400 Received: from [172.16.25.154] (helo=xantnef-ws.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hRHRl-0007Lk-SG; Thu, 16 May 2019 17:33:25 +0300 From: Anton Nefedov To: qemu-block@nongnu.org Date: Thu, 16 May 2019 17:33:10 +0300 Message-Id: <20190516143314.81302-6-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> References: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v8 5/9] scsi: store unmap offset and nb_sectors in request struct 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, vsementsov@virtuozzo.com, berto@igalia.com, den@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, Anton Nefedov , pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP it allows to report it in the error handler Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- hw/scsi/scsi-disk.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index e7e865ab3b..b43254103c 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -1602,8 +1602,6 @@ static void scsi_unmap_complete_noio(UnmapCBData *data, int ret) { SCSIDiskReq *r = data->r; SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); - uint64_t sector_num; - uint32_t nb_sectors; assert(r->req.aiocb == NULL); if (scsi_disk_req_check_error(r, ret, false)) { @@ -1611,16 +1609,16 @@ static void scsi_unmap_complete_noio(UnmapCBData *data, int ret) } if (data->count > 0) { - sector_num = ldq_be_p(&data->inbuf[0]); - nb_sectors = ldl_be_p(&data->inbuf[8]) & 0xffffffffULL; - if (!check_lba_range(s, sector_num, nb_sectors)) { + r->sector = ldq_be_p(&data->inbuf[0]); + r->sector_count = ldl_be_p(&data->inbuf[8]) & 0xffffffffULL; + if (!check_lba_range(s, r->sector, r->sector_count)) { scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE)); goto done; } r->req.aiocb = blk_aio_pdiscard(s->qdev.conf.blk, - sector_num * s->qdev.blocksize, - nb_sectors * s->qdev.blocksize, + r->sector * s->qdev.blocksize, + r->sector_count * s->qdev.blocksize, scsi_unmap_complete, data); data->count--; data->inbuf += 16; From patchwork Thu May 16 14:33:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10946739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 82D61924 for ; Thu, 16 May 2019 14:35:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73BC828C3E for ; Thu, 16 May 2019 14:35:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DC7B28CFD; Thu, 16 May 2019 14:35:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1EDD728A6E for ; Thu, 16 May 2019 14:35:45 +0000 (UTC) Received: from localhost ([127.0.0.1]:59161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHU0-0001JL-A0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 May 2019 10:35:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHRs-00080T-MB for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRHRr-0004KC-FL for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:32 -0400 Received: from relay.sw.ru ([185.231.240.75]:39680) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRHRn-0004Dw-9B; Thu, 16 May 2019 10:33:27 -0400 Received: from [172.16.25.154] (helo=xantnef-ws.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hRHRm-0007Lk-10; Thu, 16 May 2019 17:33:26 +0300 From: Anton Nefedov To: qemu-block@nongnu.org Date: Thu, 16 May 2019 17:33:11 +0300 Message-Id: <20190516143314.81302-7-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> References: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v8 6/9] scsi: move unmap error checking to the complete callback 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, vsementsov@virtuozzo.com, berto@igalia.com, den@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, Anton Nefedov , pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This will help to account the operation in the following commit. The difference is that we don't call scsi_disk_req_check_error() before the 1st discard iteration anymore. That function also checks if the request is cancelled, however it shouldn't get canceled until it yields in blk_aio() functions anyway. Same approach is already used for emulate_write_same. Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- hw/scsi/scsi-disk.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index b43254103c..6eff496b54 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -1604,9 +1604,6 @@ static void scsi_unmap_complete_noio(UnmapCBData *data, int ret) SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); assert(r->req.aiocb == NULL); - if (scsi_disk_req_check_error(r, ret, false)) { - goto done; - } if (data->count > 0) { r->sector = ldq_be_p(&data->inbuf[0]); @@ -1642,7 +1639,12 @@ static void scsi_unmap_complete(void *opaque, int ret) r->req.aiocb = NULL; aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); - scsi_unmap_complete_noio(data, ret); + if (scsi_disk_req_check_error(r, ret, false)) { + scsi_req_unref(&r->req); + g_free(data); + } else { + scsi_unmap_complete_noio(data, ret); + } aio_context_release(blk_get_aio_context(s->qdev.conf.blk)); } From patchwork Thu May 16 14:33:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10946737 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A1EC6C5 for ; Thu, 16 May 2019 14:35:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A7D628B95 for ; Thu, 16 May 2019 14:35:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 589EE28CE6; Thu, 16 May 2019 14:35:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E3E7528C6E for ; Thu, 16 May 2019 14:35:32 +0000 (UTC) Received: from localhost ([127.0.0.1]:59159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHTn-0001Ab-HG for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 May 2019 10:35:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHRs-00080F-Jy for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRHRr-0004Jp-E4 for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:32 -0400 Received: from relay.sw.ru ([185.231.240.75]:39688) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRHRn-0004E2-CO; Thu, 16 May 2019 10:33:27 -0400 Received: from [172.16.25.154] (helo=xantnef-ws.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hRHRm-0007Lk-5T; Thu, 16 May 2019 17:33:26 +0300 From: Anton Nefedov To: qemu-block@nongnu.org Date: Thu, 16 May 2019 17:33:12 +0300 Message-Id: <20190516143314.81302-8-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> References: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v8 7/9] scsi: account unmap operations 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, vsementsov@virtuozzo.com, berto@igalia.com, den@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, Anton Nefedov , pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy --- hw/scsi/scsi-disk.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 6eff496b54..5c77981d60 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -1609,10 +1609,16 @@ static void scsi_unmap_complete_noio(UnmapCBData *data, int ret) r->sector = ldq_be_p(&data->inbuf[0]); r->sector_count = ldl_be_p(&data->inbuf[8]) & 0xffffffffULL; if (!check_lba_range(s, r->sector, r->sector_count)) { + block_acct_invalid(blk_get_stats(s->qdev.conf.blk), + BLOCK_ACCT_UNMAP); scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE)); goto done; } + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, + r->sector_count * s->qdev.blocksize, + BLOCK_ACCT_UNMAP); + r->req.aiocb = blk_aio_pdiscard(s->qdev.conf.blk, r->sector * s->qdev.blocksize, r->sector_count * s->qdev.blocksize, @@ -1639,10 +1645,11 @@ static void scsi_unmap_complete(void *opaque, int ret) r->req.aiocb = NULL; aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); - if (scsi_disk_req_check_error(r, ret, false)) { + if (scsi_disk_req_check_error(r, ret, true)) { scsi_req_unref(&r->req); g_free(data); } else { + block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct); scsi_unmap_complete_noio(data, ret); } aio_context_release(blk_get_aio_context(s->qdev.conf.blk)); @@ -1674,6 +1681,7 @@ static void scsi_disk_emulate_unmap(SCSIDiskReq *r, uint8_t *inbuf) } if (blk_is_read_only(s->qdev.conf.blk)) { + block_acct_invalid(blk_get_stats(s->qdev.conf.blk), BLOCK_ACCT_UNMAP); scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED)); return; } @@ -1689,10 +1697,12 @@ static void scsi_disk_emulate_unmap(SCSIDiskReq *r, uint8_t *inbuf) return; invalid_param_len: + block_acct_invalid(blk_get_stats(s->qdev.conf.blk), BLOCK_ACCT_UNMAP); scsi_check_condition(r, SENSE_CODE(INVALID_PARAM_LEN)); return; invalid_field: + block_acct_invalid(blk_get_stats(s->qdev.conf.blk), BLOCK_ACCT_UNMAP); scsi_check_condition(r, SENSE_CODE(INVALID_FIELD)); } From patchwork Thu May 16 14:33:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10946741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F9566C5 for ; Thu, 16 May 2019 14:35:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 519F728C5A for ; Thu, 16 May 2019 14:35:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FC9428CF6; Thu, 16 May 2019 14:35:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EBEA128C5A for ; Thu, 16 May 2019 14:35:45 +0000 (UTC) Received: from localhost ([127.0.0.1]:59163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHU1-0001Ke-6t for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 May 2019 10:35:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHRs-00080B-JJ for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRHRr-0004Jg-DT for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:32 -0400 Received: from relay.sw.ru ([185.231.240.75]:39692) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRHRn-0004EB-Hr; Thu, 16 May 2019 10:33:27 -0400 Received: from [172.16.25.154] (helo=xantnef-ws.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hRHRm-0007Lk-A2; Thu, 16 May 2019 17:33:26 +0300 From: Anton Nefedov To: qemu-block@nongnu.org Date: Thu, 16 May 2019 17:33:13 +0300 Message-Id: <20190516143314.81302-9-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> References: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v8 8/9] file-posix: account discard operations 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, vsementsov@virtuozzo.com, berto@igalia.com, den@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, Anton Nefedov , pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This will help to identify how many of the user-issued discard operations (accounted on a device level) have actually suceeded down on the host file (even though the numbers will not be exactly the same if non-raw format driver is used (e.g. qcow2 sending metadata discards)). Note that these numbers will not include discards triggered by write-zeroes + MAY_UNMAP calls. Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/file-posix.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index 1cf4ee49eb..76d54b3a85 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -159,6 +159,11 @@ typedef struct BDRVRawState { bool needs_alignment; bool drop_cache; bool check_cache_dropped; + struct { + int64_t discard_nb_ok; + int64_t discard_nb_failed; + int64_t discard_bytes_ok; + } stats; PRManager *pr_mgr; } BDRVRawState; @@ -2630,11 +2635,22 @@ static void coroutine_fn raw_co_invalidate_cache(BlockDriverState *bs, #endif /* !__linux__ */ } +static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) +{ + if (ret) { + s->stats.discard_nb_failed++; + } else { + s->stats.discard_nb_ok++; + s->stats.discard_bytes_ok += nbytes; + } +} + static coroutine_fn int raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int bytes, bool blkdev) { BDRVRawState *s = bs->opaque; RawPosixAIOData acb; + int ret; acb = (RawPosixAIOData) { .bs = bs, @@ -2648,7 +2664,9 @@ raw_do_pdiscard(BlockDriverState *bs, int64_t offset, int bytes, bool blkdev) acb.aio_type |= QEMU_AIO_BLKDEV; } - return raw_thread_pool_submit(bs, handle_aiocb_discard, &acb); + ret = raw_thread_pool_submit(bs, handle_aiocb_discard, &acb); + raw_account_discard(s, bytes, ret); + return ret; } static coroutine_fn int @@ -3263,10 +3281,12 @@ static int fd_open(BlockDriverState *bs) static coroutine_fn int hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { + BDRVRawState *s = bs->opaque; int ret; ret = fd_open(bs); if (ret < 0) { + raw_account_discard(s, bytes, ret); return ret; } return raw_do_pdiscard(bs, offset, bytes, true); From patchwork Thu May 16 14:33:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10946745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD821924 for ; Thu, 16 May 2019 14:38:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B8D22883F for ; Thu, 16 May 2019 14:38:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DC6A28A94; Thu, 16 May 2019 14:38:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E8CF82883F for ; Thu, 16 May 2019 14:38:33 +0000 (UTC) Received: from localhost ([127.0.0.1]:59192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHWj-0003gm-4h for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 May 2019 10:38:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55363) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRHRt-00081f-GZ for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRHRr-0004K7-FL for qemu-devel@nongnu.org; Thu, 16 May 2019 10:33:33 -0400 Received: from relay.sw.ru ([185.231.240.75]:39694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRHRn-0004EI-N5; Thu, 16 May 2019 10:33:27 -0400 Received: from [172.16.25.154] (helo=xantnef-ws.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hRHRm-0007Lk-FQ; Thu, 16 May 2019 17:33:26 +0300 From: Anton Nefedov To: qemu-block@nongnu.org Date: Thu, 16 May 2019 17:33:14 +0300 Message-Id: <20190516143314.81302-10-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> References: <20190516143314.81302-1-anton.nefedov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v8 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, vsementsov@virtuozzo.com, berto@igalia.com, den@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, Anton Nefedov , pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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);