summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/overlayfs/copy_up.c6
-rw-r--r--fs/overlayfs/overlayfs.h1
-rw-r--r--fs/overlayfs/util.c24
3 files changed, 22 insertions, 9 deletions
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index 503c92404095..103e62dcb745 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -536,11 +536,7 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
536{ 536{
537 int err; 537 int err;
538 struct ovl_fs *ofs = c->dentry->d_sb->s_fs_info; 538 struct ovl_fs *ofs = c->dentry->d_sb->s_fs_info;
539 bool indexed = false; 539 bool indexed = ovl_need_index(c->dentry);
540
541 if (ovl_indexdir(c->dentry->d_sb) && !S_ISDIR(c->stat.mode) &&
542 c->stat.nlink > 1)
543 indexed = true;
544 540
545 if (S_ISDIR(c->stat.mode) || c->stat.nlink == 1 || indexed) 541 if (S_ISDIR(c->stat.mode) || c->stat.nlink == 1 || indexed)
546 c->origin = true; 542 c->origin = true;
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 25794a3a3fe1..d7e65284c13b 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -241,6 +241,7 @@ void ovl_clear_flag(unsigned long flag, struct inode *inode);
241bool ovl_test_flag(unsigned long flag, struct inode *inode); 241bool ovl_test_flag(unsigned long flag, struct inode *inode);
242bool ovl_inuse_trylock(struct dentry *dentry); 242bool ovl_inuse_trylock(struct dentry *dentry);
243void ovl_inuse_unlock(struct dentry *dentry); 243void ovl_inuse_unlock(struct dentry *dentry);
244bool ovl_need_index(struct dentry *dentry);
244int ovl_nlink_start(struct dentry *dentry, bool *locked); 245int ovl_nlink_start(struct dentry *dentry, bool *locked);
245void ovl_nlink_end(struct dentry *dentry, bool locked); 246void ovl_nlink_end(struct dentry *dentry, bool locked);
246int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir); 247int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir);
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index ae81d878248e..55ab99131a72 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -463,6 +463,23 @@ void ovl_inuse_unlock(struct dentry *dentry)
463 } 463 }
464} 464}
465 465
466/*
467 * Does this overlay dentry need to be indexed on copy up?
468 */
469bool ovl_need_index(struct dentry *dentry)
470{
471 struct dentry *lower = ovl_dentry_lower(dentry);
472
473 if (!lower || !ovl_indexdir(dentry->d_sb))
474 return false;
475
476 /* Index only lower hardlinks on copy up */
477 if (!d_is_dir(lower) && d_inode(lower)->i_nlink > 1)
478 return true;
479
480 return false;
481}
482
466/* Caller must hold OVL_I(inode)->lock */ 483/* Caller must hold OVL_I(inode)->lock */
467static void ovl_cleanup_index(struct dentry *dentry) 484static void ovl_cleanup_index(struct dentry *dentry)
468{ 485{
@@ -533,11 +550,11 @@ int ovl_nlink_start(struct dentry *dentry, bool *locked)
533 550
534 /* 551 /*
535 * With inodes index is enabled, we store the union overlay nlink 552 * With inodes index is enabled, we store the union overlay nlink
536 * in an xattr on the index inode. When whiting out lower hardlinks 553 * in an xattr on the index inode. When whiting out an indexed lower,
537 * we need to decrement the overlay persistent nlink, but before the 554 * we need to decrement the overlay persistent nlink, but before the
538 * first copy up, we have no upper index inode to store the xattr. 555 * first copy up, we have no upper index inode to store the xattr.
539 * 556 *
540 * As a workaround, before whiteout/rename over of a lower hardlink, 557 * As a workaround, before whiteout/rename over an indexed lower,
541 * copy up to create the upper index. Creating the upper index will 558 * copy up to create the upper index. Creating the upper index will
542 * initialize the overlay nlink, so it could be dropped if unlink 559 * initialize the overlay nlink, so it could be dropped if unlink
543 * or rename succeeds. 560 * or rename succeeds.
@@ -545,8 +562,7 @@ int ovl_nlink_start(struct dentry *dentry, bool *locked)
545 * TODO: implement metadata only index copy up when called with 562 * TODO: implement metadata only index copy up when called with
546 * ovl_copy_up_flags(dentry, O_PATH). 563 * ovl_copy_up_flags(dentry, O_PATH).
547 */ 564 */
548 if (ovl_indexdir(dentry->d_sb) && !ovl_dentry_has_upper_alias(dentry) && 565 if (ovl_need_index(dentry) && !ovl_dentry_has_upper_alias(dentry)) {
549 d_inode(ovl_dentry_lower(dentry))->i_nlink > 1) {
550 err = ovl_copy_up(dentry); 566 err = ovl_copy_up(dentry);
551 if (err) 567 if (err)
552 return err; 568 return err;