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 : -BCH_ERR_ENOENT_inode;
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 enum bkey_invalid_flags flags,
436 struct printbuf *err)
438 struct bkey_s_c_inode inode = bkey_s_c_to_inode(k);
440 if (INODE_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
441 prt_printf(err, "invalid str hash type (%llu >= %u)",
442 INODE_STR_HASH(inode.v), BCH_STR_HASH_NR);
443 return -BCH_ERR_invalid_bkey;
446 return __bch2_inode_invalid(k, err);
449 int bch2_inode_v2_invalid(const struct bch_fs *c, struct bkey_s_c k,
450 enum bkey_invalid_flags flags,
451 struct printbuf *err)
453 struct bkey_s_c_inode_v2 inode = bkey_s_c_to_inode_v2(k);
455 if (INODEv2_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
456 prt_printf(err, "invalid str hash type (%llu >= %u)",
457 INODEv2_STR_HASH(inode.v), BCH_STR_HASH_NR);
458 return -BCH_ERR_invalid_bkey;
461 return __bch2_inode_invalid(k, err);
464 int bch2_inode_v3_invalid(const struct bch_fs *c, struct bkey_s_c k,
465 enum bkey_invalid_flags flags,
466 struct printbuf *err)
468 struct bkey_s_c_inode_v3 inode = bkey_s_c_to_inode_v3(k);
470 if (INODEv3_FIELDS_START(inode.v) < INODEv3_FIELDS_START_INITIAL ||
471 INODEv3_FIELDS_START(inode.v) > bkey_val_u64s(inode.k)) {
472 prt_printf(err, "invalid fields_start (got %llu, min %u max %zu)",
473 INODEv3_FIELDS_START(inode.v),
474 INODEv3_FIELDS_START_INITIAL,
475 bkey_val_u64s(inode.k));
476 return -BCH_ERR_invalid_bkey;
479 if (INODEv3_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
480 prt_printf(err, "invalid str hash type (%llu >= %u)",
481 INODEv3_STR_HASH(inode.v), BCH_STR_HASH_NR);
482 return -BCH_ERR_invalid_bkey;
485 return __bch2_inode_invalid(k, err);
488 static void __bch2_inode_unpacked_to_text(struct printbuf *out,
489 struct bch_inode_unpacked *inode)
491 prt_printf(out, "mode %o flags %x journal_seq %llu bi_size %llu bi_sectors %llu bi_version %llu",
492 inode->bi_mode, inode->bi_flags,
493 inode->bi_journal_seq,
498 #define x(_name, _bits) \
499 prt_printf(out, " "#_name " %llu", (u64) inode->_name);
500 BCH_INODE_FIELDS_v3()
504 void bch2_inode_unpacked_to_text(struct printbuf *out, struct bch_inode_unpacked *inode)
506 prt_printf(out, "inum: %llu ", inode->bi_inum);
507 __bch2_inode_unpacked_to_text(out, inode);
510 void bch2_inode_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
512 struct bch_inode_unpacked inode;
514 if (bch2_inode_unpack(k, &inode)) {
515 prt_printf(out, "(unpack error)");
519 __bch2_inode_unpacked_to_text(out, &inode);
522 int bch2_inode_generation_invalid(const struct bch_fs *c, struct bkey_s_c k,
523 enum bkey_invalid_flags flags,
524 struct printbuf *err)
527 prt_printf(err, "nonzero k.p.inode");
528 return -BCH_ERR_invalid_bkey;
534 void bch2_inode_generation_to_text(struct printbuf *out, struct bch_fs *c,
537 struct bkey_s_c_inode_generation gen = bkey_s_c_to_inode_generation(k);
539 prt_printf(out, "generation: %u", le32_to_cpu(gen.v->bi_generation));
542 void bch2_inode_init_early(struct bch_fs *c,
543 struct bch_inode_unpacked *inode_u)
545 enum bch_str_hash_type str_hash =
546 bch2_str_hash_opt_to_type(c, c->opts.str_hash);
548 memset(inode_u, 0, sizeof(*inode_u));
551 inode_u->bi_flags |= str_hash << INODE_STR_HASH_OFFSET;
552 get_random_bytes(&inode_u->bi_hash_seed,
553 sizeof(inode_u->bi_hash_seed));
556 void bch2_inode_init_late(struct bch_inode_unpacked *inode_u, u64 now,
557 uid_t uid, gid_t gid, umode_t mode, dev_t rdev,
558 struct bch_inode_unpacked *parent)
560 inode_u->bi_mode = mode;
561 inode_u->bi_uid = uid;
562 inode_u->bi_gid = gid;
563 inode_u->bi_dev = rdev;
564 inode_u->bi_atime = now;
565 inode_u->bi_mtime = now;
566 inode_u->bi_ctime = now;
567 inode_u->bi_otime = now;
569 if (parent && parent->bi_mode & S_ISGID) {
570 inode_u->bi_gid = parent->bi_gid;
572 inode_u->bi_mode |= S_ISGID;
576 #define x(_name, ...) inode_u->bi_##_name = parent->bi_##_name;
582 void bch2_inode_init(struct bch_fs *c, struct bch_inode_unpacked *inode_u,
583 uid_t uid, gid_t gid, umode_t mode, dev_t rdev,
584 struct bch_inode_unpacked *parent)
586 bch2_inode_init_early(c, inode_u);
587 bch2_inode_init_late(inode_u, bch2_current_time(c),
588 uid, gid, mode, rdev, parent);
591 static inline u32 bkey_generation(struct bkey_s_c k)
595 case KEY_TYPE_inode_v2:
597 case KEY_TYPE_inode_generation:
598 return le32_to_cpu(bkey_s_c_to_inode_generation(k).v->bi_generation);
605 * This just finds an empty slot:
607 int bch2_inode_create(struct btree_trans *trans,
608 struct btree_iter *iter,
609 struct bch_inode_unpacked *inode_u,
610 u32 snapshot, u64 cpu)
612 struct bch_fs *c = trans->c;
614 u64 min, max, start, pos, *hint;
616 unsigned bits = (c->opts.inodes_32bit ? 31 : 63);
618 if (c->opts.shard_inode_numbers) {
619 bits -= c->inode_shard_bits;
622 max = (cpu << bits) | ~(ULLONG_MAX << bits);
624 min = max_t(u64, min, BLOCKDEV_INODE_MAX);
625 hint = c->unused_inode_hints + cpu;
627 min = BLOCKDEV_INODE_MAX;
628 max = ~(ULLONG_MAX << bits);
629 hint = c->unused_inode_hints;
632 start = READ_ONCE(*hint);
634 if (start >= max || start < min)
638 bch2_trans_iter_init(trans, iter, BTREE_ID_inodes, POS(0, pos),
639 BTREE_ITER_ALL_SNAPSHOTS|
642 while ((k = bch2_btree_iter_peek(iter)).k &&
643 !(ret = bkey_err(k)) &&
644 bkey_lt(k.k->p, POS(0, max))) {
645 if (pos < iter->pos.offset)
649 * We don't need to iterate over keys in every snapshot once
650 * we've found just one:
652 pos = iter->pos.offset + 1;
653 bch2_btree_iter_set_pos(iter, POS(0, pos));
656 if (!ret && pos < max)
659 if (!ret && start == min)
660 ret = -BCH_ERR_ENOSPC_inode_create;
663 bch2_trans_iter_exit(trans, iter);
667 /* Retry from start */
669 bch2_btree_iter_set_pos(iter, POS(0, pos));
672 bch2_btree_iter_set_pos(iter, SPOS(0, pos, snapshot));
673 k = bch2_btree_iter_peek_slot(iter);
676 bch2_trans_iter_exit(trans, iter);
680 *hint = k.k->p.offset;
681 inode_u->bi_inum = k.k->p.offset;
682 inode_u->bi_generation = bkey_generation(k);
686 static int bch2_inode_delete_keys(struct btree_trans *trans,
687 subvol_inum inum, enum btree_id id)
689 struct btree_iter iter;
691 struct bkey_i delete;
696 * We're never going to be deleting partial extents, no need to use an
699 bch2_trans_iter_init(trans, &iter, id, POS(inum.inum, 0),
700 BTREE_ITER_INTENT|BTREE_ITER_NOT_EXTENTS);
703 bch2_trans_begin(trans);
705 ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
709 bch2_btree_iter_set_snapshot(&iter, snapshot);
711 k = bch2_btree_iter_peek_upto(&iter, POS(inum.inum, U64_MAX));
719 bkey_init(&delete.k);
720 delete.k.p = iter.pos;
722 ret = bch2_trans_update(trans, &iter, &delete, 0) ?:
723 bch2_trans_commit(trans, NULL, NULL,
724 BTREE_INSERT_NOFAIL);
726 if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart))
730 bch2_trans_iter_exit(trans, &iter);
734 int bch2_inode_rm(struct bch_fs *c, subvol_inum inum)
736 struct btree_trans trans;
737 struct btree_iter iter = { NULL };
738 struct bkey_i_inode_generation delete;
739 struct bch_inode_unpacked inode_u;
744 bch2_trans_init(&trans, c, 0, 1024);
747 * If this was a directory, there shouldn't be any real dirents left -
748 * but there could be whiteouts (from hash collisions) that we should
751 * XXX: the dirent could ideally would delete whiteouts when they're no
754 ret = bch2_inode_delete_keys(&trans, inum, BTREE_ID_extents) ?:
755 bch2_inode_delete_keys(&trans, inum, BTREE_ID_xattrs) ?:
756 bch2_inode_delete_keys(&trans, inum, BTREE_ID_dirents);
760 bch2_trans_begin(&trans);
762 ret = bch2_subvolume_get_snapshot(&trans, inum.subvol, &snapshot);
766 k = bch2_bkey_get_iter(&trans, &iter, BTREE_ID_inodes,
767 SPOS(0, inum.inum, snapshot),
768 BTREE_ITER_INTENT|BTREE_ITER_CACHED);
773 if (!bkey_is_inode(k.k)) {
774 bch2_fs_inconsistent(trans.c,
775 "inode %llu:%u not found when deleting",
776 inum.inum, snapshot);
781 bch2_inode_unpack(k, &inode_u);
783 bkey_inode_generation_init(&delete.k_i);
784 delete.k.p = iter.pos;
785 delete.v.bi_generation = cpu_to_le32(inode_u.bi_generation + 1);
787 ret = bch2_trans_update(&trans, &iter, &delete.k_i, 0) ?:
788 bch2_trans_commit(&trans, NULL, NULL,
789 BTREE_INSERT_NOFAIL);
791 bch2_trans_iter_exit(&trans, &iter);
792 if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
795 bch2_trans_exit(&trans);
799 int bch2_inode_find_by_inum_trans(struct btree_trans *trans,
801 struct bch_inode_unpacked *inode)
803 struct btree_iter iter;
806 ret = bch2_inode_peek(trans, &iter, inode, inum, 0);
808 bch2_trans_iter_exit(trans, &iter);
812 int bch2_inode_find_by_inum(struct bch_fs *c, subvol_inum inum,
813 struct bch_inode_unpacked *inode)
815 return bch2_trans_do(c, NULL, NULL, 0,
816 bch2_inode_find_by_inum_trans(&trans, inum, inode));
819 int bch2_inode_nlink_inc(struct bch_inode_unpacked *bi)
821 if (bi->bi_flags & BCH_INODE_UNLINKED)
822 bi->bi_flags &= ~BCH_INODE_UNLINKED;
824 if (bi->bi_nlink == U32_MAX)
833 void bch2_inode_nlink_dec(struct btree_trans *trans, struct bch_inode_unpacked *bi)
835 if (bi->bi_nlink && (bi->bi_flags & BCH_INODE_UNLINKED)) {
836 bch2_trans_inconsistent(trans, "inode %llu unlinked but link count nonzero",
841 if (bi->bi_flags & BCH_INODE_UNLINKED) {
842 bch2_trans_inconsistent(trans, "inode %llu link count underflow", bi->bi_inum);
849 bi->bi_flags |= BCH_INODE_UNLINKED;
852 struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *inode)
854 struct bch_opts ret = { 0 };
855 #define x(_name, _bits) \
856 if (inode->bi_##_name) \
857 opt_set(ret, _name, inode->bi_##_name - 1);
863 void bch2_inode_opts_get(struct bch_io_opts *opts, struct bch_fs *c,
864 struct bch_inode_unpacked *inode)
866 #define x(_name, _bits) opts->_name = inode_opt_get(c, inode, _name);
871 opts->compression = opts->background_compression = opts->data_checksum = opts->erasure_code = 0;