linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Vivek Goyal <vgoyal@redhat.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
	yangerkun <yangerkun@huawei.com>,
	overlayfs <linux-unionfs@vger.kernel.org>
Subject: Re: [PATCH] ovl: fix some bug exist in ovl_get_inode
Date: Fri, 29 May 2020 18:46:43 +0300	[thread overview]
Message-ID: <CAOQ4uxhie2s+yvF1jpPnh6-+a-r8kz589Y5znAX_jmeWqo+SCQ@mail.gmail.com> (raw)
In-Reply-To: <20200529141623.GA196987@redhat.com>

> > > @@ -1023,7 +1020,7 @@ struct dentry *ovl_lookup(struct inode *
> > >          *
> > >          * Always lookup index of non-dir non-metacopy and non-upper.
> > >          */
> > > -       if (ctr && (!upperdentry || (!d.is_dir && !metacopy)))
> > > +       if (ctr && (!upperdentry || (!d.is_dir && !uppermetacopy)))
> > >                 origin = stack[0].dentry;
> > >
> >
> > I think this should be:
> >
> >           * Always lookup index of non-dir and non-upper.
> >           */
> >           if (!origin && ctr && (!upperdentry || !d.is_dir))
> >                  origin = stack[0].dentry;
> >
> > uppermetacopy is guaranteed to either have origin already set or
> > exit with an an error for ovl_verify_origin().
>
> Only if index is enabled and upper had origin xattr.
>
> (!d.is_dir && ofs->config.index && origin_path)
>
> So if index is disabled or uppermetacopy did not have "origin" xattr,
> we will not have origin set by the time we come out of the loop.
>

True. But if index is disabled, setting origin is moot. origin is only
ever used here to lookup the index.

About "origin" xattr. If it is not set in upper that lower fs probably does
not have file handle support. In that case, index cannot be enabled
anyway.

> I see for non-metacopy regular files, if upper did not have origin
> xattr, that means origin_path will by NULL. That means ctr will be
> 0 and that means we will not set "origin" for non-metacopy regular
> files in such case. So question is, should we set "origin" for
> metacopy upper files in such a case.
>
> We did not have origin xattr, but we looked up lower layers for
> upper metacopy. In theory, stack[0].dentry is origin for upper
> metacopy files. Should we use it? Current logic does not and that's
> why this additiona check (!d.is_dir && !uppermetacopy).
>

I agree with your analysis, but this is a very theoretical discussion.
Unless I am missing something, I think we have written a very complex
condition for a corner case that doesn't seem to be valid or interesting.

Basically, for non-dir, if there is no "origin" xattr, then there should be no
index, because the metacopy feature was added way long after we
started storing "origin" on copy up. That's not the case for directories.

There is one corner case where it may be relevant -
overlay layers with metacopy that were created on fs with no file handle
support (or no uuid) that are migrated to a filesystem with file handle
support (and metacopy xattr are preserved in migration).
In that case, index may be enabled while upper metacopy exists
without "origin".

What happens if we do not set origin and do not lookup index in that case?
We can get two overlay inodes, both from different metacopy upper inodes
redirected to the same lower inode, that have the same st_ino, but differnt
metadata.

I suppose we should have a protection in place for not making broken
upper hardlinks that are metacopy, but I don't see it...

> >
> > HOWEVER, if we set origin to lower, which turns out to be a lower
> > metacopy, we then skip this layer to the next one, but origin remains
> > set on the skipped layer dentry, which we had already dput().
> > Ay ay ay!
>
> We only skip the intermediate metacopy entries in lower. So top most
> lower metacopy will still be retained. For example, if there are 3
> lower layers where top two are metacopy and one data, then we will
> only skip middle one. And middle one should not be origin for upper.
>
>                 /*
>                  * Do not store intermediate metacopy dentries in chain,
>                  * except top most lower metacopy dentry
>                  */
>                 if (d.metacopy && ctr) {
>                         dput(this);
>                         continue;
>                 }
>
> For the first lower, ctr will be 0 and we will always store it in
> stack. So if it is metacopy dentry, it will still be stored at
> stack[0].
>
> Do you still see the problem?

No. it's fine. My eyes missed the ctr condition.
I still think since you are changing this code.
It will be much easier to follow if both simple continue statement
are at the top of the loop.

Thanks,
Amir.

  reply	other threads:[~2020-05-29 15:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-27  4:17 [PATCH] ovl: fix some bug exist in ovl_get_inode yangerkun
2020-05-27 11:16 ` Amir Goldstein
2020-05-27 14:46   ` Miklos Szeredi
2020-05-27 15:56     ` Amir Goldstein
2020-05-27 16:02     ` Vivek Goyal
2020-05-27 17:11       ` Amir Goldstein
2020-05-27 18:47   ` Vivek Goyal
2020-05-27 18:57   ` Vivek Goyal
2020-05-27 19:49   ` Vivek Goyal
2020-05-27 20:11     ` Amir Goldstein
2020-05-28 17:35       ` Vivek Goyal
2020-05-28 21:07         ` Amir Goldstein
2020-05-29 14:16           ` Vivek Goyal
2020-05-29 15:46             ` Amir Goldstein [this message]
2020-05-29 19:00               ` Vivek Goyal
2020-05-30 11:35                 ` Amir Goldstein
2020-06-02 15:57                   ` 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=CAOQ4uxhie2s+yvF1jpPnh6-+a-r8kz589Y5znAX_jmeWqo+SCQ@mail.gmail.com \
    --to=amir73il@gmail.com \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=vgoyal@redhat.com \
    --cc=yangerkun@huawei.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).