Skip to content

Commit 2002df8

Browse files
rhvgoyalMiklos Szeredi
authored andcommitted
ovl: Add helper ovl_already_copied_up()
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> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 44d5bf1 commit 2002df8

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

fs/overlayfs/copy_up.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -761,21 +761,7 @@ int ovl_copy_up_flags(struct dentry *dentry, int flags)
761761
struct dentry *next;
762762
struct dentry *parent = NULL;
763763

764-
/*
765-
* Check if copy-up has happened as well as for upper alias (in
766-
* case of hard links) is there.
767-
*
768-
* Both checks are lockless:
769-
* - false negatives: will recheck under oi->lock
770-
* - false positives:
771-
* + ovl_dentry_upper() uses memory barriers to ensure the
772-
* upper dentry is up-to-date
773-
* + ovl_dentry_has_upper_alias() relies on locking of
774-
* upper parent i_rwsem to prevent reordering copy-up
775-
* with rename.
776-
*/
777-
if (ovl_dentry_upper(dentry) &&
778-
(ovl_dentry_has_upper_alias(dentry) || disconnected))
764+
if (ovl_already_copied_up(dentry))
779765
break;
780766

781767
next = dget(dentry);
@@ -803,9 +789,7 @@ int ovl_copy_up_flags(struct dentry *dentry, int flags)
803789
static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)
804790
{
805791
/* Copy up of disconnected dentry does not set upper alias */
806-
if (ovl_dentry_upper(dentry) &&
807-
(ovl_dentry_has_upper_alias(dentry) ||
808-
(dentry->d_flags & DCACHE_DISCONNECTED)))
792+
if (ovl_already_copied_up(dentry))
809793
return false;
810794

811795
if (special_file(d_inode(dentry)->i_mode))

fs/overlayfs/overlayfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ bool ovl_is_whiteout(struct dentry *dentry);
238238
struct file *ovl_path_open(struct path *path, int flags);
239239
int ovl_copy_up_start(struct dentry *dentry);
240240
void ovl_copy_up_end(struct dentry *dentry);
241+
bool ovl_already_copied_up(struct dentry *dentry);
241242
bool ovl_check_origin_xattr(struct dentry *dentry);
242243
bool ovl_check_dir_xattr(struct dentry *dentry, const char *name);
243244
int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,

fs/overlayfs/util.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,37 @@ struct file *ovl_path_open(struct path *path, int flags)
377377
return dentry_open(path, flags | O_NOATIME, current_cred());
378378
}
379379

380+
bool ovl_already_copied_up(struct dentry *dentry)
381+
{
382+
bool disconnected = dentry->d_flags & DCACHE_DISCONNECTED;
383+
384+
/*
385+
* Check if copy-up has happened as well as for upper alias (in
386+
* case of hard links) is there.
387+
*
388+
* Both checks are lockless:
389+
* - false negatives: will recheck under oi->lock
390+
* - false positives:
391+
* + ovl_dentry_upper() uses memory barriers to ensure the
392+
* upper dentry is up-to-date
393+
* + ovl_dentry_has_upper_alias() relies on locking of
394+
* upper parent i_rwsem to prevent reordering copy-up
395+
* with rename.
396+
*/
397+
if (ovl_dentry_upper(dentry) &&
398+
(ovl_dentry_has_upper_alias(dentry) || disconnected))
399+
return true;
400+
401+
return false;
402+
}
403+
380404
int ovl_copy_up_start(struct dentry *dentry)
381405
{
382406
struct ovl_inode *oi = OVL_I(d_inode(dentry));
383407
int err;
384408

385409
err = mutex_lock_interruptible(&oi->lock);
386-
if (!err && ovl_dentry_has_upper_alias(dentry)) {
410+
if (!err && ovl_already_copied_up(dentry)) {
387411
err = 1; /* Already copied up */
388412
mutex_unlock(&oi->lock);
389413
}

0 commit comments

Comments
 (0)