Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
e539ebb8
Commit
e539ebb8
authored
Feb 06, 2024
by
Kent Overstreet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcachefs: simplify check_dirent_inode_dirent()
Signed-off-by:
Kent Overstreet
<
kent.overstreet@linux.dev
>
parent
0b498a5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
58 deletions
+56
-58
fs/bcachefs/fsck.c
fs/bcachefs/fsck.c
+56
-58
No files found.
fs/bcachefs/fsck.c
View file @
e539ebb8
...
...
@@ -1570,77 +1570,75 @@ static int check_dirent_inode_dirent(struct btree_trans *trans,
u32
target_snapshot
)
{
struct
bch_fs
*
c
=
trans
->
c
;
struct
btree_iter
bp_iter
=
{
NULL
};
struct
printbuf
buf
=
PRINTBUF
;
int
ret
=
0
;
if
(
inode_points_to_dirent
(
target
,
d
))
return
0
;
if
(
!
target
->
bi_dir
&&
!
target
->
bi_dir_offset
)
{
target
->
bi_dir
=
d
.
k
->
p
.
inode
;
target
->
bi_dir_offset
=
d
.
k
->
p
.
offset
;
ret
=
__bch2_fsck_write_inode
(
trans
,
target
,
target_snapshot
);
if
(
ret
)
goto
err
;
return
__bch2_fsck_write_inode
(
trans
,
target
,
target_snapshot
);
}
if
(
!
inode_points_to_dirent
(
target
,
d
))
{
struct
bkey_s_c_dirent
bp_dirent
=
dirent_get_by_pos
(
trans
,
&
bp_iter
,
SPOS
(
target
->
bi_dir
,
target
->
bi_dir_offset
,
target_snapshot
));
ret
=
bkey_err
(
bp_dirent
);
if
(
ret
&&
!
bch2_err_matches
(
ret
,
ENOENT
))
goto
err
;
bool
backpointer_exists
=
!
ret
;
ret
=
0
;
struct
btree_iter
bp_iter
=
{
NULL
};
struct
bkey_s_c_dirent
bp_dirent
=
dirent_get_by_pos
(
trans
,
&
bp_iter
,
SPOS
(
target
->
bi_dir
,
target
->
bi_dir_offset
,
target_snapshot
));
ret
=
bkey_err
(
bp_dirent
);
if
(
ret
&&
!
bch2_err_matches
(
ret
,
ENOENT
))
goto
err
;
bch2_bkey_val_to_text
(
&
buf
,
c
,
d
.
s_c
);
prt_newline
(
&
buf
);
if
(
backpointer_exists
)
bch2_bkey_val_to_text
(
&
buf
,
c
,
bp_dirent
.
s_c
);
bool
backpointer_exists
=
!
ret
;
ret
=
0
;
if
(
fsck_err_on
(
S_ISDIR
(
target
->
bi_mode
)
&&
backpointer_exists
,
c
,
inode_dir_multiple_links
,
"directory %llu:%u with multiple links
\n
%s"
,
target
->
bi_inum
,
target_snapshot
,
buf
.
buf
))
{
ret
=
__remove_dirent
(
trans
,
d
.
k
->
p
);
goto
out
;
}
if
(
fsck_err_on
(
!
backpointer_exists
,
c
,
inode_wrong_backpointer
,
"inode %llu:%u has wrong backpointer:
\n
"
"got %llu:%llu
\n
"
"should be %llu:%llu"
,
target
->
bi_inum
,
target_snapshot
,
target
->
bi_dir
,
target
->
bi_dir_offset
,
d
.
k
->
p
.
inode
,
d
.
k
->
p
.
offset
))
{
target
->
bi_dir
=
d
.
k
->
p
.
inode
;
target
->
bi_dir_offset
=
d
.
k
->
p
.
offset
;
ret
=
__bch2_fsck_write_inode
(
trans
,
target
,
target_snapshot
);
goto
out
;
}
/*
* hardlinked file with nlink 0:
* We're just adjusting nlink here so check_nlinks() will pick
* it up, it ignores inodes with nlink 0
*/
if
(
fsck_err_on
(
backpointer_exists
&&
!
target
->
bi_nlink
,
c
,
inode_multiple_links_but_nlink_0
,
"inode %llu:%u type %s has multiple links but i_nlink 0
\n
%s"
,
target
->
bi_inum
,
target_snapshot
,
bch2_d_types
[
d
.
v
->
d_type
],
buf
.
buf
))
{
target
->
bi_nlink
++
;
target
->
bi_flags
&=
~
BCH_INODE_unlinked
;
ret
=
__bch2_fsck_write_inode
(
trans
,
target
,
target_snapshot
);
if
(
ret
)
goto
err
;
}
bch2_bkey_val_to_text
(
&
buf
,
c
,
d
.
s_c
);
prt_newline
(
&
buf
);
if
(
backpointer_exists
)
bch2_bkey_val_to_text
(
&
buf
,
c
,
bp_dirent
.
s_c
);
if
(
fsck_err_on
(
backpointer_exists
&&
(
S_ISDIR
(
target
->
bi_mode
)
||
target
->
bi_subvol
),
c
,
inode_dir_multiple_links
,
"%s %llu:%u with multiple links
\n
%s"
,
S_ISDIR
(
target
->
bi_mode
)
?
"directory"
:
"subvolume"
,
target
->
bi_inum
,
target_snapshot
,
buf
.
buf
))
{
ret
=
__remove_dirent
(
trans
,
d
.
k
->
p
);
goto
out
;
}
if
(
fsck_err_on
(
!
backpointer_exists
,
c
,
inode_wrong_backpointer
,
"inode %llu:%u has wrong backpointer:
\n
"
"got %llu:%llu
\n
"
"should be %llu:%llu"
,
target
->
bi_inum
,
target_snapshot
,
target
->
bi_dir
,
target
->
bi_dir_offset
,
d
.
k
->
p
.
inode
,
d
.
k
->
p
.
offset
))
{
target
->
bi_dir
=
d
.
k
->
p
.
inode
;
target
->
bi_dir_offset
=
d
.
k
->
p
.
offset
;
ret
=
__bch2_fsck_write_inode
(
trans
,
target
,
target_snapshot
);
if
(
ret
)
goto
err
;
}
/*
* hardlinked file with nlink 0:
* We're just adjusting nlink here so check_nlinks() will pick
* it up, it ignores inodes with nlink 0
*/
if
(
fsck_err_on
(
backpointer_exists
&&
!
target
->
bi_nlink
,
c
,
inode_multiple_links_but_nlink_0
,
"inode %llu:%u type %s has multiple links but i_nlink 0
\n
%s"
,
target
->
bi_inum
,
target_snapshot
,
bch2_d_types
[
d
.
v
->
d_type
],
buf
.
buf
))
{
target
->
bi_nlink
++
;
target
->
bi_flags
&=
~
BCH_INODE_unlinked
;
ret
=
__bch2_fsck_write_inode
(
trans
,
target
,
target_snapshot
);
if
(
ret
)
goto
err
;
}
out:
err:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment