Commit c4d67ef8 authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Kleber Sacilotto de Souza

fuse: umount should wait for all requests

BugLink: https://bugs.launchpad.net/bugs/1792392

commit b8f95e5d upstream.

fuse_abort_conn() does not guarantee that all async requests have actually
finished aborting (i.e. their ->end() function is called).  This could
actually result in still used inodes after umount.

Add a helper to wait until all requests are fully done.  This is done by
looking at the "num_waiting" counter.  When this counter drops to zero, we
can be sure that no more requests are outstanding.

Fixes: 0d8e84b0 ("fuse: simplify request abort")
Cc: <stable@vger.kernel.org> # v4.2
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 9e768395
...@@ -144,6 +144,16 @@ static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background) ...@@ -144,6 +144,16 @@ static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background)
return !fc->initialized || (for_background && fc->blocked); return !fc->initialized || (for_background && fc->blocked);
} }
static void fuse_drop_waiting(struct fuse_conn *fc)
{
if (fc->connected) {
atomic_dec(&fc->num_waiting);
} else if (atomic_dec_and_test(&fc->num_waiting)) {
/* wake up aborters */
wake_up_all(&fc->blocked_waitq);
}
}
static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages, static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
bool for_background) bool for_background)
{ {
...@@ -194,7 +204,7 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages, ...@@ -194,7 +204,7 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
return req; return req;
out: out:
atomic_dec(&fc->num_waiting); fuse_drop_waiting(fc);
return ERR_PTR(err); return ERR_PTR(err);
} }
...@@ -301,7 +311,7 @@ void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req) ...@@ -301,7 +311,7 @@ void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
if (test_bit(FR_WAITING, &req->flags)) { if (test_bit(FR_WAITING, &req->flags)) {
__clear_bit(FR_WAITING, &req->flags); __clear_bit(FR_WAITING, &req->flags);
atomic_dec(&fc->num_waiting); fuse_drop_waiting(fc);
} }
if (req->stolen_file) if (req->stolen_file)
...@@ -387,7 +397,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req) ...@@ -387,7 +397,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
struct fuse_iqueue *fiq = &fc->iq; struct fuse_iqueue *fiq = &fc->iq;
if (test_and_set_bit(FR_FINISHED, &req->flags)) if (test_and_set_bit(FR_FINISHED, &req->flags))
goto out_put_req; goto put_request;
spin_lock(&fiq->waitq.lock); spin_lock(&fiq->waitq.lock);
list_del_init(&req->intr_entry); list_del_init(&req->intr_entry);
...@@ -417,7 +427,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req) ...@@ -417,7 +427,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
wake_up(&req->waitq); wake_up(&req->waitq);
if (req->end) if (req->end)
req->end(fc, req); req->end(fc, req);
out_put_req: put_request:
fuse_put_request(fc, req); fuse_put_request(fc, req);
} }
...@@ -2205,6 +2215,11 @@ void fuse_abort_conn(struct fuse_conn *fc) ...@@ -2205,6 +2215,11 @@ void fuse_abort_conn(struct fuse_conn *fc)
} }
EXPORT_SYMBOL_GPL(fuse_abort_conn); EXPORT_SYMBOL_GPL(fuse_abort_conn);
void fuse_wait_aborted(struct fuse_conn *fc)
{
wait_event(fc->blocked_waitq, atomic_read(&fc->num_waiting) == 0);
}
int fuse_dev_release(struct inode *inode, struct file *file) int fuse_dev_release(struct inode *inode, struct file *file)
{ {
struct fuse_dev *fud = fuse_get_dev(file); struct fuse_dev *fud = fuse_get_dev(file);
......
...@@ -850,6 +850,7 @@ void fuse_request_send_background_locked(struct fuse_conn *fc, ...@@ -850,6 +850,7 @@ void fuse_request_send_background_locked(struct fuse_conn *fc,
/* Abort all requests */ /* Abort all requests */
void fuse_abort_conn(struct fuse_conn *fc); void fuse_abort_conn(struct fuse_conn *fc);
void fuse_wait_aborted(struct fuse_conn *fc);
/** /**
* Invalidate inode attributes * Invalidate inode attributes
......
...@@ -387,6 +387,8 @@ static void fuse_put_super(struct super_block *sb) ...@@ -387,6 +387,8 @@ static void fuse_put_super(struct super_block *sb)
fuse_send_destroy(fc); fuse_send_destroy(fc);
fuse_abort_conn(fc); fuse_abort_conn(fc);
fuse_wait_aborted(fc);
mutex_lock(&fuse_mutex); mutex_lock(&fuse_mutex);
list_del(&fc->entry); list_del(&fc->entry);
fuse_ctl_remove_conn(fc); fuse_ctl_remove_conn(fc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment