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 27/28] ovl: Verify a data dentry has been found for metacopy inode
Date: Fri, 6 Apr 2018 11:37:16 -0400	[thread overview]
Message-ID: <20180406153716.GA18336@redhat.com> (raw)
In-Reply-To: <CAOQ4uxjZpVurV=8LV7X1V-oS4wVUOHYJQo6_NBXBdZ=nmLT4Ag@mail.gmail.com>

On Fri, Apr 06, 2018 at 12:46:31PM +0300, Amir Goldstein wrote:
> On Thu, Apr 5, 2018 at 11:45 PM, Vivek Goyal <vgoyal@redhat.com> wrote:
> [...]
> >> >
> >> > If you don't like this locking ovl_inode->lock model, I guess for now
> >> > I could live with not removing REDIRECT after copy up. Once that gets
> >> > merged, I could do one patch series just to clean up REDIRECT after copy
> >> > up and do proper locking.
> >> >
> >>
> >> I think we are confusing two different things in this discussion.
> >> Locking ovl_inode->lock for changing redirect is something that should
> >> stay in the patch set IMO and should be simplified by moving
> >> set redirect before taking rename locks on two inodes.
> >>
> >> I was asking about removal of REDIRECT because this patch
> >> (ovl_verify_metacopy_data) is a bit tricky for me to review and
> >> I still don't feel confident about it.
> >>
> >> My intuition says we could go other ways as well:
> >> - unite METACOPY/REDIRECT xattr (we can call the unite
> >> xattr REDIRECT and not METACOPY)
> >> - memory barriers between setting/clearing/checking
> >> METACOPY/REDIRECT (there is already a barrier for setting
> >> upperdata flag, so that's half the work already.
> >>
> >> We can either have this discussion now or, as you suggested
> >> leave it to a following patch set. Rule of thumb - if this is v13
> >> with 28 patches, might not be a bad idea to deffer 2 patches
> >> and reduce complexity...
> >>
> >
> > Hi Amir,
> >
> > Ok, let me drop removing REDIRECT from the patchset to reduce
> > complexity. Lets first try to get in a basic version in.
> >
> > Now coming to the question of locking ovl_inode->lock. If REDIRECTS
> > are never removed and only upgraded (from relative to absolute), my
> > understanding is that current VFS locking is sufficient to prevent
> > races. Only rename and link path set redirects and both the paths take
> > inode locks and that means two set redirects can't make progress in
> > parallel on an inode.
> >
> > When it comes to ovl_lookup(), we will set ovl_inode->redirect only for
> > the case of I_NEW. So no races should be there as well.
> >
> > So far we had to add locking due to copy up path and now copy up path
> > will not touch redirect xattr. I probably will not even clear
> > ovl_inode->inode redirect as we are not removing REDIRECT.
> >
> > Do you see any other path racing and still needed ovl_inode->lock?
> >
> 
> Let's see.
> 
> Current code is taking A->d_lock in ovl_set_redirect(A) to protect
> against racing with redirect path traversal in ovl_get_redirect(A/B/c).
> 
> For the purpose of protecting ancestors redirect path, d_lock is
> sufficient and is needed anyway to access d_name.
> 
> Also any rename in the filesystem is *also* serialized with
> ovl_sb->s_vfs_rename_mutex. That would make the change I suggested
> to move ovl_set_redirect() before lock_rename() a bit tricky.
> You may say that taking d_lock in ovl_set_redirect() is not strictly
> needed, but I guess it is better coding (or maybe something I am
> missing).
> 
> Now when adding ovl_set_redirect() for non-dir and in ovl_link() the
> plot thickens, because:
> 1. link is not serialized with ovl_sb->s_vfs_rename_mutex lock,
> so path traversal in ovl_get_redirect() in unstable
> 2. 'old' dentry in ovl_link() can be disconnected, so there is
> no path for ovl_get_redirect() at all.
> 
> The only way to get a disconnected dentry is with nfs export, so for
> now, it is enough to WARN_ON and return error in ovl_set_redirect()
> for (dentry->d_flags & DCACHE_DISCONNECTED)
> with a comment referring to nfs_export+metacopy support.

Hi Amir,

I can put this warning for DCACHE_DISCONNECTED dentries.

Now, most interesting part for me here is that why do we need to
stop/synchronize other renames in the system while some set_redirect/get
_redirect operation is taking place. That's the part I don't understand.
When I am looking at current code, I feel d_lock, seems to be good enough
to make sure that ovl_get_redirect() works fine when parallel renames
progressing on other cpu.

So a simple example, is say I am creating a link bar/foo-link.txt to a file
foo/foo.txt and that triggers setting absolute redirect on foo.txt
and we will call ovl_get_direct() and  traverse the tree up till root. 
Now say a part of the tree is also being renamed. Say foo/ is being
renamed to alpha/. I am wondering is d_lock is not enough to make sure
this is not a problem.

We always set redirect first and then do rename. That means d_parent
should be changed only after redirect has been set on a dentry. And
that should guarantee that if ovl_get_redirect() sees new parent, 
then parent_dentry->redirect has been already set. If it sees dentry
before rename, then redirect might be there if not, dentry name would
be used and it will also see the old parent and continue traversal
up.

Is there anything I am missing? 

> 
> Maybe the simplest solution w.r.t stabilizing path traversal
> is to move ovl_set_redirect() above lock_rename()
> as I suggested and use a new lock ofs->ovl_rename_mutex
> inside ovl_get_redirect() to protect the !samedir traversal
> and also take that lock before lock_rename() in ovl_rename().

I already made changes to move ovl_set_redirect() above lock_rename()
in my copy. I still can't see the need of ofs->ovl_rename_mutex. Please
help me understand the need with an example.

> 
> Back to the original question: how should ovl_inode->redirect
> be protected if at all it needs protection?

At this point I am thinking at max we need to just take ovl_inode->lock
to protect ovl_inode->redirect. It just makes it little safer and
relatively easier to understand.

Thanks
Vivek

> I think setting redirect need the protection of ofs->ovl_rename_mutex.
> Can either take it just around ovl_dentry_set_redirect(), probably
> instead of d_lock, or take the ovl_rename_mutex inside
> ovl_set_redirect() and around ovl_get_redirect() instead of inside
> ovl_get_redirect().
> 
> Hmm, I hope I got this right. I advise to get feedback from Miklos
> to this design before you proceed.
> 
> Thanks,
> Amir.

  reply	other threads:[~2018-04-06 15:37 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
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 [this message]
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=20180406153716.GA18336@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