From patchwork Fri Nov 24 04:10:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10073505 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 A0D4E602DC for ; Fri, 24 Nov 2017 04:10:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D1DC2A347 for ; Fri, 24 Nov 2017 04:10:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F30B2A343; Fri, 24 Nov 2017 04:10:51 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA3642A343 for ; Fri, 24 Nov 2017 04:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752677AbdKXEKS (ORCPT ); Thu, 23 Nov 2017 23:10:18 -0500 Received: from victor.provo.novell.com ([137.65.250.26]:56555 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752271AbdKXEKS (ORCPT ); Thu, 23 Nov 2017 23:10:18 -0500 Received: from adam-pc.lan (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Thu, 23 Nov 2017 21:10:12 -0700 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 1/3] btrfs: Introduce macros to handle bytes and sector conversion Date: Fri, 24 Nov 2017 12:10:06 +0800 Message-Id: <20171124041008.32656-1-wqu@suse.com> X-Mailer: git-send-email 2.15.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since block I/O is always done in unit of 512 bytes, add BI_SECTOR_SIZE and BI_SECTOR_SHIFT macros and to_sector() and to_bytes() for later use. Although the best position to define such things should be bvec.h, and to_sector() to_bytes() are also defined in device-mapper.h, there are a lot of code defining their own SECTOR_SIZE and to_bytes() in device-mapper is not using u64 (unsigned long long) but unsigned long, which doesn't fit btrfs usage. So define btrfs' own macros and inlined converters. Signed-off-by: Qu Wenruo --- fs/btrfs/ctree.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 8fc690384c58..8f6f57167661 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3734,4 +3734,17 @@ static inline int btrfs_is_testing(struct btrfs_fs_info *fs_info) #endif return 0; } + +#define BI_SECTOR_SHIFT (9) +#define BI_SECTOR_SIZE (1 << BI_SECTOR_SHIFT) + +static inline u64 to_bytes(sector_t n) +{ + return ((u64)n << BI_SECTOR_SHIFT); +} + +static inline sector_t to_sector(u64 n) +{ + return (n >> BI_SECTOR_SHIFT); +} #endif