On Sat, Jan 23, 2021 at 11:22:13PM +0800, Gao Xiang wrote:
> On Sat, Jan 23, 2021 at 09:18:30PM +0800, 胡玮文 wrote:
> > On Fri, Jan 22, 2021 at 09:49:01AM +0800, Gao Xiang wrote:
> > > Hi Weiwen,
> > > 
> > > On Fri, Jan 22, 2021 at 09:00:44AM +0800, 胡玮文 wrote:
> > > > Hi Xiang,
> > > > 
> > > > > 在 2021年1月22日,08:34,Gao Xiang <hsiang...@redhat.com> 写道:
> > > > > 
> > > > > Hi Weiwen,
> > > > > 
> > > > >> On Fri, Jan 22, 2021 at 12:31:43AM +0800, Hu Weiwen wrote:
> > > > >> readlink should fill a **null terminated** string in buffer.
> > > > >> 
> > > > >> Also, read should return number of bytes remaining on EOF.
> > > > >> 
> > > > >> Link: 
> > > > >> https://lore.kernel.org/linux-erofs/20210121101233.gc6...@desktop-n4cecto.huww98.cn/
> > > > >> Signed-off-by: Hu Weiwen <seh...@mail.scut.edu.cn>
> > > > > 
> > > > > Thanks for catching this!
> > > > > 
> > > > >> ---
> > > > >> fuse/main.c | 14 +++++++++++++-
> > > > >> 1 file changed, 13 insertions(+), 1 deletion(-)
> > > > >> 
> > > > >> diff --git a/fuse/main.c b/fuse/main.c
> > > > >> index c162912..bc1e496 100644
> > > > >> --- a/fuse/main.c
> > > > >> +++ b/fuse/main.c
> > > > >> @@ -71,6 +71,12 @@ static int erofsfuse_read(const char *path, char 
> > > > >> *buffer,
> > > > >>    if (ret)
> > > > >>        return ret;
> > > > >> 
> > > > >> +    if (offset >= vi.i_size)
> > > > >> +        return 0;
> > > > >> +
> > > > >> +    if (offset + size > vi.i_size)
> > > > >> +        size = vi.i_size - offset;
> > > > >> +
> > > > > 
> > > > > It would be better to call erofs_pread() with the original offset
> > > > > and size (also I think there is some missing memset(0) for
> > > > > !EROFS_MAP_MAPPED), and fix up the return value to the needed value.
> > > > 
> > > > Yes, that is what I have initially tried. But this way is harder than I 
> > > > thought. 
> > > > EROFS_MAP_MAPPED flag seems to be designed to handle sparse file, and 
> > > > is reused to
> > > > represent EOF. So maybe we need a new flag to represent EOF? 
> > > 
> > > Nope, I think we just need to handle return value of read, I mean
> > > 
> > > erofs_ilookup()
> > > 
> > > ret = erofs_pread()
> > > if (ret)
> > >   return ret;
> > > 
> > > if (offset + size > vi.i_size)
> > >   return vi.i_size - offset;
> > > 
> > > return size;
> > > 
> > > Is that enough? Am I missing something?
> > 
> > This should work, except we should also add this branch
> > 
> > if (offset >= vi.i_size)
> >     return 0;
> 
> yeah, agreed. It'd also be added after erofs_pread().
> 
> >
> > But how this is better than my original patch? I would say my patch should 
> > be
> > more efficient.
> > 
> > By saying "what I have initially tried" in my last mail, I mean changing
> > erofs_pread() to return the number of bytes read (just like pread system 
> > call,
> > instead of always 0). I think this is easier to understand for others, but
> > seems harder to implement. Do you think this is worthful?
> > 
> 
> There are 2 reasons for me to do it at least:
> 1) need to memset(0) for these unmapped buffers;
> 2) introduce a hook to fs to read data regardless of i_size,
>    just as linux kernel page cache approach.
> 
> Don't be confused with ->i_size (this is only a EOF-marker) and
> the real inode data, that are two different concepts for me, I'd
> like to handle all data processing in erofs_pread() (even for
> post-EOF case), but only deal with i_size in erofsfuse_read().
> 

Also, no need to follow erofs_pread() as the pread() system call.
It just used a similiar name. The core concept of this is to handle
file data itself. There is nothing to do with eof-marker (but much
related to inode extent/block mapping instead, although currently
EROFS extent mapping format internally relies on i_size.)

Thanks,
Gao Xiang

> Thanks,
> Gao Xiang
> 

Reply via email to