History

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull vfs fixes from Al Viro: "Tmpfs readdir throughput regression fix (this cycle) + some -stable fodder all over the place. One missing bit is Miklos' tonight locks.c fix - NFS folks had already grabbed that one by the time I woke up ;-)" [ The locks.c fix came through the nfsd tree just moments ago ] * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: namespace: update event counter when umounting a deleted dentry 9p: use file_dentry() ceph: fix d_obtain_alias() misuses lockless next_positive() libfs.c: new helper - next_positive() dcache_{readdir,dir_lseek}(): don't bother with nested ->d_lock

Linus Torvalds committed 10 years ago

Commit 48c45652 parents 2728c57 e06b9334 files · +78 −48Browse files

Unified · Split

4 files
  1. fs/9p/vfs_file.c +3 −3
  2. fs/ceph/export.c +3 −7
  3. fs/libfs.c +71 −38
  4. fs/namespace.c +1 −0
fs/9p/vfs_file.c+3−3
@@ -74,7 +74,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) · 73 unmodified lines
74 v9fs_proto_dotu(v9ses));74 v9fs_proto_dotu(v9ses));
75 fid = file->private_data;75 fid = file->private_data;
76 if (!fid) {76 if (!fid) {
77 fid = v9fs_fid_clone(file->f_path.dentry);77 fid = v9fs_fid_clone(file_dentry(file));
78 if (IS_ERR(fid))78 if (IS_ERR(fid))
79 return PTR_ERR(fid);79 return PTR_ERR(fid);
80 80
@@ -100,7 +100,7 @@ int v9fs_file_open(struct inode *inode, struct file *file) · 19 unmodified lines
100 * because we want write after unlink usecase100 * because we want write after unlink usecase
101 * to work.101 * to work.
102 */102 */
103 fid = v9fs_writeback_fid(file->f_path.dentry);103 fid = v9fs_writeback_fid(file_dentry(file));
104 if (IS_ERR(fid)) {104 if (IS_ERR(fid)) {
105 err = PTR_ERR(fid);105 err = PTR_ERR(fid);
106 mutex_unlock(&v9inode->v_mutex);106 mutex_unlock(&v9inode->v_mutex);
@@ -516,7 +516,7 @@ v9fs_mmap_file_mmap(struct file *filp, struct vm_area_struct *vma) · 409 unmodified lines
516 * because we want write after unlink usecase516 * because we want write after unlink usecase
517 * to work.517 * to work.
518 */518 */
519 fid = v9fs_writeback_fid(filp->f_path.dentry);519 fid = v9fs_writeback_fid(file_dentry(filp));
520 if (IS_ERR(fid)) {520 if (IS_ERR(fid)) {
521 retval = PTR_ERR(fid);521 retval = PTR_ERR(fid);
522 mutex_unlock(&v9inode->v_mutex);522 mutex_unlock(&v9inode->v_mutex);
fs/ceph/export.c+3−7
@@ -95,10 +95,8 @@ static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino) · 94 unmodified lines
95 }95 }
96 96
97 dentry = d_obtain_alias(inode);97 dentry = d_obtain_alias(inode);
98 if (IS_ERR(dentry)) {98 if (IS_ERR(dentry))
99 iput(inode);
100 return dentry;99 return dentry;
101 }
102 err = ceph_init_dentry(dentry);100 err = ceph_init_dentry(dentry);
103 if (err < 0) {101 if (err < 0) {
104 dput(dentry);102 dput(dentry);
@@ -167,10 +165,8 @@ static struct dentry *__get_parent(struct super_block *sb, · 62 unmodified lines
167 return ERR_PTR(-ENOENT);165 return ERR_PTR(-ENOENT);
168 166
169 dentry = d_obtain_alias(inode);167 dentry = d_obtain_alias(inode);
170 if (IS_ERR(dentry)) {168 if (IS_ERR(dentry))
171 iput(inode);
172 return dentry;169 return dentry;
173 }
174 err = ceph_init_dentry(dentry);170 err = ceph_init_dentry(dentry);
175 if (err < 0) {171 if (err < 0) {
176 dput(dentry);172 dput(dentry);
@@ -210,7 +206,7 @@ static struct dentry *ceph_fh_to_parent(struct super_block *sb, · 33 unmodified lines
210 206
211 dout("fh_to_parent %llx\n", cfh->parent_ino);207 dout("fh_to_parent %llx\n", cfh->parent_ino);
212 dentry = __get_parent(sb, NULL, cfh->ino);208 dentry = __get_parent(sb, NULL, cfh->ino);
213 if (IS_ERR(dentry) && PTR_ERR(dentry) == -ENOENT)209 if (unlikely(dentry == ERR_PTR(-ENOENT)))
214 dentry = __fh_to_dentry(sb, cfh->parent_ino);210 dentry = __fh_to_dentry(sb, cfh->parent_ino);
215 return dentry;211 return dentry;
216}212}
fs/libfs.c+71−38
@@ -84,6 +84,61 @@ int dcache_dir_close(struct inode *inode, struct file *file) · 83 unmodified lines
84}84}
85EXPORT_SYMBOL(dcache_dir_close);85EXPORT_SYMBOL(dcache_dir_close);
86 86
87/* parent is locked at least shared */
88static struct dentry *next_positive(struct dentry *parent,
89 struct list_head *from,
90 int count)
91{
92 unsigned *seq = &parent->d_inode->i_dir_seq, n;
93 struct dentry *res;
94 struct list_head *p;
95 bool skipped;
96 int i;
97
98retry:
99 i = count;
100 skipped = false;
101 n = smp_load_acquire(seq) & ~1;
102 res = NULL;
103 rcu_read_lock();
104 for (p = from->next; p != &parent->d_subdirs; p = p->next) {
105 struct dentry *d = list_entry(p, struct dentry, d_child);
106 if (!simple_positive(d)) {
107 skipped = true;
108 } else if (!--i) {
109 res = d;
110 break;
111 }
112 }
113 rcu_read_unlock();
114 if (skipped) {
115 smp_rmb();
116 if (unlikely(*seq != n))
117 goto retry;
118 }
119 return res;
120}
121
122static void move_cursor(struct dentry *cursor, struct list_head *after)
123{
124 struct dentry *parent = cursor->d_parent;
125 unsigned n, *seq = &parent->d_inode->i_dir_seq;
126 spin_lock(&parent->d_lock);
127 for (;;) {
128 n = *seq;
129 if (!(n & 1) && cmpxchg(seq, n, n + 1) == n)
130 break;
131 cpu_relax();
132 }
133 __list_del(cursor->d_child.prev, cursor->d_child.next);
134 if (after)
135 list_add(&cursor->d_child, after);
136 else
137 list_add_tail(&cursor->d_child, &parent->d_subdirs);
138 smp_store_release(seq, n + 2);
139 spin_unlock(&parent->d_lock);
140}
141
87loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)142loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
88{143{
89 struct dentry *dentry = file->f_path.dentry;144 struct dentry *dentry = file->f_path.dentry;
@@ -99,25 +154,14 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence) · 9 unmodified lines
99 if (offset != file->f_pos) {154 if (offset != file->f_pos) {
100 file->f_pos = offset;155 file->f_pos = offset;
101 if (file->f_pos >= 2) {156 if (file->f_pos >= 2) {
102 struct list_head *p;
103 struct dentry *cursor = file->private_data;157 struct dentry *cursor = file->private_data;
158 struct dentry *to;
104 loff_t n = file->f_pos - 2;159 loff_t n = file->f_pos - 2;
105 160
106 spin_lock(&dentry->d_lock);161 inode_lock_shared(dentry->d_inode);
107 /* d_lock not required for cursor */162 to = next_positive(dentry, &dentry->d_subdirs, n);
108 list_del(&cursor->d_child);163 move_cursor(cursor, to ? &to->d_child : NULL);
109 p = dentry->d_subdirs.next;164 inode_unlock_shared(dentry->d_inode);
110 while (n && p != &dentry->d_subdirs) {
111 struct dentry *next;
112 next = list_entry(p, struct dentry, d_child);
113 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
114 if (simple_positive(next))
115 n--;
116 spin_unlock(&next->d_lock);
117 p = p->next;
118 }
119 list_add_tail(&cursor->d_child, p);
120 spin_unlock(&dentry->d_lock);
121 }165 }
122 }166 }
123 return offset;167 return offset;
@@ -140,36 +184,25 @@ int dcache_readdir(struct file *file, struct dir_context *ctx) · 16 unmodified lines
140{184{
141 struct dentry *dentry = file->f_path.dentry;185 struct dentry *dentry = file->f_path.dentry;
142 struct dentry *cursor = file->private_data;186 struct dentry *cursor = file->private_data;
143 struct list_head *p, *q = &cursor->d_child;187 struct list_head *p = &cursor->d_child;
188 struct dentry *next;
189 bool moved = false;
144 190
145 if (!dir_emit_dots(file, ctx))191 if (!dir_emit_dots(file, ctx))
146 return 0;192 return 0;
147 spin_lock(&dentry->d_lock);
148 if (ctx->pos == 2)
149 list_move(q, &dentry->d_subdirs);
150 193
151 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {194 if (ctx->pos == 2)
152 struct dentry *next = list_entry(p, struct dentry, d_child);195 p = &dentry->d_subdirs;
153 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);196 while ((next = next_positive(dentry, p, 1)) != NULL) {
154 if (!simple_positive(next)) {
155 spin_unlock(&next->d_lock);
156 continue;
157 }
158
159 spin_unlock(&next->d_lock);
160 spin_unlock(&dentry->d_lock);
161 if (!dir_emit(ctx, next->d_name.name, next->d_name.len,197 if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
162 d_inode(next)->i_ino, dt_type(d_inode(next))))198 d_inode(next)->i_ino, dt_type(d_inode(next))))
163 return 0;199 break;
164 spin_lock(&dentry->d_lock);200 moved = true;
165 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);201 p = &next->d_child;
166 /* next is still alive */
167 list_move(q, p);
168 spin_unlock(&next->d_lock);
169 p = q;
170 ctx->pos++;202 ctx->pos++;
171 }203 }
172 spin_unlock(&dentry->d_lock);204 if (moved)
205 move_cursor(cursor, p);
173 return 0;206 return 0;
174}207}
175EXPORT_SYMBOL(dcache_readdir);208EXPORT_SYMBOL(dcache_readdir);
fs/namespace.c+1−0
@@ -1562,6 +1562,7 @@ void __detach_mounts(struct dentry *dentry) · 1561 unmodified lines
1562 goto out_unlock;1562 goto out_unlock;
1563 1563
1564 lock_mount_hash();1564 lock_mount_hash();
1565 event++;
1565 while (!hlist_empty(&mp->m_list)) {1566 while (!hlist_empty(&mp->m_list)) {
1566 mnt = hlist_entry(mp->m_list.first, struct mount, mnt_mp_list);1567 mnt = hlist_entry(mp->m_list.first, struct mount, mnt_mp_list);
1567 if (mnt->mnt.mnt_flags & MNT_UMOUNT) {1568 if (mnt->mnt.mnt_flags & MNT_UMOUNT) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t