diff mbox series

[2/7] xfs: add nowait support for xfs_seek_iomap_begin()

Message ID 20230726102603.155522-3-hao.xu@linux.dev (mailing list archive)
State New
Headers show
Series io_uring lseek | expand

Commit Message

Hao Xu July 26, 2023, 10:25 a.m. UTC
From: Hao Xu <howeyxu@tencent.com>

To support nowait llseek(), IOMAP_NOWAIT semantics should be respected.
In xfs, xfs_seek_iomap_begin() is the only place which may be blocked
by ilock and extent loading. Let's turn it into trylock logic just like
what we've done in xfs_readdir().

Signed-off-by: Hao Xu <howeyxu@tencent.com>
---
 fs/xfs/xfs_iomap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Dave Chinner July 26, 2023, 9:55 p.m. UTC | #1
On Wed, Jul 26, 2023 at 06:25:58PM +0800, Hao Xu wrote:
> From: Hao Xu <howeyxu@tencent.com>
> 
> To support nowait llseek(), IOMAP_NOWAIT semantics should be respected.
> In xfs, xfs_seek_iomap_begin() is the only place which may be blocked
> by ilock and extent loading. Let's turn it into trylock logic just like
> what we've done in xfs_readdir().
> 
> Signed-off-by: Hao Xu <howeyxu@tencent.com>
> ---
>  fs/xfs/xfs_iomap.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
> index 18c8f168b153..bbd7c6b27701 100644
> --- a/fs/xfs/xfs_iomap.c
> +++ b/fs/xfs/xfs_iomap.c
> @@ -1294,7 +1294,9 @@ xfs_seek_iomap_begin(
>  	if (xfs_is_shutdown(mp))
>  		return -EIO;
>  
> -	lockmode = xfs_ilock_data_map_shared(ip);
> +	lockmode = xfs_ilock_data_map_shared_generic(ip, flags & IOMAP_NOWAIT);

What does this magic XFS function I can't find anywhere in this
patch set do?

-Dave.
Darrick J. Wong July 26, 2023, 10:14 p.m. UTC | #2
On Thu, Jul 27, 2023 at 07:55:47AM +1000, Dave Chinner wrote:
> On Wed, Jul 26, 2023 at 06:25:58PM +0800, Hao Xu wrote:
> > From: Hao Xu <howeyxu@tencent.com>
> > 
> > To support nowait llseek(), IOMAP_NOWAIT semantics should be respected.
> > In xfs, xfs_seek_iomap_begin() is the only place which may be blocked
> > by ilock and extent loading. Let's turn it into trylock logic just like
> > what we've done in xfs_readdir().
> > 
> > Signed-off-by: Hao Xu <howeyxu@tencent.com>
> > ---
> >  fs/xfs/xfs_iomap.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
> > index 18c8f168b153..bbd7c6b27701 100644
> > --- a/fs/xfs/xfs_iomap.c
> > +++ b/fs/xfs/xfs_iomap.c
> > @@ -1294,7 +1294,9 @@ xfs_seek_iomap_begin(
> >  	if (xfs_is_shutdown(mp))
> >  		return -EIO;
> >  
> > -	lockmode = xfs_ilock_data_map_shared(ip);
> > +	lockmode = xfs_ilock_data_map_shared_generic(ip, flags & IOMAP_NOWAIT);
> 
> What does this magic XFS function I can't find anywhere in this
> patch set do?

It's in (iirc) the io_uring getdents patchset that wasn't cc'd to
linux-xfs and that I haven't looked at yet.

--D

> -Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
Hao Xu July 27, 2023, 12:17 p.m. UTC | #3
On 7/27/23 06:14, Darrick J. Wong wrote:
> On Thu, Jul 27, 2023 at 07:55:47AM +1000, Dave Chinner wrote:
>> On Wed, Jul 26, 2023 at 06:25:58PM +0800, Hao Xu wrote:
>>> From: Hao Xu <howeyxu@tencent.com>
>>>
>>> To support nowait llseek(), IOMAP_NOWAIT semantics should be respected.
>>> In xfs, xfs_seek_iomap_begin() is the only place which may be blocked
>>> by ilock and extent loading. Let's turn it into trylock logic just like
>>> what we've done in xfs_readdir().
>>>
>>> Signed-off-by: Hao Xu <howeyxu@tencent.com>
>>> ---
>>>   fs/xfs/xfs_iomap.c | 4 +++-
>>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
>>> index 18c8f168b153..bbd7c6b27701 100644
>>> --- a/fs/xfs/xfs_iomap.c
>>> +++ b/fs/xfs/xfs_iomap.c
>>> @@ -1294,7 +1294,9 @@ xfs_seek_iomap_begin(
>>>   	if (xfs_is_shutdown(mp))
>>>   		return -EIO;
>>>   
>>> -	lockmode = xfs_ilock_data_map_shared(ip);
>>> +	lockmode = xfs_ilock_data_map_shared_generic(ip, flags & IOMAP_NOWAIT);
>>
>> What does this magic XFS function I can't find anywhere in this
>> patch set do?

Sorry, forgot to say, It was xfs_ilock_for_readdir() in io_uring
getdents patchset, I changed the name since it is now used for
lseek as well.

> 
> It's in (iirc) the io_uring getdents patchset that wasn't cc'd to
> linux-xfs and that I haven't looked at yet.
> 

Hi Darrick, I forwarded the xfs related patch in that series. Forgot to
cc xfs list at the beginning. I'll make xfs list be Cc-ed when sending
next version. Sorry for inconvenience.

Regards,
Hao

> --D
> 
>> -Dave.
>> -- 
>> Dave Chinner
>> david@fromorbit.com
diff mbox series

Patch

diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 18c8f168b153..bbd7c6b27701 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -1294,7 +1294,9 @@  xfs_seek_iomap_begin(
 	if (xfs_is_shutdown(mp))
 		return -EIO;
 
-	lockmode = xfs_ilock_data_map_shared(ip);
+	lockmode = xfs_ilock_data_map_shared_generic(ip, flags & IOMAP_NOWAIT);
+	if (!lockmode)
+		return -EAGAIN;
 	error = xfs_iread_extents(NULL, ip, XFS_DATA_FORK);
 	if (error)
 		goto out_unlock;