Message ID | 2f474ee209a89b42c2471aab71a0df038f7e8d4c.1629969541.git.anand.jain@oracle.com |
---|---|
State | New |
Headers | show |
Series | [stable-5.4.y] btrfs: fix race between marking inode needs to be logged and log syncing | expand |
On Sat, Aug 28, 2021 at 06:37:28AM +0800, Anand Jain wrote: > From: Filipe Manana <fdmanana@suse.com> > > commit bc0939fcfab0d7efb2ed12896b1af3d819954a14 upstream. 5.10 also needs this, can you provide a working backport for that as well so that no one would get a regression if they moved to a newer kernel release? Then we could take this patch. thanks, greg k-h
On 29/08/2021 14:55, Greg KH wrote: > On Sat, Aug 28, 2021 at 06:37:28AM +0800, Anand Jain wrote: >> From: Filipe Manana <fdmanana@suse.com> >> >> commit bc0939fcfab0d7efb2ed12896b1af3d819954a14 upstream. > > 5.10 also needs this, can you provide a working backport for that as > well so that no one would get a regression if they moved to a newer > kernel release? Then we could take this patch. Ok, will do. Why are we keen on stable-5.10.y only, while there are other stable releases in between? I just found that this patch applies conflict-free for the stable-5.4.y to stable-5.8.y, you may consider integrating. I will send a separate backport for stable-5.10.y. Thanks, Anand > > thanks, > > greg k-h >
On Mon, Aug 30, 2021 at 05:28:57AM +0800, Anand Jain wrote: > On 29/08/2021 14:55, Greg KH wrote: > > On Sat, Aug 28, 2021 at 06:37:28AM +0800, Anand Jain wrote: > > > From: Filipe Manana <fdmanana@suse.com> > > > > > > commit bc0939fcfab0d7efb2ed12896b1af3d819954a14 upstream. > > > > 5.10 also needs this, can you provide a working backport for that as > > well so that no one would get a regression if they moved to a newer > > kernel release? Then we could take this patch. > > Ok, will do. Why are we keen on stable-5.10.y only, while there are > other stable releases in between? There are no other stable releases in between that are currently supported. Please see the front page of www.kernel.org for the active list. thanks, greg k-h
On 30/08/2021 13:55, Greg KH wrote: > On Mon, Aug 30, 2021 at 05:28:57AM +0800, Anand Jain wrote: >> On 29/08/2021 14:55, Greg KH wrote: >>> On Sat, Aug 28, 2021 at 06:37:28AM +0800, Anand Jain wrote: >>>> From: Filipe Manana <fdmanana@suse.com> >>>> >>>> commit bc0939fcfab0d7efb2ed12896b1af3d819954a14 upstream. >>> >>> 5.10 also needs this, can you provide a working backport for that as >>> well so that no one would get a regression if they moved to a newer >>> kernel release? Then we could take this patch. >> >> Ok, will do. Why are we keen on stable-5.10.y only, while there are >> other stable releases in between? > > There are no other stable releases in between that are currently > supported. Please see the front page of www.kernel.org for the active > list. Ah. Thx. I was confused by the stable-5.x.y branches in the repo. -Anand
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index f853835c409c..f3ff57b93158 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -268,6 +268,21 @@ static inline void btrfs_mod_outstanding_extents(struct btrfs_inode *inode, mod); } +/* + * Called every time after doing a buffered, direct IO or memory mapped write. + * + * This is to ensure that if we write to a file that was previously fsynced in + * the current transaction, then try to fsync it again in the same transaction, + * we will know that there were changes in the file and that it needs to be + * logged. + */ +static inline void btrfs_set_inode_last_sub_trans(struct btrfs_inode *inode) +{ + spin_lock(&inode->lock); + inode->last_sub_trans = inode->root->log_transid; + spin_unlock(&inode->lock); +} + static inline int btrfs_inode_in_log(struct btrfs_inode *inode, u64 generation) { int ret = 0; diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 400b0717b9d4..1279359ed172 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2004,14 +2004,8 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb, inode_unlock(inode); - /* - * We also have to set last_sub_trans to the current log transid, - * otherwise subsequent syncs to a file that's been synced in this - * transaction will appear to have already occurred. - */ - spin_lock(&BTRFS_I(inode)->lock); - BTRFS_I(inode)->last_sub_trans = root->log_transid; - spin_unlock(&BTRFS_I(inode)->lock); + btrfs_set_inode_last_sub_trans(BTRFS_I(inode)); + if (num_written > 0) num_written = generic_write_sync(iocb, num_written); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b044b1d910de..1117335374ff 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -9250,9 +9250,7 @@ vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf) set_page_dirty(page); SetPageUptodate(page); - BTRFS_I(inode)->last_trans = fs_info->generation; - BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; - BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->root->last_log_commit; + btrfs_set_inode_last_sub_trans(BTRFS_I(inode)); unlock_extent_cached(io_tree, page_start, page_end, &cached_state); diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h index d8a7d460e436..cbede328bda5 100644 --- a/fs/btrfs/transaction.h +++ b/fs/btrfs/transaction.h @@ -160,7 +160,7 @@ static inline void btrfs_set_inode_last_trans(struct btrfs_trans_handle *trans, spin_lock(&BTRFS_I(inode)->lock); BTRFS_I(inode)->last_trans = trans->transaction->transid; BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; - BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->root->last_log_commit; + BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->last_sub_trans - 1; spin_unlock(&BTRFS_I(inode)->lock); }