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
58677a1d
Commit
58677a1d
authored
Oct 01, 2019
by
Kent Overstreet
Committed by
Kent Overstreet
Oct 22, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcachefs: bch2_inode_peek()/bch2_inode_write()
Signed-off-by:
Kent Overstreet
<
kent.overstreet@linux.dev
>
parent
618b9e57
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
198 additions
and
192 deletions
+198
-192
fs/bcachefs/acl.c
fs/bcachefs/acl.c
+27
-24
fs/bcachefs/fs-io.c
fs/bcachefs/fs-io.c
+32
-55
fs/bcachefs/fs.c
fs/bcachefs/fs.c
+87
-113
fs/bcachefs/inode.c
fs/bcachefs/inode.c
+47
-0
fs/bcachefs/inode.h
fs/bcachefs/inode.h
+5
-0
No files found.
fs/bcachefs/acl.c
View file @
58677a1d
...
@@ -281,51 +281,54 @@ int bch2_set_acl_trans(struct btree_trans *trans,
...
@@ -281,51 +281,54 @@ int bch2_set_acl_trans(struct btree_trans *trans,
return
ret
==
-
ENOENT
?
0
:
ret
;
return
ret
==
-
ENOENT
?
0
:
ret
;
}
}
static
int
inode_update_for_set_acl_fn
(
struct
bch_inode_info
*
inode
,
struct
bch_inode_unpacked
*
bi
,
void
*
p
)
{
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
umode_t
mode
=
(
unsigned
long
)
p
;
bi
->
bi_ctime
=
bch2_current_time
(
c
);
bi
->
bi_mode
=
mode
;
return
0
;
}
int
bch2_set_acl
(
struct
mnt_idmap
*
idmap
,
int
bch2_set_acl
(
struct
mnt_idmap
*
idmap
,
struct
dentry
*
dentry
,
struct
dentry
*
dentry
,
struct
posix_acl
*
acl
,
int
type
)
struct
posix_acl
*
_
acl
,
int
type
)
{
{
struct
bch_inode_info
*
inode
=
to_bch_ei
(
dentry
->
d_inode
);
struct
bch_inode_info
*
inode
=
to_bch_ei
(
dentry
->
d_inode
);
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
struct
btree_trans
trans
;
struct
btree_trans
trans
;
struct
btree_iter
*
inode_iter
;
struct
bch_inode_unpacked
inode_u
;
struct
bch_inode_unpacked
inode_u
;
umode_t
mode
=
inode
->
v
.
i_mode
;
struct
posix_acl
*
acl
;
umode_t
mode
;
int
ret
;
int
ret
;
mutex_lock
(
&
inode
->
ei_update_lock
);
mutex_lock
(
&
inode
->
ei_update_lock
);
bch2_trans_init
(
&
trans
,
c
,
0
,
0
);
bch2_trans_init
(
&
trans
,
c
,
0
,
0
);
retry:
bch2_trans_begin
(
&
trans
);
acl
=
_acl
;
if
(
type
==
ACL_TYPE_ACCESS
&&
acl
)
{
inode_iter
=
bch2_inode_peek
(
&
trans
,
&
inode_u
,
inode
->
v
.
i_ino
,
BTREE_ITER_INTENT
);
ret
=
PTR_ERR_OR_ZERO
(
inode_iter
);
if
(
ret
)
goto
btree_err
;
mode
=
inode_u
.
bi_mode
;
if
(
type
==
ACL_TYPE_ACCESS
)
{
ret
=
posix_acl_update_mode
(
idmap
,
&
inode
->
v
,
&
mode
,
&
acl
);
ret
=
posix_acl_update_mode
(
idmap
,
&
inode
->
v
,
&
mode
,
&
acl
);
if
(
ret
)
if
(
ret
)
goto
err
;
goto
err
;
}
}
retry:
bch2_trans_begin
(
&
trans
);
ret
=
bch2_set_acl_trans
(
&
trans
,
ret
=
bch2_set_acl_trans
(
&
trans
,
&
inode_u
,
&
inode
->
ei_inode
,
&
inode
->
ei_str_hash
,
&
inode
->
ei_str_hash
,
acl
,
type
);
acl
,
type
)
?:
if
(
ret
)
bch2_write_inode_trans
(
&
trans
,
inode
,
&
inode_u
,
goto
btree_err
;
inode_update_for_set_acl_fn
,
(
void
*
)(
unsigned
long
)
mode
)
?:
inode_u
.
bi_ctime
=
bch2_current_time
(
c
);
inode_u
.
bi_mode
=
mode
;
ret
=
bch2_inode_write
(
&
trans
,
inode_iter
,
&
inode_u
)
?:
bch2_trans_commit
(
&
trans
,
NULL
,
bch2_trans_commit
(
&
trans
,
NULL
,
&
inode
->
ei_journal_seq
,
&
inode
->
ei_journal_seq
,
BTREE_INSERT_ATOMIC
|
BTREE_INSERT_ATOMIC
|
BTREE_INSERT_NOUNLOCK
);
BTREE_INSERT_NOUNLOCK
);
btree_err:
if
(
ret
==
-
EINTR
)
if
(
ret
==
-
EINTR
)
goto
retry
;
goto
retry
;
if
(
unlikely
(
ret
))
if
(
unlikely
(
ret
))
...
...
fs/bcachefs/fs-io.c
View file @
58677a1d
...
@@ -241,11 +241,13 @@ static void i_sectors_acct(struct bch_fs *c, struct bch_inode_info *inode,
...
@@ -241,11 +241,13 @@ static void i_sectors_acct(struct bch_fs *c, struct bch_inode_info *inode,
static
int
sum_sector_overwrites
(
struct
btree_trans
*
trans
,
static
int
sum_sector_overwrites
(
struct
btree_trans
*
trans
,
struct
btree_iter
*
extent_iter
,
struct
btree_iter
*
extent_iter
,
struct
bkey_i
*
new
,
bool
*
allocating
,
struct
bkey_i
*
new
,
bool
may_allocate
,
s64
*
delta
)
s64
*
delta
)
{
{
struct
btree_iter
*
iter
;
struct
btree_iter
*
iter
;
struct
bkey_s_c
old
;
struct
bkey_s_c
old
;
int
ret
=
0
;
*
delta
=
0
;
*
delta
=
0
;
...
@@ -253,21 +255,13 @@ static int sum_sector_overwrites(struct btree_trans *trans,
...
@@ -253,21 +255,13 @@ static int sum_sector_overwrites(struct btree_trans *trans,
if
(
IS_ERR
(
iter
))
if
(
IS_ERR
(
iter
))
return
PTR_ERR
(
iter
);
return
PTR_ERR
(
iter
);
old
=
bch2_btree_iter_peek_slot
(
iter
);
for_each_btree_key_continue
(
iter
,
BTREE_ITER_SLOTS
,
old
,
ret
)
{
if
(
!
may_allocate
&&
while
(
1
)
{
/*
* should not be possible to get an error here, since we're
* carefully not advancing past @new and thus whatever leaf node
* @_iter currently points to:
*/
BUG_ON
(
bkey_err
(
old
));
if
(
allocating
&&
!*
allocating
&&
bch2_bkey_nr_ptrs_allocated
(
old
)
<
bch2_bkey_nr_ptrs_allocated
(
old
)
<
bch2_bkey_nr_dirty_ptrs
(
bkey_i_to_s_c
(
new
)))
bch2_bkey_nr_dirty_ptrs
(
bkey_i_to_s_c
(
new
)))
{
*
allocating
=
true
;
ret
=
-
ENOSPC
;
break
;
}
*
delta
+=
(
min
(
new
->
k
.
p
.
offset
,
*
delta
+=
(
min
(
new
->
k
.
p
.
offset
,
old
.
k
->
p
.
offset
)
-
old
.
k
->
p
.
offset
)
-
...
@@ -278,12 +272,10 @@ static int sum_sector_overwrites(struct btree_trans *trans,
...
@@ -278,12 +272,10 @@ static int sum_sector_overwrites(struct btree_trans *trans,
if
(
bkey_cmp
(
old
.
k
->
p
,
new
->
k
.
p
)
>=
0
)
if
(
bkey_cmp
(
old
.
k
->
p
,
new
->
k
.
p
)
>=
0
)
break
;
break
;
old
=
bch2_btree_iter_next_slot
(
iter
);
}
}
bch2_trans_iter_put
(
trans
,
iter
);
bch2_trans_iter_put
(
trans
,
iter
);
return
0
;
return
ret
;
}
}
int
bch2_extent_update
(
struct
btree_trans
*
trans
,
int
bch2_extent_update
(
struct
btree_trans
*
trans
,
...
@@ -301,9 +293,7 @@ int bch2_extent_update(struct btree_trans *trans,
...
@@ -301,9 +293,7 @@ int bch2_extent_update(struct btree_trans *trans,
struct
btree_iter
*
inode_iter
=
NULL
;
struct
btree_iter
*
inode_iter
=
NULL
;
struct
bch_inode_unpacked
inode_u
;
struct
bch_inode_unpacked
inode_u
;
struct
bkey_inode_buf
inode_p
;
struct
bkey_inode_buf
inode_p
;
bool
allocating
=
false
;
bool
extended
=
false
;
bool
extended
=
false
;
bool
inode_locked
=
false
;
s64
i_sectors_delta
;
s64
i_sectors_delta
;
int
ret
;
int
ret
;
...
@@ -315,15 +305,11 @@ int bch2_extent_update(struct btree_trans *trans,
...
@@ -315,15 +305,11 @@ int bch2_extent_update(struct btree_trans *trans,
if
(
ret
)
if
(
ret
)
return
ret
;
return
ret
;
ret
=
sum_sector_overwrites
(
trans
,
extent_iter
,
ret
=
sum_sector_overwrites
(
trans
,
extent_iter
,
k
,
k
,
&
allocating
,
may_allocate
,
&
i_sectors_delta
);
&
i_sectors_delta
);
if
(
ret
)
if
(
ret
)
return
ret
;
return
ret
;
if
(
!
may_allocate
&&
allocating
)
return
-
ENOSPC
;
bch2_trans_update
(
trans
,
extent_iter
,
k
);
bch2_trans_update
(
trans
,
extent_iter
,
k
);
new_i_size
=
min
(
k
->
k
.
p
.
offset
<<
9
,
new_i_size
);
new_i_size
=
min
(
k
->
k
.
p
.
offset
<<
9
,
new_i_size
);
...
@@ -331,29 +317,28 @@ int bch2_extent_update(struct btree_trans *trans,
...
@@ -331,29 +317,28 @@ int bch2_extent_update(struct btree_trans *trans,
/* XXX: inode->i_size locking */
/* XXX: inode->i_size locking */
if
(
i_sectors_delta
||
if
(
i_sectors_delta
||
new_i_size
>
inode
->
ei_inode
.
bi_size
)
{
new_i_size
>
inode
->
ei_inode
.
bi_size
)
{
inode_iter
=
bch2_trans_get_iter
(
trans
,
inode_iter
=
bch2_inode_peek
(
trans
,
&
inode_u
,
BTREE_ID_INODES
,
k
->
k
.
p
.
inode
,
BTREE_ITER_INTENT
);
POS
(
k
->
k
.
p
.
inode
,
0
),
BTREE_ITER_SLOTS
|
BTREE_ITER_INTENT
);
if
(
IS_ERR
(
inode_iter
))
if
(
IS_ERR
(
inode_iter
))
return
PTR_ERR
(
inode_iter
);
return
PTR_ERR
(
inode_iter
);
ret
=
bch2_btree_iter_traverse
(
inode_iter
);
if
(
ret
)
goto
err
;
inode_u
=
inode
->
ei_inode
;
inode_u
.
bi_sectors
+=
i_sectors_delta
;
inode_u
.
bi_sectors
+=
i_sectors_delta
;
/* XXX: this is slightly suspect */
/*
* XXX: can BCH_INODE_I_SIZE_DIRTY be true here? i.e. can we
* race with truncate?
*/
if
(
!
(
inode_u
.
bi_flags
&
BCH_INODE_I_SIZE_DIRTY
)
&&
if
(
!
(
inode_u
.
bi_flags
&
BCH_INODE_I_SIZE_DIRTY
)
&&
new_i_size
>
inode_u
.
bi_size
)
{
new_i_size
>
inode_u
.
bi_size
)
{
inode_u
.
bi_size
=
new_i_size
;
inode_u
.
bi_size
=
new_i_size
;
extended
=
true
;
extended
=
true
;
}
}
bch2_inode_pack
(
&
inode_p
,
&
inode_u
);
if
(
i_sectors_delta
||
extended
)
{
bch2_trans_update
(
trans
,
inode_iter
,
&
inode_p
.
inode
.
k_i
);
bch2_inode_pack
(
&
inode_p
,
&
inode_u
);
bch2_trans_update
(
trans
,
inode_iter
,
&
inode_p
.
inode
.
k_i
);
}
}
}
ret
=
bch2_trans_commit
(
trans
,
disk_res
,
ret
=
bch2_trans_commit
(
trans
,
disk_res
,
...
@@ -365,33 +350,25 @@ int bch2_extent_update(struct btree_trans *trans,
...
@@ -365,33 +350,25 @@ int bch2_extent_update(struct btree_trans *trans,
if
(
ret
)
if
(
ret
)
goto
err
;
goto
err
;
inode
->
ei_inode
.
bi_sectors
+=
i_sectors_delta
;
if
(
i_sectors_delta
||
extended
)
{
inode
->
ei_inode
.
bi_sectors
=
inode_u
.
bi_sectors
;
EBUG_ON
(
i_sectors_delta
&&
inode
->
ei_inode
.
bi_size
=
inode_u
.
bi_size
;
inode
->
ei_inode
.
bi_sectors
!=
inode_u
.
bi_sectors
);
if
(
extended
)
{
inode
->
ei_inode
.
bi_size
=
new_i_size
;
if
(
direct
)
{
spin_lock
(
&
inode
->
v
.
i_lock
);
if
(
new_i_size
>
inode
->
v
.
i_size
)
i_size_write
(
&
inode
->
v
,
new_i_size
);
spin_unlock
(
&
inode
->
v
.
i_lock
);
}
}
}
if
(
direct
)
if
(
direct
)
i_sectors_acct
(
c
,
inode
,
quota_res
,
i_sectors_delta
);
i_sectors_acct
(
c
,
inode
,
quota_res
,
i_sectors_delta
);
if
(
direct
&&
extended
)
{
spin_lock
(
&
inode
->
v
.
i_lock
);
if
(
new_i_size
>
inode
->
v
.
i_size
)
i_size_write
(
&
inode
->
v
,
new_i_size
);
spin_unlock
(
&
inode
->
v
.
i_lock
);
}
if
(
total_delta
)
if
(
total_delta
)
*
total_delta
+=
i_sectors_delta
;
*
total_delta
+=
i_sectors_delta
;
err:
err:
if
(
!
IS_ERR_OR_NULL
(
inode_iter
))
if
(
!
IS_ERR_OR_NULL
(
inode_iter
))
bch2_trans_iter_put
(
trans
,
inode_iter
);
bch2_trans_iter_put
(
trans
,
inode_iter
);
if
(
inode_locked
)
mutex_unlock
(
&
inode
->
ei_update_lock
);
return
ret
;
return
ret
;
}
}
...
...
fs/bcachefs/fs.c
View file @
58677a1d
...
@@ -155,41 +155,19 @@ int __must_check bch2_write_inode_trans(struct btree_trans *trans,
...
@@ -155,41 +155,19 @@ int __must_check bch2_write_inode_trans(struct btree_trans *trans,
void
*
p
)
void
*
p
)
{
{
struct
btree_iter
*
iter
=
NULL
;
struct
btree_iter
*
iter
=
NULL
;
struct
bkey_inode_buf
*
inode_p
;
struct
bkey_s_c
k
;
int
ret
=
0
;
int
ret
=
0
;
iter
=
bch2_trans_get_iter
(
trans
,
BTREE_ID_INODES
,
iter
=
bch2_inode_peek
(
trans
,
inode_u
,
inode
->
v
.
i_ino
,
POS
(
inode
->
v
.
i_ino
,
0
),
BTREE_ITER_INTENT
);
BTREE_ITER_SLOTS
|
BTREE_ITER_INTENT
);
ret
=
PTR_ERR_OR_ZERO
(
iter
);
if
(
IS_ERR
(
iter
))
return
PTR_ERR
(
iter
);
k
=
bch2_btree_iter_peek_slot
(
iter
);
ret
=
bkey_err
(
k
);
if
(
ret
)
if
(
ret
)
return
ret
;
return
ret
;
if
(
k
.
k
->
type
!=
KEY_TYPE_inode
)
ret
=
set
?
set
(
inode
,
inode_u
,
p
)
:
0
;
return
-
EIO
;
ret
=
bch2_inode_unpack
(
bkey_s_c_to_inode
(
k
),
inode_u
);
if
(
ret
)
if
(
ret
)
return
ret
;
return
ret
;
if
(
set
)
{
return
bch2_inode_write
(
trans
,
iter
,
inode_u
);
ret
=
set
(
inode
,
inode_u
,
p
);
if
(
ret
)
return
ret
;
}
inode_p
=
bch2_trans_kmalloc
(
trans
,
sizeof
(
*
inode_p
));
if
(
IS_ERR
(
inode_p
))
return
PTR_ERR
(
inode_p
);
bch2_inode_pack
(
inode_p
,
inode_u
);
bch2_trans_update
(
trans
,
iter
,
&
inode_p
->
inode
.
k_i
);
return
0
;
}
}
int
__must_check
bch2_write_inode
(
struct
bch_fs
*
c
,
int
__must_check
bch2_write_inode
(
struct
bch_fs
*
c
,
...
@@ -531,23 +509,13 @@ static int bch2_create(struct mnt_idmap *idmap,
...
@@ -531,23 +509,13 @@ static int bch2_create(struct mnt_idmap *idmap,
return
0
;
return
0
;
}
}
static
int
inode_update_for_link_fn
(
struct
bch_inode_info
*
inode
,
struct
bch_inode_unpacked
*
bi
,
void
*
p
)
{
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
bi
->
bi_ctime
=
bch2_current_time
(
c
);
bch2_inode_nlink_inc
(
bi
);
return
0
;
}
static
int
__bch2_link
(
struct
bch_fs
*
c
,
static
int
__bch2_link
(
struct
bch_fs
*
c
,
struct
bch_inode_info
*
inode
,
struct
bch_inode_info
*
inode
,
struct
bch_inode_info
*
dir
,
struct
bch_inode_info
*
dir
,
struct
dentry
*
dentry
)
struct
dentry
*
dentry
)
{
{
struct
btree_trans
trans
;
struct
btree_trans
trans
;
struct
btree_iter
*
inode_iter
;
struct
bch_inode_unpacked
inode_u
;
struct
bch_inode_unpacked
inode_u
;
int
ret
;
int
ret
;
...
@@ -555,21 +523,30 @@ static int __bch2_link(struct bch_fs *c,
...
@@ -555,21 +523,30 @@ static int __bch2_link(struct bch_fs *c,
bch2_trans_init
(
&
trans
,
c
,
4
,
1024
);
bch2_trans_init
(
&
trans
,
c
,
4
,
1024
);
retry:
retry:
bch2_trans_begin
(
&
trans
);
bch2_trans_begin
(
&
trans
);
ret
=
__bch2_dirent_create
(
&
trans
,
dir
->
v
.
i_ino
,
ret
=
__bch2_dirent_create
(
&
trans
,
dir
->
v
.
i_ino
,
&
dir
->
ei_str_hash
,
&
dir
->
ei_str_hash
,
mode_to_type
(
inode
->
v
.
i_mode
),
mode_to_type
(
inode
->
v
.
i_mode
),
&
dentry
->
d_name
,
&
dentry
->
d_name
,
inode
->
v
.
i_ino
,
inode
->
v
.
i_ino
,
BCH_HASH_SET_MUST_CREATE
)
?:
BCH_HASH_SET_MUST_CREATE
);
bch2_write_inode_trans
(
&
trans
,
inode
,
&
inode_u
,
if
(
ret
)
inode_update_for_link_fn
,
goto
err
;
NULL
)
?:
bch2_trans_commit
(
&
trans
,
NULL
,
inode_iter
=
bch2_inode_peek
(
&
trans
,
&
inode_u
,
inode
->
v
.
i_ino
,
&
inode
->
ei_journal_seq
,
BTREE_ITER_INTENT
);
BTREE_INSERT_ATOMIC
|
ret
=
PTR_ERR_OR_ZERO
(
inode_iter
);
BTREE_INSERT_NOUNLOCK
);
if
(
ret
)
goto
err
;
inode_u
.
bi_ctime
=
bch2_current_time
(
c
);
bch2_inode_nlink_inc
(
&
inode_u
);
ret
=
bch2_inode_write
(
&
trans
,
inode_iter
,
&
inode_u
)
?:
bch2_trans_commit
(
&
trans
,
NULL
,
&
inode
->
ei_journal_seq
,
BTREE_INSERT_ATOMIC
|
BTREE_INSERT_NOUNLOCK
);
err:
if
(
ret
==
-
EINTR
)
if
(
ret
==
-
EINTR
)
goto
retry
;
goto
retry
;
...
@@ -600,36 +577,12 @@ static int bch2_link(struct dentry *old_dentry, struct inode *vdir,
...
@@ -600,36 +577,12 @@ static int bch2_link(struct dentry *old_dentry, struct inode *vdir,
return
0
;
return
0
;
}
}
static
int
inode_update_dir_for_unlink_fn
(
struct
bch_inode_info
*
inode
,
struct
bch_inode_unpacked
*
bi
,
void
*
p
)
{
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
struct
bch_inode_info
*
unlink_inode
=
p
;
bi
->
bi_mtime
=
bi
->
bi_ctime
=
bch2_current_time
(
c
);
bi
->
bi_nlink
-=
S_ISDIR
(
unlink_inode
->
v
.
i_mode
);
return
0
;
}
static
int
inode_update_for_unlink_fn
(
struct
bch_inode_info
*
inode
,
struct
bch_inode_unpacked
*
bi
,
void
*
p
)
{
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
bi
->
bi_ctime
=
bch2_current_time
(
c
);
bch2_inode_nlink_dec
(
bi
);
return
0
;
}
static
int
bch2_unlink
(
struct
inode
*
vdir
,
struct
dentry
*
dentry
)
static
int
bch2_unlink
(
struct
inode
*
vdir
,
struct
dentry
*
dentry
)
{
{
struct
bch_fs
*
c
=
vdir
->
i_sb
->
s_fs_info
;
struct
bch_fs
*
c
=
vdir
->
i_sb
->
s_fs_info
;
struct
bch_inode_info
*
dir
=
to_bch_ei
(
vdir
);
struct
bch_inode_info
*
dir
=
to_bch_ei
(
vdir
);
struct
bch_inode_info
*
inode
=
to_bch_ei
(
dentry
->
d_inode
);
struct
bch_inode_info
*
inode
=
to_bch_ei
(
dentry
->
d_inode
);
struct
btree_iter
*
dir_iter
,
*
inode_iter
;
struct
bch_inode_unpacked
dir_u
,
inode_u
;
struct
bch_inode_unpacked
dir_u
,
inode_u
;
struct
btree_trans
trans
;
struct
btree_trans
trans
;
int
ret
;
int
ret
;
...
@@ -641,25 +594,42 @@ static int bch2_unlink(struct inode *vdir, struct dentry *dentry)
...
@@ -641,25 +594,42 @@ static int bch2_unlink(struct inode *vdir, struct dentry *dentry)
ret
=
__bch2_dirent_delete
(
&
trans
,
dir
->
v
.
i_ino
,
ret
=
__bch2_dirent_delete
(
&
trans
,
dir
->
v
.
i_ino
,
&
dir
->
ei_str_hash
,
&
dir
->
ei_str_hash
,
&
dentry
->
d_name
)
?:
&
dentry
->
d_name
);
bch2_write_inode_trans
(
&
trans
,
dir
,
&
dir_u
,
if
(
ret
)
inode_update_dir_for_unlink_fn
,
goto
btree_err
;
inode
)
?:
bch2_write_inode_trans
(
&
trans
,
inode
,
&
inode_u
,
dir_iter
=
bch2_inode_peek
(
&
trans
,
&
dir_u
,
dir
->
v
.
i_ino
,
inode_update_for_unlink_fn
,
BTREE_ITER_INTENT
);
NULL
)
?:
ret
=
PTR_ERR_OR_ZERO
(
dir_iter
);
if
(
ret
)
goto
btree_err
;
inode_iter
=
bch2_inode_peek
(
&
trans
,
&
inode_u
,
inode
->
v
.
i_ino
,
BTREE_ITER_INTENT
);
ret
=
PTR_ERR_OR_ZERO
(
inode_iter
);
if
(
ret
)
goto
btree_err
;
dir_u
.
bi_mtime
=
dir_u
.
bi_ctime
=
inode_u
.
bi_ctime
=
bch2_current_time
(
c
);
dir_u
.
bi_nlink
-=
S_ISDIR
(
inode_u
.
bi_mode
);
bch2_inode_nlink_dec
(
&
inode_u
);
ret
=
bch2_inode_write
(
&
trans
,
dir_iter
,
&
dir_u
)
?:
bch2_inode_write
(
&
trans
,
inode_iter
,
&
inode_u
)
?:
bch2_trans_commit
(
&
trans
,
NULL
,
bch2_trans_commit
(
&
trans
,
NULL
,
&
dir
->
ei_journal_seq
,
&
dir
->
ei_journal_seq
,
BTREE_INSERT_ATOMIC
|
BTREE_INSERT_ATOMIC
|
BTREE_INSERT_NOUNLOCK
|
BTREE_INSERT_NOUNLOCK
|
BTREE_INSERT_NOFAIL
);
BTREE_INSERT_NOFAIL
);
btree_err:
if
(
ret
==
-
EINTR
)
if
(
ret
==
-
EINTR
)
goto
retry
;
goto
retry
;
if
(
ret
)
if
(
ret
)
goto
err
;
goto
err
;
if
(
dir
->
ei_journal_seq
>
inode
->
ei_journal_seq
)
journal_seq_copy
(
inode
,
dir
->
ei_journal_seq
);
inode
->
ei_journal_seq
=
dir
->
ei_journal_seq
;
bch2_inode_update_after_write
(
c
,
dir
,
&
dir_u
,
bch2_inode_update_after_write
(
c
,
dir
,
&
dir_u
,
ATTR_MTIME
|
ATTR_CTIME
);
ATTR_MTIME
|
ATTR_CTIME
);
...
@@ -953,67 +923,60 @@ static int bch2_rename2(struct mnt_idmap *idmap,
...
@@ -953,67 +923,60 @@ static int bch2_rename2(struct mnt_idmap *idmap,
return
ret
;
return
ret
;
}
}
struct
inode_write_setattr
{
static
void
bch2_setattr_copy
(
struct
mnt_idmap
*
idmap
,
struct
iattr
*
attr
;
struct
bch_inode_info
*
inode
,
struct
mnt_idmap
*
idmap
;
struct
bch_inode_unpacked
*
bi
,
};
struct
iattr
*
attr
)
static
int
inode_update_for_setattr_fn
(
struct
bch_inode_info
*
inode
,
struct
bch_inode_unpacked
*
bi
,
void
*
p
)
{
{
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
struct
inode_write_setattr
*
s
=
p
;
unsigned
int
ia_valid
=
attr
->
ia_valid
;
unsigned
int
ia_valid
=
s
->
attr
->
ia_valid
;
if
(
ia_valid
&
ATTR_UID
)
if
(
ia_valid
&
ATTR_UID
)
bi
->
bi_uid
=
from_kuid
(
i_user_ns
(
&
inode
->
v
),
s
->
attr
->
ia_uid
);
bi
->
bi_uid
=
from_kuid
(
i_user_ns
(
&
inode
->
v
),
attr
->
ia_uid
);
if
(
ia_valid
&
ATTR_GID
)
if
(
ia_valid
&
ATTR_GID
)
bi
->
bi_gid
=
from_kgid
(
i_user_ns
(
&
inode
->
v
),
s
->
attr
->
ia_gid
);
bi
->
bi_gid
=
from_kgid
(
i_user_ns
(
&
inode
->
v
),
attr
->
ia_gid
);
if
(
ia_valid
&
ATTR_ATIME
)
if
(
ia_valid
&
ATTR_ATIME
)
bi
->
bi_atime
=
timespec_to_bch2_time
(
c
,
s
->
attr
->
ia_atime
);
bi
->
bi_atime
=
timespec_to_bch2_time
(
c
,
attr
->
ia_atime
);
if
(
ia_valid
&
ATTR_MTIME
)
if
(
ia_valid
&
ATTR_MTIME
)
bi
->
bi_mtime
=
timespec_to_bch2_time
(
c
,
s
->
attr
->
ia_mtime
);
bi
->
bi_mtime
=
timespec_to_bch2_time
(
c
,
attr
->
ia_mtime
);
if
(
ia_valid
&
ATTR_CTIME
)
if
(
ia_valid
&
ATTR_CTIME
)
bi
->
bi_ctime
=
timespec_to_bch2_time
(
c
,
s
->
attr
->
ia_ctime
);
bi
->
bi_ctime
=
timespec_to_bch2_time
(
c
,
attr
->
ia_ctime
);
if
(
ia_valid
&
ATTR_MODE
)
{
if
(
ia_valid
&
ATTR_MODE
)
{
umode_t
mode
=
s
->
attr
->
ia_mode
;
umode_t
mode
=
attr
->
ia_mode
;
kgid_t
gid
=
ia_valid
&
ATTR_GID
kgid_t
gid
=
ia_valid
&
ATTR_GID
?
s
->
attr
->
ia_gid
?
attr
->
ia_gid
:
inode
->
v
.
i_gid
;
:
inode
->
v
.
i_gid
;
if
(
!
in_group_p
(
gid
)
&&
if
(
!
in_group_p
(
gid
)
&&
!
capable_wrt_inode_uidgid
(
s
->
idmap
,
&
inode
->
v
,
CAP_FSETID
))
!
capable_wrt_inode_uidgid
(
idmap
,
&
inode
->
v
,
CAP_FSETID
))
mode
&=
~
S_ISGID
;
mode
&=
~
S_ISGID
;
bi
->
bi_mode
=
mode
;
bi
->
bi_mode
=
mode
;
}
}
return
0
;
}
}
static
int
bch2_setattr_nonsize
(
struct
mnt_idmap
*
idmap
,
static
int
bch2_setattr_nonsize
(
struct
mnt_idmap
*
idmap
,
struct
bch_inode_info
*
inode
,
struct
bch_inode_info
*
inode
,
struct
iattr
*
i
attr
)
struct
iattr
*
attr
)
{
{
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
struct
bch_fs
*
c
=
inode
->
v
.
i_sb
->
s_fs_info
;
struct
bch_qid
qid
;
struct
bch_qid
qid
;
struct
btree_trans
trans
;
struct
btree_trans
trans
;
struct
btree_iter
*
inode_iter
;
struct
bch_inode_unpacked
inode_u
;
struct
bch_inode_unpacked
inode_u
;
struct
posix_acl
*
acl
=
NULL
;
struct
posix_acl
*
acl
=
NULL
;
struct
inode_write_setattr
s
=
{
iattr
,
idmap
};
int
ret
;
int
ret
;
mutex_lock
(
&
inode
->
ei_update_lock
);
mutex_lock
(
&
inode
->
ei_update_lock
);
qid
=
inode
->
ei_qid
;
qid
=
inode
->
ei_qid
;
if
(
i
attr
->
ia_valid
&
ATTR_UID
)
if
(
attr
->
ia_valid
&
ATTR_UID
)
qid
.
q
[
QTYP_USR
]
=
from_kuid
(
i_user_ns
(
&
inode
->
v
),
i
attr
->
ia_uid
);
qid
.
q
[
QTYP_USR
]
=
from_kuid
(
i_user_ns
(
&
inode
->
v
),
attr
->
ia_uid
);
if
(
i
attr
->
ia_valid
&
ATTR_GID
)
if
(
attr
->
ia_valid
&
ATTR_GID
)
qid
.
q
[
QTYP_GRP
]
=
from_kgid
(
i_user_ns
(
&
inode
->
v
),
i
attr
->
ia_gid
);
qid
.
q
[
QTYP_GRP
]
=
from_kgid
(
i_user_ns
(
&
inode
->
v
),
attr
->
ia_gid
);
ret
=
bch2_fs_quota_transfer
(
c
,
inode
,
qid
,
~
0
,
ret
=
bch2_fs_quota_transfer
(
c
,
inode
,
qid
,
~
0
,
KEY_TYPE_QUOTA_PREALLOC
);
KEY_TYPE_QUOTA_PREALLOC
);
...
@@ -1026,22 +989,33 @@ static int bch2_setattr_nonsize(struct mnt_idmap *idmap,
...
@@ -1026,22 +989,33 @@ static int bch2_setattr_nonsize(struct mnt_idmap *idmap,
kfree
(
acl
);
kfree
(
acl
);
acl
=
NULL
;
acl
=
NULL
;
ret
=
bch2_write_inode_trans
(
&
trans
,
inode
,
&
inode_u
,
inode_iter
=
bch2_inode_peek
(
&
trans
,
&
inode_u
,
inode
->
v
.
i_ino
,
inode_update_for_setattr_fn
,
&
s
)
?:
BTREE_ITER_INTENT
);
(
iattr
->
ia_valid
&
ATTR_MODE
ret
=
PTR_ERR_OR_ZERO
(
inode_iter
);
?
bch2_acl_chmod
(
&
trans
,
inode
,
iattr
->
ia_mode
,
&
acl
)
if
(
ret
)
:
0
)
?:
goto
btree_err
;
bch2_setattr_copy
(
idmap
,
inode
,
&
inode_u
,
attr
);
if
(
attr
->
ia_valid
&
ATTR_MODE
)
{
ret
=
bch2_acl_chmod
(
&
trans
,
inode
,
inode_u
.
bi_mode
,
&
acl
);
if
(
ret
)
goto
btree_err
;
}
ret
=
bch2_inode_write
(
&
trans
,
inode_iter
,
&
inode_u
)
?:
bch2_trans_commit
(
&
trans
,
NULL
,
bch2_trans_commit
(
&
trans
,
NULL
,
&
inode
->
ei_journal_seq
,
&
inode
->
ei_journal_seq
,
BTREE_INSERT_ATOMIC
|
BTREE_INSERT_ATOMIC
|
BTREE_INSERT_NOUNLOCK
|
BTREE_INSERT_NOUNLOCK
|
BTREE_INSERT_NOFAIL
);
BTREE_INSERT_NOFAIL
);
btree_err:
if
(
ret
==
-
EINTR
)
if
(
ret
==
-
EINTR
)
goto
retry
;
goto
retry
;
if
(
unlikely
(
ret
))
if
(
unlikely
(
ret
))
goto
err_trans
;
goto
err_trans
;
bch2_inode_update_after_write
(
c
,
inode
,
&
inode_u
,
i
attr
->
ia_valid
);
bch2_inode_update_after_write
(
c
,
inode
,
&
inode_u
,
attr
->
ia_valid
);
if
(
acl
)
if
(
acl
)
set_cached_acl
(
&
inode
->
v
,
ACL_TYPE_ACCESS
,
acl
);
set_cached_acl
(
&
inode
->
v
,
ACL_TYPE_ACCESS
,
acl
);
...
...
fs/bcachefs/inode.c
View file @
58677a1d
...
@@ -181,6 +181,53 @@ int bch2_inode_unpack(struct bkey_s_c_inode inode,
...
@@ -181,6 +181,53 @@ int bch2_inode_unpack(struct bkey_s_c_inode inode,
return
0
;
return
0
;
}
}
struct
btree_iter
*
bch2_inode_peek
(
struct
btree_trans
*
trans
,
struct
bch_inode_unpacked
*
inode
,
u64
inum
,
unsigned
flags
)
{
struct
btree_iter
*
iter
;
struct
bkey_s_c
k
;
int
ret
;
iter
=
bch2_trans_get_iter
(
trans
,
BTREE_ID_INODES
,
POS
(
inum
,
0
),
BTREE_ITER_SLOTS
|
flags
);
if
(
IS_ERR
(
iter
))
return
iter
;
k
=
bch2_btree_iter_peek_slot
(
iter
);
ret
=
bkey_err
(
k
);
if
(
ret
)
goto
err
;
ret
=
k
.
k
->
type
==
KEY_TYPE_inode
?
0
:
-
EIO
;
if
(
ret
)
goto
err
;
ret
=
bch2_inode_unpack
(
bkey_s_c_to_inode
(
k
),
inode
);
if
(
ret
)
goto
err
;
return
iter
;
err:
bch2_trans_iter_put
(
trans
,
iter
);
return
ERR_PTR
(
ret
);
}
int
bch2_inode_write
(
struct
btree_trans
*
trans
,
struct
btree_iter
*
iter
,
struct
bch_inode_unpacked
*
inode
)
{
struct
bkey_inode_buf
*
inode_p
;
inode_p
=
bch2_trans_kmalloc
(
trans
,
sizeof
(
*
inode_p
));
if
(
IS_ERR
(
inode_p
))
return
PTR_ERR
(
inode_p
);
bch2_inode_pack
(
inode_p
,
inode
);
bch2_trans_update
(
trans
,
iter
,
&
inode_p
->
inode
.
k_i
);
return
0
;
}
const
char
*
bch2_inode_invalid
(
const
struct
bch_fs
*
c
,
struct
bkey_s_c
k
)
const
char
*
bch2_inode_invalid
(
const
struct
bch_fs
*
c
,
struct
bkey_s_c
k
)
{
{
struct
bkey_s_c_inode
inode
=
bkey_s_c_to_inode
(
k
);
struct
bkey_s_c_inode
inode
=
bkey_s_c_to_inode
(
k
);
...
...
fs/bcachefs/inode.h
View file @
58677a1d
...
@@ -46,6 +46,11 @@ struct bkey_inode_buf {
...
@@ -46,6 +46,11 @@ struct bkey_inode_buf {
void
bch2_inode_pack
(
struct
bkey_inode_buf
*
,
const
struct
bch_inode_unpacked
*
);
void
bch2_inode_pack
(
struct
bkey_inode_buf
*
,
const
struct
bch_inode_unpacked
*
);
int
bch2_inode_unpack
(
struct
bkey_s_c_inode
,
struct
bch_inode_unpacked
*
);
int
bch2_inode_unpack
(
struct
bkey_s_c_inode
,
struct
bch_inode_unpacked
*
);
struct
btree_iter
*
bch2_inode_peek
(
struct
btree_trans
*
,
struct
bch_inode_unpacked
*
,
u64
,
unsigned
);
int
bch2_inode_write
(
struct
btree_trans
*
,
struct
btree_iter
*
,
struct
bch_inode_unpacked
*
);
void
bch2_inode_init
(
struct
bch_fs
*
,
struct
bch_inode_unpacked
*
,
void
bch2_inode_init
(
struct
bch_fs
*
,
struct
bch_inode_unpacked
*
,
uid_t
,
gid_t
,
umode_t
,
dev_t
,
uid_t
,
gid_t
,
umode_t
,
dev_t
,
struct
bch_inode_unpacked
*
);
struct
bch_inode_unpacked
*
);
...
...
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