Skip to content

Commit 408d8af

Browse files
author
Al Viro
committed
for_each_alias(): helper macro for iterating through dentries of given inode
Most of the places using d_alias are loops iterating through all aliases for given inode; introduce a helper macro (for_each_alias(dentry, inode)) and convert open-coded instances of such loop to it. They are easier to read that way and it reduces the noise on the next steps. You _must_ hold inode->i_lock over that thing. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 7aaa804 commit 408d8af

11 files changed

Lines changed: 25 additions & 11 deletions

File tree

Documentation/filesystems/porting.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,3 +1361,13 @@ to match what strlen() would return if it was ran on the string.
13611361

13621362
However, if the string is freely accessible for the duration of inode's
13631363
lifetime, consider using inode_set_cached_link() instead.
1364+
1365+
---
1366+
1367+
**recommended**
1368+
1369+
If you really need to iterate through dentries for given inode, use
1370+
for_each_alias(dentry, inode) instead of hlist_for_each_entry; better
1371+
yet, see if any of the exported primitives could be used instead of
1372+
the entire loop. You still need to hold ->i_lock of the inode over
1373+
either form of manual loop.

fs/affs/amigaffs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ affs_fix_dcache(struct inode *inode, u32 entry_ino)
126126
{
127127
struct dentry *dentry;
128128
spin_lock(&inode->i_lock);
129-
hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
129+
for_each_alias(dentry, inode) {
130130
if (entry_ino == (u32)(long)dentry->d_fsdata) {
131131
dentry->d_fsdata = (void *)inode->i_ino;
132132
break;

fs/ceph/mds_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4614,7 +4614,7 @@ static struct dentry* d_find_primary(struct inode *inode)
46144614
goto out_unlock;
46154615
}
46164616

4617-
hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
4617+
for_each_alias(alias, inode) {
46184618
spin_lock(&alias->d_lock);
46194619
if (!d_unhashed(alias) &&
46204620
(ceph_dentry(alias)->flags & CEPH_DENTRY_PRIMARY_LINK)) {

fs/dcache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ void d_mark_dontcache(struct inode *inode)
790790
struct dentry *de;
791791

792792
spin_lock(&inode->i_lock);
793-
hlist_for_each_entry(de, &inode->i_dentry, d_u.d_alias) {
793+
for_each_alias(de, inode) {
794794
spin_lock(&de->d_lock);
795795
de->d_flags |= DCACHE_DONTCACHE;
796796
spin_unlock(&de->d_lock);
@@ -1040,7 +1040,7 @@ static struct dentry *__d_find_alias(struct inode *inode)
10401040
if (S_ISDIR(inode->i_mode))
10411041
return __d_find_any_alias(inode);
10421042

1043-
hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
1043+
for_each_alias(alias, inode) {
10441044
spin_lock(&alias->d_lock);
10451045
if (!d_unhashed(alias)) {
10461046
dget_dlock(alias);
@@ -1133,7 +1133,7 @@ void d_prune_aliases(struct inode *inode)
11331133
struct dentry *dentry;
11341134

11351135
spin_lock(&inode->i_lock);
1136-
hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias)
1136+
for_each_alias(dentry, inode)
11371137
d_dispose_if_unused(dentry, &dispose);
11381138
spin_unlock(&inode->i_lock);
11391139
shrink_dentry_list(&dispose);

fs/exportfs/expfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ find_acceptable_alias(struct dentry *result,
5252

5353
inode = result->d_inode;
5454
spin_lock(&inode->i_lock);
55-
hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
55+
for_each_alias(dentry, inode) {
5656
dget(dentry);
5757
spin_unlock(&inode->i_lock);
5858
if (toput)

fs/nfs/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ static void nfs_clear_verifier_file(struct inode *inode)
14711471
struct dentry *alias;
14721472
struct inode *dir;
14731473

1474-
hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
1474+
for_each_alias(alias, inode) {
14751475
spin_lock(&alias->d_lock);
14761476
dir = d_inode_rcu(alias->d_parent);
14771477
if (!dir ||

fs/notify/fsnotify.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void fsnotify_set_children_dentry_flags(struct inode *inode)
7676
spin_lock(&inode->i_lock);
7777
/* run all of the dentries associated with this inode. Since this is a
7878
* directory, there damn well better only be one item on this list */
79-
hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
79+
for_each_alias(alias, inode) {
8080
struct dentry *child;
8181

8282
/* run all of the children of the original inode and fix their

fs/ocfs2/dcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ struct dentry *ocfs2_find_local_alias(struct inode *inode,
145145
struct dentry *dentry;
146146

147147
spin_lock(&inode->i_lock);
148-
hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
148+
for_each_alias(dentry, inode) {
149149
spin_lock(&dentry->d_lock);
150150
if (ocfs2_match_dentry(dentry, parent_blkno, skip_unhashed)) {
151151
trace_ocfs2_find_local_alias(dentry->d_name.len,

fs/overlayfs/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ static void ovl_drop_nlink(struct dentry *dentry)
904904

905905
/* Try to find another, hashed alias */
906906
spin_lock(&inode->i_lock);
907-
hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
907+
for_each_alias(alias, inode) {
908908
if (alias != dentry && !d_unhashed(alias))
909909
break;
910910
}

fs/smb/client/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ inode_has_hashed_dentries(struct inode *inode)
15951595
struct dentry *dentry;
15961596

15971597
spin_lock(&inode->i_lock);
1598-
hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
1598+
for_each_alias(dentry, inode) {
15991599
if (!d_unhashed(dentry) || IS_ROOT(dentry)) {
16001600
spin_unlock(&inode->i_lock);
16011601
return true;

0 commit comments

Comments
 (0)