From: Vivek Goyal <vgoyal@redhat.com>
To: linux-unionfs@vger.kernel.org
Cc: miklos@szeredi.hu, amir73il@gmail.com, vgoyal@redhat.com
Subject: [PATCH v12 06/17] ovl: Add helper ovl_already_copied_up()
Date: Tue, 6 Mar 2018 15:53:57 -0500 [thread overview]
Message-ID: <20180306205408.23383-7-vgoyal@redhat.com> (raw)
In-Reply-To: <20180306205408.23383-1-vgoyal@redhat.com>
There are couple of places where we need to know if file is already copied
up (in lockless manner). Right now its open coded and there are only
two conditions to check. Soon this patch series will introduce another
condition to check and Amir wants to introduce one more. So introduce
a helper instead to check this so that code is easier to read.
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/copy_up.c | 20 ++------------------
fs/overlayfs/overlayfs.h | 1 +
fs/overlayfs/util.c | 26 +++++++++++++++++++++++++-
3 files changed, 28 insertions(+), 19 deletions(-)
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index 45e396a0fd6a..8d9af7fdc8a4 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -810,21 +810,7 @@ int ovl_copy_up_flags(struct dentry *dentry, int flags)
struct dentry *next;
struct dentry *parent = NULL;
- /*
- * Check if copy-up has happened as well as for upper alias (in
- * case of hard links) is there.
- *
- * Both checks are lockless:
- * - false negatives: will recheck under oi->lock
- * - false positives:
- * + ovl_dentry_upper() uses memory barriers to ensure the
- * upper dentry is up-to-date
- * + ovl_dentry_has_upper_alias() relies on locking of
- * upper parent i_rwsem to prevent reordering copy-up
- * with rename.
- */
- if (ovl_dentry_upper(dentry) &&
- (ovl_dentry_has_upper_alias(dentry) || disconnected))
+ if (ovl_already_copied_up(dentry))
break;
next = dget(dentry);
@@ -852,9 +838,7 @@ int ovl_copy_up_flags(struct dentry *dentry, int flags)
static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)
{
/* Copy up of disconnected dentry does not set upper alias */
- if (ovl_dentry_upper(dentry) &&
- (ovl_dentry_has_upper_alias(dentry) ||
- (dentry->d_flags & DCACHE_DISCONNECTED)))
+ if (ovl_already_copied_up(dentry))
return false;
if (special_file(d_inode(dentry)->i_mode))
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 21f3bfea665c..11f87f3099a1 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -241,6 +241,7 @@ bool ovl_is_whiteout(struct dentry *dentry);
struct file *ovl_path_open(struct path *path, int flags);
int ovl_copy_up_start(struct dentry *dentry);
void ovl_copy_up_end(struct dentry *dentry);
+bool ovl_already_copied_up(struct dentry *dentry);
bool ovl_check_origin_xattr(struct dentry *dentry);
bool ovl_check_dir_xattr(struct dentry *dentry, const char *name);
int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index 930784a26623..4e537eeb594e 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -339,13 +339,37 @@ struct file *ovl_path_open(struct path *path, int flags)
return dentry_open(path, flags | O_NOATIME, current_cred());
}
+bool ovl_already_copied_up(struct dentry *dentry)
+{
+ bool disconnected = dentry->d_flags & DCACHE_DISCONNECTED;
+
+ /*
+ * Check if copy-up has happened as well as for upper alias (in
+ * case of hard links) is there.
+ *
+ * Both checks are lockless:
+ * - false negatives: will recheck under oi->lock
+ * - false positives:
+ * + ovl_dentry_upper() uses memory barriers to ensure the
+ * upper dentry is up-to-date
+ * + ovl_dentry_has_upper_alias() relies on locking of
+ * upper parent i_rwsem to prevent reordering copy-up
+ * with rename.
+ */
+ if (ovl_dentry_upper(dentry) &&
+ (ovl_dentry_has_upper_alias(dentry) || disconnected))
+ return true;
+
+ return false;
+}
+
int ovl_copy_up_start(struct dentry *dentry)
{
struct ovl_inode *oi = OVL_I(d_inode(dentry));
int err;
err = mutex_lock_interruptible(&oi->lock);
- if (!err && ovl_dentry_has_upper_alias(dentry)) {
+ if (!err && ovl_already_copied_up(dentry)) {
err = 1; /* Already copied up */
mutex_unlock(&oi->lock);
}
--
2.13.6
next prev parent reply other threads:[~2018-03-06 20:53 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 ` Vivek Goyal [this message]
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
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=20180306205408.23383-7-vgoyal@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