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
b43a0f60
Commit
b43a0f60
authored
Sep 25, 2019
by
Kent Overstreet
Committed by
Kent Overstreet
Oct 22, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcachefs: Cleanup i_nlink handling
Signed-off-by:
Kent Overstreet
<
kent.overstreet@linux.dev
>
parent
d55460bb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
34 deletions
+49
-34
fs/bcachefs/fs.c
fs/bcachefs/fs.c
+4
-18
fs/bcachefs/fs.h
fs/bcachefs/fs.h
+0
-5
fs/bcachefs/fsck.c
fs/bcachefs/fsck.c
+2
-11
fs/bcachefs/inode.h
fs/bcachefs/inode.h
+43
-0
No files found.
fs/bcachefs/fs.c
View file @
b43a0f60
...
@@ -131,9 +131,7 @@ void bch2_inode_update_after_write(struct bch_fs *c,
...
@@ -131,9 +131,7 @@ void bch2_inode_update_after_write(struct bch_fs *c,
struct
bch_inode_unpacked
*
bi
,
struct
bch_inode_unpacked
*
bi
,
unsigned
fields
)
unsigned
fields
)
{
{
set_nlink
(
&
inode
->
v
,
bi
->
bi_flags
&
BCH_INODE_UNLINKED
set_nlink
(
&
inode
->
v
,
bch2_inode_nlink_get
(
bi
));
?
0
:
bi
->
bi_nlink
+
nlink_bias
(
inode
->
v
.
i_mode
));
i_uid_write
(
&
inode
->
v
,
bi
->
bi_uid
);
i_uid_write
(
&
inode
->
v
,
bi
->
bi_uid
);
i_gid_write
(
&
inode
->
v
,
bi
->
bi_gid
);
i_gid_write
(
&
inode
->
v
,
bi
->
bi_gid
);
inode
->
v
.
i_mode
=
bi
->
bi_mode
;
inode
->
v
.
i_mode
=
bi
->
bi_mode
;
...
@@ -552,12 +550,7 @@ static int inode_update_for_link_fn(struct bch_inode_info *inode,
...
@@ -552,12 +550,7 @@ static int inode_update_for_link_fn(struct bch_inode_info *inode,
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
bi
->
bi_ctime
=
bch2_current_time
(
c
);
bi
->
bi_ctime
=
bch2_current_time
(
c
);
bch2_inode_nlink_inc
(
bi
);
if
(
bi
->
bi_flags
&
BCH_INODE_UNLINKED
)
bi
->
bi_flags
&=
~
BCH_INODE_UNLINKED
;
else
bi
->
bi_nlink
++
;
return
0
;
return
0
;
}
}
...
@@ -640,11 +633,7 @@ static int inode_update_for_unlink_fn(struct bch_inode_info *inode,
...
@@ -640,11 +633,7 @@ static int inode_update_for_unlink_fn(struct bch_inode_info *inode,
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
bi
->
bi_ctime
=
bch2_current_time
(
c
);
bi
->
bi_ctime
=
bch2_current_time
(
c
);
if
(
bi
->
bi_nlink
)
bch2_inode_nlink_dec
(
bi
);
bi
->
bi_nlink
--
;
else
bi
->
bi_flags
|=
BCH_INODE_UNLINKED
;
return
0
;
return
0
;
}
}
...
@@ -815,10 +804,7 @@ static int inode_update_for_rename_fn(struct bch_inode_info *inode,
...
@@ -815,10 +804,7 @@ static int inode_update_for_rename_fn(struct bch_inode_info *inode,
BUG_ON
(
bi
->
bi_nlink
&&
BUG_ON
(
bi
->
bi_nlink
&&
S_ISDIR
(
info
->
dst_inode
->
v
.
i_mode
));
S_ISDIR
(
info
->
dst_inode
->
v
.
i_mode
));
if
(
bi
->
bi_nlink
)
bch2_inode_nlink_dec
(
bi
);
bi
->
bi_nlink
--
;
else
bi
->
bi_flags
|=
BCH_INODE_UNLINKED
;
}
}
if
(
inode
==
info
->
src_dir
||
if
(
inode
==
info
->
src_dir
||
...
...
fs/bcachefs/fs.h
View file @
b43a0f60
...
@@ -109,11 +109,6 @@ static inline u8 mode_to_type(umode_t mode)
...
@@ -109,11 +109,6 @@ static inline u8 mode_to_type(umode_t mode)
return
(
mode
>>
12
)
&
15
;
return
(
mode
>>
12
)
&
15
;
}
}
static
inline
unsigned
nlink_bias
(
umode_t
mode
)
{
return
S_ISDIR
(
mode
)
?
2
:
1
;
}
static
inline
bool
inode_attr_changing
(
struct
bch_inode_info
*
dir
,
static
inline
bool
inode_attr_changing
(
struct
bch_inode_info
*
dir
,
struct
bch_inode_info
*
inode
,
struct
bch_inode_info
*
inode
,
enum
inode_opt_id
id
)
enum
inode_opt_id
id
)
...
...
fs/bcachefs/fsck.c
View file @
b43a0f60
...
@@ -1116,9 +1116,7 @@ static int check_inode_nlink(struct bch_fs *c,
...
@@ -1116,9 +1116,7 @@ static int check_inode_nlink(struct bch_fs *c,
struct
nlink
*
link
,
struct
nlink
*
link
,
bool
*
do_update
)
bool
*
do_update
)
{
{
u32
i_nlink
=
u
->
bi_flags
&
BCH_INODE_UNLINKED
u32
i_nlink
=
bch2_inode_nlink_get
(
u
);
?
0
:
u
->
bi_nlink
+
nlink_bias
(
u
->
bi_mode
);
u32
real_i_nlink
=
u32
real_i_nlink
=
link
->
count
*
nlink_bias
(
u
->
bi_mode
)
+
link
->
count
*
nlink_bias
(
u
->
bi_mode
)
+
link
->
dir_count
;
link
->
dir_count
;
...
@@ -1197,14 +1195,7 @@ static int check_inode_nlink(struct bch_fs *c,
...
@@ -1197,14 +1195,7 @@ static int check_inode_nlink(struct bch_fs *c,
u
->
bi_inum
,
i_nlink
,
real_i_nlink
);
u
->
bi_inum
,
i_nlink
,
real_i_nlink
);
set_i_nlink:
set_i_nlink:
if
(
i_nlink
!=
real_i_nlink
)
{
if
(
i_nlink
!=
real_i_nlink
)
{
if
(
real_i_nlink
)
{
bch2_inode_nlink_set
(
u
,
real_i_nlink
);
u
->
bi_nlink
=
real_i_nlink
-
nlink_bias
(
u
->
bi_mode
);
u
->
bi_flags
&=
~
BCH_INODE_UNLINKED
;
}
else
{
u
->
bi_nlink
=
0
;
u
->
bi_flags
|=
BCH_INODE_UNLINKED
;
}
*
do_update
=
true
;
*
do_update
=
true
;
}
}
fsck_err:
fsck_err:
...
...
fs/bcachefs/inode.h
View file @
b43a0f60
...
@@ -103,6 +103,49 @@ static inline u64 bch2_inode_opt_get(struct bch_inode_unpacked *inode,
...
@@ -103,6 +103,49 @@ static inline u64 bch2_inode_opt_get(struct bch_inode_unpacked *inode,
}
}
}
}
/* i_nlink: */
static
inline
unsigned
nlink_bias
(
umode_t
mode
)
{
return
S_ISDIR
(
mode
)
?
2
:
1
;
}
static
inline
void
bch2_inode_nlink_inc
(
struct
bch_inode_unpacked
*
bi
)
{
if
(
bi
->
bi_flags
&
BCH_INODE_UNLINKED
)
bi
->
bi_flags
&=
~
BCH_INODE_UNLINKED
;
else
bi
->
bi_nlink
++
;
}
static
inline
void
bch2_inode_nlink_dec
(
struct
bch_inode_unpacked
*
bi
)
{
BUG_ON
(
bi
->
bi_flags
&
BCH_INODE_UNLINKED
);
if
(
bi
->
bi_nlink
)
bi
->
bi_nlink
--
;
else
bi
->
bi_flags
|=
BCH_INODE_UNLINKED
;
}
static
inline
unsigned
bch2_inode_nlink_get
(
struct
bch_inode_unpacked
*
bi
)
{
return
bi
->
bi_flags
&
BCH_INODE_UNLINKED
?
0
:
bi
->
bi_nlink
+
nlink_bias
(
bi
->
bi_mode
);
}
static
inline
void
bch2_inode_nlink_set
(
struct
bch_inode_unpacked
*
bi
,
unsigned
nlink
)
{
if
(
nlink
)
{
bi
->
bi_nlink
=
nlink
-
nlink_bias
(
bi
->
bi_mode
);
bi
->
bi_flags
&=
~
BCH_INODE_UNLINKED
;
}
else
{
bi
->
bi_nlink
=
0
;
bi
->
bi_flags
|=
BCH_INODE_UNLINKED
;
}
}
#ifdef CONFIG_BCACHEFS_DEBUG
#ifdef CONFIG_BCACHEFS_DEBUG
void
bch2_inode_pack_test
(
void
);
void
bch2_inode_pack_test
(
void
);
#else
#else
...
...
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