ceph-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Dryomov <idryomov@gmail.com>
To: Jeff Layton <jlayton@kernel.org>
Cc: Ceph Development <ceph-devel@vger.kernel.org>
Subject: Re: [PATCH] ceph: fix error handling in ceph_atomic_open and ceph_lookup
Date: Mon, 21 Jun 2021 21:20:09 +0200	[thread overview]
Message-ID: <CAOi1vP8vcs8da2+fUUuo25S0M0bdVKqp_qxDyTRaAAYDMnvJGA@mail.gmail.com> (raw)
In-Reply-To: <20210603123850.74421-1-jlayton@kernel.org>

On Thu, Jun 3, 2021 at 2:38 PM Jeff Layton <jlayton@kernel.org> wrote:
>
> Commit aa60cfc3f7ee broke the error handling in these functions such
> that they don't handle non-ENOENT errors from ceph_mdsc_do_request
> properly.
>
> Move the checking of -ENOENT out of ceph_handle_snapdir and into the
> callers, and if we get a different error, return it immediately.
>
> Fixes: aa60cfc3f7ee ("ceph: don't use d_add in ceph_handle_snapdir")
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
>  fs/ceph/dir.c   | 17 ++++++-----------
>  fs/ceph/file.c  |  6 +++---
>  fs/ceph/super.h |  2 +-
>  3 files changed, 10 insertions(+), 15 deletions(-)
>
> diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
> index 5624fae7a603..ac431246e0c9 100644
> --- a/fs/ceph/dir.c
> +++ b/fs/ceph/dir.c
> @@ -668,14 +668,13 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int whence)
>   * Handle lookups for the hidden .snap directory.
>   */
>  struct dentry *ceph_handle_snapdir(struct ceph_mds_request *req,
> -                                  struct dentry *dentry, int err)
> +                                  struct dentry *dentry)
>  {
>         struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
>         struct inode *parent = d_inode(dentry->d_parent); /* we hold i_mutex */
>
>         /* .snap dir? */
> -       if (err == -ENOENT &&
> -           ceph_snap(parent) == CEPH_NOSNAP &&
> +       if (ceph_snap(parent) == CEPH_NOSNAP &&
>             strcmp(dentry->d_name.name, fsc->mount_options->snapdir_name) == 0) {
>                 struct dentry *res;
>                 struct inode *inode = ceph_get_snapdir(parent);
> @@ -742,7 +741,6 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
>         struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
>         struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(dir->i_sb);
>         struct ceph_mds_request *req;
> -       struct dentry *res;
>         int op;
>         int mask;
>         int err;
> @@ -793,13 +791,10 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
>         req->r_parent = dir;
>         set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
>         err = ceph_mdsc_do_request(mdsc, NULL, req);
> -       res = ceph_handle_snapdir(req, dentry, err);
> -       if (IS_ERR(res)) {
> -               err = PTR_ERR(res);
> -       } else {
> -               dentry = res;
> -               err = 0;
> -       }
> +       if (err == -ENOENT)
> +               dentry = ceph_handle_snapdir(req, dentry);
> +       if (IS_ERR(dentry))
> +               err = PTR_ERR(dentry);
>         dentry = ceph_finish_lookup(req, dentry, err);
>         ceph_mdsc_put_request(req);  /* will dput(dentry) */
>         dout("lookup result=%p\n", dentry);
> diff --git a/fs/ceph/file.c b/fs/ceph/file.c
> index 7aa20d50a231..a01ad342a91d 100644
> --- a/fs/ceph/file.c
> +++ b/fs/ceph/file.c
> @@ -739,14 +739,14 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
>         err = ceph_mdsc_do_request(mdsc,
>                                    (flags & (O_CREAT|O_TRUNC)) ? dir : NULL,
>                                    req);
> -       dentry = ceph_handle_snapdir(req, dentry, err);
> +       if (err == -ENOENT)
> +               dentry = ceph_handle_snapdir(req, dentry);
>         if (IS_ERR(dentry)) {
>                 err = PTR_ERR(dentry);
>                 goto out_req;
>         }

Hi Jeff,

This doesn't seem right to me.  Looking at 5.12, ENOENT from
ceph_mdsc_do_request() could be resolved by ceph_handle_snapdir()
meaning that ceph_handle_notrace_create() could be called and
ceph_finish_lookup() could be passed err == 0.

With this patch err would remain ENOENT, resulting in skipping
the potential ceph_handle_notrace_create() call and passing that
ENOENT to ceph_finish_lookup().

Thanks,

                Ilya

  reply	other threads:[~2021-06-21 19:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03 12:38 [PATCH] ceph: fix error handling in ceph_atomic_open and ceph_lookup Jeff Layton
2021-06-21 19:20 ` Ilya Dryomov [this message]
2021-06-21 23:49   ` Jeff Layton
2021-06-21 23:57 ` [PATCH v2] " Jeff Layton
2021-06-22 12:09   ` Ilya Dryomov
2021-06-22 12:24     ` Jeff Layton

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=CAOi1vP8vcs8da2+fUUuo25S0M0bdVKqp_qxDyTRaAAYDMnvJGA@mail.gmail.com \
    --to=idryomov@gmail.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=jlayton@kernel.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).