linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] btrfs: Introduce macros to handle bytes and sector conversion
@ 2017-11-24  4:10 Qu Wenruo
  2017-11-24  4:10 ` [PATCH 2/3] btrfs: Cleanup open coded sector and bytes convert Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Qu Wenruo @ 2017-11-24  4:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

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 <wqu@suse.com>
---
 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
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-11-24 11:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-24  4:10 [PATCH 1/3] btrfs: Introduce macros to handle bytes and sector conversion Qu Wenruo
2017-11-24  4:10 ` [PATCH 2/3] btrfs: Cleanup open coded sector and bytes convert Qu Wenruo
2017-11-24  4:10 ` [PATCH 3/3] btrfs: extent-tree: Use round up to replace align macro Qu Wenruo
2017-11-24  6:53 ` [PATCH 1/3] btrfs: Introduce macros to handle bytes and sector conversion Nikolay Borisov
2017-11-24  6:59   ` Qu Wenruo
2017-11-24 11:25   ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).