From: Kent Overstreet Date: Thu, 13 Dec 2018 11:01:30 +0000 (-0500) Subject: bcachefs: use x-macros more consistently X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=a3e70fb287ee62ee14512a69e9a3e1870a057e11;p=linux.git bcachefs: use x-macros more consistently Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h index 8ef17c7ddaf7a..2e048d25d3a91 100644 --- a/fs/bcachefs/bcachefs_format.h +++ b/fs/bcachefs/bcachefs_format.h @@ -694,38 +694,38 @@ struct bch_inode_generation { __le32 pad; } __attribute__((packed, aligned(8))); -#define BCH_INODE_FIELDS() \ - BCH_INODE_FIELD(bi_atime, 64) \ - BCH_INODE_FIELD(bi_ctime, 64) \ - BCH_INODE_FIELD(bi_mtime, 64) \ - BCH_INODE_FIELD(bi_otime, 64) \ - BCH_INODE_FIELD(bi_size, 64) \ - BCH_INODE_FIELD(bi_sectors, 64) \ - BCH_INODE_FIELD(bi_uid, 32) \ - BCH_INODE_FIELD(bi_gid, 32) \ - BCH_INODE_FIELD(bi_nlink, 32) \ - BCH_INODE_FIELD(bi_generation, 32) \ - BCH_INODE_FIELD(bi_dev, 32) \ - BCH_INODE_FIELD(bi_data_checksum, 8) \ - BCH_INODE_FIELD(bi_compression, 8) \ - BCH_INODE_FIELD(bi_project, 32) \ - BCH_INODE_FIELD(bi_background_compression, 8) \ - BCH_INODE_FIELD(bi_data_replicas, 8) \ - BCH_INODE_FIELD(bi_promote_target, 16) \ - BCH_INODE_FIELD(bi_foreground_target, 16) \ - BCH_INODE_FIELD(bi_background_target, 16) \ - BCH_INODE_FIELD(bi_erasure_code, 16) - -#define BCH_INODE_FIELDS_INHERIT() \ - BCH_INODE_FIELD(bi_data_checksum) \ - BCH_INODE_FIELD(bi_compression) \ - BCH_INODE_FIELD(bi_project) \ - BCH_INODE_FIELD(bi_background_compression) \ - BCH_INODE_FIELD(bi_data_replicas) \ - BCH_INODE_FIELD(bi_promote_target) \ - BCH_INODE_FIELD(bi_foreground_target) \ - BCH_INODE_FIELD(bi_background_target) \ - BCH_INODE_FIELD(bi_erasure_code) +#define BCH_INODE_FIELDS() \ + x(bi_atime, 64) \ + x(bi_ctime, 64) \ + x(bi_mtime, 64) \ + x(bi_otime, 64) \ + x(bi_size, 64) \ + x(bi_sectors, 64) \ + x(bi_uid, 32) \ + x(bi_gid, 32) \ + x(bi_nlink, 32) \ + x(bi_generation, 32) \ + x(bi_dev, 32) \ + x(bi_data_checksum, 8) \ + x(bi_compression, 8) \ + x(bi_project, 32) \ + x(bi_background_compression, 8) \ + x(bi_data_replicas, 8) \ + x(bi_promote_target, 16) \ + x(bi_foreground_target, 16) \ + x(bi_background_target, 16) \ + x(bi_erasure_code, 16) + +#define BCH_INODE_FIELDS_INHERIT() \ + x(bi_data_checksum) \ + x(bi_compression) \ + x(bi_project) \ + x(bi_background_compression) \ + x(bi_data_replicas) \ + x(bi_promote_target) \ + x(bi_foreground_target) \ + x(bi_background_target) \ + x(bi_erasure_code) enum { /* diff --git a/fs/bcachefs/inode.c b/fs/bcachefs/inode.c index 30f93fbe280d4..f967029584a7c 100644 --- a/fs/bcachefs/inode.c +++ b/fs/bcachefs/inode.c @@ -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_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); \ nr_fields++; \ \ @@ -108,7 +108,7 @@ void bch2_inode_pack(struct bkey_inode_buf *packed, } BCH_INODE_FIELDS() -#undef BCH_INODE_FIELD +#undef x out = last_nonzero_field; nr_fields = last_nonzero_fieldnr; @@ -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_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() -#undef BCH_INODE_FIELD +#undef x } } @@ -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_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)) { \ unsigned offset = offsetof(struct bch_inode_unpacked, _name);\ memset((void *) unpacked + offset, 0, \ @@ -169,7 +169,7 @@ int bch2_inode_unpack(struct bkey_s_c_inode inode, in += ret; BCH_INODE_FIELDS() -#undef BCH_INODE_FIELD +#undef x /* 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, return; } -#define BCH_INODE_FIELD(_name, _bits) \ +#define x(_name, _bits) \ pr_buf(out, #_name ": %llu ", (u64) unpacked._name); BCH_INODE_FIELDS() -#undef BCH_INODE_FIELD +#undef x } 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, inode_u->bi_otime = now; if (parent) { -#define BCH_INODE_FIELD(_name) inode_u->_name = parent->_name; +#define x(_name) inode_u->_name = parent->_name; BCH_INODE_FIELDS_INHERIT() -#undef BCH_INODE_FIELD +#undef x } } diff --git a/fs/bcachefs/inode.h b/fs/bcachefs/inode.h index 0bc852e693550..74fa6ff84111b 100644 --- a/fs/bcachefs/inode.h +++ b/fs/bcachefs/inode.h @@ -30,17 +30,17 @@ struct bch_inode_unpacked { u32 bi_flags; u16 bi_mode; -#define BCH_INODE_FIELD(_name, _bits) u##_bits _name; +#define x(_name, _bits) u##_bits _name; BCH_INODE_FIELDS() -#undef BCH_INODE_FIELD +#undef x }; struct bkey_inode_buf { 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()]; -#undef BCH_INODE_FIELD +#undef x } __attribute__((packed, aligned(8))); 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 * { struct bch_io_opts ret = { 0 }; -#define BCH_INODE_OPT(_name, _bits) \ +#define x(_name, _bits) \ if (inode->bi_##_name) \ opt_set(ret, _name, inode->bi_##_name - 1); BCH_INODE_OPTS() -#undef BCH_INODE_OPT +#undef x return ret; } @@ -77,12 +77,12 @@ static inline void __bch2_inode_opt_set(struct bch_inode_unpacked *inode, enum bch_opt_id id, u64 v) { switch (id) { -#define BCH_INODE_OPT(_name, ...) \ +#define x(_name, ...) \ case Opt_##_name: \ inode->bi_##_name = v; \ break; BCH_INODE_OPTS() -#undef BCH_INODE_OPT +#undef x default: BUG(); } diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c index 4d86c4bc4a5f9..17245e0b4a73f 100644 --- a/fs/bcachefs/opts.c +++ b/fs/bcachefs/opts.c @@ -377,40 +377,40 @@ no_val: struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts src) { struct bch_io_opts ret = { 0 }; -#define BCH_INODE_OPT(_name, _bits) \ +#define x(_name, _bits) \ if (opt_defined(src, _name)) \ opt_set(ret, _name, src._name); BCH_INODE_OPTS() -#undef BCH_INODE_OPT +#undef x return ret; } struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts src) { struct bch_opts ret = { 0 }; -#define BCH_INODE_OPT(_name, _bits) \ +#define x(_name, _bits) \ if (opt_defined(src, _name)) \ opt_set(ret, _name, src._name); BCH_INODE_OPTS() -#undef BCH_INODE_OPT +#undef x return ret; } 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)) \ opt_set(*dst, _name, src._name); BCH_INODE_OPTS() -#undef BCH_INODE_OPT +#undef x } bool bch2_opt_is_inode_opt(enum bch_opt_id id) { 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() -#undef BCH_INODE_OPT +#undef x }; unsigned i; diff --git a/fs/bcachefs/opts.h b/fs/bcachefs/opts.h index acdc952c48bec..222c130c2054b 100644 --- a/fs/bcachefs/opts.h +++ b/fs/bcachefs/opts.h @@ -281,24 +281,24 @@ int bch2_parse_mount_opts(struct bch_opts *, char *); /* inode opts: */ -#define BCH_INODE_OPTS() \ - BCH_INODE_OPT(data_checksum, 8) \ - BCH_INODE_OPT(compression, 8) \ - BCH_INODE_OPT(background_compression, 8) \ - BCH_INODE_OPT(data_replicas, 8) \ - BCH_INODE_OPT(promote_target, 16) \ - BCH_INODE_OPT(foreground_target, 16) \ - BCH_INODE_OPT(background_target, 16) \ - BCH_INODE_OPT(erasure_code, 16) +#define BCH_INODE_OPTS() \ + x(data_checksum, 8) \ + x(compression, 8) \ + x(background_compression, 8) \ + x(data_replicas, 8) \ + x(promote_target, 16) \ + x(foreground_target, 16) \ + x(background_target, 16) \ + x(erasure_code, 16) 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() -#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() -#undef BCH_INODE_OPT +#undef x }; struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);