Skip to content

Commit 02d7009

Browse files
committed
ovl: remove redundant ofs->indexdir member
When the index feature is disabled, ofs->indexdir is NULL. When the index feature is enabled, ofs->indexdir has the same value as ofs->workdir and takes an extra reference. This makes the code harder to understand when it is not always clear that ofs->indexdir in one function is the same dentry as ofs->workdir in another function. Remove this redundancy, by referencing ofs->workdir directly in index helpers and by using the ovl_indexdir() accessor in generic code. Signed-off-by: Amir Goldstein <[email protected]>
1 parent 98b1cc8 commit 02d7009

File tree

7 files changed

+15
-23
lines changed

7 files changed

+15
-23
lines changed

fs/overlayfs/export.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ static struct dentry *ovl_lookup_real_inode(struct super_block *sb,
460460
* For decoded lower dir file handle, lookup index by origin to check
461461
* if lower dir was copied up and and/or removed.
462462
*/
463-
if (!this && layer->idx && ofs->indexdir && !WARN_ON(!d_is_dir(real))) {
463+
if (!this && layer->idx && ovl_indexdir(sb) && !WARN_ON(!d_is_dir(real))) {
464464
index = ovl_lookup_index(ofs, NULL, real, false);
465465
if (IS_ERR(index))
466466
return index;
@@ -733,7 +733,7 @@ static struct dentry *ovl_lower_fh_to_d(struct super_block *sb,
733733
}
734734

735735
/* Then lookup indexed upper/whiteout by origin fh */
736-
if (ofs->indexdir) {
736+
if (ovl_indexdir(sb)) {
737737
index = ovl_get_index_fh(ofs, fh);
738738
err = PTR_ERR(index);
739739
if (IS_ERR(index)) {

fs/overlayfs/namei.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh)
754754
if (err)
755755
return ERR_PTR(err);
756756

757-
index = lookup_positive_unlocked(name.name, ofs->indexdir, name.len);
757+
index = lookup_positive_unlocked(name.name, ofs->workdir, name.len);
758758
kfree(name.name);
759759
if (IS_ERR(index)) {
760760
if (PTR_ERR(index) == -ENOENT)
@@ -787,7 +787,7 @@ struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper,
787787
return ERR_PTR(err);
788788

789789
index = lookup_one_positive_unlocked(ovl_upper_mnt_idmap(ofs), name.name,
790-
ofs->indexdir, name.len);
790+
ofs->workdir, name.len);
791791
if (IS_ERR(index)) {
792792
err = PTR_ERR(index);
793793
if (err == -ENOENT) {

fs/overlayfs/ovl_entry.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ struct ovl_fs {
6363
struct ovl_sb *fs;
6464
/* workbasedir is the path at workdir= mount option */
6565
struct dentry *workbasedir;
66-
/* workdir is the 'work' directory under workbasedir */
66+
/* workdir is the 'work' or 'index' directory under workbasedir */
6767
struct dentry *workdir;
68-
/* index directory listing overlay inodes by origin file handle */
69-
struct dentry *indexdir;
7068
long namelen;
7169
/* pathnames of lower and upper dirs, for show_options */
7270
struct ovl_config config;
@@ -81,7 +79,6 @@ struct ovl_fs {
8179
/* Traps in ovl inode cache */
8280
struct inode *workbasedir_trap;
8381
struct inode *workdir_trap;
84-
struct inode *indexdir_trap;
8582
/* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
8683
int xino_mode;
8784
/* For allocation of non-persistent inode numbers */

fs/overlayfs/params.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,8 @@ void ovl_free_fs(struct ovl_fs *ofs)
743743
unsigned i;
744744

745745
iput(ofs->workbasedir_trap);
746-
iput(ofs->indexdir_trap);
747746
iput(ofs->workdir_trap);
748747
dput(ofs->whiteout);
749-
dput(ofs->indexdir);
750748
dput(ofs->workdir);
751749
if (ofs->workdir_locked)
752750
ovl_inuse_unlock(ofs->workbasedir);

fs/overlayfs/readdir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ int ovl_workdir_cleanup(struct ovl_fs *ofs, struct inode *dir,
11691169
int ovl_indexdir_cleanup(struct ovl_fs *ofs)
11701170
{
11711171
int err;
1172-
struct dentry *indexdir = ofs->indexdir;
1172+
struct dentry *indexdir = ofs->workdir;
11731173
struct dentry *index = NULL;
11741174
struct inode *dir = indexdir->d_inode;
11751175
struct path path = { .mnt = ovl_upper_mnt(ofs), .dentry = indexdir };

fs/overlayfs/super.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,8 @@ static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs,
853853
if (IS_ERR(indexdir)) {
854854
err = PTR_ERR(indexdir);
855855
} else if (indexdir) {
856-
ofs->indexdir = indexdir;
857-
ofs->workdir = dget(indexdir);
858-
859-
err = ovl_setup_trap(sb, ofs->indexdir, &ofs->indexdir_trap,
856+
ofs->workdir = indexdir;
857+
err = ovl_setup_trap(sb, indexdir, &ofs->workdir_trap,
860858
"indexdir");
861859
if (err)
862860
goto out;
@@ -869,24 +867,23 @@ static int ovl_get_indexdir(struct super_block *sb, struct ovl_fs *ofs,
869867
* ".overlay.upper" to indicate that index may have
870868
* directory entries.
871869
*/
872-
if (ovl_check_origin_xattr(ofs, ofs->indexdir)) {
873-
err = ovl_verify_origin_xattr(ofs, ofs->indexdir,
870+
if (ovl_check_origin_xattr(ofs, indexdir)) {
871+
err = ovl_verify_origin_xattr(ofs, indexdir,
874872
OVL_XATTR_ORIGIN,
875873
upperpath->dentry, true,
876874
false);
877875
if (err)
878876
pr_err("failed to verify index dir 'origin' xattr\n");
879877
}
880-
err = ovl_verify_upper(ofs, ofs->indexdir, upperpath->dentry,
881-
true);
878+
err = ovl_verify_upper(ofs, indexdir, upperpath->dentry, true);
882879
if (err)
883880
pr_err("failed to verify index dir 'upper' xattr\n");
884881

885882
/* Cleanup bad/stale/orphan index entries */
886883
if (!err)
887884
err = ovl_indexdir_cleanup(ofs);
888885
}
889-
if (err || !ofs->indexdir)
886+
if (err || !indexdir)
890887
pr_warn("try deleting index dir or mounting with '-o index=off' to disable inodes index.\n");
891888

892889
out:
@@ -1406,7 +1403,7 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc)
14061403
goto out_free_oe;
14071404

14081405
/* Force r/o mount with no index dir */
1409-
if (!ofs->indexdir)
1406+
if (!ofs->workdir)
14101407
sb->s_flags |= SB_RDONLY;
14111408
}
14121409

@@ -1415,7 +1412,7 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc)
14151412
goto out_free_oe;
14161413

14171414
/* Show index=off in /proc/mounts for forced r/o mount */
1418-
if (!ofs->indexdir) {
1415+
if (!ofs->workdir) {
14191416
ofs->config.index = false;
14201417
if (ovl_upper_mnt(ofs) && ofs->config.nfs_export) {
14211418
pr_warn("NFS export requires an index dir, falling back to nfs_export=off.\n");

fs/overlayfs/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct dentry *ovl_indexdir(struct super_block *sb)
9191
{
9292
struct ovl_fs *ofs = OVL_FS(sb);
9393

94-
return ofs->indexdir;
94+
return ofs->config.index ? ofs->workdir : NULL;
9595
}
9696

9797
/* Index all files on copy up. For now only enabled for NFS export */

0 commit comments

Comments
 (0)