Commit 408d8af0 authored by Al Viro's avatar Al Viro
Browse files

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: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 7aaa8047
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1361,3 +1361,13 @@ to match what strlen() would return if it was ran on the string.

However, if the string is freely accessible for the duration of inode's
lifetime, consider using inode_set_cached_link() instead.

---

**recommended**

If you really need to iterate through dentries for given inode, use
for_each_alias(dentry, inode) instead of hlist_for_each_entry; better
yet, see if any of the exported primitives could be used instead of
the entire loop.  You still need to hold ->i_lock of the inode over
either form of manual loop.
+1 −1
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ affs_fix_dcache(struct inode *inode, u32 entry_ino)
{
	struct dentry *dentry;
	spin_lock(&inode->i_lock);
	hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
	for_each_alias(dentry, inode) {
		if (entry_ino == (u32)(long)dentry->d_fsdata) {
			dentry->d_fsdata = (void *)inode->i_ino;
			break;
+1 −1
Original line number Diff line number Diff line
@@ -4614,7 +4614,7 @@ static struct dentry* d_find_primary(struct inode *inode)
		goto out_unlock;
	}

	hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
	for_each_alias(alias, inode) {
		spin_lock(&alias->d_lock);
		if (!d_unhashed(alias) &&
		    (ceph_dentry(alias)->flags & CEPH_DENTRY_PRIMARY_LINK)) {
+3 −3
Original line number Diff line number Diff line
@@ -790,7 +790,7 @@ void d_mark_dontcache(struct inode *inode)
	struct dentry *de;

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

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

	spin_lock(&inode->i_lock);
	hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias)
	for_each_alias(dentry, inode)
		d_dispose_if_unused(dentry, &dispose);
	spin_unlock(&inode->i_lock);
	shrink_dentry_list(&dispose);
+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ find_acceptable_alias(struct dentry *result,

	inode = result->d_inode;
	spin_lock(&inode->i_lock);
	hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
	for_each_alias(dentry, inode) {
		dget(dentry);
		spin_unlock(&inode->i_lock);
		if (toput)
Loading