aboutsummaryrefslogtreecommitdiffstats
path: root/fs/fuse/dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/fuse/dev.c')
-rw-r--r--fs/fuse/dev.c121
1 files changed, 90 insertions, 31 deletions
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index fba571648a8e..ba76b68c52ff 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1,6 +1,6 @@
1/* 1/*
2 FUSE: Filesystem in Userspace 2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> 3 Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
4 4
5 This program can be distributed under the terms of the GNU GPL. 5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING. 6 See the file COPYING.
@@ -269,7 +269,7 @@ static void flush_bg_queue(struct fuse_conn *fc)
269 * Called with fc->lock, unlocks it 269 * Called with fc->lock, unlocks it
270 */ 270 */
271static void request_end(struct fuse_conn *fc, struct fuse_req *req) 271static void request_end(struct fuse_conn *fc, struct fuse_req *req)
272 __releases(fc->lock) 272__releases(&fc->lock)
273{ 273{
274 void (*end) (struct fuse_conn *, struct fuse_req *) = req->end; 274 void (*end) (struct fuse_conn *, struct fuse_req *) = req->end;
275 req->end = NULL; 275 req->end = NULL;
@@ -281,7 +281,8 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
281 fc->blocked = 0; 281 fc->blocked = 0;
282 wake_up_all(&fc->blocked_waitq); 282 wake_up_all(&fc->blocked_waitq);
283 } 283 }
284 if (fc->num_background == FUSE_CONGESTION_THRESHOLD) { 284 if (fc->num_background == FUSE_CONGESTION_THRESHOLD &&
285 fc->connected) {
285 clear_bdi_congested(&fc->bdi, READ); 286 clear_bdi_congested(&fc->bdi, READ);
286 clear_bdi_congested(&fc->bdi, WRITE); 287 clear_bdi_congested(&fc->bdi, WRITE);
287 } 288 }
@@ -293,13 +294,13 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
293 wake_up(&req->waitq); 294 wake_up(&req->waitq);
294 if (end) 295 if (end)
295 end(fc, req); 296 end(fc, req);
296 else 297 fuse_put_request(fc, req);
297 fuse_put_request(fc, req);
298} 298}
299 299
300static void wait_answer_interruptible(struct fuse_conn *fc, 300static void wait_answer_interruptible(struct fuse_conn *fc,
301 struct fuse_req *req) 301 struct fuse_req *req)
302 __releases(fc->lock) __acquires(fc->lock) 302__releases(&fc->lock)
303__acquires(&fc->lock)
303{ 304{
304 if (signal_pending(current)) 305 if (signal_pending(current))
305 return; 306 return;
@@ -317,7 +318,8 @@ static void queue_interrupt(struct fuse_conn *fc, struct fuse_req *req)
317} 318}
318 319
319static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req) 320static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
320 __releases(fc->lock) __acquires(fc->lock) 321__releases(&fc->lock)
322__acquires(&fc->lock)
321{ 323{
322 if (!fc->no_interrupt) { 324 if (!fc->no_interrupt) {
323 /* Any signal may interrupt this */ 325 /* Any signal may interrupt this */
@@ -380,7 +382,7 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
380 } 382 }
381} 383}
382 384
383void request_send(struct fuse_conn *fc, struct fuse_req *req) 385void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
384{ 386{
385 req->isreply = 1; 387 req->isreply = 1;
386 spin_lock(&fc->lock); 388 spin_lock(&fc->lock);
@@ -399,8 +401,8 @@ void request_send(struct fuse_conn *fc, struct fuse_req *req)
399 spin_unlock(&fc->lock); 401 spin_unlock(&fc->lock);
400} 402}
401 403
402static void request_send_nowait_locked(struct fuse_conn *fc, 404static void fuse_request_send_nowait_locked(struct fuse_conn *fc,
403 struct fuse_req *req) 405 struct fuse_req *req)
404{ 406{
405 req->background = 1; 407 req->background = 1;
406 fc->num_background++; 408 fc->num_background++;
@@ -414,11 +416,11 @@ static void request_send_nowait_locked(struct fuse_conn *fc,
414 flush_bg_queue(fc); 416 flush_bg_queue(fc);
415} 417}
416 418
417static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req) 419static void fuse_request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
418{ 420{
419 spin_lock(&fc->lock); 421 spin_lock(&fc->lock);
420 if (fc->connected) { 422 if (fc->connected) {
421 request_send_nowait_locked(fc, req); 423 fuse_request_send_nowait_locked(fc, req);
422 spin_unlock(&fc->lock); 424 spin_unlock(&fc->lock);
423 } else { 425 } else {
424 req->out.h.error = -ENOTCONN; 426 req->out.h.error = -ENOTCONN;
@@ -426,16 +428,16 @@ static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
426 } 428 }
427} 429}
428 430
429void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req) 431void fuse_request_send_noreply(struct fuse_conn *fc, struct fuse_req *req)
430{ 432{
431 req->isreply = 0; 433 req->isreply = 0;
432 request_send_nowait(fc, req); 434 fuse_request_send_nowait(fc, req);
433} 435}
434 436
435void request_send_background(struct fuse_conn *fc, struct fuse_req *req) 437void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req)
436{ 438{
437 req->isreply = 1; 439 req->isreply = 1;
438 request_send_nowait(fc, req); 440 fuse_request_send_nowait(fc, req);
439} 441}
440 442
441/* 443/*
@@ -443,10 +445,11 @@ void request_send_background(struct fuse_conn *fc, struct fuse_req *req)
443 * 445 *
444 * fc->connected must have been checked previously 446 * fc->connected must have been checked previously
445 */ 447 */
446void request_send_background_locked(struct fuse_conn *fc, struct fuse_req *req) 448void fuse_request_send_background_locked(struct fuse_conn *fc,
449 struct fuse_req *req)
447{ 450{
448 req->isreply = 1; 451 req->isreply = 1;
449 request_send_nowait_locked(fc, req); 452 fuse_request_send_nowait_locked(fc, req);
450} 453}
451 454
452/* 455/*
@@ -539,8 +542,8 @@ static int fuse_copy_fill(struct fuse_copy_state *cs)
539 BUG_ON(!cs->nr_segs); 542 BUG_ON(!cs->nr_segs);
540 cs->seglen = cs->iov[0].iov_len; 543 cs->seglen = cs->iov[0].iov_len;
541 cs->addr = (unsigned long) cs->iov[0].iov_base; 544 cs->addr = (unsigned long) cs->iov[0].iov_base;
542 cs->iov ++; 545 cs->iov++;
543 cs->nr_segs --; 546 cs->nr_segs--;
544 } 547 }
545 down_read(&current->mm->mmap_sem); 548 down_read(&current->mm->mmap_sem);
546 err = get_user_pages(current, current->mm, cs->addr, 1, cs->write, 0, 549 err = get_user_pages(current, current->mm, cs->addr, 1, cs->write, 0,
@@ -589,9 +592,11 @@ static int fuse_copy_page(struct fuse_copy_state *cs, struct page *page,
589 kunmap_atomic(mapaddr, KM_USER1); 592 kunmap_atomic(mapaddr, KM_USER1);
590 } 593 }
591 while (count) { 594 while (count) {
592 int err; 595 if (!cs->len) {
593 if (!cs->len && (err = fuse_copy_fill(cs))) 596 int err = fuse_copy_fill(cs);
594 return err; 597 if (err)
598 return err;
599 }
595 if (page) { 600 if (page) {
596 void *mapaddr = kmap_atomic(page, KM_USER1); 601 void *mapaddr = kmap_atomic(page, KM_USER1);
597 void *buf = mapaddr + offset; 602 void *buf = mapaddr + offset;
@@ -631,9 +636,11 @@ static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes,
631static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size) 636static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size)
632{ 637{
633 while (size) { 638 while (size) {
634 int err; 639 if (!cs->len) {
635 if (!cs->len && (err = fuse_copy_fill(cs))) 640 int err = fuse_copy_fill(cs);
636 return err; 641 if (err)
642 return err;
643 }
637 fuse_copy_do(cs, &val, &size); 644 fuse_copy_do(cs, &val, &size);
638 } 645 }
639 return 0; 646 return 0;
@@ -664,6 +671,8 @@ static int request_pending(struct fuse_conn *fc)
664 671
665/* Wait until a request is available on the pending list */ 672/* Wait until a request is available on the pending list */
666static void request_wait(struct fuse_conn *fc) 673static void request_wait(struct fuse_conn *fc)
674__releases(&fc->lock)
675__acquires(&fc->lock)
667{ 676{
668 DECLARE_WAITQUEUE(wait, current); 677 DECLARE_WAITQUEUE(wait, current);
669 678
@@ -691,7 +700,7 @@ static void request_wait(struct fuse_conn *fc)
691 */ 700 */
692static int fuse_read_interrupt(struct fuse_conn *fc, struct fuse_req *req, 701static int fuse_read_interrupt(struct fuse_conn *fc, struct fuse_req *req,
693 const struct iovec *iov, unsigned long nr_segs) 702 const struct iovec *iov, unsigned long nr_segs)
694 __releases(fc->lock) 703__releases(&fc->lock)
695{ 704{
696 struct fuse_copy_state cs; 705 struct fuse_copy_state cs;
697 struct fuse_in_header ih; 706 struct fuse_in_header ih;
@@ -813,6 +822,40 @@ static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
813 return err; 822 return err;
814} 823}
815 824
825static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size,
826 struct fuse_copy_state *cs)
827{
828 struct fuse_notify_poll_wakeup_out outarg;
829 int err = -EINVAL;
830
831 if (size != sizeof(outarg))
832 goto err;
833
834 err = fuse_copy_one(cs, &outarg, sizeof(outarg));
835 if (err)
836 goto err;
837
838 fuse_copy_finish(cs);
839 return fuse_notify_poll_wakeup(fc, &outarg);
840
841err:
842 fuse_copy_finish(cs);
843 return err;
844}
845
846static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
847 unsigned int size, struct fuse_copy_state *cs)
848{
849 switch (code) {
850 case FUSE_NOTIFY_POLL:
851 return fuse_notify_poll(fc, size, cs);
852
853 default:
854 fuse_copy_finish(cs);
855 return -EINVAL;
856 }
857}
858
816/* Look up request on processing list by unique ID */ 859/* Look up request on processing list by unique ID */
817static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique) 860static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique)
818{ 861{
@@ -876,9 +919,22 @@ static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
876 err = fuse_copy_one(&cs, &oh, sizeof(oh)); 919 err = fuse_copy_one(&cs, &oh, sizeof(oh));
877 if (err) 920 if (err)
878 goto err_finish; 921 goto err_finish;
922
923 err = -EINVAL;
924 if (oh.len != nbytes)
925 goto err_finish;
926
927 /*
928 * Zero oh.unique indicates unsolicited notification message
929 * and error contains notification code.
930 */
931 if (!oh.unique) {
932 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), &cs);
933 return err ? err : nbytes;
934 }
935
879 err = -EINVAL; 936 err = -EINVAL;
880 if (!oh.unique || oh.error <= -1000 || oh.error > 0 || 937 if (oh.error <= -1000 || oh.error > 0)
881 oh.len != nbytes)
882 goto err_finish; 938 goto err_finish;
883 939
884 spin_lock(&fc->lock); 940 spin_lock(&fc->lock);
@@ -966,6 +1022,8 @@ static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
966 * This function releases and reacquires fc->lock 1022 * This function releases and reacquires fc->lock
967 */ 1023 */
968static void end_requests(struct fuse_conn *fc, struct list_head *head) 1024static void end_requests(struct fuse_conn *fc, struct list_head *head)
1025__releases(&fc->lock)
1026__acquires(&fc->lock)
969{ 1027{
970 while (!list_empty(head)) { 1028 while (!list_empty(head)) {
971 struct fuse_req *req; 1029 struct fuse_req *req;
@@ -988,7 +1046,8 @@ static void end_requests(struct fuse_conn *fc, struct list_head *head)
988 * locked). 1046 * locked).
989 */ 1047 */
990static void end_io_requests(struct fuse_conn *fc) 1048static void end_io_requests(struct fuse_conn *fc)
991 __releases(fc->lock) __acquires(fc->lock) 1049__releases(&fc->lock)
1050__acquires(&fc->lock)
992{ 1051{
993 while (!list_empty(&fc->io)) { 1052 while (!list_empty(&fc->io)) {
994 struct fuse_req *req = 1053 struct fuse_req *req =
@@ -1002,11 +1061,11 @@ static void end_io_requests(struct fuse_conn *fc)
1002 wake_up(&req->waitq); 1061 wake_up(&req->waitq);
1003 if (end) { 1062 if (end) {
1004 req->end = NULL; 1063 req->end = NULL;
1005 /* The end function will consume this reference */
1006 __fuse_get_request(req); 1064 __fuse_get_request(req);
1007 spin_unlock(&fc->lock); 1065 spin_unlock(&fc->lock);
1008 wait_event(req->waitq, !req->locked); 1066 wait_event(req->waitq, !req->locked);
1009 end(fc, req); 1067 end(fc, req);
1068 fuse_put_request(fc, req);
1010 spin_lock(&fc->lock); 1069 spin_lock(&fc->lock);
1011 } 1070 }
1012 } 1071 }