Skip to content

Commit 949854d

Browse files
author
Nick Piggin
committed
fs: Use rename lock and RCU for multi-step operations
The remaining usages for dcache_lock is to allow atomic, multi-step read-side operations over the directory tree by excluding modifications to the tree. Also, to walk in the leaf->root direction in the tree where we don't have a natural d_lock ordering. This could be accomplished by taking every d_lock, but this would mean a huge number of locks and actually gets very tricky. Solve this instead by using the rename seqlock for multi-step read-side operations, retry in case of a rename so we don't walk up the wrong parent. Concurrent dentry insertions are not serialised against. Concurrent deletes are tricky when walking up the directory: our parent might have been deleted when dropping locks so also need to check and retry for that. We can also use the rename lock in cases where livelock is a worry (and it is introduced in subsequent patch). Signed-off-by: Nick Piggin <npiggin@kernel.dk>
1 parent 9abca36 commit 949854d

5 files changed

Lines changed: 152 additions & 30 deletions

File tree

‎drivers/staging/pohmelfs/path_entry.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ int pohmelfs_construct_path_string(struct pohmelfs_inode *pi, void *data, int le
8383
int pohmelfs_path_length(struct pohmelfs_inode *pi)
8484
{
8585
struct dentry *d, *root, *first;
86-
int len = 1; /* Root slash */
86+
int len;
87+
unsigned seq;
8788

88-
first = d = d_find_alias(&pi->vfs_inode);
89-
if (!d) {
89+
first = d_find_alias(&pi->vfs_inode);
90+
if (!first) {
9091
dprintk("%s: ino: %llu, mode: %o.\n", __func__, pi->ino, pi->vfs_inode.i_mode);
9192
return -ENOENT;
9293
}
@@ -95,6 +96,11 @@ int pohmelfs_path_length(struct pohmelfs_inode *pi)
9596
root = dget(current->fs->root.dentry);
9697
spin_unlock(&current->fs->lock);
9798

99+
rename_retry:
100+
len = 1; /* Root slash */
101+
d = first;
102+
seq = read_seqbegin(&rename_lock);
103+
rcu_read_lock();
98104
spin_lock(&dcache_lock);
99105

100106
if (!IS_ROOT(d) && d_unhashed(d))
@@ -105,6 +111,9 @@ int pohmelfs_path_length(struct pohmelfs_inode *pi)
105111
d = d->d_parent;
106112
}
107113
spin_unlock(&dcache_lock);
114+
rcu_read_unlock();
115+
if (read_seqretry(&rename_lock, seq))
116+
goto rename_retry;
108117

109118
dput(root);
110119
dput(first);

‎fs/autofs4/waitq.c‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,25 @@ static int autofs4_getpath(struct autofs_sb_info *sbi,
186186
{
187187
struct dentry *root = sbi->sb->s_root;
188188
struct dentry *tmp;
189-
char *buf = *name;
189+
char *buf;
190190
char *p;
191-
int len = 0;
192-
191+
int len;
192+
unsigned seq;
193+
194+
rename_retry:
195+
buf = *name;
196+
len = 0;
197+
seq = read_seqbegin(&rename_lock);
198+
rcu_read_lock();
193199
spin_lock(&dcache_lock);
194200
for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
195201
len += tmp->d_name.len + 1;
196202

197203
if (!len || --len > NAME_MAX) {
198204
spin_unlock(&dcache_lock);
205+
rcu_read_unlock();
206+
if (read_seqretry(&rename_lock, seq))
207+
goto rename_retry;
199208
return 0;
200209
}
201210

@@ -209,6 +218,9 @@ static int autofs4_getpath(struct autofs_sb_info *sbi,
209218
strncpy(p, tmp->d_name.name, tmp->d_name.len);
210219
}
211220
spin_unlock(&dcache_lock);
221+
rcu_read_unlock();
222+
if (read_seqretry(&rename_lock, seq))
223+
goto rename_retry;
212224

213225
return len;
214226
}

0 commit comments

Comments
 (0)