1 // SPDX-License-Identifier: GPL-2.0
4 #include "btree_key_cache.h"
5 #include "bkey_methods.h"
6 #include "btree_update.h"
10 #include "extent_update.h"
13 #include "subvolume.h"
16 #include <linux/random.h>
18 #include <asm/unaligned.h>
20 const char * const bch2_inode_opts[] = {
21 #define x(name, ...) #name,
27 static const u8 byte_table[8] = { 1, 2, 3, 4, 6, 8, 10, 13 };
29 static int inode_decode_field(const u8 *in, const u8 *end,
30 u64 out[2], unsigned *out_bits)
32 __be64 be[2] = { 0, 0 };
33 unsigned bytes, shift;
43 * position of highest set bit indicates number of bytes:
44 * shift = number of bits to remove in high byte:
46 shift = 8 - __fls(*in); /* 1 <= shift <= 8 */
47 bytes = byte_table[shift - 1];
52 p = (u8 *) be + 16 - bytes;
54 *p ^= (1 << 8) >> shift;
56 out[0] = be64_to_cpu(be[0]);
57 out[1] = be64_to_cpu(be[1]);
58 *out_bits = out[0] ? 64 + fls64(out[0]) : fls64(out[1]);
63 static inline void bch2_inode_pack_inlined(struct bkey_inode_buf *packed,
64 const struct bch_inode_unpacked *inode)
66 struct bkey_i_inode_v3 *k = &packed->inode;
67 u8 *out = k->v.fields;
68 u8 *end = (void *) &packed[1];
69 u8 *last_nonzero_field = out;
70 unsigned nr_fields = 0, last_nonzero_fieldnr = 0;
74 bkey_inode_v3_init(&packed->inode.k_i);
75 packed->inode.k.p.offset = inode->bi_inum;
76 packed->inode.v.bi_journal_seq = cpu_to_le64(inode->bi_journal_seq);
77 packed->inode.v.bi_hash_seed = inode->bi_hash_seed;
78 packed->inode.v.bi_flags = cpu_to_le64(inode->bi_flags);
79 packed->inode.v.bi_sectors = cpu_to_le64(inode->bi_sectors);
80 packed->inode.v.bi_size = cpu_to_le64(inode->bi_size);
81 packed->inode.v.bi_version = cpu_to_le64(inode->bi_version);
82 SET_INODEv3_MODE(&packed->inode.v, inode->bi_mode);
83 SET_INODEv3_FIELDS_START(&packed->inode.v, INODEv3_FIELDS_START_CUR);
86 #define x(_name, _bits) \
90 ret = bch2_varint_encode_fast(out, inode->_name); \
96 last_nonzero_field = out; \
97 last_nonzero_fieldnr = nr_fields; \
105 BCH_INODE_FIELDS_v3()
109 out = last_nonzero_field;
110 nr_fields = last_nonzero_fieldnr;
112 bytes = out - (u8 *) &packed->inode.v;
113 set_bkey_val_bytes(&packed->inode.k, bytes);
114 memset_u64s_tail(&packed->inode.v, 0, bytes);
116 SET_INODEv3_NR_FIELDS(&k->v, nr_fields);
118 if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG)) {
119 struct bch_inode_unpacked unpacked;
121 int ret = bch2_inode_unpack(bkey_i_to_s_c(&packed->inode.k_i),
124 BUG_ON(unpacked.bi_inum != inode->bi_inum);
125 BUG_ON(unpacked.bi_hash_seed != inode->bi_hash_seed);
126 BUG_ON(unpacked.bi_sectors != inode->bi_sectors);
127 BUG_ON(unpacked.bi_size != inode->bi_size);
128 BUG_ON(unpacked.bi_version != inode->bi_version);
129 BUG_ON(unpacked.bi_mode != inode->bi_mode);
131 #define x(_name, _bits) if (unpacked._name != inode->_name) \
132 panic("unpacked %llu should be %llu", \
133 (u64) unpacked._name, (u64) inode->_name);
134 BCH_INODE_FIELDS_v3()
139 void bch2_inode_pack(struct bkey_inode_buf *packed,
140 const struct bch_inode_unpacked *inode)
142 bch2_inode_pack_inlined(packed, inode);
145 static noinline int bch2_inode_unpack_v1(struct bkey_s_c_inode inode,
146 struct bch_inode_unpacked *unpacked)
148 const u8 *in = inode.v->fields;
149 const u8 *end = bkey_val_end(inode);
151 unsigned fieldnr = 0, field_bits;
154 #define x(_name, _bits) \
155 if (fieldnr++ == INODE_NR_FIELDS(inode.v)) { \
156 unsigned offset = offsetof(struct bch_inode_unpacked, _name);\
157 memset((void *) unpacked + offset, 0, \
158 sizeof(*unpacked) - offset); \
162 ret = inode_decode_field(in, end, field, &field_bits); \
166 if (field_bits > sizeof(unpacked->_name) * 8) \
169 unpacked->_name = field[1]; \
172 BCH_INODE_FIELDS_v2()
175 /* XXX: signal if there were more fields than expected? */
179 static int bch2_inode_unpack_v2(struct bch_inode_unpacked *unpacked,
180 const u8 *in, const u8 *end,
183 unsigned fieldnr = 0;
187 #define x(_name, _bits) \
188 if (fieldnr < nr_fields) { \
189 ret = bch2_varint_decode_fast(in, end, &v[0]); \
195 ret = bch2_varint_decode_fast(in, end, &v[1]); \
206 unpacked->_name = v[0]; \
207 if (v[1] || v[0] != unpacked->_name) \
211 BCH_INODE_FIELDS_v2()
214 /* XXX: signal if there were more fields than expected? */
218 static int bch2_inode_unpack_v3(struct bkey_s_c k,
219 struct bch_inode_unpacked *unpacked)
221 struct bkey_s_c_inode_v3 inode = bkey_s_c_to_inode_v3(k);
222 const u8 *in = inode.v->fields;
223 const u8 *end = bkey_val_end(inode);
224 unsigned nr_fields = INODEv3_NR_FIELDS(inode.v);
225 unsigned fieldnr = 0;
229 unpacked->bi_inum = inode.k->p.offset;
230 unpacked->bi_journal_seq= le64_to_cpu(inode.v->bi_journal_seq);
231 unpacked->bi_hash_seed = inode.v->bi_hash_seed;
232 unpacked->bi_flags = le64_to_cpu(inode.v->bi_flags);
233 unpacked->bi_sectors = le64_to_cpu(inode.v->bi_sectors);
234 unpacked->bi_size = le64_to_cpu(inode.v->bi_size);
235 unpacked->bi_version = le64_to_cpu(inode.v->bi_version);
236 unpacked->bi_mode = INODEv3_MODE(inode.v);
238 #define x(_name, _bits) \
239 if (fieldnr < nr_fields) { \
240 ret = bch2_varint_decode_fast(in, end, &v[0]); \
246 ret = bch2_varint_decode_fast(in, end, &v[1]); \
257 unpacked->_name = v[0]; \
258 if (v[1] || v[0] != unpacked->_name) \
262 BCH_INODE_FIELDS_v3()
265 /* XXX: signal if there were more fields than expected? */
269 static noinline int bch2_inode_unpack_slowpath(struct bkey_s_c k,
270 struct bch_inode_unpacked *unpacked)
272 memset(unpacked, 0, sizeof(*unpacked));
275 case KEY_TYPE_inode: {
276 struct bkey_s_c_inode inode = bkey_s_c_to_inode(k);
278 unpacked->bi_inum = inode.k->p.offset;
279 unpacked->bi_journal_seq= 0;
280 unpacked->bi_hash_seed = inode.v->bi_hash_seed;
281 unpacked->bi_flags = le32_to_cpu(inode.v->bi_flags);
282 unpacked->bi_mode = le16_to_cpu(inode.v->bi_mode);
284 if (INODE_NEW_VARINT(inode.v)) {
285 return bch2_inode_unpack_v2(unpacked, inode.v->fields,
287 INODE_NR_FIELDS(inode.v));
289 return bch2_inode_unpack_v1(inode, unpacked);
293 case KEY_TYPE_inode_v2: {
294 struct bkey_s_c_inode_v2 inode = bkey_s_c_to_inode_v2(k);
296 unpacked->bi_inum = inode.k->p.offset;
297 unpacked->bi_journal_seq= le64_to_cpu(inode.v->bi_journal_seq);
298 unpacked->bi_hash_seed = inode.v->bi_hash_seed;
299 unpacked->bi_flags = le64_to_cpu(inode.v->bi_flags);
300 unpacked->bi_mode = le16_to_cpu(inode.v->bi_mode);
302 return bch2_inode_unpack_v2(unpacked, inode.v->fields,
304 INODEv2_NR_FIELDS(inode.v));
311 int bch2_inode_unpack(struct bkey_s_c k,
312 struct bch_inode_unpacked *unpacked)
314 if (likely(k.k->type == KEY_TYPE_inode_v3))
315 return bch2_inode_unpack_v3(k, unpacked);
316 return bch2_inode_unpack_slowpath(k, unpacked);
319 int bch2_inode_peek(struct btree_trans *trans,
320 struct btree_iter *iter,
321 struct bch_inode_unpacked *inode,
322 subvol_inum inum, unsigned flags)
328 ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
332 k = bch2_bkey_get_iter(trans, iter, BTREE_ID_inodes,
333 SPOS(0, inum.inum, snapshot),
334 flags|BTREE_ITER_CACHED);
339 ret = bkey_is_inode(k.k) ? 0 : -ENOENT;
343 ret = bch2_inode_unpack(k, inode);
349 bch2_trans_iter_exit(trans, iter);
353 int bch2_inode_write(struct btree_trans *trans,
354 struct btree_iter *iter,
355 struct bch_inode_unpacked *inode)
357 struct bkey_inode_buf *inode_p;
359 inode_p = bch2_trans_kmalloc(trans, sizeof(*inode_p));
361 return PTR_ERR(inode_p);
363 bch2_inode_pack_inlined(inode_p, inode);
364 inode_p->inode.k.p.snapshot = iter->snapshot;
365 return bch2_trans_update(trans, iter, &inode_p->inode.k_i, 0);
368 struct bkey_i *bch2_inode_to_v3(struct btree_trans *trans, struct bkey_i *k)
370 struct bch_inode_unpacked u;
371 struct bkey_inode_buf *inode_p;
374 if (!bkey_is_inode(&k->k))
375 return ERR_PTR(-ENOENT);
377 inode_p = bch2_trans_kmalloc(trans, sizeof(*inode_p));
379 return ERR_CAST(inode_p);
381 ret = bch2_inode_unpack(bkey_i_to_s_c(k), &u);
385 bch2_inode_pack(inode_p, &u);
386 return &inode_p->inode.k_i;
389 static int __bch2_inode_invalid(struct bkey_s_c k, struct printbuf *err)
391 struct bch_inode_unpacked unpacked;
394 prt_printf(err, "nonzero k.p.inode");
395 return -BCH_ERR_invalid_bkey;
398 if (k.k->p.offset < BLOCKDEV_INODE_MAX) {
399 prt_printf(err, "fs inode in blockdev range");
400 return -BCH_ERR_invalid_bkey;
403 if (bch2_inode_unpack(k, &unpacked)) {
404 prt_printf(err, "invalid variable length fields");
405 return -BCH_ERR_invalid_bkey;
408 if (unpacked.bi_data_checksum >= BCH_CSUM_OPT_NR + 1) {
409 prt_printf(err, "invalid data checksum type (%u >= %u",
410 unpacked.bi_data_checksum, BCH_CSUM_OPT_NR + 1);
411 return -BCH_ERR_invalid_bkey;
414 if (unpacked.bi_compression >= BCH_COMPRESSION_OPT_NR + 1) {
415 prt_printf(err, "invalid data checksum type (%u >= %u)",
416 unpacked.bi_compression, BCH_COMPRESSION_OPT_NR + 1);
417 return -BCH_ERR_invalid_bkey;
420 if ((unpacked.bi_flags & BCH_INODE_UNLINKED) &&
421 unpacked.bi_nlink != 0) {
422 prt_printf(err, "flagged as unlinked but bi_nlink != 0");
423 return -BCH_ERR_invalid_bkey;
426 if (unpacked.bi_subvol && !S_ISDIR(unpacked.bi_mode)) {
427 prt_printf(err, "subvolume root but not a directory");
428 return -BCH_ERR_invalid_bkey;
434 int bch2_inode_invalid(const struct bch_fs *c, struct bkey_s_c k,
435 unsigned flags, struct printbuf *err)
437 struct bkey_s_c_inode inode = bkey_s_c_to_inode(k);
439 if (INODE_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
440 prt_printf(err, "invalid str hash type (%llu >= %u)",
441 INODE_STR_HASH(inode.v), BCH_STR_HASH_NR);
442 return -BCH_ERR_invalid_bkey;
445 return __bch2_inode_invalid(k, err);
448 int bch2_inode_v2_invalid(const struct bch_fs *c, struct bkey_s_c k,
449 unsigned flags, struct printbuf *err)
451 struct bkey_s_c_inode_v2 inode = bkey_s_c_to_inode_v2(k);
453 if (INODEv2_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
454 prt_printf(err, "invalid str hash type (%llu >= %u)",
455 INODEv2_STR_HASH(inode.v), BCH_STR_HASH_NR);
456 return -BCH_ERR_invalid_bkey;
459 return __bch2_inode_invalid(k, err);
462 int bch2_inode_v3_invalid(const struct bch_fs *c, struct bkey_s_c k,
463 unsigned flags, struct printbuf *err)
465 struct bkey_s_c_inode_v3 inode = bkey_s_c_to_inode_v3(k);
467 if (INODEv3_FIELDS_START(inode.v) < INODEv3_FIELDS_START_INITIAL ||
468 INODEv3_FIELDS_START(inode.v) > bkey_val_u64s(inode.k)) {
469 prt_printf(err, "invalid fields_start (got %llu, min %u max %zu)",
470 INODEv3_FIELDS_START(inode.v),
471 INODEv3_FIELDS_START_INITIAL,
472 bkey_val_u64s(inode.k));
473 return -BCH_ERR_invalid_bkey;
476 if (INODEv3_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
477 prt_printf(err, "invalid str hash type (%llu >= %u)",
478 INODEv3_STR_HASH(inode.v), BCH_STR_HASH_NR);
479 return -BCH_ERR_invalid_bkey;
482 return __bch2_inode_invalid(k, err);
485 static void __bch2_inode_unpacked_to_text(struct printbuf *out,
486 struct bch_inode_unpacked *inode)
488 prt_printf(out, "mode %o flags %x journal_seq %llu bi_size %llu bi_sectors %llu bi_version %llu",
489 inode->bi_mode, inode->bi_flags,
490 inode->bi_journal_seq,
495 #define x(_name, _bits) \
496 prt_printf(out, " "#_name " %llu", (u64) inode->_name);
497 BCH_INODE_FIELDS_v3()
501 void bch2_inode_unpacked_to_text(struct printbuf *out, struct bch_inode_unpacked *inode)
503 prt_printf(out, "inum: %llu ", inode->bi_inum);
504 __bch2_inode_unpacked_to_text(out, inode);
507 void bch2_inode_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
509 struct bch_inode_unpacked inode;
511 if (bch2_inode_unpack(k, &inode)) {
512 prt_printf(out, "(unpack error)");
516 __bch2_inode_unpacked_to_text(out, &inode);
519 int bch2_inode_generation_invalid(const struct bch_fs *c, struct bkey_s_c k,
520 unsigned flags, struct printbuf *err)
523 prt_printf(err, "nonzero k.p.inode");
524 return -BCH_ERR_invalid_bkey;
530 void bch2_inode_generation_to_text(struct printbuf *out, struct bch_fs *c,
533 struct bkey_s_c_inode_generation gen = bkey_s_c_to_inode_generation(k);
535 prt_printf(out, "generation: %u", le32_to_cpu(gen.v->bi_generation));
538 void bch2_inode_init_early(struct bch_fs *c,
539 struct bch_inode_unpacked *inode_u)
541 enum bch_str_hash_type str_hash =
542 bch2_str_hash_opt_to_type(c, c->opts.str_hash);
544 memset(inode_u, 0, sizeof(*inode_u));
547 inode_u->bi_flags |= str_hash << INODE_STR_HASH_OFFSET;
548 get_random_bytes(&inode_u->bi_hash_seed,
549 sizeof(inode_u->bi_hash_seed));
552 void bch2_inode_init_late(struct bch_inode_unpacked *inode_u, u64 now,
553 uid_t uid, gid_t gid, umode_t mode, dev_t rdev,
554 struct bch_inode_unpacked *parent)
556 inode_u->bi_mode = mode;
557 inode_u->bi_uid = uid;
558 inode_u->bi_gid = gid;
559 inode_u->bi_dev = rdev;
560 inode_u->bi_atime = now;
561 inode_u->bi_mtime = now;
562 inode_u->bi_ctime = now;
563 inode_u->bi_otime = now;
565 if (parent && parent->bi_mode & S_ISGID) {
566 inode_u->bi_gid = parent->bi_gid;
568 inode_u->bi_mode |= S_ISGID;
572 #define x(_name, ...) inode_u->bi_##_name = parent->bi_##_name;
578 void bch2_inode_init(struct bch_fs *c, struct bch_inode_unpacked *inode_u,
579 uid_t uid, gid_t gid, umode_t mode, dev_t rdev,
580 struct bch_inode_unpacked *parent)
582 bch2_inode_init_early(c, inode_u);
583 bch2_inode_init_late(inode_u, bch2_current_time(c),
584 uid, gid, mode, rdev, parent);
587 static inline u32 bkey_generation(struct bkey_s_c k)
591 case KEY_TYPE_inode_v2:
593 case KEY_TYPE_inode_generation:
594 return le32_to_cpu(bkey_s_c_to_inode_generation(k).v->bi_generation);
601 * This just finds an empty slot:
603 int bch2_inode_create(struct btree_trans *trans,
604 struct btree_iter *iter,
605 struct bch_inode_unpacked *inode_u,
606 u32 snapshot, u64 cpu)
608 struct bch_fs *c = trans->c;
610 u64 min, max, start, pos, *hint;
612 unsigned bits = (c->opts.inodes_32bit ? 31 : 63);
614 if (c->opts.shard_inode_numbers) {
615 bits -= c->inode_shard_bits;
618 max = (cpu << bits) | ~(ULLONG_MAX << bits);
620 min = max_t(u64, min, BLOCKDEV_INODE_MAX);
621 hint = c->unused_inode_hints + cpu;
623 min = BLOCKDEV_INODE_MAX;
624 max = ~(ULLONG_MAX << bits);
625 hint = c->unused_inode_hints;
628 start = READ_ONCE(*hint);
630 if (start >= max || start < min)
634 bch2_trans_iter_init(trans, iter, BTREE_ID_inodes, POS(0, pos),
635 BTREE_ITER_ALL_SNAPSHOTS|
638 while ((k = bch2_btree_iter_peek(iter)).k &&
639 !(ret = bkey_err(k)) &&
640 bkey_lt(k.k->p, POS(0, max))) {
641 if (pos < iter->pos.offset)
645 * We don't need to iterate over keys in every snapshot once
646 * we've found just one:
648 pos = iter->pos.offset + 1;
649 bch2_btree_iter_set_pos(iter, POS(0, pos));
652 if (!ret && pos < max)
655 if (!ret && start == min)
656 ret = -BCH_ERR_ENOSPC_inode_create;
659 bch2_trans_iter_exit(trans, iter);
663 /* Retry from start */
665 bch2_btree_iter_set_pos(iter, POS(0, pos));
668 bch2_btree_iter_set_pos(iter, SPOS(0, pos, snapshot));
669 k = bch2_btree_iter_peek_slot(iter);
672 bch2_trans_iter_exit(trans, iter);
676 *hint = k.k->p.offset;
677 inode_u->bi_inum = k.k->p.offset;
678 inode_u->bi_generation = bkey_generation(k);
682 static int bch2_inode_delete_keys(struct btree_trans *trans,
683 subvol_inum inum, enum btree_id id)
685 struct btree_iter iter;
687 struct bkey_i delete;
692 * We're never going to be deleting partial extents, no need to use an
695 bch2_trans_iter_init(trans, &iter, id, POS(inum.inum, 0),
696 BTREE_ITER_INTENT|BTREE_ITER_NOT_EXTENTS);
699 bch2_trans_begin(trans);
701 ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
705 bch2_btree_iter_set_snapshot(&iter, snapshot);
707 k = bch2_btree_iter_peek_upto(&iter, POS(inum.inum, U64_MAX));
715 bkey_init(&delete.k);
716 delete.k.p = iter.pos;
718 ret = bch2_trans_update(trans, &iter, &delete, 0) ?:
719 bch2_trans_commit(trans, NULL, NULL,
720 BTREE_INSERT_NOFAIL);
722 if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart))
726 bch2_trans_iter_exit(trans, &iter);
730 int bch2_inode_rm(struct bch_fs *c, subvol_inum inum)
732 struct btree_trans trans;
733 struct btree_iter iter = { NULL };
734 struct bkey_i_inode_generation delete;
735 struct bch_inode_unpacked inode_u;
740 bch2_trans_init(&trans, c, 0, 1024);
743 * If this was a directory, there shouldn't be any real dirents left -
744 * but there could be whiteouts (from hash collisions) that we should
747 * XXX: the dirent could ideally would delete whiteouts when they're no
750 ret = bch2_inode_delete_keys(&trans, inum, BTREE_ID_extents) ?:
751 bch2_inode_delete_keys(&trans, inum, BTREE_ID_xattrs) ?:
752 bch2_inode_delete_keys(&trans, inum, BTREE_ID_dirents);
756 bch2_trans_begin(&trans);
758 ret = bch2_subvolume_get_snapshot(&trans, inum.subvol, &snapshot);
762 k = bch2_bkey_get_iter(&trans, &iter, BTREE_ID_inodes,
763 SPOS(0, inum.inum, snapshot),
764 BTREE_ITER_INTENT|BTREE_ITER_CACHED);
769 if (!bkey_is_inode(k.k)) {
770 bch2_fs_inconsistent(trans.c,
771 "inode %llu:%u not found when deleting",
772 inum.inum, snapshot);
777 bch2_inode_unpack(k, &inode_u);
779 bkey_inode_generation_init(&delete.k_i);
780 delete.k.p = iter.pos;
781 delete.v.bi_generation = cpu_to_le32(inode_u.bi_generation + 1);
783 ret = bch2_trans_update(&trans, &iter, &delete.k_i, 0) ?:
784 bch2_trans_commit(&trans, NULL, NULL,
785 BTREE_INSERT_NOFAIL);
787 bch2_trans_iter_exit(&trans, &iter);
788 if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
791 bch2_trans_exit(&trans);
795 int bch2_inode_find_by_inum_trans(struct btree_trans *trans,
797 struct bch_inode_unpacked *inode)
799 struct btree_iter iter;
802 ret = bch2_inode_peek(trans, &iter, inode, inum, 0);
804 bch2_trans_iter_exit(trans, &iter);
808 int bch2_inode_find_by_inum(struct bch_fs *c, subvol_inum inum,
809 struct bch_inode_unpacked *inode)
811 return bch2_trans_do(c, NULL, NULL, 0,
812 bch2_inode_find_by_inum_trans(&trans, inum, inode));
815 int bch2_inode_nlink_inc(struct bch_inode_unpacked *bi)
817 if (bi->bi_flags & BCH_INODE_UNLINKED)
818 bi->bi_flags &= ~BCH_INODE_UNLINKED;
820 if (bi->bi_nlink == U32_MAX)
829 void bch2_inode_nlink_dec(struct btree_trans *trans, struct bch_inode_unpacked *bi)
831 if (bi->bi_nlink && (bi->bi_flags & BCH_INODE_UNLINKED)) {
832 bch2_trans_inconsistent(trans, "inode %llu unlinked but link count nonzero",
837 if (bi->bi_flags & BCH_INODE_UNLINKED) {
838 bch2_trans_inconsistent(trans, "inode %llu link count underflow", bi->bi_inum);
845 bi->bi_flags |= BCH_INODE_UNLINKED;
848 struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *inode)
850 struct bch_opts ret = { 0 };
851 #define x(_name, _bits) \
852 if (inode->bi_##_name) \
853 opt_set(ret, _name, inode->bi_##_name - 1);
859 void bch2_inode_opts_get(struct bch_io_opts *opts, struct bch_fs *c,
860 struct bch_inode_unpacked *inode)
862 #define x(_name, _bits) opts->_name = inode_opt_get(c, inode, _name);
867 opts->compression = opts->background_compression = opts->data_checksum = opts->erasure_code = 0;