diff options
author | Amir Goldstein <amir73il@gmail.com> | 2017-09-26 00:55:26 -0400 |
---|---|---|
committer | Miklos Szeredi <mszeredi@redhat.com> | 2018-01-24 05:25:54 -0500 |
commit | 24b33ee104ecd5a4e1e71412f8966199d6a0bf02 (patch) | |
tree | 05d5e761abe8c637a4e93e5d1700c3e863757d52 /fs/overlayfs/util.c | |
parent | 9ee60ce2491166c73a381e5f04dc4c3a147e169d (diff) |
ovl: create ovl_need_index() helper
The helper determines which lower file needs to be indexed
on copy up and before nlink changes.
For index=on, the helper evaluates to true for lower hardlinks.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/overlayfs/util.c')
-rw-r--r-- | fs/overlayfs/util.c | 24 |
1 files changed, 20 insertions, 4 deletions
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 | */ | ||
469 | bool 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 */ |
467 | static void ovl_cleanup_index(struct dentry *dentry) | 484 | static 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; |