summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2016-06-15 10:33:06 -0400
committerDavid Sterba <dsterba@suse.com>2016-07-26 07:54:25 -0400
commit1db1ff92b6ce2247999787480c2eeb63a1811e79 (patch)
treed6123aa0666467421ab8343c6bece5f7e2e0318e
parent14a1e067b45614d6236e3c82b36f62caef44ac62 (diff)
btrfs: convert nodesize macros to static inlines
This patch converts the macros used to calculate various node size limits to static inlines. That way we get type checking for free. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/ctree.h48
1 files changed, 33 insertions, 15 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 1d46ceec1fc0..85e0b608b7c0 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -145,21 +145,6 @@ struct btrfs_header {
145 u8 level; 145 u8 level;
146} __attribute__ ((__packed__)); 146} __attribute__ ((__packed__));
147 147
148#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
149 sizeof(struct btrfs_header)) / \
150 sizeof(struct btrfs_key_ptr))
151#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
152#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->nodesize))
153#define BTRFS_MAX_ITEM_SIZE(r) \
154 (BTRFS_LEAF_DATA_SIZE(r) - sizeof(struct btrfs_item))
155#define BTRFS_FILE_EXTENT_INLINE_DATA_START \
156 (offsetof(struct btrfs_file_extent_item, disk_bytenr))
157#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_MAX_ITEM_SIZE(r) - \
158 BTRFS_FILE_EXTENT_INLINE_DATA_START)
159#define BTRFS_MAX_XATTR_SIZE(r) (BTRFS_MAX_ITEM_SIZE(r) - \
160 sizeof(struct btrfs_dir_item))
161
162
163/* 148/*
164 * this is a very generous portion of the super block, giving us 149 * this is a very generous portion of the super block, giving us
165 * room to translate 14 chunks with 3 stripes each. 150 * room to translate 14 chunks with 3 stripes each.
@@ -1261,6 +1246,39 @@ struct btrfs_root {
1261 atomic_t qgroup_meta_rsv; 1246 atomic_t qgroup_meta_rsv;
1262}; 1247};
1263 1248
1249static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 blocksize)
1250{
1251 return blocksize - sizeof(struct btrfs_header);
1252}
1253
1254static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_root *root)
1255{
1256 return __BTRFS_LEAF_DATA_SIZE(root->nodesize);
1257}
1258
1259static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_root *root)
1260{
1261 return BTRFS_LEAF_DATA_SIZE(root) - sizeof(struct btrfs_item);
1262}
1263
1264static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_root *root)
1265{
1266 return BTRFS_LEAF_DATA_SIZE(root) / sizeof(struct btrfs_key_ptr);
1267}
1268
1269#define BTRFS_FILE_EXTENT_INLINE_DATA_START \
1270 (offsetof(struct btrfs_file_extent_item, disk_bytenr))
1271static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_root *root)
1272{
1273 return BTRFS_MAX_ITEM_SIZE(root) -
1274 BTRFS_FILE_EXTENT_INLINE_DATA_START;
1275}
1276
1277static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_root *root)
1278{
1279 return BTRFS_MAX_ITEM_SIZE(root) - sizeof(struct btrfs_dir_item);
1280}
1281
1264/* 1282/*
1265 * Flags for mount options. 1283 * Flags for mount options.
1266 * 1284 *