linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: fix fast commit may miss tracking range for FALLOC_FL_ZERO_RANGE
@ 2021-12-01  9:52 Xin Yin
  2021-12-17 20:43 ` Harshad Shirwadkar
  0 siblings, 1 reply; 3+ messages in thread
From: Xin Yin @ 2021-12-01  9:52 UTC (permalink / raw)
  To: harshadshirwadkar, tytso, adilger.kernel
  Cc: linux-ext4, linux-kernel, Xin Yin

when call falloc with FALLOC_FL_ZERO_RANGE, to set an range to unwritten,
which has been already initialized. If the range is align to blocksize,
fast commit will not track range for this change.

change to track range during allocating blocks.

Signed-off-by: Xin Yin <yinxin.x@bytedance.com>
---
 fs/ext4/extents.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 9229ab1f99c5..4108896d471b 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4433,6 +4433,8 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
 			ret2 = ext4_journal_stop(handle);
 			break;
 		}
+		ext4_fc_track_range(handle, inode, map.m_lblk,
+					map.m_lblk + map.m_len - 1);
 		map.m_lblk += ret;
 		map.m_len = len = len - ret;
 		epos = (loff_t)map.m_lblk << inode->i_blkbits;
@@ -4599,8 +4601,6 @@ static long ext4_zero_range(struct file *file, loff_t offset,
 	ret = ext4_mark_inode_dirty(handle, inode);
 	if (unlikely(ret))
 		goto out_handle;
-	ext4_fc_track_range(handle, inode, offset >> inode->i_sb->s_blocksize_bits,
-			(offset + len - 1) >> inode->i_sb->s_blocksize_bits);
 	/* Zero out partial block at the edges of the range */
 	ret = ext4_zero_partial_blocks(handle, inode, offset, len);
 	if (ret >= 0)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ext4: fix fast commit may miss tracking range for FALLOC_FL_ZERO_RANGE
  2021-12-01  9:52 [PATCH] ext4: fix fast commit may miss tracking range for FALLOC_FL_ZERO_RANGE Xin Yin
@ 2021-12-17 20:43 ` Harshad Shirwadkar
  2021-12-19  4:45   ` [External] " Xin Yin
  0 siblings, 1 reply; 3+ messages in thread
From: Harshad Shirwadkar @ 2021-12-17 20:43 UTC (permalink / raw)
  To: yinxin.x; +Cc: adilger.kernel, harshadshirwadkar, linux-ext4, linux-kernel

> fs/ext4/extents.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
>index 9229ab1f99c5..4108896d471b 100644
>--- a/fs/ext4/extents.c
>+++ b/fs/ext4/extents.c
>@@ -4433,6 +4433,8 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
> 			ret2 = ext4_journal_stop(handle);
> 			break;
> 		}
>+		ext4_fc_track_range(handle, inode, map.m_lblk,
>+					map.m_lblk + map.m_len - 1);

ext4_alloc_file_blocks() calls ext4_map_blocks(), inside which we do
call ext4_fc_track_range(). However, we are doing that only if
map.m_flags & EXT4_MAP_MAPPED is true. So, unwritten flag is set we
are not calling track_range there. Perhaps the right fix is to call
ext4_fc_track_range() from ext4_map_blocks() if MAPPED or UNWRITTEN
flag is set?

> 		map.m_lblk += ret;
> 		map.m_len = len = len - ret;
> 		epos = (loff_t)map.m_lblk << inode->i_blkbits;
>@@ -4599,8 +4601,6 @@ static long ext4_zero_range(struct file *file, loff_t offset,
> 	ret = ext4_mark_inode_dirty(handle, inode);
> 	if (unlikely(ret))
> 		goto out_handle;
>-	ext4_fc_track_range(handle, inode, offset >> inode->i_sb->s_blocksize_bits,
>-			(offset + len - 1) >> inode->i_sb->s_blocksize_bits);
> 	/* Zero out partial block at the edges of the range */
> 	ret = ext4_zero_partial_blocks(handle, inode, offset, len);
> 	if (ret >= 0)
>-- 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [External] Re: [PATCH] ext4: fix fast commit may miss tracking range for FALLOC_FL_ZERO_RANGE
  2021-12-17 20:43 ` Harshad Shirwadkar
@ 2021-12-19  4:45   ` Xin Yin
  0 siblings, 0 replies; 3+ messages in thread
From: Xin Yin @ 2021-12-19  4:45 UTC (permalink / raw)
  To: Harshad Shirwadkar; +Cc: adilger.kernel, linux-ext4, linux-kernel

On Sat, Dec 18, 2021 at 4:43 AM Harshad Shirwadkar
<harshadshirwadkar@gmail.com> wrote:
>
> > fs/ext4/extents.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> >diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> >index 9229ab1f99c5..4108896d471b 100644
> >--- a/fs/ext4/extents.c
> >+++ b/fs/ext4/extents.c
> >@@ -4433,6 +4433,8 @@ static int ext4_alloc_file_blocks(struct file *file, ext4_lblk_t offset,
> >                       ret2 = ext4_journal_stop(handle);
> >                       break;
> >               }
> >+              ext4_fc_track_range(handle, inode, map.m_lblk,
> >+                                      map.m_lblk + map.m_len - 1);
>
> ext4_alloc_file_blocks() calls ext4_map_blocks(), inside which we do
> call ext4_fc_track_range(). However, we are doing that only if
> map.m_flags & EXT4_MAP_MAPPED is true. So, unwritten flag is set we
> are not calling track_range there. Perhaps the right fix is to call
> ext4_fc_track_range() from ext4_map_blocks() if MAPPED or UNWRITTEN
> flag is set?

Thanks, you are right, this should be better. I will test this way and
resend a v2 patch for this issue.

>
> >               map.m_lblk += ret;
> >               map.m_len = len = len - ret;
> >               epos = (loff_t)map.m_lblk << inode->i_blkbits;
> >@@ -4599,8 +4601,6 @@ static long ext4_zero_range(struct file *file, loff_t offset,
> >       ret = ext4_mark_inode_dirty(handle, inode);
> >       if (unlikely(ret))
> >               goto out_handle;
> >-      ext4_fc_track_range(handle, inode, offset >> inode->i_sb->s_blocksize_bits,
> >-                      (offset + len - 1) >> inode->i_sb->s_blocksize_bits);
> >       /* Zero out partial block at the edges of the range */
> >       ret = ext4_zero_partial_blocks(handle, inode, offset, len);
> >       if (ret >= 0)
> >--

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-19  4:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01  9:52 [PATCH] ext4: fix fast commit may miss tracking range for FALLOC_FL_ZERO_RANGE Xin Yin
2021-12-17 20:43 ` Harshad Shirwadkar
2021-12-19  4:45   ` [External] " Xin Yin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).