All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Vivek Goyal <vgoyal@redhat.com>
Cc: overlayfs <linux-unionfs@vger.kernel.org>,
	Miklos Szeredi <miklos@szeredi.hu>
Subject: Re: [PATCH v13 15/28] ovl: Move some of ovl_nlink_start() functionality in ovl_nlink_prep()
Date: Fri, 30 Mar 2018 09:23:37 +0300	[thread overview]
Message-ID: <CAOQ4uxjYDNFwHG6i8cHDmUgpSd6UhwFgM7S=G8Hr1rQ+7Z2yoQ@mail.gmail.com> (raw)
In-Reply-To: <20180329193854.13814-16-vgoyal@redhat.com>

On Thu, Mar 29, 2018 at 10:38 PM, Vivek Goyal <vgoyal@redhat.com> wrote:
> Soon I want to write patches to enable redirects on non-dir files. That means
> it is possible that we have to deal with the case where multiple dentries
> might be sharing inode and ovl_inode->redirect field setting/resetting
> will need to be protected by taking ovl_inode->lock. Current dentry based
> locking alone will not be sufficient for this case.
>
> As of now, nlink based code takes ovl_inode->lock in some cases. For redirect
> case, during ovl_rename() I might have to take ovl_inode->lock both on
> old as well as new ovl_inode. And that means that I need to make sure
> there are no deadlocks.
>
> I want to separate out logic for taking lock in a new function. Hence will
> need to break down ovl_nlink_start() a bit.
>
> ovl_nlink_start() does the copy up and then takes ovl_inode->lock. Move
> copy up related portions in a separate function called ovl_nlink_prep().

The sensible thing to do is to call 2 helpers from ovl_nlink_start()
ovl_nlink_prep() and ovl_nlink_???() and then you can use helpers
directly in rename, but don't need to change all other places.
The changes to other places do not make the code better, they make
it worse.

>
> This patch is just code reorganization and no funcitonal change.
>
> Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
> ---
>  fs/overlayfs/dir.c       | 14 ++++++++++++++
>  fs/overlayfs/overlayfs.h |  1 +
>  fs/overlayfs/util.c      | 26 ++++++++++++++++++--------
>  3 files changed, 33 insertions(+), 8 deletions(-)
>
> diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
> index 7617a03acc30..1f003be4a19e 100644
> --- a/fs/overlayfs/dir.c
> +++ b/fs/overlayfs/dir.c
> @@ -595,6 +595,10 @@ static int ovl_link(struct dentry *old, struct inode *newdir,
>         if (err)
>                 goto out_drop_write;
>
> +       err = ovl_nlink_prep(old);
> +       if (err)
> +               goto out_drop_write;
> +
>         err = ovl_nlink_start(old, &locked);
>         if (err)
>                 goto out_drop_write;
> @@ -752,6 +756,10 @@ static int ovl_do_remove(struct dentry *dentry, bool is_dir)
>         if (err)
>                 goto out_drop_write;
>
> +       err = ovl_nlink_prep(dentry);
> +       if (err)
> +               goto out_drop_write;
> +
>         err = ovl_nlink_start(dentry, &locked);
>         if (err)
>                 goto out_drop_write;
> @@ -960,6 +968,12 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
>                 if (err)
>                         goto out_drop_write;
>         } else {
> +               err = ovl_nlink_prep(new);
> +               if (err)
> +                       goto out_drop_write;
> +       }
> +
> +       if (overwrite) {
>                 err = ovl_nlink_start(new, &new_locked);
>                 if (err)
>                         goto out_drop_write;
> diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
> index 214d9f08c574..aa5b0c121fc7 100644
> --- a/fs/overlayfs/overlayfs.h
> +++ b/fs/overlayfs/overlayfs.h
> @@ -271,6 +271,7 @@ bool ovl_test_flag(unsigned long flag, struct inode *inode);
>  bool ovl_inuse_trylock(struct dentry *dentry);
>  void ovl_inuse_unlock(struct dentry *dentry);
>  bool ovl_need_index(struct dentry *dentry);
> +int ovl_nlink_prep(struct dentry *dentry);
>  int ovl_nlink_start(struct dentry *dentry, bool *locked);
>  void ovl_nlink_end(struct dentry *dentry, bool locked);
>  int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir);
> diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
> index 394674c4c820..ed93e233894f 100644
> --- a/fs/overlayfs/util.c
> +++ b/fs/overlayfs/util.c
> @@ -675,15 +675,9 @@ static void ovl_cleanup_index(struct dentry *dentry)
>         goto out;
>  }
>
> -/*
> - * Operations that change overlay inode and upper inode nlink need to be
> - * synchronized with copy up for persistent nlink accounting.
> - */
> -int ovl_nlink_start(struct dentry *dentry, bool *locked)
> +int ovl_nlink_prep(struct dentry *dentry)
>  {
> -       struct ovl_inode *oi = OVL_I(d_inode(dentry));
> -       const struct cred *old_cred;
> -       int err;
> +       int err = 0;
>
>         if (!d_inode(dentry))
>                 return 0;
> @@ -708,6 +702,22 @@ int ovl_nlink_start(struct dentry *dentry, bool *locked)
>                         return err;
>         }
>
> +       return err;
> +}
> +
> +/*
> + * Operations that change overlay inode and upper inode nlink need to be
> + * synchronized with copy up for persistent nlink accounting.
> + */
> +int ovl_nlink_start(struct dentry *dentry, bool *locked)
> +{
> +       struct ovl_inode *oi = OVL_I(d_inode(dentry));
> +       const struct cred *old_cred;
> +       int err;
> +
> +       if (!d_inode(dentry))
> +               return 0;
> +
>         err = mutex_lock_interruptible(&oi->lock);
>         if (err)
>                 return err;
> --
> 2.13.6
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-unionfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2018-03-30  6:23 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 [this message]
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
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='CAOQ4uxjYDNFwHG6i8cHDmUgpSd6UhwFgM7S=G8Hr1rQ+7Z2yoQ@mail.gmail.com' \
    --to=amir73il@gmail.com \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=vgoyal@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.