bcachefs: Improve bch2_inode_opts_to_opts()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 24 Nov 2022 01:28:15 +0000 (20:28 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:46 +0000 (17:09 -0400)
It turns out the *_defined entries of bch_io_opts are only used in one
place - in the xattr get path - and there we immediately convert to a
bch_opts struct, which also has the *_defined entries.

This patch changes bch2_inode_opts_to_opts() to go directly from
bch_inode_unpacked to bch_opts, which is a minor simplification and will
also let us slim down struct bch_io_opts in another patch.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/inode.c
fs/bcachefs/inode.h
fs/bcachefs/opts.c
fs/bcachefs/opts.h
fs/bcachefs/xattr.c

index f026e2f70dcdf8e308842328218d31448e20042e..827a0b04b00f0626eeae3d1b402badba19576610 100644 (file)
@@ -763,3 +763,14 @@ void bch2_inode_nlink_dec(struct btree_trans *trans, struct bch_inode_unpacked *
        else
                bi->bi_flags |= BCH_INODE_UNLINKED;
 }
+
+struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *inode)
+{
+       struct bch_opts ret = { 0 };
+#define x(_name, _bits)                                                        \
+       if (inode->bi_##_name)                                          \
+               opt_set(ret, _name, inode->bi_##_name - 1);
+       BCH_INODE_OPTS()
+#undef x
+       return ret;
+}
index 9ea0d575a183991e4f0f0c5e38f84819ca89b6d7..27744f78ae96014fd2ccccb80d9af62a8785a5b0 100644 (file)
@@ -187,4 +187,6 @@ static inline void bch2_inode_nlink_set(struct bch_inode_unpacked *bi,
 int bch2_inode_nlink_inc(struct bch_inode_unpacked *);
 void bch2_inode_nlink_dec(struct btree_trans *, struct bch_inode_unpacked *);
 
+struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *);
+
 #endif /* _BCACHEFS_INODE_H */
index 98568f21d6d07407169e50a4195f0482753ef7cc..9c49d543b0628088422476e07a6d57c244398626 100644 (file)
@@ -540,17 +540,6 @@ struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts src)
        return ret;
 }
 
-struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts src)
-{
-       struct bch_opts ret = { 0 };
-#define x(_name, _bits)                                        \
-       if (opt_defined(src, _name))                                    \
-               opt_set(ret, _name, src._name);
-       BCH_INODE_OPTS()
-#undef x
-       return ret;
-}
-
 void bch2_io_opts_apply(struct bch_io_opts *dst, struct bch_io_opts src)
 {
 #define x(_name, _bits)                                        \
index 6e2bd6e01f8cc042d69ef3f45bd59a7fd19da9a3..a32a7ab73bd52dabf1c91238187bb7c899f259da 100644 (file)
@@ -513,7 +513,6 @@ struct bch_io_opts {
 };
 
 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
-struct bch_opts bch2_inode_opts_to_opts(struct bch_io_opts);
 void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
 bool bch2_opt_is_inode_opt(enum bch_opt_id);
 
index 2b9fb4941e9f7253a6e891cda2a202ebaa437f93..bd118f6ea08b98f33893e5a1a57de3ad60b1c139 100644 (file)
@@ -444,7 +444,7 @@ static int __bch2_xattr_bcachefs_get(const struct xattr_handler *handler,
        struct bch_inode_info *inode = to_bch_ei(vinode);
        struct bch_fs *c = inode->v.i_sb->s_fs_info;
        struct bch_opts opts =
-               bch2_inode_opts_to_opts(bch2_inode_opts_get(&inode->ei_inode));
+               bch2_inode_opts_to_opts(&inode->ei_inode);
        const struct bch_option *opt;
        int id, inode_opt_id;
        struct printbuf out = PRINTBUF;