From patchwork Fri Dec 30 22:13:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13084970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED4B3C3DA7C for ; Fri, 30 Dec 2022 23:51:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235776AbiL3Xu7 (ORCPT ); Fri, 30 Dec 2022 18:50:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235566AbiL3Xu6 (ORCPT ); Fri, 30 Dec 2022 18:50:58 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1BC11123; Fri, 30 Dec 2022 15:50:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5E0CC61C43; Fri, 30 Dec 2022 23:50:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BACD1C433D2; Fri, 30 Dec 2022 23:50:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672444255; bh=oMY1tm5eTfkoXJGAz0d+4HAjxv6YvR1JlylNE7b1Pvs=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=CjSxOUJXU/Z7v1TZ0A7pR2vrmVYC+LieryLbAIhz7j3dKL8agScwVqPFQU2lrEEXY Tfzu3JTBpa+Pa7kYjrJ64eQBBhgu4TMO8ibeuw1vgmPThEBw1TtZcynHCA/cfSqSVD yILSFGU+NyFYVtQNnAew6un6Oi2Vq1iQCFAGDUTs0ddNy7IG3tygfAZu1QXQmp5bbN 6322pG4TEN2PZ8yS86KmnwKMuxuHThpA3z7mtwRwdNVoZoaqqnt/Nh8qHbZvJ3GyoJ dmixmR3yV8lTl1YM5KZ5qWbmS+9ba7irzpTctLy6JiKyTatNM0GejJiCTmCHlgJtVc vSxJOiG3fAKRg== Subject: [PATCH 03/21] xfs: refactor non-power-of-two alignment checks From: "Darrick J. Wong" To: djwong@kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Date: Fri, 30 Dec 2022 14:13:55 -0800 Message-ID: <167243843564.699466.13518512328247458894.stgit@magnolia> In-Reply-To: <167243843494.699466.5163281976943635014.stgit@magnolia> References: <167243843494.699466.5163281976943635014.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Darrick J. Wong Create a helper function that can compute if a 64-bit number is an integer multiple of a 32-bit number, where the 32-bit number is not required to be an even power of two. This is needed for some new code for the realtime device, where we can set 37k allocation units and then have to remap them. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 12 +++--------- fs/xfs/xfs_linux.h | 5 +++++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index b382380656d7..78323574021c 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -46,15 +46,9 @@ xfs_is_falloc_aligned( { unsigned int alloc_unit = xfs_inode_alloc_unitsize(ip); - if (XFS_IS_REALTIME_INODE(ip) && !is_power_of_2(alloc_unit)) { - u32 mod; - - div_u64_rem(pos, alloc_unit, &mod); - if (mod) - return false; - div_u64_rem(len, alloc_unit, &mod); - return mod == 0; - } + if (XFS_IS_REALTIME_INODE(ip) && !is_power_of_2(alloc_unit)) + return isaligned_64(pos, alloc_unit) && + isaligned_64(len, alloc_unit); return !((pos | len) & (alloc_unit - 1)); } diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index 3847719c3026..7e9bf03c80a3 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h @@ -197,6 +197,11 @@ static inline uint64_t howmany_64(uint64_t x, uint32_t y) return x; } +static inline bool isaligned_64(uint64_t x, uint32_t y) +{ + return do_div(x, y) == 0; +} + int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count, char *data, enum req_op op);