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)
273 case KEY_TYPE_inode: {
274 struct bkey_s_c_inode inode = bkey_s_c_to_inode(k);
276 unpacked->bi_inum = inode.k->p.offset;
277 unpacked->bi_journal_seq= 0;
278 unpacked->bi_hash_seed = inode.v->bi_hash_seed;
279 unpacked->bi_flags = le32_to_cpu(inode.v->bi_flags);
280 unpacked->bi_mode = le16_to_cpu(inode.v->bi_mode);
282 if (INODE_NEW_VARINT(inode.v)) {
283 return bch2_inode_unpack_v2(unpacked, inode.v->fields,
285 INODE_NR_FIELDS(inode.v));
287 return bch2_inode_unpack_v1(inode, unpacked);
291 case KEY_TYPE_inode_v2: {
292 struct bkey_s_c_inode_v2 inode = bkey_s_c_to_inode_v2(k);
294 unpacked->bi_inum = inode.k->p.offset;
295 unpacked->bi_journal_seq= le64_to_cpu(inode.v->bi_journal_seq);
296 unpacked->bi_hash_seed = inode.v->bi_hash_seed;
297 unpacked->bi_flags = le64_to_cpu(inode.v->bi_flags);
298 unpacked->bi_mode = le16_to_cpu(inode.v->bi_mode);
300 return bch2_inode_unpack_v2(unpacked, inode.v->fields,
302 INODEv2_NR_FIELDS(inode.v));
309 int bch2_inode_unpack(struct bkey_s_c k,
310 struct bch_inode_unpacked *unpacked)
312 if (likely(k.k->type == KEY_TYPE_inode_v3))
313 return bch2_inode_unpack_v3(k, unpacked);
314 return bch2_inode_unpack_slowpath(k, unpacked);
317 int bch2_inode_peek(struct btree_trans *trans,
318 struct btree_iter *iter,
319 struct bch_inode_unpacked *inode,
320 subvol_inum inum, unsigned flags)
326 ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
330 bch2_trans_iter_init(trans, iter, BTREE_ID_inodes,
331 SPOS(0, inum.inum, snapshot),
332 flags|BTREE_ITER_CACHED);
333 k = bch2_btree_iter_peek_slot(iter);
338 ret = bkey_is_inode(k.k) ? 0 : -ENOENT;
342 ret = bch2_inode_unpack(k, inode);
348 bch2_trans_iter_exit(trans, iter);
352 int bch2_inode_write(struct btree_trans *trans,
353 struct btree_iter *iter,
354 struct bch_inode_unpacked *inode)
356 struct bkey_inode_buf *inode_p;
358 inode_p = bch2_trans_kmalloc(trans, sizeof(*inode_p));
360 return PTR_ERR(inode_p);
362 bch2_inode_pack_inlined(inode_p, inode);
363 inode_p->inode.k.p.snapshot = iter->snapshot;
364 return bch2_trans_update(trans, iter, &inode_p->inode.k_i, 0);
367 struct bkey_s_c bch2_inode_to_v3(struct btree_trans *trans, struct bkey_s_c k)
369 struct bch_inode_unpacked u;
370 struct bkey_inode_buf *inode_p;
373 inode_p = bch2_trans_kmalloc(trans, sizeof(*inode_p));
375 return bkey_s_c_err(PTR_ERR(inode_p));
377 ret = bch2_inode_unpack(k, &u);
379 return bkey_s_c_err(ret);
381 bch2_inode_pack(inode_p, &u);
382 return bkey_i_to_s_c(&inode_p->inode.k_i);
385 static int __bch2_inode_invalid(struct bkey_s_c k, struct printbuf *err)
387 struct bch_inode_unpacked unpacked;
390 prt_printf(err, "nonzero k.p.inode");
394 if (k.k->p.offset < BLOCKDEV_INODE_MAX) {
395 prt_printf(err, "fs inode in blockdev range");
399 if (bch2_inode_unpack(k, &unpacked)) {
400 prt_printf(err, "invalid variable length fields");
404 if (unpacked.bi_data_checksum >= BCH_CSUM_OPT_NR + 1) {
405 prt_printf(err, "invalid data checksum type (%u >= %u",
406 unpacked.bi_data_checksum, BCH_CSUM_OPT_NR + 1);
410 if (unpacked.bi_compression >= BCH_COMPRESSION_OPT_NR + 1) {
411 prt_printf(err, "invalid data checksum type (%u >= %u)",
412 unpacked.bi_compression, BCH_COMPRESSION_OPT_NR + 1);
416 if ((unpacked.bi_flags & BCH_INODE_UNLINKED) &&
417 unpacked.bi_nlink != 0) {
418 prt_printf(err, "flagged as unlinked but bi_nlink != 0");
422 if (unpacked.bi_subvol && !S_ISDIR(unpacked.bi_mode)) {
423 prt_printf(err, "subvolume root but not a directory");
430 int bch2_inode_invalid(const struct bch_fs *c, struct bkey_s_c k,
431 int rw, struct printbuf *err)
433 struct bkey_s_c_inode inode = bkey_s_c_to_inode(k);
435 if (bkey_val_bytes(k.k) < sizeof(*inode.v)) {
436 prt_printf(err, "incorrect value size (%zu < %zu)",
437 bkey_val_bytes(k.k), sizeof(*inode.v));
441 if (INODE_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
442 prt_printf(err, "invalid str hash type (%llu >= %u)",
443 INODE_STR_HASH(inode.v), BCH_STR_HASH_NR);
447 return __bch2_inode_invalid(k, err);
450 int bch2_inode_v2_invalid(const struct bch_fs *c, struct bkey_s_c k,
451 int rw, struct printbuf *err)
453 struct bkey_s_c_inode_v2 inode = bkey_s_c_to_inode_v2(k);
455 if (bkey_val_bytes(k.k) < sizeof(*inode.v)) {
456 prt_printf(err, "incorrect value size (%zu < %zu)",
457 bkey_val_bytes(k.k), sizeof(*inode.v));
461 if (INODEv2_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
462 prt_printf(err, "invalid str hash type (%llu >= %u)",
463 INODEv2_STR_HASH(inode.v), BCH_STR_HASH_NR);
467 return __bch2_inode_invalid(k, err);
470 int bch2_inode_v3_invalid(const struct bch_fs *c, struct bkey_s_c k,
471 int rw, struct printbuf *err)
473 struct bkey_s_c_inode_v3 inode = bkey_s_c_to_inode_v3(k);
475 if (bkey_val_bytes(k.k) < sizeof(*inode.v)) {
476 prt_printf(err, "incorrect value size (%zu < %zu)",
477 bkey_val_bytes(k.k), sizeof(*inode.v));
481 if (INODEv3_FIELDS_START(inode.v) < INODEv3_FIELDS_START_INITIAL ||
482 INODEv3_FIELDS_START(inode.v) > bkey_val_u64s(inode.k)) {
483 prt_printf(err, "invalid fields_start (got %llu, min %u max %zu)",
484 INODEv3_FIELDS_START(inode.v),
485 INODEv3_FIELDS_START_INITIAL,
486 bkey_val_u64s(inode.k));
490 if (INODEv3_STR_HASH(inode.v) >= BCH_STR_HASH_NR) {
491 prt_printf(err, "invalid str hash type (%llu >= %u)",
492 INODEv3_STR_HASH(inode.v), BCH_STR_HASH_NR);
496 return __bch2_inode_invalid(k, err);
499 static void __bch2_inode_unpacked_to_text(struct printbuf *out,
500 struct bch_inode_unpacked *inode)
502 prt_printf(out, "mode %o flags %x journal_seq %llu bi_size %llu bi_sectors %llu bi_version %llu",
503 inode->bi_mode, inode->bi_flags,
504 inode->bi_journal_seq,
509 #define x(_name, _bits) \
510 prt_printf(out, " "#_name " %llu", (u64) inode->_name);
511 BCH_INODE_FIELDS_v3()
515 void bch2_inode_unpacked_to_text(struct printbuf *out, struct bch_inode_unpacked *inode)
517 prt_printf(out, "inum: %llu ", inode->bi_inum);
518 __bch2_inode_unpacked_to_text(out, inode);
521 void bch2_inode_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k)
523 struct bch_inode_unpacked inode;
525 if (bch2_inode_unpack(k, &inode)) {
526 prt_printf(out, "(unpack error)");
530 __bch2_inode_unpacked_to_text(out, &inode);
533 int bch2_inode_generation_invalid(const struct bch_fs *c, struct bkey_s_c k,
534 int rw, struct printbuf *err)
537 prt_printf(err, "nonzero k.p.inode");
541 if (bkey_val_bytes(k.k) != sizeof(struct bch_inode_generation)) {
542 prt_printf(err, "incorrect value size (%zu != %zu)",
543 bkey_val_bytes(k.k), sizeof(struct bch_inode_generation));
550 void bch2_inode_generation_to_text(struct printbuf *out, struct bch_fs *c,
553 struct bkey_s_c_inode_generation gen = bkey_s_c_to_inode_generation(k);
555 prt_printf(out, "generation: %u", le32_to_cpu(gen.v->bi_generation));
558 void bch2_inode_init_early(struct bch_fs *c,
559 struct bch_inode_unpacked *inode_u)
561 enum bch_str_hash_type str_hash =
562 bch2_str_hash_opt_to_type(c, c->opts.str_hash);
564 memset(inode_u, 0, sizeof(*inode_u));
567 inode_u->bi_flags |= str_hash << INODE_STR_HASH_OFFSET;
568 get_random_bytes(&inode_u->bi_hash_seed,
569 sizeof(inode_u->bi_hash_seed));
572 void bch2_inode_init_late(struct bch_inode_unpacked *inode_u, u64 now,
573 uid_t uid, gid_t gid, umode_t mode, dev_t rdev,
574 struct bch_inode_unpacked *parent)
576 inode_u->bi_mode = mode;
577 inode_u->bi_uid = uid;
578 inode_u->bi_gid = gid;
579 inode_u->bi_dev = rdev;
580 inode_u->bi_atime = now;
581 inode_u->bi_mtime = now;
582 inode_u->bi_ctime = now;
583 inode_u->bi_otime = now;
585 if (parent && parent->bi_mode & S_ISGID) {
586 inode_u->bi_gid = parent->bi_gid;
588 inode_u->bi_mode |= S_ISGID;
592 #define x(_name, ...) inode_u->bi_##_name = parent->bi_##_name;
598 void bch2_inode_init(struct bch_fs *c, struct bch_inode_unpacked *inode_u,
599 uid_t uid, gid_t gid, umode_t mode, dev_t rdev,
600 struct bch_inode_unpacked *parent)
602 bch2_inode_init_early(c, inode_u);
603 bch2_inode_init_late(inode_u, bch2_current_time(c),
604 uid, gid, mode, rdev, parent);
607 static inline u32 bkey_generation(struct bkey_s_c k)
611 case KEY_TYPE_inode_v2:
613 case KEY_TYPE_inode_generation:
614 return le32_to_cpu(bkey_s_c_to_inode_generation(k).v->bi_generation);
621 * This just finds an empty slot:
623 int bch2_inode_create(struct btree_trans *trans,
624 struct btree_iter *iter,
625 struct bch_inode_unpacked *inode_u,
626 u32 snapshot, u64 cpu)
628 struct bch_fs *c = trans->c;
630 u64 min, max, start, pos, *hint;
632 unsigned bits = (c->opts.inodes_32bit ? 31 : 63);
634 if (c->opts.shard_inode_numbers) {
635 bits -= c->inode_shard_bits;
638 max = (cpu << bits) | ~(ULLONG_MAX << bits);
640 min = max_t(u64, min, BLOCKDEV_INODE_MAX);
641 hint = c->unused_inode_hints + cpu;
643 min = BLOCKDEV_INODE_MAX;
644 max = ~(ULLONG_MAX << bits);
645 hint = c->unused_inode_hints;
648 start = READ_ONCE(*hint);
650 if (start >= max || start < min)
654 bch2_trans_iter_init(trans, iter, BTREE_ID_inodes, POS(0, pos),
655 BTREE_ITER_ALL_SNAPSHOTS|
658 while ((k = bch2_btree_iter_peek(iter)).k &&
659 !(ret = bkey_err(k)) &&
660 bkey_cmp(k.k->p, POS(0, max)) < 0) {
661 while (pos < iter->pos.offset) {
662 if (!bch2_btree_key_cache_find(c, BTREE_ID_inodes, POS(0, pos)))
668 if (k.k->p.snapshot == snapshot &&
669 !bkey_is_inode(k.k) &&
670 !bch2_btree_key_cache_find(c, BTREE_ID_inodes, SPOS(0, pos, snapshot))) {
671 bch2_btree_iter_advance(iter);
676 * We don't need to iterate over keys in every snapshot once
677 * we've found just one:
679 pos = iter->pos.offset + 1;
680 bch2_btree_iter_set_pos(iter, POS(0, pos));
683 while (!ret && pos < max) {
684 if (!bch2_btree_key_cache_find(c, BTREE_ID_inodes, POS(0, pos)))
690 if (!ret && start == min)
691 ret = -BCH_ERR_ENOSPC_inode_create;
694 bch2_trans_iter_exit(trans, iter);
698 /* Retry from start */
700 bch2_btree_iter_set_pos(iter, POS(0, pos));
703 bch2_btree_iter_set_pos(iter, SPOS(0, pos, snapshot));
704 k = bch2_btree_iter_peek_slot(iter);
707 bch2_trans_iter_exit(trans, iter);
711 /* We may have raced while the iterator wasn't pointing at pos: */
712 if (bkey_is_inode(k.k) ||
713 bch2_btree_key_cache_find(c, BTREE_ID_inodes, k.k->p))
716 *hint = k.k->p.offset;
717 inode_u->bi_inum = k.k->p.offset;
718 inode_u->bi_generation = bkey_generation(k);
722 static int bch2_inode_delete_keys(struct btree_trans *trans,
723 subvol_inum inum, enum btree_id id)
725 struct btree_iter iter;
727 struct bkey_i delete;
732 * We're never going to be deleting extents, no need to use an extent
735 bch2_trans_iter_init(trans, &iter, id, POS(inum.inum, 0),
736 BTREE_ITER_NOT_EXTENTS|
740 bch2_trans_begin(trans);
742 ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
746 bch2_btree_iter_set_snapshot(&iter, snapshot);
748 k = bch2_btree_iter_peek_upto(&iter, POS(inum.inum, U64_MAX));
756 bkey_init(&delete.k);
757 delete.k.p = iter.pos;
759 ret = bch2_trans_update(trans, &iter, &delete, 0) ?:
760 bch2_trans_commit(trans, NULL, NULL,
761 BTREE_INSERT_NOFAIL);
763 if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart))
767 bch2_trans_iter_exit(trans, &iter);
771 int bch2_inode_rm(struct bch_fs *c, subvol_inum inum)
773 struct btree_trans trans;
774 struct btree_iter iter = { NULL };
775 struct bkey_i_inode_generation delete;
776 struct bch_inode_unpacked inode_u;
781 bch2_trans_init(&trans, c, 0, 1024);
784 * If this was a directory, there shouldn't be any real dirents left -
785 * but there could be whiteouts (from hash collisions) that we should
788 * XXX: the dirent could ideally would delete whiteouts when they're no
791 ret = bch2_inode_delete_keys(&trans, inum, BTREE_ID_extents) ?:
792 bch2_inode_delete_keys(&trans, inum, BTREE_ID_xattrs) ?:
793 bch2_inode_delete_keys(&trans, inum, BTREE_ID_dirents);
797 bch2_trans_begin(&trans);
799 ret = bch2_subvolume_get_snapshot(&trans, inum.subvol, &snapshot);
803 bch2_trans_iter_init(&trans, &iter, BTREE_ID_inodes,
804 SPOS(0, inum.inum, snapshot),
805 BTREE_ITER_INTENT|BTREE_ITER_CACHED);
806 k = bch2_btree_iter_peek_slot(&iter);
812 if (!bkey_is_inode(k.k)) {
813 bch2_fs_inconsistent(trans.c,
814 "inode %llu not found when deleting",
820 bch2_inode_unpack(k, &inode_u);
822 /* Subvolume root? */
823 BUG_ON(inode_u.bi_subvol);
825 bkey_inode_generation_init(&delete.k_i);
826 delete.k.p = iter.pos;
827 delete.v.bi_generation = cpu_to_le32(inode_u.bi_generation + 1);
829 ret = bch2_trans_update(&trans, &iter, &delete.k_i, 0) ?:
830 bch2_trans_commit(&trans, NULL, NULL,
831 BTREE_INSERT_NOFAIL);
833 bch2_trans_iter_exit(&trans, &iter);
834 if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
837 bch2_trans_exit(&trans);
841 int bch2_inode_find_by_inum_trans(struct btree_trans *trans,
843 struct bch_inode_unpacked *inode)
845 struct btree_iter iter;
848 ret = bch2_inode_peek(trans, &iter, inode, inum, 0);
850 bch2_trans_iter_exit(trans, &iter);
854 int bch2_inode_find_by_inum(struct bch_fs *c, subvol_inum inum,
855 struct bch_inode_unpacked *inode)
857 return bch2_trans_do(c, NULL, NULL, 0,
858 bch2_inode_find_by_inum_trans(&trans, inum, inode));
861 int bch2_inode_nlink_inc(struct bch_inode_unpacked *bi)
863 if (bi->bi_flags & BCH_INODE_UNLINKED)
864 bi->bi_flags &= ~BCH_INODE_UNLINKED;
866 if (bi->bi_nlink == U32_MAX)
875 void bch2_inode_nlink_dec(struct btree_trans *trans, struct bch_inode_unpacked *bi)
877 if (bi->bi_nlink && (bi->bi_flags & BCH_INODE_UNLINKED)) {
878 bch2_trans_inconsistent(trans, "inode %llu unlinked but link count nonzero",
883 if (bi->bi_flags & BCH_INODE_UNLINKED) {
884 bch2_trans_inconsistent(trans, "inode %llu link count underflow", bi->bi_inum);
891 bi->bi_flags |= BCH_INODE_UNLINKED;