Commit a3e70fb2 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: use x-macros more consistently

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 7121643e
...@@ -694,38 +694,38 @@ struct bch_inode_generation { ...@@ -694,38 +694,38 @@ struct bch_inode_generation {
__le32 pad; __le32 pad;
} __attribute__((packed, aligned(8))); } __attribute__((packed, aligned(8)));
#define BCH_INODE_FIELDS() \ #define BCH_INODE_FIELDS() \
BCH_INODE_FIELD(bi_atime, 64) \ x(bi_atime, 64) \
BCH_INODE_FIELD(bi_ctime, 64) \ x(bi_ctime, 64) \
BCH_INODE_FIELD(bi_mtime, 64) \ x(bi_mtime, 64) \
BCH_INODE_FIELD(bi_otime, 64) \ x(bi_otime, 64) \
BCH_INODE_FIELD(bi_size, 64) \ x(bi_size, 64) \
BCH_INODE_FIELD(bi_sectors, 64) \ x(bi_sectors, 64) \
BCH_INODE_FIELD(bi_uid, 32) \ x(bi_uid, 32) \
BCH_INODE_FIELD(bi_gid, 32) \ x(bi_gid, 32) \
BCH_INODE_FIELD(bi_nlink, 32) \ x(bi_nlink, 32) \
BCH_INODE_FIELD(bi_generation, 32) \ x(bi_generation, 32) \
BCH_INODE_FIELD(bi_dev, 32) \ x(bi_dev, 32) \
BCH_INODE_FIELD(bi_data_checksum, 8) \ x(bi_data_checksum, 8) \
BCH_INODE_FIELD(bi_compression, 8) \ x(bi_compression, 8) \
BCH_INODE_FIELD(bi_project, 32) \ x(bi_project, 32) \
BCH_INODE_FIELD(bi_background_compression, 8) \ x(bi_background_compression, 8) \
BCH_INODE_FIELD(bi_data_replicas, 8) \ x(bi_data_replicas, 8) \
BCH_INODE_FIELD(bi_promote_target, 16) \ x(bi_promote_target, 16) \
BCH_INODE_FIELD(bi_foreground_target, 16) \ x(bi_foreground_target, 16) \
BCH_INODE_FIELD(bi_background_target, 16) \ x(bi_background_target, 16) \
BCH_INODE_FIELD(bi_erasure_code, 16) x(bi_erasure_code, 16)
#define BCH_INODE_FIELDS_INHERIT() \ #define BCH_INODE_FIELDS_INHERIT() \
BCH_INODE_FIELD(bi_data_checksum) \ x(bi_data_checksum) \
BCH_INODE_FIELD(bi_compression) \ x(bi_compression) \
BCH_INODE_FIELD(bi_project) \ x(bi_project) \
BCH_INODE_FIELD(bi_background_compression) \ x(bi_background_compression) \
BCH_INODE_FIELD(bi_data_replicas) \ x(bi_data_replicas) \
BCH_INODE_FIELD(bi_promote_target) \ x(bi_promote_target) \
BCH_INODE_FIELD(bi_foreground_target) \ x(bi_foreground_target) \
BCH_INODE_FIELD(bi_background_target) \ x(bi_background_target) \
BCH_INODE_FIELD(bi_erasure_code) x(bi_erasure_code)
enum { enum {
/* /*
......
...@@ -98,7 +98,7 @@ void bch2_inode_pack(struct bkey_inode_buf *packed, ...@@ -98,7 +98,7 @@ void bch2_inode_pack(struct bkey_inode_buf *packed,
packed->inode.v.bi_flags = cpu_to_le32(inode->bi_flags); packed->inode.v.bi_flags = cpu_to_le32(inode->bi_flags);
packed->inode.v.bi_mode = cpu_to_le16(inode->bi_mode); packed->inode.v.bi_mode = cpu_to_le16(inode->bi_mode);
#define BCH_INODE_FIELD(_name, _bits) \ #define x(_name, _bits) \
out += inode_encode_field(out, end, 0, inode->_name); \ out += inode_encode_field(out, end, 0, inode->_name); \
nr_fields++; \ nr_fields++; \
\ \
...@@ -108,7 +108,7 @@ void bch2_inode_pack(struct bkey_inode_buf *packed, ...@@ -108,7 +108,7 @@ void bch2_inode_pack(struct bkey_inode_buf *packed,
} }
BCH_INODE_FIELDS() BCH_INODE_FIELDS()
#undef BCH_INODE_FIELD #undef x
out = last_nonzero_field; out = last_nonzero_field;
nr_fields = last_nonzero_fieldnr; nr_fields = last_nonzero_fieldnr;
...@@ -130,9 +130,9 @@ void bch2_inode_pack(struct bkey_inode_buf *packed, ...@@ -130,9 +130,9 @@ void bch2_inode_pack(struct bkey_inode_buf *packed,
BUG_ON(unpacked.bi_hash_seed != inode->bi_hash_seed); BUG_ON(unpacked.bi_hash_seed != inode->bi_hash_seed);
BUG_ON(unpacked.bi_mode != inode->bi_mode); BUG_ON(unpacked.bi_mode != inode->bi_mode);
#define BCH_INODE_FIELD(_name, _bits) BUG_ON(unpacked._name != inode->_name); #define x(_name, _bits) BUG_ON(unpacked._name != inode->_name);
BCH_INODE_FIELDS() BCH_INODE_FIELDS()
#undef BCH_INODE_FIELD #undef x
} }
} }
...@@ -150,7 +150,7 @@ int bch2_inode_unpack(struct bkey_s_c_inode inode, ...@@ -150,7 +150,7 @@ int bch2_inode_unpack(struct bkey_s_c_inode inode,
unpacked->bi_flags = le32_to_cpu(inode.v->bi_flags); unpacked->bi_flags = le32_to_cpu(inode.v->bi_flags);
unpacked->bi_mode = le16_to_cpu(inode.v->bi_mode); unpacked->bi_mode = le16_to_cpu(inode.v->bi_mode);
#define BCH_INODE_FIELD(_name, _bits) \ #define x(_name, _bits) \
if (fieldnr++ == INODE_NR_FIELDS(inode.v)) { \ if (fieldnr++ == INODE_NR_FIELDS(inode.v)) { \
unsigned offset = offsetof(struct bch_inode_unpacked, _name);\ unsigned offset = offsetof(struct bch_inode_unpacked, _name);\
memset((void *) unpacked + offset, 0, \ memset((void *) unpacked + offset, 0, \
...@@ -169,7 +169,7 @@ int bch2_inode_unpack(struct bkey_s_c_inode inode, ...@@ -169,7 +169,7 @@ int bch2_inode_unpack(struct bkey_s_c_inode inode,
in += ret; in += ret;
BCH_INODE_FIELDS() BCH_INODE_FIELDS()
#undef BCH_INODE_FIELD #undef x
/* XXX: signal if there were more fields than expected? */ /* XXX: signal if there were more fields than expected? */
...@@ -220,10 +220,10 @@ void bch2_inode_to_text(struct printbuf *out, struct bch_fs *c, ...@@ -220,10 +220,10 @@ void bch2_inode_to_text(struct printbuf *out, struct bch_fs *c,
return; return;
} }
#define BCH_INODE_FIELD(_name, _bits) \ #define x(_name, _bits) \
pr_buf(out, #_name ": %llu ", (u64) unpacked._name); pr_buf(out, #_name ": %llu ", (u64) unpacked._name);
BCH_INODE_FIELDS() BCH_INODE_FIELDS()
#undef BCH_INODE_FIELD #undef x
} }
const char *bch2_inode_generation_invalid(const struct bch_fs *c, const char *bch2_inode_generation_invalid(const struct bch_fs *c,
...@@ -265,9 +265,9 @@ void bch2_inode_init(struct bch_fs *c, struct bch_inode_unpacked *inode_u, ...@@ -265,9 +265,9 @@ void bch2_inode_init(struct bch_fs *c, struct bch_inode_unpacked *inode_u,
inode_u->bi_otime = now; inode_u->bi_otime = now;
if (parent) { if (parent) {
#define BCH_INODE_FIELD(_name) inode_u->_name = parent->_name; #define x(_name) inode_u->_name = parent->_name;
BCH_INODE_FIELDS_INHERIT() BCH_INODE_FIELDS_INHERIT()
#undef BCH_INODE_FIELD #undef x
} }
} }
......
...@@ -30,17 +30,17 @@ struct bch_inode_unpacked { ...@@ -30,17 +30,17 @@ struct bch_inode_unpacked {
u32 bi_flags; u32 bi_flags;
u16 bi_mode; u16 bi_mode;
#define BCH_INODE_FIELD(_name, _bits) u##_bits _name; #define x(_name, _bits) u##_bits _name;
BCH_INODE_FIELDS() BCH_INODE_FIELDS()
#undef BCH_INODE_FIELD #undef x
}; };
struct bkey_inode_buf { struct bkey_inode_buf {
struct bkey_i_inode inode; struct bkey_i_inode inode;
#define BCH_INODE_FIELD(_name, _bits) + 8 + _bits / 8 #define x(_name, _bits) + 8 + _bits / 8
u8 _pad[0 + BCH_INODE_FIELDS()]; u8 _pad[0 + BCH_INODE_FIELDS()];
#undef BCH_INODE_FIELD #undef x
} __attribute__((packed, aligned(8))); } __attribute__((packed, aligned(8)));
void bch2_inode_pack(struct bkey_inode_buf *, const struct bch_inode_unpacked *); void bch2_inode_pack(struct bkey_inode_buf *, const struct bch_inode_unpacked *);
...@@ -65,11 +65,11 @@ static inline struct bch_io_opts bch2_inode_opts_get(struct bch_inode_unpacked * ...@@ -65,11 +65,11 @@ static inline struct bch_io_opts bch2_inode_opts_get(struct bch_inode_unpacked *
{ {
struct bch_io_opts ret = { 0 }; struct bch_io_opts ret = { 0 };
#define BCH_INODE_OPT(_name, _bits) \ #define x(_name, _bits) \
if (inode->bi_##_name) \ if (inode->bi_##_name) \
opt_set(ret, _name, inode->bi_##_name - 1); opt_set(ret, _name, inode->bi_##_name - 1);
BCH_INODE_OPTS() BCH_INODE_OPTS()
#undef BCH_INODE_OPT #undef x
return ret; return ret;
} }
...@@ -77,12 +77,12 @@ static inline void __bch2_inode_opt_set(struct bch_inode_unpacked *inode, ...@@ -77,12 +77,12 @@ static inline void __bch2_inode_opt_set(struct bch_inode_unpacked *inode,
enum bch_opt_id id, u64 v) enum bch_opt_id id, u64 v)
{ {
switch (id) { switch (id) {
#define BCH_INODE_OPT(_name, ...) \ #define x(_name, ...) \
case Opt_##_name: \ case Opt_##_name: \
inode->bi_##_name = v; \ inode->bi_##_name = v; \
break; break;
BCH_INODE_OPTS() BCH_INODE_OPTS()
#undef BCH_INODE_OPT #undef x
default: default:
BUG(); BUG();
} }
......
...@@ -377,40 +377,40 @@ int bch2_parse_mount_opts(struct bch_opts *opts, char *options) ...@@ -377,40 +377,40 @@ int bch2_parse_mount_opts(struct bch_opts *opts, char *options)
struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts src) struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts src)
{ {
struct bch_io_opts ret = { 0 }; struct bch_io_opts ret = { 0 };
#define BCH_INODE_OPT(_name, _bits) \ #define x(_name, _bits) \
if (opt_defined(src, _name)) \ if (opt_defined(src, _name)) \
opt_set(ret, _name, src._name); opt_set(ret, _name, src._name);
BCH_INODE_OPTS() BCH_INODE_OPTS()
#undef BCH_INODE_OPT #undef x
return ret; return ret;
} }
struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts src) struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts src)
{ {
struct bch_opts ret = { 0 }; struct bch_opts ret = { 0 };
#define BCH_INODE_OPT(_name, _bits) \ #define x(_name, _bits) \
if (opt_defined(src, _name)) \ if (opt_defined(src, _name)) \
opt_set(ret, _name, src._name); opt_set(ret, _name, src._name);
BCH_INODE_OPTS() BCH_INODE_OPTS()
#undef BCH_INODE_OPT #undef x
return ret; return ret;
} }
void bch2_io_opts_apply(struct bch_io_opts *dst, struct bch_io_opts src) void bch2_io_opts_apply(struct bch_io_opts *dst, struct bch_io_opts src)
{ {
#define BCH_INODE_OPT(_name, _bits) \ #define x(_name, _bits) \
if (opt_defined(src, _name)) \ if (opt_defined(src, _name)) \
opt_set(*dst, _name, src._name); opt_set(*dst, _name, src._name);
BCH_INODE_OPTS() BCH_INODE_OPTS()
#undef BCH_INODE_OPT #undef x
} }
bool bch2_opt_is_inode_opt(enum bch_opt_id id) bool bch2_opt_is_inode_opt(enum bch_opt_id id)
{ {
static const enum bch_opt_id inode_opt_list[] = { static const enum bch_opt_id inode_opt_list[] = {
#define BCH_INODE_OPT(_name, _bits) Opt_##_name, #define x(_name, _bits) Opt_##_name,
BCH_INODE_OPTS() BCH_INODE_OPTS()
#undef BCH_INODE_OPT #undef x
}; };
unsigned i; unsigned i;
......
...@@ -281,24 +281,24 @@ int bch2_parse_mount_opts(struct bch_opts *, char *); ...@@ -281,24 +281,24 @@ int bch2_parse_mount_opts(struct bch_opts *, char *);
/* inode opts: */ /* inode opts: */
#define BCH_INODE_OPTS() \ #define BCH_INODE_OPTS() \
BCH_INODE_OPT(data_checksum, 8) \ x(data_checksum, 8) \
BCH_INODE_OPT(compression, 8) \ x(compression, 8) \
BCH_INODE_OPT(background_compression, 8) \ x(background_compression, 8) \
BCH_INODE_OPT(data_replicas, 8) \ x(data_replicas, 8) \
BCH_INODE_OPT(promote_target, 16) \ x(promote_target, 16) \
BCH_INODE_OPT(foreground_target, 16) \ x(foreground_target, 16) \
BCH_INODE_OPT(background_target, 16) \ x(background_target, 16) \
BCH_INODE_OPT(erasure_code, 16) x(erasure_code, 16)
struct bch_io_opts { struct bch_io_opts {
#define BCH_INODE_OPT(_name, _bits) unsigned _name##_defined:1; #define x(_name, _bits) unsigned _name##_defined:1;
BCH_INODE_OPTS() BCH_INODE_OPTS()
#undef BCH_INODE_OPT #undef x
#define BCH_INODE_OPT(_name, _bits) u##_bits _name; #define x(_name, _bits) u##_bits _name;
BCH_INODE_OPTS() BCH_INODE_OPTS()
#undef BCH_INODE_OPT #undef x
}; };
struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts); struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment