ext4: use ext4_journal_start/stop for fast commit transactions
This patch drops all calls to ext4_fc_start_update() and ext4_fc_stop_update(). To ensure that there are no ongoing journal updates during fast commit, we also make jbd2_fc_begin_commit() lock journal for updates. This way we don't have to maintain two different transaction start stop APIs for fast commit and full commit. This patch doesn't remove the functions altogether since in future we want to have inode level locking for fast commits. Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com> Link: https://lore.kernel.org/r/20211223202140.2061101-2-harshads@google.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
committed by
Theodore Ts'o
parent
960e0ab63b
commit
2729cfdcfa
@@ -246,7 +246,6 @@ retry:
|
|||||||
handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits);
|
handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits);
|
||||||
if (IS_ERR(handle))
|
if (IS_ERR(handle))
|
||||||
return PTR_ERR(handle);
|
return PTR_ERR(handle);
|
||||||
ext4_fc_start_update(inode);
|
|
||||||
|
|
||||||
if ((type == ACL_TYPE_ACCESS) && acl) {
|
if ((type == ACL_TYPE_ACCESS) && acl) {
|
||||||
error = posix_acl_update_mode(mnt_userns, inode, &mode, &acl);
|
error = posix_acl_update_mode(mnt_userns, inode, &mode, &acl);
|
||||||
@@ -264,7 +263,6 @@ retry:
|
|||||||
}
|
}
|
||||||
out_stop:
|
out_stop:
|
||||||
ext4_journal_stop(handle);
|
ext4_journal_stop(handle);
|
||||||
ext4_fc_stop_update(inode);
|
|
||||||
if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
|
if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
|
||||||
goto retry;
|
goto retry;
|
||||||
return error;
|
return error;
|
||||||
|
@@ -4697,8 +4697,6 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
|
|||||||
FALLOC_FL_INSERT_RANGE))
|
FALLOC_FL_INSERT_RANGE))
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
ext4_fc_start_update(inode);
|
|
||||||
|
|
||||||
if (mode & FALLOC_FL_PUNCH_HOLE) {
|
if (mode & FALLOC_FL_PUNCH_HOLE) {
|
||||||
ret = ext4_punch_hole(inode, offset, len);
|
ret = ext4_punch_hole(inode, offset, len);
|
||||||
goto exit;
|
goto exit;
|
||||||
@@ -4762,7 +4760,6 @@ out:
|
|||||||
inode_unlock(inode);
|
inode_unlock(inode);
|
||||||
trace_ext4_fallocate_exit(inode, offset, max_blocks, ret);
|
trace_ext4_fallocate_exit(inode, offset, max_blocks, ret);
|
||||||
exit:
|
exit:
|
||||||
ext4_fc_stop_update(inode);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -259,7 +259,6 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb,
|
|||||||
if (iocb->ki_flags & IOCB_NOWAIT)
|
if (iocb->ki_flags & IOCB_NOWAIT)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
ext4_fc_start_update(inode);
|
|
||||||
inode_lock(inode);
|
inode_lock(inode);
|
||||||
ret = ext4_write_checks(iocb, from);
|
ret = ext4_write_checks(iocb, from);
|
||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
@@ -271,7 +270,6 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb,
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
inode_unlock(inode);
|
inode_unlock(inode);
|
||||||
ext4_fc_stop_update(inode);
|
|
||||||
if (likely(ret > 0)) {
|
if (likely(ret > 0)) {
|
||||||
iocb->ki_pos += ret;
|
iocb->ki_pos += ret;
|
||||||
ret = generic_write_sync(iocb, ret);
|
ret = generic_write_sync(iocb, ret);
|
||||||
@@ -552,9 +550,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ext4_fc_start_update(inode);
|
|
||||||
ret = ext4_orphan_add(handle, inode);
|
ret = ext4_orphan_add(handle, inode);
|
||||||
ext4_fc_stop_update(inode);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ext4_journal_stop(handle);
|
ext4_journal_stop(handle);
|
||||||
goto out;
|
goto out;
|
||||||
|
@@ -5320,7 +5320,7 @@ int ext4_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
|
|||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
ext4_fc_start_update(inode);
|
|
||||||
if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
|
if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
|
||||||
(ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
|
(ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
|
||||||
handle_t *handle;
|
handle_t *handle;
|
||||||
@@ -5344,7 +5344,6 @@ int ext4_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
|
|||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
ext4_journal_stop(handle);
|
ext4_journal_stop(handle);
|
||||||
ext4_fc_stop_update(inode);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
/* Update corresponding info in inode so that everything is in
|
/* Update corresponding info in inode so that everything is in
|
||||||
@@ -5356,7 +5355,6 @@ int ext4_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
|
|||||||
error = ext4_mark_inode_dirty(handle, inode);
|
error = ext4_mark_inode_dirty(handle, inode);
|
||||||
ext4_journal_stop(handle);
|
ext4_journal_stop(handle);
|
||||||
if (unlikely(error)) {
|
if (unlikely(error)) {
|
||||||
ext4_fc_stop_update(inode);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5370,12 +5368,10 @@ int ext4_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
|
|||||||
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
|
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
|
||||||
|
|
||||||
if (attr->ia_size > sbi->s_bitmap_maxbytes) {
|
if (attr->ia_size > sbi->s_bitmap_maxbytes) {
|
||||||
ext4_fc_stop_update(inode);
|
|
||||||
return -EFBIG;
|
return -EFBIG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!S_ISREG(inode->i_mode)) {
|
if (!S_ISREG(inode->i_mode)) {
|
||||||
ext4_fc_stop_update(inode);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5499,7 +5495,6 @@ err_out:
|
|||||||
ext4_std_error(inode->i_sb, error);
|
ext4_std_error(inode->i_sb, error);
|
||||||
if (!error)
|
if (!error)
|
||||||
error = rc;
|
error = rc;
|
||||||
ext4_fc_stop_update(inode);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -743,7 +743,6 @@ int ext4_fileattr_set(struct user_namespace *mnt_userns,
|
|||||||
u32 flags = fa->flags;
|
u32 flags = fa->flags;
|
||||||
int err = -EOPNOTSUPP;
|
int err = -EOPNOTSUPP;
|
||||||
|
|
||||||
ext4_fc_start_update(inode);
|
|
||||||
if (flags & ~EXT4_FL_USER_VISIBLE)
|
if (flags & ~EXT4_FL_USER_VISIBLE)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
@@ -764,7 +763,6 @@ int ext4_fileattr_set(struct user_namespace *mnt_userns,
|
|||||||
goto out;
|
goto out;
|
||||||
err = ext4_ioctl_setproject(inode, fa->fsx_projid);
|
err = ext4_ioctl_setproject(inode, fa->fsx_projid);
|
||||||
out:
|
out:
|
||||||
ext4_fc_stop_update(inode);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1273,13 +1271,7 @@ resizefs_out:
|
|||||||
|
|
||||||
long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
long ret;
|
return __ext4_ioctl(filp, cmd, arg);
|
||||||
|
|
||||||
ext4_fc_start_update(file_inode(filp));
|
|
||||||
ret = __ext4_ioctl(filp, cmd, arg);
|
|
||||||
ext4_fc_stop_update(file_inode(filp));
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_COMPAT
|
#ifdef CONFIG_COMPAT
|
||||||
|
@@ -757,6 +757,7 @@ int jbd2_fc_begin_commit(journal_t *journal, tid_t tid)
|
|||||||
}
|
}
|
||||||
journal->j_flags |= JBD2_FAST_COMMIT_ONGOING;
|
journal->j_flags |= JBD2_FAST_COMMIT_ONGOING;
|
||||||
write_unlock(&journal->j_state_lock);
|
write_unlock(&journal->j_state_lock);
|
||||||
|
jbd2_journal_lock_updates(journal);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -768,6 +769,7 @@ EXPORT_SYMBOL(jbd2_fc_begin_commit);
|
|||||||
*/
|
*/
|
||||||
static int __jbd2_fc_end_commit(journal_t *journal, tid_t tid, bool fallback)
|
static int __jbd2_fc_end_commit(journal_t *journal, tid_t tid, bool fallback)
|
||||||
{
|
{
|
||||||
|
jbd2_journal_unlock_updates(journal);
|
||||||
if (journal->j_fc_cleanup_callback)
|
if (journal->j_fc_cleanup_callback)
|
||||||
journal->j_fc_cleanup_callback(journal, 0);
|
journal->j_fc_cleanup_callback(journal, 0);
|
||||||
write_lock(&journal->j_state_lock);
|
write_lock(&journal->j_state_lock);
|
||||||
|
Reference in New Issue
Block a user