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 v12 08/17] ovl: Modify ovl_lookup() and friends to lookup metacopy dentry
Date: Thu, 8 Mar 2018 12:03:43 -0500 [thread overview]
Message-ID: <20180308170343.GB2732@redhat.com> (raw)
In-Reply-To: <CAOQ4uxhLXv-iw-JzWury11X2tVn-mX0JEmig2dJZurHMM+CcCQ@mail.gmail.com>
On Thu, Mar 08, 2018 at 10:43:09AM +0200, Amir Goldstein wrote:
> On Wed, Mar 7, 2018 at 10:27 PM, Vivek Goyal <vgoyal@redhat.com> wrote:
> > On Wed, Mar 07, 2018 at 04:42:54PM +0200, Amir Goldstein wrote:
> [...]
>
> >> > static bool ovl_is_opaquedir(struct dentry *dentry)
> >> > {
> >> > return ovl_check_dir_xattr(dentry, OVL_XATTR_OPAQUE);
> >> > @@ -242,9 +265,16 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
> >> > goto put_and_out;
> >> > }
> >> > if (!d_can_lookup(this)) {
> >> > - d->stop = true;
> >> > if (d->is_dir)
> >>
> >> You need to set d->stop here because this is a non-dir below upper dir.
> >
> > With metacopy dentry on regular files, we want to do d->stop=true only
> > if this is not a metacopy. Otherwise we want to continue to do path
> > based lookup in lower layers. That's the whole point of this patch
> > series.
> >
>
> Yes we do, but the point that yo missed about (d->is_dir) check is that it means
> that upper layer was a directory (e.g. upperdir/foo) and underneath it we find
> a non-dir (e.g. lowerdir/foo). This is a case were lookup needs to stop and
> result in a non-merge pure upper dir.
But d->is_dir does not necessarily reflect the state of upper. It
reflects the state of last found dentry. And in case of redirect, last
found dentry can very well be parent of current dentry.
For example, say you have upperdir/foo and it has redirect set to
lowerdir/bar/bar-child.txt. Now, by the time we find bar-child.txt
d->is_dir is always true because it reflects the state of parent "bar"
dentry which is always directory. I mean it does not reflect state
of upperdir/foo. And that state is already lost.
If we really want to make sure that we don't merge upper dir with lower
non-dir, then we need to do this check in ovl_lookup() and not in
ovl_lookup_single(), IMHO.
>
> >>
> >> > goto put_and_out;
> >> > + err = ovl_check_metacopy_xattr(this);
> >> > + if (err < 0)
> >> > + goto out_err;
> >> > + if (!err) {
> >> > + d->stop = true;
> >> > + d->metacopy = false;
> >> > + } else
> >> > + d->metacopy = true;
> >>
> >> Need to have {} in both if and else, but better not use if at all:
> >> d->stop = !err;
> >> d->metacopy = !!err;
> >
> > I think I will put {}. Its much easier to read the code that way.
>
> Well, execution branch is less efficient and I don't know if compiler
> will optimize it away, but in any case I think d->metacopy = err is
> nicer because ovl_check_metacopy_xattr() returns an error or
> an answer to is_metacopy.
>
> [...]
>
> >> > + /*
> >> > + * For non-dir dentry, make sure dentry found by lookup
> >> > + * matches the origin stored in upper
> >> > + */
> >> > + if (!d.is_dir && upperdentry && !ctr && origin_path) {
> >> > + err = ovl_verify_origin(upperdentry, this, false);
> >> > + if (err) {
> >> > + dput(this);
> >> > + goto out_put;
> >> > + }
> >> > + }
> >> > +
> >>
> >> Why is this code duplicated from d.is_dir case?
> >
> > Primarily because for the case of dir, you are verifying origin only
> > if nfs_export is enabled. While I doing this verification even when
> > nfs_export is not enabled.
>
> (d.is_dir && ovl_verify_lower(dentry->d_sb)) || (!d.is_dir && origin_path)
>
> The case of verifying dir found by path and file found by found is exactly
> the same case. You should just include the new case in the comment above
> current code. The idea is to make metacopy lookup as similar as possible
> to merge dir lookup, not to have a different code path for it.
Ok, will do.
>
> >
> > So far by default we always installed origin in lowerstack[0] for non-dir.
> > Now we are doing lookup for non-dir files and looked up file might
> > be different from origin. So we need to make sure file found by lookup
> > is same as pointed by origin, otherwise something is not right?
> >
>
> [...]
>
> >> > + } else if (!d.is_dir && upperdentry && !ctr && origin_path) {
> >> > + if (WARN_ON(stack != NULL)) {
> >> > + err = -EIO;
> >> > + goto out_put;
> >> > + }
> >> > + stack = origin_path;
> >> > + ctr = 1;
> >> > + origin_path = NULL;
> >>
> >> I am having a hard time understanding why origin_path is needed at all
> >> and why not lookup only by path and then ovl_verify_origin().
> >
> > Right now we look for non-dir file in lower only if upper is metacopy. So
> > if upper is not metacopy, then origin has to be installed in
> > lowerstack[0]. That's why I save origin in origin_path, and install it
> > in lowerstack[0] when there is no lower.
>
> OK. you don't need to allocate origin_path, because it is limited to stack
> size of 1. See how ovl_verify_index() initializes stock and origin vars.
Ok, I can allocate origin_path on stack in caller instead of relying on
ovl_check_origin_fh() doing kmalloc.
>
> >
> > Now other way could be that we lookup for dentry in lower even for
> > non-metacopy non-dir files and do ovl_verify_origin(). I think that's
> > what you are referring to. But that seems like unnecessary lookup in
> > lower. We don't have to do it.
> >
>
> Nah, that will require also doing redirect on non-dir without metacopy.
Thanks
Vivek
next prev parent reply other threads:[~2018-03-08 17:03 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-06 20:53 [PATCH v12 00/17] overlayfs: Delayed copy up of data Vivek Goyal
2018-03-06 20:53 ` [PATCH v12 01/17] ovl: redirect_dir=nofollow can follow redirect for opaque lower Vivek Goyal
2018-03-06 20:53 ` [PATCH v12 02/17] ovl: Provide a mount option metacopy=on/off for metadata copyup Vivek Goyal
2018-03-07 8:47 ` Amir Goldstein
2018-03-07 15:43 ` Vivek Goyal
2018-03-06 20:53 ` [PATCH v12 03/17] ovl: During copy up, first copy up metadata and then data Vivek Goyal
2018-03-06 20:53 ` [PATCH v12 04/17] ovl: Move the copy up helpers to copy_up.c Vivek Goyal
2018-03-06 20:53 ` [PATCH v12 05/17] ovl: Copy up only metadata during copy up where it makes sense Vivek Goyal
2018-03-06 20:53 ` [PATCH v12 06/17] ovl: Add helper ovl_already_copied_up() Vivek Goyal
2018-03-06 20:53 ` [PATCH v12 07/17] ovl: A new xattr OVL_XATTR_METACOPY for file on upper Vivek Goyal
2018-03-06 20:53 ` [PATCH v12 08/17] ovl: Modify ovl_lookup() and friends to lookup metacopy dentry Vivek Goyal
2018-03-07 14:42 ` Amir Goldstein
2018-03-07 20:27 ` Vivek Goyal
2018-03-08 8:43 ` Amir Goldstein
2018-03-08 17:03 ` Vivek Goyal [this message]
2018-03-08 17:54 ` Amir Goldstein
2018-03-06 20:54 ` [PATCH v12 09/17] ovl: Do not mark a non dir as _OVL_PATH_MERGE in ovl_path_type() Vivek Goyal
2018-03-07 7:07 ` Amir Goldstein
2018-03-07 13:21 ` Vivek Goyal
2018-03-07 13:37 ` Amir Goldstein
2018-03-28 19:43 ` Vivek Goyal
2018-03-29 4:27 ` Amir Goldstein
2018-03-06 20:54 ` [PATCH v12 10/17] ovl: Copy up meta inode data from lowest data inode Vivek Goyal
2018-03-07 7:19 ` Amir Goldstein
2018-03-07 13:30 ` Vivek Goyal
2018-03-06 20:54 ` [PATCH v12 11/17] ovl: Fix ovl_getattr() to get number of blocks from lower Vivek Goyal
2018-03-06 20:54 ` [PATCH v12 12/17] ovl: Do not expose metacopy only upper dentry from d_real() Vivek Goyal
2018-03-07 7:15 ` Amir Goldstein
2018-03-07 13:29 ` Vivek Goyal
2018-03-07 13:40 ` Amir Goldstein
2018-03-07 19:13 ` Vivek Goyal
2018-03-06 20:54 ` [PATCH v12 13/17] ovl: Check redirects for metacopy files Vivek Goyal
2018-03-07 12:16 ` Amir Goldstein
2018-03-07 18:52 ` Vivek Goyal
2018-03-08 8:55 ` Amir Goldstein
2018-03-06 20:54 ` [PATCH v12 14/17] ovl: Set redirect on metacopy files upon rename Vivek Goyal
2018-03-07 7:48 ` Amir Goldstein
2018-03-07 15:15 ` Vivek Goyal
2018-03-07 16:26 ` Amir Goldstein
2018-03-07 20:43 ` Vivek Goyal
2018-03-08 8:04 ` Amir Goldstein
2018-03-06 20:54 ` [PATCH v12 15/17] ovl: Remove redirect when data of a metacopy file is copied up Vivek Goyal
2018-03-07 8:21 ` Amir Goldstein
2018-03-14 19:15 ` Vivek Goyal
2018-03-15 18:47 ` Vivek Goyal
2018-03-15 20:42 ` Amir Goldstein
2018-03-16 12:52 ` Vivek Goyal
2018-03-16 13:17 ` Amir Goldstein
2018-03-16 15:06 ` Vivek Goyal
2018-03-16 16:09 ` Amir Goldstein
2018-03-16 18:09 ` Vivek Goyal
2018-03-20 19:26 ` Vivek Goyal
2018-03-20 20:35 ` Vivek Goyal
2018-03-21 6:23 ` Amir Goldstein
2018-03-29 14:08 ` Vivek Goyal
2018-04-04 13:41 ` Vivek Goyal
2018-04-04 16:04 ` Amir Goldstein
2018-03-06 20:54 ` [PATCH v12 16/17] ovl: Set redirect on upper inode when it is linked Vivek Goyal
2018-03-07 8:02 ` Amir Goldstein
2018-03-07 15:19 ` Vivek Goyal
2018-03-29 14:01 ` Vivek Goyal
2018-03-29 14:09 ` Amir Goldstein
2018-03-06 20:54 ` [PATCH v12 17/17] 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=20180308170343.GB2732@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