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
a91bc5e5
Commit
a91bc5e5
authored
Jan 25, 2024
by
Kent Overstreet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcachefs: bch2_inode_insert()
Signed-off-by:
Kent Overstreet
<
kent.overstreet@linux.dev
>
parent
eab0af90
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
62 deletions
+76
-62
fs/bcachefs/fs.c
fs/bcachefs/fs.c
+76
-62
No files found.
fs/bcachefs/fs.c
View file @
a91bc5e5
...
@@ -176,45 +176,88 @@ static unsigned bch2_inode_hash(subvol_inum inum)
...
@@ -176,45 +176,88 @@ static unsigned bch2_inode_hash(subvol_inum inum)
return
jhash_3words
(
inum
.
subvol
,
inum
.
inum
>>
32
,
inum
.
inum
,
JHASH_INITVAL
);
return
jhash_3words
(
inum
.
subvol
,
inum
.
inum
>>
32
,
inum
.
inum
,
JHASH_INITVAL
);
}
}
st
ruct
inode
*
bch2_vfs_inode_get
(
struct
bch_fs
*
c
,
subvol_inum
inum
)
st
atic
struct
bch_inode_info
*
bch2_inode_insert
(
struct
bch_fs
*
c
,
struct
bch_inode_info
*
inode
)
{
{
struct
bch_inode_unpacked
inode_u
;
subvol_inum
inum
=
inode_inum
(
inode
);
struct
bch_inode_info
*
inode
;
struct
bch_inode_info
*
old
=
to_bch_ei
(
inode_insert5
(
&
inode
->
v
,
struct
btree_trans
*
trans
;
struct
bch_subvolume
subvol
;
int
ret
;
inode
=
to_bch_ei
(
iget5_locked
(
c
->
vfs_sb
,
bch2_inode_hash
(
inum
),
bch2_inode_hash
(
inum
),
bch2_iget5_test
,
bch2_iget5_test
,
bch2_iget5_set
,
bch2_iget5_set
,
&
inum
));
&
inum
));
if
(
unlikely
(
!
inode
))
BUG_ON
(
!
old
);
return
ERR_PTR
(
-
ENOMEM
);
if
(
!
(
inode
->
v
.
i_state
&
I_NEW
))
return
&
inode
->
v
;
trans
=
bch2_trans_get
(
c
);
ret
=
lockrestart_do
(
trans
,
bch2_subvolume_get
(
trans
,
inum
.
subvol
,
true
,
0
,
&
subvol
)
?:
bch2_inode_find_by_inum_trans
(
trans
,
inum
,
&
inode_u
));
if
(
!
ret
)
bch2_vfs_inode_init
(
trans
,
inum
,
inode
,
&
inode_u
,
&
subvol
);
bch2_trans_put
(
trans
);
if
(
ret
)
{
iget_failed
(
&
inode
->
v
);
return
ERR_PTR
(
bch2_err_class
(
ret
));
}
if
(
unlikely
(
old
!=
inode
))
{
discard_new_inode
(
&
inode
->
v
);
inode
=
old
;
}
else
{
mutex_lock
(
&
c
->
vfs_inodes_lock
);
mutex_lock
(
&
c
->
vfs_inodes_lock
);
list_add
(
&
inode
->
ei_vfs_inode_list
,
&
c
->
vfs_inodes_list
);
list_add
(
&
inode
->
ei_vfs_inode_list
,
&
c
->
vfs_inodes_list
);
mutex_unlock
(
&
c
->
vfs_inodes_lock
);
mutex_unlock
(
&
c
->
vfs_inodes_lock
);
/*
* we really don't want insert_inode_locked2() to be setting
* I_NEW...
*/
unlock_new_inode
(
&
inode
->
v
);
unlock_new_inode
(
&
inode
->
v
);
}
return
inode
;
}
#define memalloc_flags_do(_flags, _do) \
({ \
unsigned _saved_flags = memalloc_flags_save(_flags); \
typeof(_do) _ret = _do; \
memalloc_noreclaim_restore(_saved_flags); \
_ret; \
})
/*
* Allocate a new inode, dropping/retaking btree locks if necessary:
*/
static
struct
bch_inode_info
*
bch2_new_inode
(
struct
btree_trans
*
trans
)
{
struct
bch_fs
*
c
=
trans
->
c
;
struct
bch_inode_info
*
inode
=
memalloc_flags_do
(
PF_MEMALLOC_NORECLAIM
|
PF_MEMALLOC_NOWARN
,
to_bch_ei
(
new_inode
(
c
->
vfs_sb
)));
if
(
unlikely
(
!
inode
))
{
int
ret
=
drop_locks_do
(
trans
,
(
inode
=
to_bch_ei
(
new_inode
(
c
->
vfs_sb
)))
?
0
:
-
ENOMEM
);
if
(
ret
&&
inode
)
discard_new_inode
(
&
inode
->
v
);
if
(
ret
)
return
ERR_PTR
(
ret
);
}
return
inode
;
}
struct
inode
*
bch2_vfs_inode_get
(
struct
bch_fs
*
c
,
subvol_inum
inum
)
{
struct
bch_inode_info
*
inode
=
to_bch_ei
(
ilookup5_nowait
(
c
->
vfs_sb
,
bch2_inode_hash
(
inum
),
bch2_iget5_test
,
&
inum
));
if
(
inode
)
return
&
inode
->
v
;
return
&
inode
->
v
;
struct
btree_trans
*
trans
=
bch2_trans_get
(
c
);
struct
bch_inode_unpacked
inode_u
;
struct
bch_subvolume
subvol
;
int
ret
=
lockrestart_do
(
trans
,
bch2_subvolume_get
(
trans
,
inum
.
subvol
,
true
,
0
,
&
subvol
)
?:
bch2_inode_find_by_inum_trans
(
trans
,
inum
,
&
inode_u
))
?:
PTR_ERR_OR_ZERO
(
inode
=
bch2_new_inode
(
trans
));
if
(
!
ret
)
{
bch2_vfs_inode_init
(
trans
,
inum
,
inode
,
&
inode_u
,
&
subvol
);
inode
=
bch2_inode_insert
(
c
,
inode
);
}
bch2_trans_put
(
trans
);
return
ret
?
ERR_PTR
(
ret
)
:
&
inode
->
v
;
}
}
struct
bch_inode_info
*
struct
bch_inode_info
*
...
@@ -226,7 +269,7 @@ __bch2_create(struct mnt_idmap *idmap,
...
@@ -226,7 +269,7 @@ __bch2_create(struct mnt_idmap *idmap,
struct
bch_fs
*
c
=
dir
->
v
.
i_sb
->
s_fs_info
;
struct
bch_fs
*
c
=
dir
->
v
.
i_sb
->
s_fs_info
;
struct
btree_trans
*
trans
;
struct
btree_trans
*
trans
;
struct
bch_inode_unpacked
dir_u
;
struct
bch_inode_unpacked
dir_u
;
struct
bch_inode_info
*
inode
,
*
old
;
struct
bch_inode_info
*
inode
;
struct
bch_inode_unpacked
inode_u
;
struct
bch_inode_unpacked
inode_u
;
struct
posix_acl
*
default_acl
=
NULL
,
*
acl
=
NULL
;
struct
posix_acl
*
default_acl
=
NULL
,
*
acl
=
NULL
;
subvol_inum
inum
;
subvol_inum
inum
;
...
@@ -293,7 +336,6 @@ __bch2_create(struct mnt_idmap *idmap,
...
@@ -293,7 +336,6 @@ __bch2_create(struct mnt_idmap *idmap,
mutex_unlock
(
&
dir
->
ei_update_lock
);
mutex_unlock
(
&
dir
->
ei_update_lock
);
}
}
bch2_iget5_set
(
&
inode
->
v
,
&
inum
);
bch2_vfs_inode_init
(
trans
,
inum
,
inode
,
&
inode_u
,
&
subvol
);
bch2_vfs_inode_init
(
trans
,
inum
,
inode
,
&
inode_u
,
&
subvol
);
set_cached_acl
(
&
inode
->
v
,
ACL_TYPE_ACCESS
,
acl
);
set_cached_acl
(
&
inode
->
v
,
ACL_TYPE_ACCESS
,
acl
);
...
@@ -304,36 +346,7 @@ __bch2_create(struct mnt_idmap *idmap,
...
@@ -304,36 +346,7 @@ __bch2_create(struct mnt_idmap *idmap,
* bch2_trans_exit() and dropping locks, else we could race with another
* bch2_trans_exit() and dropping locks, else we could race with another
* thread pulling the inode in and modifying it:
* thread pulling the inode in and modifying it:
*/
*/
inode
=
bch2_inode_insert
(
c
,
inode
);
inode
->
v
.
i_state
|=
I_CREATING
;
old
=
to_bch_ei
(
inode_insert5
(
&
inode
->
v
,
bch2_inode_hash
(
inum
),
bch2_iget5_test
,
bch2_iget5_set
,
&
inum
));
BUG_ON
(
!
old
);
if
(
unlikely
(
old
!=
inode
))
{
/*
* We raced, another process pulled the new inode into cache
* before us:
*/
make_bad_inode
(
&
inode
->
v
);
iput
(
&
inode
->
v
);
inode
=
old
;
}
else
{
mutex_lock
(
&
c
->
vfs_inodes_lock
);
list_add
(
&
inode
->
ei_vfs_inode_list
,
&
c
->
vfs_inodes_list
);
mutex_unlock
(
&
c
->
vfs_inodes_lock
);
/*
* we really don't want insert_inode_locked2() to be setting
* I_NEW...
*/
unlock_new_inode
(
&
inode
->
v
);
}
bch2_trans_put
(
trans
);
bch2_trans_put
(
trans
);
err:
err:
posix_acl_release
(
default_acl
);
posix_acl_release
(
default_acl
);
...
@@ -1372,6 +1385,7 @@ static void bch2_vfs_inode_init(struct btree_trans *trans, subvol_inum inum,
...
@@ -1372,6 +1385,7 @@ static void bch2_vfs_inode_init(struct btree_trans *trans, subvol_inum inum,
struct
bch_inode_unpacked
*
bi
,
struct
bch_inode_unpacked
*
bi
,
struct
bch_subvolume
*
subvol
)
struct
bch_subvolume
*
subvol
)
{
{
bch2_iget5_set
(
&
inode
->
v
,
&
inum
);
bch2_inode_update_after_write
(
trans
,
inode
,
bi
,
~
0
);
bch2_inode_update_after_write
(
trans
,
inode
,
bi
,
~
0
);
if
(
BCH_SUBVOLUME_SNAP
(
subvol
))
if
(
BCH_SUBVOLUME_SNAP
(
subvol
))
...
...
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