linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leif Sahlberg <lsahlber@redhat.com>
To: Tom Talpey <tom@talpey.com>
Cc: linux-cifs <linux-cifs@vger.kernel.org>,
	Steve French <smfrench@gmail.com>
Subject: Re: [PATCH] cifs: fix skipping to incorrect offset in emit_cached_dirents
Date: Wed, 12 Oct 2022 11:04:19 +1000	[thread overview]
Message-ID: <CAGvGhF7sSVC=+jzq+LAbVLU0fWyEba=b9x6D-arH2NuXdcWppg@mail.gmail.com> (raw)
In-Reply-To: <bd9a1a65-8565-e5ca-8d48-f7c3430e6e7c@talpey.com>

On Wed, Oct 12, 2022 at 10:49 AM Tom Talpey <tom@talpey.com> wrote:
>
> On 10/11/2022 6:07 PM, Ronnie Sahlberg wrote:
> > When application has done lseek() to a different offset on a directory fd
> > we skipped one entry too many before we start emitting directory entries
> > from the cache.
> >
> > We need to also make sure that when we are starting to emit directory
> > entries from the cache, the ->pos sequence might have holes and skip
> > some indices.
> >
> > Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> > ---
> >   fs/cifs/readdir.c | 29 +++++++++++++++++++++++------
> >   1 file changed, 23 insertions(+), 6 deletions(-)
> >
> > diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
> > index 8e060c00c969..1bb4624e768b 100644
> > --- a/fs/cifs/readdir.c
> > +++ b/fs/cifs/readdir.c
> > @@ -844,17 +844,34 @@ static bool emit_cached_dirents(struct cached_dirents *cde,
> >                               struct dir_context *ctx)
> >   {
> >       struct cached_dirent *dirent;
> > -     int rc;
> > +     bool rc;
> >
> >       list_for_each_entry(dirent, &cde->entries, entry) {
> > -             if (ctx->pos >= dirent->pos)
> > +             /*
> > +              * Skip all early entries prior to the current lseek()
> > +              * position.
> > +              */
> > +             if (ctx->pos > dirent->pos)
> >                       continue;
> > +             /*
> > +              * We recorded the current ->pos value for the dirent
> > +              * when we stored it in the cache.
> > +              * However, this sequence of ->pos values may have holes
> > +              * in it, for example dot-dirs returned from the server
> > +              * are suppressed.
> > +              * Handle this bu forcing ctx->pos to be the same as the
> > +              * ->pos of the current dirent we emit from the cache.
> > +              * This means that when we emit these entries from the cache
> > +              * we now emit them with the same ->pos value as in the
> > +              * initial scan.
> > +              */
>
> It's a little wordy, but it's better, so ok.
>
> >               ctx->pos = dirent->pos;
> >               rc = dir_emit(ctx, dirent->name, dirent->namelen,
> >                             dirent->fattr.cf_uniqueid,
> >                             dirent->fattr.cf_dtype);
> >               if (!rc)
> >                       return rc;
>
> Well, I still think it would be clearer as "return false". And the
> name "rc" really seems odd now for a bool. But again, ok I guess.
>
> Either way, I learned a thing or two chasing down dir_emit() and the
> overall approach seems good.
>
> > +             ctx->pos++;
> >       }
> >       return true;
> >   }
> > @@ -1202,10 +1219,10 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
> >                                ctx->pos, tmp_buf);
> >                       cifs_save_resume_key(current_entry, cifsFile);
> >                       break;
> > -             } else
> > -                     current_entry =
> > -                             nxt_dir_entry(current_entry, end_of_smb,
> > -                                     cifsFile->srch_inf.info_level);
> > +             }
> > +             current_entry =
> > +                     nxt_dir_entry(current_entry, end_of_smb,
> > +                                   cifsFile->srch_inf.info_level);
>
> This change isn't actually changing anything. Would it be
> better to leave out on principle?

I wanted this change since previously it was a little confusing. A
quick glance might raise questions "why only do this conditionally?"
and then when looking more carefully "oh, we actually do this
unconditionally before every new iteration".

It is as you say a no-op change.
It should arguably be done in a separate patch but it is so small I
just took the lazy path and put it in this patch instead of a separate
patch.

Thanks for the review.
>
>
> >       }
> >       kfree(tmp_buf);
> >
> Overall,
>
> Reviewed-by: Tom Talpey <tom@talpey.com>
>


  reply	other threads:[~2022-10-12  1:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-11 22:07 cifs: fix emitting cached direntries Ronnie Sahlberg
2022-10-11 22:07 ` [PATCH] cifs: fix skipping to incorrect offset in emit_cached_dirents Ronnie Sahlberg
2022-10-12  0:49   ` Tom Talpey
2022-10-12  1:04     ` Leif Sahlberg [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-10-11  6:46 cifs: fix skipping to incorrect offset in emit_cached_diretns Ronnie Sahlberg
2022-10-11  6:46 ` [PATCH] cifs: fix skipping to incorrect offset in emit_cached_dirents Ronnie Sahlberg
2022-10-11 16:38   ` Tom Talpey
2022-10-11 21:38     ` Steve French
2022-10-11 21:54     ` ronnie sahlberg
2022-10-10 20:42 cifs: fix bug when skipping one entry too many after lseek() Ronnie Sahlberg
2022-10-10 20:42 ` [PATCH] cifs: fix skipping to incorrect offset in emit_cached_dirents Ronnie Sahlberg
2022-10-06  4:36 cifs: fix failure for generic/257 Ronnie Sahlberg
2022-10-06  4:36 ` [PATCH] cifs: fix skipping to incorrect offset in emit_cached_dirents Ronnie Sahlberg
2022-10-06  5:18   ` Steve French
2022-10-06  5:21   ` Steve French
2022-10-08 15:21   ` Steve French
2022-10-09 17:54   ` Aurélien Aptel
2022-10-10  5:12     ` ronnie sahlberg

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='CAGvGhF7sSVC=+jzq+LAbVLU0fWyEba=b9x6D-arH2NuXdcWppg@mail.gmail.com' \
    --to=lsahlber@redhat.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=smfrench@gmail.com \
    --cc=tom@talpey.com \
    /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).