linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: 胡玮文 <sehuww@mail.scut.edu.cn>
To: Gao Xiang <hsiangkao@redhat.com>
Cc: linux-erofs@lists.ozlabs.org
Subject: Re: [PATCH] erofs-utils: fuse: fix random readlink error
Date: Sat, 23 Jan 2021 21:18:30 +0800	[thread overview]
Message-ID: <20210123131830.GA16490@DESKTOP-N4CECTO.huww98.cn> (raw)
In-Reply-To: <20210122014901.GB2918836@xiangao.remote.csb>

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 <hsiangkao@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.GC6680@DESKTOP-N4CECTO.huww98.cn/
> > >> Signed-off-by: Hu Weiwen <sehuww@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;

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?

> > So that we can distinguish EOF and hole in the middle, and return the bytes read.
> > Or we just abandon the sparse file support, and use EROFS_MAP_MAPPED to indicate
> > EOF exclusively. Since erofs current does not actually support this, right?
> 
> Actually, Pratik was working on it months ago, if you have some interest
> of uncompressed sparse files (since for compressed files, 0-ed data would
> be highly compressed by fixed-sized output compression.), could you pick
> his feature up if possible? That would be of great help to EROFS as long
> as you have some interest and extra time... :)
> 
> https://lore.kernel.org/r/20200102094732.31567-1-pratikshinde320@gmail.com/
> 
> Thanks,
> Gao Xiang
> 
> > 
> > > Thanks,
> > > Gao Xiang
> > > 
> > >>    ret = erofs_pread(&vi, buffer, size, offset);
> > >>    if (ret)
> > >>        return ret;
> > >> @@ -79,10 +85,16 @@ static int erofsfuse_read(const char *path, char *buffer,
> > >> 
> > >> static int erofsfuse_readlink(const char *path, char *buffer, size_t size)
> > >> {
> > >> -    int ret = erofsfuse_read(path, buffer, size, 0, NULL);
> > >> +    int ret;
> > >> +    size_t path_len;
> > >> +
> > >> +    erofs_dbg("path:%s size=%zd", path, size);
> > >> +    ret = erofsfuse_read(path, buffer, size, 0, NULL);
> > >> 
> > >>    if (ret < 0)
> > >>        return ret;
> > >> +    path_len = min(size - 1, (size_t)ret);
> > >> +    buffer[path_len] = '\0';
> > >>    return 0;
> > >> }
> > >> 
> > >> -- 
> > >> 2.30.0
> > >> 
> > 


  reply	other threads:[~2021-01-23 13:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 10:12 fuse returns ENOENT to openat() for symlink probabilistically 胡玮文
2021-01-21 11:27 ` Gao Xiang
2021-01-21 16:31   ` [PATCH] erofs-utils: fuse: fix random readlink error Hu Weiwen
2021-01-22  0:34     ` Gao Xiang
2021-01-22  1:00       ` 胡玮文
2021-01-22  1:49         ` Gao Xiang
2021-01-23 13:18           ` 胡玮文 [this message]
2021-01-23 15:22             ` Gao Xiang
2021-01-23 15:36               ` Gao Xiang
2021-01-29 18:07               ` [PATCH v2] " Hu Weiwen
2021-02-09 19:38                 ` Gao Xiang via Linux-erofs
2021-02-13 14:36                   ` [PATCH v3] " 胡玮文
2021-02-28 13:30                   ` [PATCH v2] " Li GuiFu via Linux-erofs
2021-02-28 13:53                   ` [PATCH v4] " Gao Xiang via Linux-erofs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210123131830.GA16490@DESKTOP-N4CECTO.huww98.cn \
    --to=sehuww@mail.scut.edu.cn \
    --cc=hsiangkao@redhat.com \
    --cc=linux-erofs@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).