Skip to content

Commit ce9a217

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_inum_path() no longer returns an error for disconnected inums
bch2_inum_path() should work even if the filesystem is corrupted - we don't want it to cause fsck to fail. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 6adc5af commit ce9a217

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

fs/bcachefs/fs-common.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ static inline void prt_bytes_reversed(struct printbuf *out, const void *b, unsig
574574
printbuf_nul_terminate(out);
575575
}
576576

577+
static inline void prt_str_reversed(struct printbuf *out, const char *s)
578+
{
579+
prt_bytes_reversed(out, s, strlen(s));
580+
}
581+
577582
static inline void reverse_bytes(void *b, size_t n)
578583
{
579584
char *e = b + n, *s = b;
@@ -596,25 +601,25 @@ int bch2_inum_to_path(struct btree_trans *trans, subvol_inum inum, struct printb
596601
struct bch_inode_unpacked inode;
597602
ret = bch2_inode_find_by_inum_trans(trans, inum, &inode);
598603
if (ret)
599-
goto err;
604+
goto disconnected;
600605

601606
if (!inode.bi_dir && !inode.bi_dir_offset) {
602607
ret = -BCH_ERR_ENOENT_inode_no_backpointer;
603-
goto err;
608+
goto disconnected;
604609
}
605610

606611
u32 snapshot;
607612
ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
608613
if (ret)
609-
goto err;
614+
goto disconnected;
610615

611616
struct btree_iter d_iter;
612617
struct bkey_s_c_dirent d = bch2_bkey_get_iter_typed(trans, &d_iter,
613618
BTREE_ID_dirents, SPOS(inode.bi_dir, inode.bi_dir_offset, snapshot),
614619
0, dirent);
615620
ret = bkey_err(d.s_c);
616621
if (ret)
617-
goto err;
622+
goto disconnected;
618623

619624
struct qstr dirent_name = bch2_dirent_get_name(d);
620625
prt_bytes_reversed(path, dirent_name.name, dirent_name.len);
@@ -630,7 +635,7 @@ int bch2_inum_to_path(struct btree_trans *trans, subvol_inum inum, struct printb
630635

631636
if (orig_pos == path->pos)
632637
prt_char(path, '/');
633-
638+
out:
634639
ret = path->allocation_failure ? -ENOMEM : 0;
635640
if (ret)
636641
goto err;
@@ -639,4 +644,10 @@ int bch2_inum_to_path(struct btree_trans *trans, subvol_inum inum, struct printb
639644
return 0;
640645
err:
641646
return ret;
647+
disconnected:
648+
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
649+
goto err;
650+
651+
prt_str_reversed(path, "(disconnected)");
652+
goto out;
642653
}

0 commit comments

Comments
 (0)