From patchwork Tue May 14 12:10:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10942825 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 C580514DB for ; Tue, 14 May 2019 12:22:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B37B7285A1 for ; Tue, 14 May 2019 12:22:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6740286A7; Tue, 14 May 2019 12:22:03 +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.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 38525285A1 for ; Tue, 14 May 2019 12:22:03 +0000 (UTC) Received: from localhost ([127.0.0.1]:47445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQWRW-0003gS-7i for patchwork-qemu-devel@patchwork.kernel.org; Tue, 14 May 2019 08:22:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:32840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQWGy-0003YP-Qi for qemu-devel@nongnu.org; Tue, 14 May 2019 08:11:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQWGw-0002C8-Hz for qemu-devel@nongnu.org; Tue, 14 May 2019 08:11:08 -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 1hQWGq-00020g-Po; Tue, 14 May 2019 08:11:01 -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=lYLyh+9bxLXOkoak9kC6UGRcqlEZ9Oc04EES8GyG2Aw=; b=EZLnJ4oBQaIasSMZMqKIOMnxvSWZJWXnZCHBmWsMvpCuP96ZE8dLJhKkLmF4Rq8RSweYhJGe91UTGt5lCpC1Wc8f1uORt8E9nolsVJ0FUZ8h9KaRtocp2JeVvnPOf/2u0iyKMANp0Y7ruIGXYbmoEUhCO9/qU/Wq86JzoiohqWw= 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:49 +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:49 +0000 From: Anton Nefedov To: "qemu-block@nongnu.org" Thread-Topic: [PATCH v7 8/9] file-posix: account discard operations Thread-Index: AQHVCk4RAFKe40evC0O/XAe8I3+ubQ== Date: Tue, 14 May 2019 12:10:49 +0000 Message-ID: <20190514121015.32190-9-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: 7fa40454-adb8-4570-22da-08d6d86533d7 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:873; 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)(15650500001)(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: VbwZ32X7XDw+sDBOobjBho2CTTV6kfdFUp1CpWqNveb7iiUuHuFi3NHsfGUjyHhowtAi0nzy9ORGQ8Nm15OqxrtFs5cfgMRrk0jqo+5ZdG049m8nm1Kk0JYgS664tt6WxNf/fQ/0Sjby6QUBHTOIstllUgrlerobx1fAAeWs25YACUzEFzOdmt/DgPhY3Qr5GSGT1Q5+iSPAcE4cyvR6CysmB/S9WeLl+kdd0/OzIV3sjHOw/WAg2/GpZf3GbB9soF/9qIkc6iSxtWPjjULJoArD5G6rwERKD2OT2fIRpJGymFUkxHYXlKu4gRvyGa8pu53mJVj4CLUFynVQGA+HdqKLzyweS335wPJQd6nbffCqiGAVAHuStDk9uO/4yrOXBFW5KoPHCjCmn6mk0+UgHd/oEVON8iFS9h5tqhMVNHU= MIME-Version: 1.0 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7fa40454-adb8-4570-22da-08d6d86533d7 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 May 2019 12:10:49.5239 (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 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" , 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+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 --- 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);