public inbox for linux-unionfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: overlayfs <linux-unionfs@vger.kernel.org>,
	Miklos Szeredi <miklos@szeredi.hu>
Subject: Re: [PATCH v13 26/28] ovl: Re-check redirect xattr during inode initialization
Date: Mon, 2 Apr 2018 15:35:18 -0400	[thread overview]
Message-ID: <20180402193518.GF23306@redhat.com> (raw)
In-Reply-To: <CAOQ4uxiXV-tZHU6ZKkHkZ3+bWk90AB2B7f_DcFHYGL9+mqtNpQ@mail.gmail.com>

On Fri, Mar 30, 2018 at 11:56:42AM +0300, Amir Goldstein wrote:
> On Thu, Mar 29, 2018 at 10:38 PM, Vivek Goyal <vgoyal@redhat.com> wrote:
> > So far redirect could be placed on directories only and now it can be
> > placed on regular files as well. Also it could be completely removed
> > when a metacopy copy up file's data is copied up. That means if a redirect
> > is present during ovl_lookup(), it could be gone by the time ovl_get_inode()
> > happens.
> >
> 
> There is a bit of a mess in the assumptions.
> 
> If the inode is pure upper or indexed origin, than the alleged race ends up
> in !(inode->i_state & I_NEW) and you discard redirect anyway.

Can't these also happen when I_NEW=true. I mean inode could be flushed
out of cache. Say one cpu is doing ovl_lookup() and thread got blocked
while other cpu did copy up of file on other cpu, removed redirect and
inode got flushed out of cache. Now cpu1 resumes execuction, creates
a new inode but it needs to re-check if redirect is still present or
not?

> 
> If the inode is non-indexed copyup, then it is a different inode on disk
> and different struct ovl_inode in memory than the inode of the copy up
> we are allegedly racing with (they are broken hardlinks), so there is no
> issue.

Agreed that in case of broken hardlinks this race does not exist. But
do we really want to optimize it here? 

> 
> > Or it is possible that ovl_lookup() does not see a redirect and a rename
> > is taking place on a hard link and that places a redirect. And by the
> > time ovl_lookup() calls ovl_get_inode(), it sets ovl_inode->redirect = NULL
> > (Assume inode got flushed out of cache and was allocated new).
> 
> Same as above.
> 
> I am not saying there are no races between lookup and rename/link,
> but IMO the text above does not describe them or proves that they exist.
> 

I can try to give more details. But I think if inode gets flushed out
of cache, then we need to query redirect info again.

Vivek
> >
> > IOW, because we check and process redirect without locks in ovl_lookup(),
> > many possibilities open up for regular files. So for such cases, do not
> > use the redirect provided by the caller. Instead query it and install
> > in ovl_inode->redirect.
> >
> > Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
> > ---
> >  fs/overlayfs/inode.c     | 19 ++++++++++++++++++-
> >  fs/overlayfs/overlayfs.h |  1 +
> >  fs/overlayfs/util.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 61 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
> > index 3dccfa1ee123..6a0c85699024 100644
> > --- a/fs/overlayfs/inode.c
> > +++ b/fs/overlayfs/inode.c
> > @@ -694,6 +694,7 @@ struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry,
> >         bool bylower = ovl_hash_bylower(sb, upperdentry, lowerdentry, index);
> >         bool is_dir, metacopy = false;
> >         int err = -ENOMEM;
> > +       char *new_redirect = NULL;
> >
> >         if (!realinode)
> >                 realinode = d_inode(lowerdentry);
> > @@ -754,7 +755,18 @@ struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry,
> >         if (upperdentry && !metacopy)
> >                 ovl_set_flag(OVL_UPPERDATA, inode);
> >
> > -       OVL_I(inode)->redirect = redirect;
> > +       if (!metacopy) {
> > +               OVL_I(inode)->redirect = redirect;
> > +               redirect = NULL;
> > +       } else if (upperdentry) {
> > +               new_redirect = ovl_get_redirect_xattr(upperdentry);
> > +               if (IS_ERR(new_redirect)) {
> > +                       err = PTR_ERR(new_redirect);
> > +                       goto out_err_inode;
> > +               }
> > +               OVL_I(inode)->redirect = new_redirect;
> > +               new_redirect = NULL;
> > +       }
> >
> >         /* Check for non-merge dir that may have whiteouts */
> >         if (is_dir) {
> > @@ -764,11 +776,16 @@ struct inode *ovl_get_inode(struct super_block *sb, struct dentry *upperdentry,
> >                 }
> >         }
> >
> > +       kfree(redirect);
> >         if (inode->i_state & I_NEW)
> >                 unlock_new_inode(inode);
> >  out:
> >         return inode;
> >
> > +out_err_inode:
> > +       if (inode->i_state & I_NEW)
> > +               unlock_new_inode(inode);
> > +       iput(inode);
> >  out_err:
> >         inode = ERR_PTR(err);
> >         goto out;
> > diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
> > index 429713653b3b..a3bee7619fbb 100644
> > --- a/fs/overlayfs/overlayfs.h
> > +++ b/fs/overlayfs/overlayfs.h
> > @@ -279,6 +279,7 @@ void ovl_nlink_end_locked(struct dentry *dentry);
> >  int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir);
> >  int ovl_check_metacopy_xattr(struct dentry *dentry);
> >  bool ovl_is_metacopy_dentry(struct dentry *dentry);
> > +char *ovl_get_redirect_xattr(struct dentry *dentry);
> >
> >  static inline bool ovl_is_impuredir(struct dentry *dentry)
> >  {
> > diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
> > index 961d65bd25c9..3d090b6f9fc2 100644
> > --- a/fs/overlayfs/util.c
> > +++ b/fs/overlayfs/util.c
> > @@ -833,3 +833,45 @@ bool ovl_is_metacopy_dentry(struct dentry *dentry)
> >
> >         return (oe->numlower > 1);
> >  }
> > +
> > +char *ovl_get_redirect_xattr(struct dentry *dentry)
> > +{
> > +       int res;
> > +       char *s, *next, *buf = NULL;
> > +
> > +       res = vfs_getxattr(dentry, OVL_XATTR_REDIRECT, NULL, 0);
> > +       if (res < 0) {
> > +               if (res == -ENODATA || res == -EOPNOTSUPP)
> > +                       return NULL;
> > +               return ERR_PTR(res);
> > +       }
> > +
> > +       buf = kzalloc(res + 1, GFP_KERNEL);
> > +       if (!buf)
> > +               return ERR_PTR(-ENOMEM);
> > +
> > +       res = vfs_getxattr(dentry, OVL_XATTR_REDIRECT, buf, res);
> > +       if (res < 0) {
> > +               kfree(buf);
> > +               return ERR_PTR(res);
> > +        }
> > +       if (res == 0)
> > +               goto invalid;
> > +
> > +       if (buf[0] == '/') {
> > +               for (s = buf; *s++ == '/'; s = next) {
> > +                       next = strchrnul(s, '/');
> > +                       if (s == next)
> > +                               goto invalid;
> > +               }
> > +       } else {
> > +               if (strchr(buf, '/') != NULL)
> > +                       goto invalid;
> > +       }
> > +
> > +       return buf;
> > +invalid:
> > +       pr_warn_ratelimited("overlayfs: invalid redirect (%s)\n", buf);
> > +       kfree(buf);
> > +       return ERR_PTR(-EINVAL);
> > +}
> > --
> > 2.13.6
> >
> 
> If you really end up needing this helper, you should use it from lookup as well.
> 
> Thanks,
> Amir.

  reply	other threads:[~2018-04-02 19:35 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-29 19:38 [PATCH v13 00/28] overlayfs: Delayed copy up of data Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 01/28] ovl: Set OVL_INDEX flag in ovl_get_inode() Vivek Goyal
2018-03-30  4:59   ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 02/28] ovl: Initialize ovl_inode->redirect " Vivek Goyal
2018-03-30  4:57   ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 03/28] ovl: Rename local variable locked to new_locked Vivek Goyal
2018-03-30  4:58   ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 04/28] ovl: Provide a mount option metacopy=on/off for metadata copyup Vivek Goyal
2018-03-30  4:52   ` Amir Goldstein
2018-04-02 13:56     ` Vivek Goyal
2018-04-05 20:16       ` Amir Goldstein
2018-04-06 13:51         ` Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 05/28] ovl: During copy up, first copy up metadata and then data Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 06/28] ovl: Move the copy up helpers to copy_up.c Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 07/28] ovl: Copy up only metadata during copy up where it makes sense Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 08/28] ovl: Add helper ovl_already_copied_up() Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 09/28] ovl: A new xattr OVL_XATTR_METACOPY for file on upper Vivek Goyal
2018-04-11 15:10   ` Amir Goldstein
2018-04-11 15:53     ` Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 10/28] ovl: Modify ovl_lookup() and friends to lookup metacopy dentry Vivek Goyal
2018-03-30  5:49   ` Amir Goldstein
2018-03-30  9:12     ` Amir Goldstein
2018-04-02 19:45       ` Vivek Goyal
2018-04-02 20:07         ` Amir Goldstein
2018-04-02 15:06     ` Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 11/28] ovl: Copy up meta inode data from lowest data inode Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 12/28] ovl: Fix ovl_getattr() to get number of blocks from lower Vivek Goyal
2018-03-30  9:24   ` Amir Goldstein
2018-04-02 20:11     ` Vivek Goyal
2018-04-02 20:27       ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 13/28] ovl: Add helper ovl_dentry_lowerdata() to get lower data dentry Vivek Goyal
2018-03-30  6:01   ` Amir Goldstein
2018-04-02 15:08     ` Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 14/28] ovl: Do not expose metacopy only dentry from d_real() Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 15/28] ovl: Move some of ovl_nlink_start() functionality in ovl_nlink_prep() Vivek Goyal
2018-03-30  6:23   ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 16/28] ovl: Create locked version of ovl_nlink_start() and ovl_nlink_end() Vivek Goyal
2018-03-30  6:28   ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 17/28] ovl: During rename lock both source and target ovl_inode Vivek Goyal
2018-03-30  6:50   ` Amir Goldstein
2018-04-02 17:34     ` Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 18/28] ovl: Check redirects for metacopy files Vivek Goyal
2018-03-30 10:02   ` Amir Goldstein
2018-04-02 20:29     ` Vivek Goyal
2018-04-03  5:44       ` Amir Goldstein
2018-04-03 12:31         ` Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 19/28] ovl: Treat metacopy dentries as type OVL_PATH_MERGE Vivek Goyal
2018-03-30  6:52   ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 20/28] ovl: Do not set dentry type ORIGIN for broken hardlinks Vivek Goyal
2018-03-30  9:54   ` Amir Goldstein
2018-04-10 14:00     ` Vivek Goyal
2018-04-10 19:20       ` Amir Goldstein
2018-04-10 19:29         ` Amir Goldstein
2018-04-10 20:59           ` Vivek Goyal
2018-04-10 20:51         ` Vivek Goyal
2018-04-11  8:58           ` Amir Goldstein
2018-04-11 13:31             ` Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 21/28] ovl: Set redirect on metacopy files upon rename Vivek Goyal
2018-03-30  7:31   ` Amir Goldstein
2018-04-11 15:12     ` Vivek Goyal
2018-04-11 17:01       ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 22/28] ovl: Set redirect on upper inode when it is linked Vivek Goyal
2018-03-30  7:04   ` Amir Goldstein
2018-04-11 15:59     ` Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 23/28] ovl: Remove redirect when data of a metacopy file is copied up Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 24/28] ovl: Do not error if REDIRECT XATTR is missing Vivek Goyal
2018-03-30  7:41   ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 25/28] ovl: Use out_err insteada of out_nomem Vivek Goyal
2018-03-30  7:35   ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 26/28] ovl: Re-check redirect xattr during inode initialization Vivek Goyal
2018-03-30  8:56   ` Amir Goldstein
2018-04-02 19:35     ` Vivek Goyal [this message]
2018-04-02 20:25       ` Amir Goldstein
2018-03-29 19:38 ` [PATCH v13 27/28] ovl: Verify a data dentry has been found for metacopy inode Vivek Goyal
2018-03-30 10:53   ` Amir Goldstein
2018-04-02 12:39     ` Vivek Goyal
2018-04-04 12:29     ` Vivek Goyal
2018-04-04 12:51       ` Amir Goldstein
2018-04-04 13:21         ` Vivek Goyal
2018-04-04 15:51           ` Amir Goldstein
2018-04-05 14:37             ` Vivek Goyal
2018-04-05 18:22               ` Vivek Goyal
2018-04-05 19:58                 ` Amir Goldstein
2018-04-05 20:45                   ` Vivek Goyal
2018-04-06  9:46                     ` Amir Goldstein
2018-04-06 15:37                       ` Vivek Goyal
2018-04-06 16:21                         ` Amir Goldstein
2018-04-06 17:32                           ` Vivek Goyal
2018-04-06 20:10                             ` Amir Goldstein
2018-04-09 12:18                               ` Vivek Goyal
2018-03-29 19:38 ` [PATCH v13 28/28] ovl: Enable metadata only feature Vivek Goyal

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=20180402193518.GF23306@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=amir73il@gmail.com \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /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