[fuse] fix deadlock between fuse_put_super() and request_end(), try #2

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 solution is to move the fput() outside the region protected by
sbput_sem.

Signed-off-by: Miklos Szeredi <miklos@szeredi.hu>

+11 -2
+11 -2
fs/fuse/dev.c
··· 128 } 129 } 130 131 void fuse_release_background(struct fuse_conn *fc, struct fuse_req *req) 132 { 133 iput(req->inode); 134 iput(req->inode2); 135 - if (req->file) 136 - fput(req->file); 137 spin_lock(&fc->lock); 138 list_del(&req->bg_entry); 139 if (fc->num_background == FUSE_MAX_BACKGROUND) { ··· 182 if (fc->mounted) 183 fuse_release_background(fc, req); 184 up_read(&fc->sbput_sem); 185 if (end) 186 end(fc, req); 187 else
··· 128 } 129 } 130 131 + /* 132 + * Called with sbput_sem held for read (request_end) or write 133 + * (fuse_put_super). By the time fuse_put_super() is finished, all 134 + * inodes belonging to background requests must be released, so the 135 + * iputs have to be done within the locked region. 136 + */ 137 void fuse_release_background(struct fuse_conn *fc, struct fuse_req *req) 138 { 139 iput(req->inode); 140 iput(req->inode2); 141 spin_lock(&fc->lock); 142 list_del(&req->bg_entry); 143 if (fc->num_background == FUSE_MAX_BACKGROUND) { ··· 178 if (fc->mounted) 179 fuse_release_background(fc, req); 180 up_read(&fc->sbput_sem); 181 + 182 + /* fput must go outside sbput_sem, otherwise it can deadlock */ 183 + if (req->file) 184 + fput(req->file); 185 + 186 if (end) 187 end(fc, req); 188 else