From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF2CBC3A59E for ; Wed, 4 Sep 2019 04:36:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A76E522CF5 for ; Wed, 4 Sep 2019 04:36:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="fvK9ajto" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725963AbfIDEgg (ORCPT ); Wed, 4 Sep 2019 00:36:36 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:46088 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725947AbfIDEgg (ORCPT ); Wed, 4 Sep 2019 00:36:36 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x844ZCe3038363; Wed, 4 Sep 2019 04:35:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=ukcardIwQXoqp8PMWawh/6kz72tXf3tUxR6gBKDBfw4=; b=fvK9ajtoXGQmGSLzXd6/3gF/NNQ21Cr7ZTV8sWr0q2ughPPrQTtn+gCZSECMPvOgKYGX 8uMJyMnMfxjpyPxrN3OmKmDG1KxqhmabPA9ramFWDP3Os7i7rxrCwdotMHI5DnFXlXWh F1bBWzrE/oGbYpI8Ae1fuvw7eWmzLtLtLdWdaAOq6WOaHivH9SG1okORFLHixlGl93vU cjzT9hHQuZ8P55uwA5Gf+uPZf7AVRVG/iWjTfcbNF81ls/HtFpLqD+Sp6wjYA6XrgcbJ VhwpFUNMT2cygy+VsBGPTZDO5+hXatFWemHyY6J4dNlKSWgU9TtrCC+36cIfkOzv1D/1 Vw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2ut6cdr01f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 Sep 2019 04:35:50 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x844XFJB027388; Wed, 4 Sep 2019 04:35:19 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2ut1hmtu62-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 04 Sep 2019 04:35:19 +0000 Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x844ZI1s029941; Wed, 4 Sep 2019 04:35:18 GMT Received: from localhost (/10.159.228.126) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Sep 2019 21:35:17 -0700 Subject: [PATCH 5/8] libfrog: create online fs geometry converters From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, Allison Collins , Dave Chinner Date: Tue, 03 Sep 2019 21:35:16 -0700 Message-ID: <156757171642.1836891.5012962551379818316.stgit@magnolia> In-Reply-To: <156757168368.1836891.15043200811666785244.stgit@magnolia> References: <156757168368.1836891.15043200811666785244.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9369 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909040047 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9369 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909040047 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Create helper functions to perform unit conversions against a runtime filesystem, then remove the open-coded versions in scrub. Signed-off-by: Darrick J. Wong Reviewed-by: Allison Collins Reviewed-by: Dave Chinner --- include/fsgeom.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ libfrog/fsgeom.c | 1 + scrub/fscounters.c | 4 ++-- scrub/inodes.c | 4 ++-- scrub/phase3.c | 6 +++-- scrub/phase5.c | 4 ++-- scrub/phase6.c | 3 ++- scrub/phase7.c | 6 +++-- 8 files changed, 72 insertions(+), 13 deletions(-) diff --git a/include/fsgeom.h b/include/fsgeom.h index 7837c700..771732f2 100644 --- a/include/fsgeom.h +++ b/include/fsgeom.h @@ -32,6 +32,9 @@ struct xfs_fd { /* log2 of sb_inopblock */ unsigned int inopblog; + + /* bits for agino in inum */ + unsigned int aginolog; }; /* Static initializers */ @@ -41,4 +44,58 @@ struct xfs_fd { int xfd_prepare_geometry(struct xfs_fd *xfd); int xfd_close(struct xfs_fd *xfd); +/* Convert AG number and AG inode number into fs inode number. */ +static inline uint64_t +cvt_agino_to_ino( + const struct xfs_fd *xfd, + uint32_t agno, + uint32_t agino) +{ + return ((uint64_t)agno << xfd->aginolog) + agino; +} + +/* Convert fs inode number into AG number. */ +static inline uint32_t +cvt_ino_to_agno( + const struct xfs_fd *xfd, + uint64_t ino) +{ + return ino >> xfd->aginolog; +} + +/* Convert fs inode number into AG inode number. */ +static inline uint32_t +cvt_ino_to_agino( + const struct xfs_fd *xfd, + uint64_t ino) +{ + return ino & ((1ULL << xfd->aginolog) - 1); +} + +/* + * Convert a linear fs block offset number into bytes. This is the runtime + * equivalent of XFS_FSB_TO_B, which means that it is /not/ for segmented fsbno + * format (= agno | agbno) that we use internally for the data device. + */ +static inline uint64_t +cvt_off_fsb_to_b( + const struct xfs_fd *xfd, + uint64_t fsb) +{ + return fsb << xfd->blocklog; +} + +/* + * Convert bytes into a (rounded down) linear fs block offset number. This is + * the runtime equivalent of XFS_B_TO_FSBT. It does not produce segmented + * fsbno numbers (= agno | agbno). + */ +static inline uint64_t +cvt_b_to_off_fsbt( + const struct xfs_fd *xfd, + uint64_t bytes) +{ + return bytes >> xfd->blocklog; +} + #endif /* _LIBFROG_FSGEOM_H_ */ diff --git a/libfrog/fsgeom.c b/libfrog/fsgeom.c index b7e2b2f8..39604556 100644 --- a/libfrog/fsgeom.c +++ b/libfrog/fsgeom.c @@ -112,6 +112,7 @@ xfd_prepare_geometry( xfd->blocklog = highbit32(xfd->fsgeom.blocksize); xfd->inodelog = highbit32(xfd->fsgeom.inodesize); xfd->inopblog = xfd->blocklog - xfd->inodelog; + xfd->aginolog = xfd->agblklog + xfd->inopblog; return 0; } diff --git a/scrub/fscounters.c b/scrub/fscounters.c index ac898764..ea6af156 100644 --- a/scrub/fscounters.c +++ b/scrub/fscounters.c @@ -91,8 +91,8 @@ xfs_count_ag_inodes( minor(ctx->fsinfo.fs_datadev), agno); - ag_ino = (__u64)agno << (ctx->mnt.inopblog + ctx->mnt.agblklog); - next_ag_ino = (__u64)(agno + 1) << (ctx->mnt.inopblog + ctx->mnt.agblklog); + ag_ino = cvt_agino_to_ino(&ctx->mnt, agno, 0); + next_ag_ino = cvt_agino_to_ino(&ctx->mnt, agno + 1, 0); moveon = xfs_count_inodes_range(ctx, descr, ag_ino, next_ag_ino - 1, &ci->counters[agno]); diff --git a/scrub/inodes.c b/scrub/inodes.c index 873ad425..700e5200 100644 --- a/scrub/inodes.c +++ b/scrub/inodes.c @@ -228,8 +228,8 @@ xfs_scan_ag_inodes( minor(ctx->fsinfo.fs_datadev), agno); - ag_ino = (__u64)agno << (ctx->mnt.inopblog + ctx->mnt.agblklog); - next_ag_ino = (__u64)(agno + 1) << (ctx->mnt.inopblog + ctx->mnt.agblklog); + ag_ino = cvt_agino_to_ino(&ctx->mnt, agno, 0); + next_ag_ino = cvt_agino_to_ino(&ctx->mnt, agno + 1, 0); moveon = xfs_iterate_inodes_range(ctx, descr, ctx->fshandle, ag_ino, next_ag_ino - 1, si->fn, si->arg); diff --git a/scrub/phase3.c b/scrub/phase3.c index 579e08c3..8c02f1cb 100644 --- a/scrub/phase3.c +++ b/scrub/phase3.c @@ -52,8 +52,8 @@ xfs_scrub_inode_vfs_error( xfs_agino_t agino; int old_errno = errno; - agno = bstat->bs_ino / (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog)); - agino = bstat->bs_ino % (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog)); + agno = cvt_ino_to_agno(&ctx->mnt, bstat->bs_ino); + agino = cvt_ino_to_agino(&ctx->mnt, bstat->bs_ino); snprintf(descr, DESCR_BUFSZ, _("inode %"PRIu64" (%u/%u)"), (uint64_t)bstat->bs_ino, agno, agino); errno = old_errno; @@ -77,7 +77,7 @@ xfs_scrub_inode( int error; xfs_action_list_init(&alist); - agno = bstat->bs_ino / (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog)); + agno = cvt_ino_to_agno(&ctx->mnt, bstat->bs_ino); background_sleep(); /* Try to open the inode to pin it. */ diff --git a/scrub/phase5.c b/scrub/phase5.c index 36ec27b3..f3ee22e6 100644 --- a/scrub/phase5.c +++ b/scrub/phase5.c @@ -239,8 +239,8 @@ xfs_scrub_connections( int fd = -1; int error; - agno = bstat->bs_ino / (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog)); - agino = bstat->bs_ino % (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog)); + agno = cvt_ino_to_agno(&ctx->mnt, bstat->bs_ino); + agino = cvt_ino_to_agino(&ctx->mnt, bstat->bs_ino); snprintf(descr, DESCR_BUFSZ, _("inode %"PRIu64" (%u/%u)"), (uint64_t)bstat->bs_ino, agno, agino); background_sleep(); diff --git a/scrub/phase6.c b/scrub/phase6.c index 48971270..5628b926 100644 --- a/scrub/phase6.c +++ b/scrub/phase6.c @@ -547,7 +547,8 @@ xfs_estimate_verify_work( if (!moveon) return moveon; - *items = ((d_blocks - d_bfree) + (r_blocks - r_bfree)) << ctx->mnt.blocklog; + *items = cvt_off_fsb_to_b(&ctx->mnt, + (d_blocks - d_bfree) + (r_blocks - r_bfree)); *nr_threads = disk_heads(ctx->datadev); *rshift = 20; return moveon; diff --git a/scrub/phase7.c b/scrub/phase7.c index 41a77356..8a028e19 100644 --- a/scrub/phase7.c +++ b/scrub/phase7.c @@ -148,11 +148,11 @@ xfs_scan_summary( * filesystem treats them as "free", but since we scanned * them, we'll consider them used. */ - d_bfree -= totalcount.agbytes >> ctx->mnt.blocklog; + d_bfree -= cvt_b_to_off_fsbt(&ctx->mnt, totalcount.agbytes); /* Report on what we found. */ - used_data = (d_blocks - d_bfree) << ctx->mnt.blocklog; - used_rt = (r_blocks - r_bfree) << ctx->mnt.blocklog; + used_data = cvt_off_fsb_to_b(&ctx->mnt, d_blocks - d_bfree); + used_rt = cvt_off_fsb_to_b(&ctx->mnt, r_blocks - r_bfree); used_files = f_files - f_free; stat_data = totalcount.dbytes; stat_rt = totalcount.rbytes;