aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fuse/inode.c
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2006-04-11 15:14:26 -0400
committerMiklos Szeredi <miklos@szeredi.hu>2006-04-11 15:14:26 -0400
commit73ce8355c243a434524a34c05cc417dd0467996e (patch)
treea5bc5bfb31c41a5806caf763533943e7411e6543 /fs/fuse/inode.c
parent2514395ef88b46e895726a8d40966cb83de7940c (diff)
[fuse] fix deadlock between fuse_put_super() and request_end()
A deadlock was possible, when the last reference to the superblock was held due to a background request containing a file reference. Releasing the file would release the vfsmount which in turn would release the superblock. Since sbput_sem is held during the fput() and fuse_put_super() tries to acquire this same semaphore, a deadlock results. The chosen soltuion is to get rid of sbput_sem, and instead use the spinlock to ensure the referenced inodes/file are released only once. Since the actual release may sleep, defer these outside the locked region, but using local variables instead of the structure members. This is a much more rubust solution. Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>
Diffstat (limited to 'fs/fuse/inode.c')
-rw-r--r--fs/fuse/inode.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index fd34037b0588..43a6fc0db8a7 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -204,17 +204,26 @@ static void fuse_put_super(struct super_block *sb)
204{ 204{
205 struct fuse_conn *fc = get_fuse_conn_super(sb); 205 struct fuse_conn *fc = get_fuse_conn_super(sb);
206 206
207 down_write(&fc->sbput_sem);
208 while (!list_empty(&fc->background))
209 fuse_release_background(fc,
210 list_entry(fc->background.next,
211 struct fuse_req, bg_entry));
212
213 spin_lock(&fc->lock); 207 spin_lock(&fc->lock);
214 fc->mounted = 0;
215 fc->connected = 0; 208 fc->connected = 0;
209 while (!list_empty(&fc->background)) {
210 struct fuse_req *req = list_entry(fc->background.next,
211 struct fuse_req, bg_entry);
212 struct inode *inode = req->inode;
213 struct inode *inode2 = req->inode2;
214
215 /* File would hold a reference to vfsmount */
216 BUG_ON(req->file);
217 req->inode = NULL;
218 req->inode2 = NULL;
219 fuse_remove_background(fc, req);
220
221 spin_unlock(&fc->lock);
222 iput(inode);
223 iput(inode2);
224 spin_lock(&fc->lock);
225 }
216 spin_unlock(&fc->lock); 226 spin_unlock(&fc->lock);
217 up_write(&fc->sbput_sem);
218 /* Flush all readers on this fs */ 227 /* Flush all readers on this fs */
219 kill_fasync(&fc->fasync, SIGIO, POLL_IN); 228 kill_fasync(&fc->fasync, SIGIO, POLL_IN);
220 wake_up_all(&fc->waitq); 229 wake_up_all(&fc->waitq);
@@ -386,7 +395,6 @@ static struct fuse_conn *new_conn(void)
386 INIT_LIST_HEAD(&fc->processing); 395 INIT_LIST_HEAD(&fc->processing);
387 INIT_LIST_HEAD(&fc->io); 396 INIT_LIST_HEAD(&fc->io);
388 INIT_LIST_HEAD(&fc->background); 397 INIT_LIST_HEAD(&fc->background);
389 init_rwsem(&fc->sbput_sem);
390 kobj_set_kset_s(fc, connections_subsys); 398 kobj_set_kset_s(fc, connections_subsys);
391 kobject_init(&fc->kobj); 399 kobject_init(&fc->kobj);
392 atomic_set(&fc->num_waiting, 0); 400 atomic_set(&fc->num_waiting, 0);
@@ -541,7 +549,6 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
541 goto err_free_req; 549 goto err_free_req;
542 550
543 sb->s_root = root_dentry; 551 sb->s_root = root_dentry;
544 fc->mounted = 1;
545 fc->connected = 1; 552 fc->connected = 1;
546 kobject_get(&fc->kobj); 553 kobject_get(&fc->kobj);
547 file->private_data = fc; 554 file->private_data = fc;