From patchwork Thu Aug 25 13:44:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9299481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 628DF60459 for ; Thu, 25 Aug 2016 15:22:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 536E029378 for ; Thu, 25 Aug 2016 15:22:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47FD32937E; Thu, 25 Aug 2016 15:22:13 +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=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 79EF429378 for ; Thu, 25 Aug 2016 15:22:12 +0000 (UTC) Received: from localhost ([::1]:56801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcwTr-0003J4-N2 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Aug 2016 11:22:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcwR7-0001kn-W6 for qemu-devel@nongnu.org; Thu, 25 Aug 2016 11:19:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcwR6-0005Z5-FM for qemu-devel@nongnu.org; Thu, 25 Aug 2016 11:19:21 -0400 Received: from mail-db5eur01on0138.outbound.protection.outlook.com ([104.47.2.138]:49713 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcwQz-0005Xu-Hs; Thu, 25 Aug 2016 11:19:13 -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; bh=UdrpHWEpRVD013OZ6aEkBZOApv25vBiyupAYOLZBU9E=; b=M3ToZA3REdoLtDJmuHqUMyY97kiZmgCRMdw4Nzrh5mpj3XmWdl29fhyPp/k62o+2d3U6BKiEu03rQD0N+EKdZkkA7tfEeCPNXJROiYgK71hrbCCwtihe0HgUpX1bqDrWh0a2s5NA+tXPrENod8NNSjP5Ad3dtXSOHXwh9mDDVZM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by DB6PR0802MB2549.eurprd08.prod.outlook.com (10.172.251.147) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Thu, 25 Aug 2016 13:45:46 +0000 From: Pavel Butsykin To: , Date: Thu, 25 Aug 2016 16:44:18 +0300 Message-ID: <20160825134421.20231-20-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160825134421.20231-1-pbutsykin@virtuozzo.com> References: <20160825134421.20231-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AMSPR02CA0013.eurprd02.prod.outlook.com (10.242.225.141) To DB6PR0802MB2549.eurprd08.prod.outlook.com (10.172.251.147) X-MS-Office365-Filtering-Correlation-Id: 5568494b-1e85-4c02-82f1-08d3ccee1e12 X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 2:YRO1LDLfs3d19IrEYoJQo+a67ScpCHVCsEVeOlMYlk6/ckvJYVuTPKkuUPDr/5KF+8UADNxZwmOUDESWWHn5vj452UzxL8+/1v/N2qQjK31hMvAHztuX5SS30PVD5RTxrubzLagi8mMBbtZiT0qw1YTXE0RhKIJ5F0i0c99MRV4GABUToZjg0Iv9UTaBDAxP; 3:nLGl30goE6vp2TfeCsXTx3Qk0SDahsAoUuJ9AQBLsRIMJcINUwN/W6HpwquRGuAABxSuVdT18IFSxRQbhe8shZWZDW55V5PVdODp9wLLFgrfdaIuwSFkHN17V44gj0tL; 25:JsQKaXtGaN+57Hg+rFoQkL9meKEIVirY+ZJAdrTmC5swiahF2RvCIR1HgQBalb+f9EcBaVYr1N+hCLx2Y2txLQsiNSkuOuFdX0CO0ZVDZePwfIwwNbq5YLFR41vJ0sSLNhHQKaJUlRQleo1wCF74NniAy3HHWUu+HVIfhkebAw70HgYor4z9WkbooOUe0yWL2TPMAINspFrzOQ0ti/mVxMtcFXR90csAHQ33zn7mzoI22Z2a1z+LHT0M/BRnYPEzoo+awW8JqckEC6a2Ln0VFMldCFoFXqwKw4yVfaDu84zC9s90vauxB7FrnWbpbsfoIiVE/AZHHgommA8gRbG4tv50dPfJER91/XaXmZh9QQUIHniqDlRm38mjlBxCJhohSYEqK1C+gbncAQYAux8OSQDiMLh98ds1AoKnq4ftQaI= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0802MB2549; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 31:uiHiuzQD+vC9+Q2WUy+wLUJhfZMGEHXHOOM3Tij8wevB4PVREXDv2CuBassXIL1UQO5zhwIJN/PukQxhEBIz6TynMM/UTwMagvlryxwKEq1tRrfXUAMOlKzXXgzaGTYGsZgTgvL6GygMO5GzWbXSjSOnMv3+BOhGkacqoae6jrBg2cPiuMdUQL9bFuwH1sh00CE7+Eb7IggX/0JafIl5mJmM4i8k3StLYmZXtJq4IrY=; 4:HtxeFqm5glzauZxItAu9u4IbRC5RULyF/axp+oWuBBUfU6qZekRa28rq3bEGPYlrTrNb48YOvFyaH6aSpfa8CwTMtZNAe6MCBRgfZWu+LsSJUFRsFA8SKRwtkTQRY+UpSCwYfrS39XAK4N6vwOTuO1nujB3vpXJ4virX572DAnFcgteUtPuqciMnGP21mPIAQvFf08ssukRhvFK7TaAzyGmWMsd8EZugVy2qW8KcO/KWrvDUQSsXHg6NS2gsTrKt97uZgJo/5Zb5N+dliEO1LZhplZqdL+BClsiMbZPtyF9zbl20jPh5RxoOD5F+XjWOEiQSeJFJ34Yq12GCXFGhjcZUlHJeLKLWW3WFNeTff/BbLjuaCyUHBkWAblK5Cm2srmmzDGWp1wGB0Ub30TjpZXRygIAIQzD8hPOZu8rmxkM= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6043046)(6042046); SRVR:DB6PR0802MB2549; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0802MB2549; X-Forefront-PRVS: 0045236D47 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(189002)(199003)(86362001)(33646002)(1076002)(69596002)(5003940100001)(42186005)(68736007)(189998001)(92566002)(66066001)(106356001)(47776003)(6116002)(3846002)(586003)(36756003)(5001770100001)(97736004)(2906002)(4326007)(2950100001)(5660300001)(76176999)(48376002)(53416004)(105586002)(50466002)(81156014)(8676002)(50226002)(77096005)(81166006)(19580405001)(50986999)(229853001)(101416001)(7846002)(7736002)(305945005)(19580395003)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0802MB2549; H:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0802MB2549; 23:Fy8WrakeuThtwfoxK0YoBRWOlkae3g0fsNFNpDZ?= =?us-ascii?Q?MRwhX2OqwMhSepFwa8U1vMH1y3NWaNl1+5UFos3El1WuSRsUV068yVxINkHj?= =?us-ascii?Q?G86pu+feT4mP3cBYPdUtr+IJBEYKrXj3rYCG00vI3++inZYP1wVLuJLmjdMd?= =?us-ascii?Q?LI138ytOEtGmqS/LNC2lPhq5db/6Qb3c8Vlhfcq5BHONvAfS9q5yzD7VYpGP?= =?us-ascii?Q?aEWT5HT8OetXU33d7hPQOtM0VA1mdcs4m2lOHKIFW1tHHp3MRQ0NFREft1dJ?= =?us-ascii?Q?2b53XlmH441PuEkKK0cC0aS+il4eMUWGRTy1gttDFSC/zU74iBttGbzHAOXZ?= =?us-ascii?Q?Yx8DBs1mcK3dXFdo0hlGyol9QOeyUdltRgfRNxhPDGazpcBMffwduVS68B/V?= =?us-ascii?Q?ugcWoQcrB6SewOl5O273UWP9oQh8NWsxhxAdJ/h7NH1J/srF6OI2cUy15CK2?= =?us-ascii?Q?IB4vxrIbJY88EHA5YLsI6kN5WnaRIc69PpeHSsoTVToJLg2y+Y2/FnRb4YKP?= =?us-ascii?Q?VtUm1eapv+yM4tTOZNXUNVqApNWh0zbDlPQpJEIZZF6jJnS8oW8N6m4iHe/r?= =?us-ascii?Q?f59lEFH6o5axNkywL+V05Ps7FiC+7eIP/v3rQGZshP4G99fSmW6K/5R0LBB4?= =?us-ascii?Q?AjQCURXwjvMjk9FFd6QpolJmJ4EpiEh4c14KXq6QaDHI3ovH0yLK+RunFdgu?= =?us-ascii?Q?VuUwHW4kHokYGRBwPkTZmBqJHdhs25EOAyhg90RluOG8ufKbHIlCgWG71lm2?= =?us-ascii?Q?JtT7TXnfyIGY/Z20ZoWKhtCCtdfJnwse+uNy0hEMibTYqKzIgb/7NXcHflMU?= =?us-ascii?Q?jYTLwcY4FoBnDDumNpSngk8I9IqXAWLw3Csmo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qn0+ARP3LtB7/bzgPkwavfaVfNbZzWEFWDUdWCNOKkrf3yyJV6nZVjXjE7QzQLVnJteGOr15zXZZw82T7J+QJiERjLYaNzbVdI6mdxsDEHrIFwG6M3+7i+AGs2tqpOF77OEeKVrpwbxprXIt1jh8jS1tbxWxrNxcdUt2Mq1pPVV5kfMF5eqUpeFmP5MGMtDi8fMLe97lJFWgryYKlu7831picVoVxtq3nIZTtQpAwikL SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:oM4zep1syR5lQbOXG6AWFG0gTnZ7/yrQr70S6dkn2HZcl/OHsjNXKt7ZQTBRG/KZiO5GcJ8mlBGO+Bq0+4TriPf/2jlcrS3ShFmxu6HdQRCYRm8hVWZfJeb2TyHsHthWBTgzZ5R3CYp4LKce7LLXo0hl0zD9Xi1b0wVeqTqJ0n4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2016 13:45:46.0187 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2549 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.138 Subject: [Qemu-devel] [PATCH RFC 19/22] block/pcache: add pcache node assert 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, den@openvz.org, jsnow@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In case of node assert we will print the fields of a pcache node, this can be useful for catching bugs. Signed-off-by: Pavel Butsykin --- block/pcache.c | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index 287156a..7b4a9a9 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -38,6 +38,24 @@ #define DPRINTF(fmt, ...) do { } while (0) #endif +#define NODE_PRINT(_node) \ + printf("node:\n" \ + "num: %jd size: %d\n" \ + "ref: %d\nstatus: %d\n" \ + "node_wait_cnt: %d\n" \ + "data: %p\nlock %u\n", \ + (_node)->cm.sector_num, (_node)->cm.nb_sectors, \ + (_node)->ref, (_node)->status, (_node)->wait.cnt, \ + (_node)->data, (_node)->lock.locked) + +#define NODE_ASSERT(_assert, _node) \ + do { \ + if (!(_assert)) { \ + NODE_PRINT(_node); \ + assert(_assert); \ + } \ + } while (0) + typedef struct RbNodeKey { uint64_t num; uint32_t size; @@ -201,7 +219,7 @@ enum { static inline void pcache_node_unref(BDRVPCacheState *s, PCNode *node) { if (atomic_fetch_dec(&node->ref) == 0) { - assert(node->status == NODE_REMOVE_STATUS); + NODE_ASSERT(node->status == NODE_REMOVE_STATUS, node); node->status = NODE_GHOST_STATUS; @@ -217,8 +235,8 @@ static inline void pcache_node_unref(BDRVPCacheState *s, PCNode *node) static inline PCNode *pcache_node_ref(PCNode *node) { - assert(node->status == NODE_SUCCESS_STATUS || - node->status == NODE_WAIT_STATUS); + NODE_ASSERT(node->status == NODE_SUCCESS_STATUS || + node->status == NODE_WAIT_STATUS, node); atomic_inc(&node->ref); return node; @@ -422,8 +440,8 @@ static PrefCachePartReq *pcache_req_get(PrefCacheAIOCB *acb, PCNode *node) req->node = node; req->acb = acb; - assert(acb->sector_num <= node->cm.sector_num + node->cm.nb_sectors); - + NODE_ASSERT(acb->sector_num <= node->cm.sector_num + node->cm.nb_sectors, + node); qemu_iovec_init(&req->qiov, 1); qemu_iovec_add(&req->qiov, node->data, node->cm.nb_sectors << BDRV_SECTOR_BITS); @@ -554,10 +572,10 @@ static inline void pcache_node_read_wait(PrefCacheAIOCB *acb, PCNode *node) static void pcache_node_read(PrefCacheAIOCB *acb, PCNode* node) { - assert(node->status == NODE_SUCCESS_STATUS || - node->status == NODE_WAIT_STATUS || - node->status == NODE_REMOVE_STATUS); - assert(node->data != NULL); + NODE_ASSERT(node->status == NODE_SUCCESS_STATUS || + node->status == NODE_WAIT_STATUS || + node->status == NODE_REMOVE_STATUS, node); + NODE_ASSERT(node->data != NULL, node); qemu_co_mutex_lock(&node->lock); if (node->status == NODE_WAIT_STATUS) { @@ -694,13 +712,13 @@ static void pcache_complete_acb_wait_queue(BDRVPCacheState *s, PCNode *node) pcache_node_read_buf(wait_acb, node); - assert(node->ref != 0); + NODE_ASSERT(node->ref != 0, node); pcache_node_unref(s, node); complete_aio_request(wait_acb); atomic_dec(&node->wait.cnt); } - assert(atomic_read(&node->wait.cnt) == 0); + NODE_ASSERT(atomic_read(&node->wait.cnt) == 0, node); } static void pcache_node_submit(PrefCachePartReq *req) @@ -709,8 +727,8 @@ static void pcache_node_submit(PrefCachePartReq *req) BDRVPCacheState *s = req->acb->s; assert(node != NULL); - assert(atomic_read(&node->ref) != 0); - assert(node->data != NULL); + NODE_ASSERT(atomic_read(&node->ref) != 0, node); + NODE_ASSERT(node->data != NULL, node); qemu_co_mutex_lock(&node->lock); if (node->status == NODE_WAIT_STATUS) { @@ -733,7 +751,7 @@ static void pcache_merge_requests(PrefCacheAIOCB *acb) QTAILQ_REMOVE(&acb->requests.list, req, entry); assert(req != NULL); - assert(node->status == NODE_WAIT_STATUS); + NODE_ASSERT(node->status == NODE_WAIT_STATUS, node); pcache_node_submit(req); @@ -768,7 +786,7 @@ static void pcache_try_node_drop(PrefCacheAIOCB *acb) return; } if (node->status != NODE_WAIT_STATUS) { - assert(node->status == NODE_SUCCESS_STATUS); + NODE_ASSERT(node->status == NODE_SUCCESS_STATUS, node); pcache_node_drop(s, node); } key.num = node->cm.sector_num + node->cm.nb_sectors; @@ -1081,8 +1099,8 @@ fail: static void pcache_node_check_and_free(BDRVPCacheState *s, PCNode *node) { - assert(node->status == NODE_SUCCESS_STATUS); - assert(node->ref == 0); + NODE_ASSERT(node->status == NODE_SUCCESS_STATUS, node); + NODE_ASSERT(node->ref == 0, node); node->status = NODE_REMOVE_STATUS; rb_erase(&node->cm.rb_node, &s->pcache.tree.root);