diff options
author | Miklos Szeredi <mszeredi@redhat.com> | 2018-07-26 10:13:11 -0400 |
---|---|---|
committer | Miklos Szeredi <mszeredi@redhat.com> | 2018-07-26 10:13:11 -0400 |
commit | b8f95e5d13f5f0191dcb4b9113113d241636e7cb (patch) | |
tree | 91bafee58d39bf8b75a6f6aa81ad553d5b389dcb | |
parent | 45ff350bbd9d0f0977ff270a0d427c71520c0c37 (diff) |
fuse: umount should wait for all requests
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: 0d8e84b0432b ("fuse: simplify request abort")
Cc: <stable@vger.kernel.org> # v4.2
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
-rw-r--r-- | fs/fuse/dev.c | 23 | ||||
-rw-r--r-- | fs/fuse/fuse_i.h | 1 | ||||
-rw-r--r-- | fs/fuse/inode.c | 2 |
3 files changed, 22 insertions, 4 deletions
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index c8b197e4af9a..ec83b107c1a0 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c | |||
@@ -127,6 +127,16 @@ static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background) | |||
127 | return !fc->initialized || (for_background && fc->blocked); | 127 | return !fc->initialized || (for_background && fc->blocked); |
128 | } | 128 | } |
129 | 129 | ||
130 | static void fuse_drop_waiting(struct fuse_conn *fc) | ||
131 | { | ||
132 | if (fc->connected) { | ||
133 | atomic_dec(&fc->num_waiting); | ||
134 | } else if (atomic_dec_and_test(&fc->num_waiting)) { | ||
135 | /* wake up aborters */ | ||
136 | wake_up_all(&fc->blocked_waitq); | ||
137 | } | ||
138 | } | ||
139 | |||
130 | static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages, | 140 | static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages, |
131 | bool for_background) | 141 | bool for_background) |
132 | { | 142 | { |
@@ -175,7 +185,7 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages, | |||
175 | return req; | 185 | return req; |
176 | 186 | ||
177 | out: | 187 | out: |
178 | atomic_dec(&fc->num_waiting); | 188 | fuse_drop_waiting(fc); |
179 | return ERR_PTR(err); | 189 | return ERR_PTR(err); |
180 | } | 190 | } |
181 | 191 | ||
@@ -285,7 +295,7 @@ void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req) | |||
285 | 295 | ||
286 | if (test_bit(FR_WAITING, &req->flags)) { | 296 | if (test_bit(FR_WAITING, &req->flags)) { |
287 | __clear_bit(FR_WAITING, &req->flags); | 297 | __clear_bit(FR_WAITING, &req->flags); |
288 | atomic_dec(&fc->num_waiting); | 298 | fuse_drop_waiting(fc); |
289 | } | 299 | } |
290 | 300 | ||
291 | if (req->stolen_file) | 301 | if (req->stolen_file) |
@@ -371,7 +381,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req) | |||
371 | struct fuse_iqueue *fiq = &fc->iq; | 381 | struct fuse_iqueue *fiq = &fc->iq; |
372 | 382 | ||
373 | if (test_and_set_bit(FR_FINISHED, &req->flags)) | 383 | if (test_and_set_bit(FR_FINISHED, &req->flags)) |
374 | goto out_put_req; | 384 | goto put_request; |
375 | 385 | ||
376 | spin_lock(&fiq->waitq.lock); | 386 | spin_lock(&fiq->waitq.lock); |
377 | list_del_init(&req->intr_entry); | 387 | list_del_init(&req->intr_entry); |
@@ -400,7 +410,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req) | |||
400 | wake_up(&req->waitq); | 410 | wake_up(&req->waitq); |
401 | if (req->end) | 411 | if (req->end) |
402 | req->end(fc, req); | 412 | req->end(fc, req); |
403 | out_put_req: | 413 | put_request: |
404 | fuse_put_request(fc, req); | 414 | fuse_put_request(fc, req); |
405 | } | 415 | } |
406 | 416 | ||
@@ -2143,6 +2153,11 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort) | |||
2143 | } | 2153 | } |
2144 | EXPORT_SYMBOL_GPL(fuse_abort_conn); | 2154 | EXPORT_SYMBOL_GPL(fuse_abort_conn); |
2145 | 2155 | ||
2156 | void fuse_wait_aborted(struct fuse_conn *fc) | ||
2157 | { | ||
2158 | wait_event(fc->blocked_waitq, atomic_read(&fc->num_waiting) == 0); | ||
2159 | } | ||
2160 | |||
2146 | int fuse_dev_release(struct inode *inode, struct file *file) | 2161 | int fuse_dev_release(struct inode *inode, struct file *file) |
2147 | { | 2162 | { |
2148 | struct fuse_dev *fud = fuse_get_dev(file); | 2163 | struct fuse_dev *fud = fuse_get_dev(file); |
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 5256ad333b05..582b1756a011 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h | |||
@@ -862,6 +862,7 @@ void fuse_request_send_background_locked(struct fuse_conn *fc, | |||
862 | 862 | ||
863 | /* Abort all requests */ | 863 | /* Abort all requests */ |
864 | void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); | 864 | void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); |
865 | void fuse_wait_aborted(struct fuse_conn *fc); | ||
865 | 866 | ||
866 | /** | 867 | /** |
867 | * Invalidate inode attributes | 868 | * Invalidate inode attributes |
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index a24df8861b40..eeab70e7904d 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c | |||
@@ -394,6 +394,8 @@ static void fuse_put_super(struct super_block *sb) | |||
394 | fuse_send_destroy(fc); | 394 | fuse_send_destroy(fc); |
395 | 395 | ||
396 | fuse_abort_conn(fc, false); | 396 | fuse_abort_conn(fc, false); |
397 | fuse_wait_aborted(fc); | ||
398 | |||
397 | mutex_lock(&fuse_mutex); | 399 | mutex_lock(&fuse_mutex); |
398 | list_del(&fc->entry); | 400 | list_del(&fc->entry); |
399 | fuse_ctl_remove_conn(fc); | 401 | fuse_ctl_remove_conn(fc); |