aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 20:01:20 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 20:01:20 -0500
commit5fec8bdbf9a1c4df4ad3f20e52aa2d8caed490c8 (patch)
treee8c1b1a9f3ea6b6a0edb972f082d0d7338c98af4
parent59e3af21e94bd56f6a31ba774786a2bfc753581b (diff)
parent5d9ec854bfb6f1e122b1d96b344164a71eac5be8 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse: fuse: clean up annotations of fc->lock fuse: fix sparse warning in ioctl fuse: update interface version fuse: add fuse_conn->release() fuse: separate out fuse_conn_init() from new_conn() fuse: add fuse_ prefix to several functions fuse: implement poll support fuse: implement unsolicited notification fuse: add file kernel handle fuse: implement ioctl support fuse: don't let fuse_req->end() put the base reference fuse: move FUSE_MINOR to miscdevice.h fuse: style fixes
-rw-r--r--fs/fuse/control.c6
-rw-r--r--fs/fuse/dev.c113
-rw-r--r--fs/fuse/dir.c48
-rw-r--r--fs/fuse/file.c457
-rw-r--r--fs/fuse/fuse_i.h83
-rw-r--r--fs/fuse/inode.c157
-rw-r--r--include/linux/fuse.h79
-rw-r--r--include/linux/miscdevice.h42
8 files changed, 783 insertions, 202 deletions
diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index 4f3cab321415..99c99dfb0373 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.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.
@@ -48,11 +48,13 @@ static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf,
48 size_t size; 48 size_t size;
49 49
50 if (!*ppos) { 50 if (!*ppos) {
51 long value;
51 struct fuse_conn *fc = fuse_ctl_file_conn_get(file); 52 struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
52 if (!fc) 53 if (!fc)
53 return 0; 54 return 0;
54 55
55 file->private_data=(void *)(long)atomic_read(&fc->num_waiting); 56 value = atomic_read(&fc->num_waiting);
57 file->private_data = (void *)value;
56 fuse_conn_put(fc); 58 fuse_conn_put(fc);
57 } 59 }
58 size = sprintf(tmp, "%ld\n", (long)file->private_data); 60 size = sprintf(tmp, "%ld\n", (long)file->private_data);
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index fba571648a8e..e0c7ada08a1f 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;
@@ -293,13 +293,13 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
293 wake_up(&req->waitq); 293 wake_up(&req->waitq);
294 if (end) 294 if (end)
295 end(fc, req); 295 end(fc, req);
296 else 296 fuse_put_request(fc, req);
297 fuse_put_request(fc, req);
298} 297}
299 298
300static void wait_answer_interruptible(struct fuse_conn *fc, 299static void wait_answer_interruptible(struct fuse_conn *fc,
301 struct fuse_req *req) 300 struct fuse_req *req)
302 __releases(fc->lock) __acquires(fc->lock) 301__releases(&fc->lock)
302__acquires(&fc->lock)
303{ 303{
304 if (signal_pending(current)) 304 if (signal_pending(current))
305 return; 305 return;
@@ -317,7 +317,8 @@ static void queue_interrupt(struct fuse_conn *fc, struct fuse_req *req)
317} 317}
318 318
319static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req) 319static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
320 __releases(fc->lock) __acquires(fc->lock) 320__releases(&fc->lock)
321__acquires(&fc->lock)
321{ 322{
322 if (!fc->no_interrupt) { 323 if (!fc->no_interrupt) {
323 /* Any signal may interrupt this */ 324 /* Any signal may interrupt this */
@@ -380,7 +381,7 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
380 } 381 }
381} 382}
382 383
383void request_send(struct fuse_conn *fc, struct fuse_req *req) 384void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
384{ 385{
385 req->isreply = 1; 386 req->isreply = 1;
386 spin_lock(&fc->lock); 387 spin_lock(&fc->lock);
@@ -399,8 +400,8 @@ void request_send(struct fuse_conn *fc, struct fuse_req *req)
399 spin_unlock(&fc->lock); 400 spin_unlock(&fc->lock);
400} 401}
401 402
402static void request_send_nowait_locked(struct fuse_conn *fc, 403static void fuse_request_send_nowait_locked(struct fuse_conn *fc,
403 struct fuse_req *req) 404 struct fuse_req *req)
404{ 405{
405 req->background = 1; 406 req->background = 1;
406 fc->num_background++; 407 fc->num_background++;
@@ -414,11 +415,11 @@ static void request_send_nowait_locked(struct fuse_conn *fc,
414 flush_bg_queue(fc); 415 flush_bg_queue(fc);
415} 416}
416 417
417static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req) 418static void fuse_request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
418{ 419{
419 spin_lock(&fc->lock); 420 spin_lock(&fc->lock);
420 if (fc->connected) { 421 if (fc->connected) {
421 request_send_nowait_locked(fc, req); 422 fuse_request_send_nowait_locked(fc, req);
422 spin_unlock(&fc->lock); 423 spin_unlock(&fc->lock);
423 } else { 424 } else {
424 req->out.h.error = -ENOTCONN; 425 req->out.h.error = -ENOTCONN;
@@ -426,16 +427,16 @@ static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
426 } 427 }
427} 428}
428 429
429void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req) 430void fuse_request_send_noreply(struct fuse_conn *fc, struct fuse_req *req)
430{ 431{
431 req->isreply = 0; 432 req->isreply = 0;
432 request_send_nowait(fc, req); 433 fuse_request_send_nowait(fc, req);
433} 434}
434 435
435void request_send_background(struct fuse_conn *fc, struct fuse_req *req) 436void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req)
436{ 437{
437 req->isreply = 1; 438 req->isreply = 1;
438 request_send_nowait(fc, req); 439 fuse_request_send_nowait(fc, req);
439} 440}
440 441
441/* 442/*
@@ -443,10 +444,11 @@ void request_send_background(struct fuse_conn *fc, struct fuse_req *req)
443 * 444 *
444 * fc->connected must have been checked previously 445 * fc->connected must have been checked previously
445 */ 446 */
446void request_send_background_locked(struct fuse_conn *fc, struct fuse_req *req) 447void fuse_request_send_background_locked(struct fuse_conn *fc,
448 struct fuse_req *req)
447{ 449{
448 req->isreply = 1; 450 req->isreply = 1;
449 request_send_nowait_locked(fc, req); 451 fuse_request_send_nowait_locked(fc, req);
450} 452}
451 453
452/* 454/*
@@ -539,8 +541,8 @@ static int fuse_copy_fill(struct fuse_copy_state *cs)
539 BUG_ON(!cs->nr_segs); 541 BUG_ON(!cs->nr_segs);
540 cs->seglen = cs->iov[0].iov_len; 542 cs->seglen = cs->iov[0].iov_len;
541 cs->addr = (unsigned long) cs->iov[0].iov_base; 543 cs->addr = (unsigned long) cs->iov[0].iov_base;
542 cs->iov ++; 544 cs->iov++;
543 cs->nr_segs --; 545 cs->nr_segs--;
544 } 546 }
545 down_read(&current->mm->mmap_sem); 547 down_read(&current->mm->mmap_sem);
546 err = get_user_pages(current, current->mm, cs->addr, 1, cs->write, 0, 548 err = get_user_pages(current, current->mm, cs->addr, 1, cs->write, 0,
@@ -589,9 +591,11 @@ static int fuse_copy_page(struct fuse_copy_state *cs, struct page *page,
589 kunmap_atomic(mapaddr, KM_USER1); 591 kunmap_atomic(mapaddr, KM_USER1);
590 } 592 }
591 while (count) { 593 while (count) {
592 int err; 594 if (!cs->len) {
593 if (!cs->len && (err = fuse_copy_fill(cs))) 595 int err = fuse_copy_fill(cs);
594 return err; 596 if (err)
597 return err;
598 }
595 if (page) { 599 if (page) {
596 void *mapaddr = kmap_atomic(page, KM_USER1); 600 void *mapaddr = kmap_atomic(page, KM_USER1);
597 void *buf = mapaddr + offset; 601 void *buf = mapaddr + offset;
@@ -631,9 +635,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) 635static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size)
632{ 636{
633 while (size) { 637 while (size) {
634 int err; 638 if (!cs->len) {
635 if (!cs->len && (err = fuse_copy_fill(cs))) 639 int err = fuse_copy_fill(cs);
636 return err; 640 if (err)
641 return err;
642 }
637 fuse_copy_do(cs, &val, &size); 643 fuse_copy_do(cs, &val, &size);
638 } 644 }
639 return 0; 645 return 0;
@@ -664,6 +670,8 @@ static int request_pending(struct fuse_conn *fc)
664 670
665/* Wait until a request is available on the pending list */ 671/* Wait until a request is available on the pending list */
666static void request_wait(struct fuse_conn *fc) 672static void request_wait(struct fuse_conn *fc)
673__releases(&fc->lock)
674__acquires(&fc->lock)
667{ 675{
668 DECLARE_WAITQUEUE(wait, current); 676 DECLARE_WAITQUEUE(wait, current);
669 677
@@ -691,7 +699,7 @@ static void request_wait(struct fuse_conn *fc)
691 */ 699 */
692static int fuse_read_interrupt(struct fuse_conn *fc, struct fuse_req *req, 700static int fuse_read_interrupt(struct fuse_conn *fc, struct fuse_req *req,
693 const struct iovec *iov, unsigned long nr_segs) 701 const struct iovec *iov, unsigned long nr_segs)
694 __releases(fc->lock) 702__releases(&fc->lock)
695{ 703{
696 struct fuse_copy_state cs; 704 struct fuse_copy_state cs;
697 struct fuse_in_header ih; 705 struct fuse_in_header ih;
@@ -813,6 +821,34 @@ static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
813 return err; 821 return err;
814} 822}
815 823
824static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size,
825 struct fuse_copy_state *cs)
826{
827 struct fuse_notify_poll_wakeup_out outarg;
828 int err;
829
830 if (size != sizeof(outarg))
831 return -EINVAL;
832
833 err = fuse_copy_one(cs, &outarg, sizeof(outarg));
834 if (err)
835 return err;
836
837 return fuse_notify_poll_wakeup(fc, &outarg);
838}
839
840static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
841 unsigned int size, struct fuse_copy_state *cs)
842{
843 switch (code) {
844 case FUSE_NOTIFY_POLL:
845 return fuse_notify_poll(fc, size, cs);
846
847 default:
848 return -EINVAL;
849 }
850}
851
816/* Look up request on processing list by unique ID */ 852/* Look up request on processing list by unique ID */
817static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique) 853static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique)
818{ 854{
@@ -876,9 +912,23 @@ static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
876 err = fuse_copy_one(&cs, &oh, sizeof(oh)); 912 err = fuse_copy_one(&cs, &oh, sizeof(oh));
877 if (err) 913 if (err)
878 goto err_finish; 914 goto err_finish;
915
916 err = -EINVAL;
917 if (oh.len != nbytes)
918 goto err_finish;
919
920 /*
921 * Zero oh.unique indicates unsolicited notification message
922 * and error contains notification code.
923 */
924 if (!oh.unique) {
925 err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), &cs);
926 fuse_copy_finish(&cs);
927 return err ? err : nbytes;
928 }
929
879 err = -EINVAL; 930 err = -EINVAL;
880 if (!oh.unique || oh.error <= -1000 || oh.error > 0 || 931 if (oh.error <= -1000 || oh.error > 0)
881 oh.len != nbytes)
882 goto err_finish; 932 goto err_finish;
883 933
884 spin_lock(&fc->lock); 934 spin_lock(&fc->lock);
@@ -966,6 +1016,8 @@ static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
966 * This function releases and reacquires fc->lock 1016 * This function releases and reacquires fc->lock
967 */ 1017 */
968static void end_requests(struct fuse_conn *fc, struct list_head *head) 1018static void end_requests(struct fuse_conn *fc, struct list_head *head)
1019__releases(&fc->lock)
1020__acquires(&fc->lock)
969{ 1021{
970 while (!list_empty(head)) { 1022 while (!list_empty(head)) {
971 struct fuse_req *req; 1023 struct fuse_req *req;
@@ -988,7 +1040,8 @@ static void end_requests(struct fuse_conn *fc, struct list_head *head)
988 * locked). 1040 * locked).
989 */ 1041 */
990static void end_io_requests(struct fuse_conn *fc) 1042static void end_io_requests(struct fuse_conn *fc)
991 __releases(fc->lock) __acquires(fc->lock) 1043__releases(&fc->lock)
1044__acquires(&fc->lock)
992{ 1045{
993 while (!list_empty(&fc->io)) { 1046 while (!list_empty(&fc->io)) {
994 struct fuse_req *req = 1047 struct fuse_req *req =
@@ -1002,11 +1055,11 @@ static void end_io_requests(struct fuse_conn *fc)
1002 wake_up(&req->waitq); 1055 wake_up(&req->waitq);
1003 if (end) { 1056 if (end) {
1004 req->end = NULL; 1057 req->end = NULL;
1005 /* The end function will consume this reference */
1006 __fuse_get_request(req); 1058 __fuse_get_request(req);
1007 spin_unlock(&fc->lock); 1059 spin_unlock(&fc->lock);
1008 wait_event(req->waitq, !req->locked); 1060 wait_event(req->waitq, !req->locked);
1009 end(fc, req); 1061 end(fc, req);
1062 fuse_put_request(fc, req);
1010 spin_lock(&fc->lock); 1063 spin_lock(&fc->lock);
1011 } 1064 }
1012 } 1065 }
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 95bc22bdd060..fdff346e96fd 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.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.
@@ -189,7 +189,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
189 parent = dget_parent(entry); 189 parent = dget_parent(entry);
190 fuse_lookup_init(fc, req, get_node_id(parent->d_inode), 190 fuse_lookup_init(fc, req, get_node_id(parent->d_inode),
191 &entry->d_name, &outarg); 191 &entry->d_name, &outarg);
192 request_send(fc, req); 192 fuse_request_send(fc, req);
193 dput(parent); 193 dput(parent);
194 err = req->out.h.error; 194 err = req->out.h.error;
195 fuse_put_request(fc, req); 195 fuse_put_request(fc, req);
@@ -204,7 +204,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
204 return 0; 204 return 0;
205 } 205 }
206 spin_lock(&fc->lock); 206 spin_lock(&fc->lock);
207 fi->nlookup ++; 207 fi->nlookup++;
208 spin_unlock(&fc->lock); 208 spin_unlock(&fc->lock);
209 } 209 }
210 fuse_put_request(fc, forget_req); 210 fuse_put_request(fc, forget_req);
@@ -283,7 +283,7 @@ int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
283 attr_version = fuse_get_attr_version(fc); 283 attr_version = fuse_get_attr_version(fc);
284 284
285 fuse_lookup_init(fc, req, nodeid, name, outarg); 285 fuse_lookup_init(fc, req, nodeid, name, outarg);
286 request_send(fc, req); 286 fuse_request_send(fc, req);
287 err = req->out.h.error; 287 err = req->out.h.error;
288 fuse_put_request(fc, req); 288 fuse_put_request(fc, req);
289 /* Zero nodeid is same as -ENOENT, but with valid timeout */ 289 /* Zero nodeid is same as -ENOENT, but with valid timeout */
@@ -369,7 +369,7 @@ static void fuse_sync_release(struct fuse_conn *fc, struct fuse_file *ff,
369{ 369{
370 fuse_release_fill(ff, nodeid, flags, FUSE_RELEASE); 370 fuse_release_fill(ff, nodeid, flags, FUSE_RELEASE);
371 ff->reserved_req->force = 1; 371 ff->reserved_req->force = 1;
372 request_send(fc, ff->reserved_req); 372 fuse_request_send(fc, ff->reserved_req);
373 fuse_put_request(fc, ff->reserved_req); 373 fuse_put_request(fc, ff->reserved_req);
374 kfree(ff); 374 kfree(ff);
375} 375}
@@ -408,7 +408,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
408 goto out_put_forget_req; 408 goto out_put_forget_req;
409 409
410 err = -ENOMEM; 410 err = -ENOMEM;
411 ff = fuse_file_alloc(); 411 ff = fuse_file_alloc(fc);
412 if (!ff) 412 if (!ff)
413 goto out_put_request; 413 goto out_put_request;
414 414
@@ -432,7 +432,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
432 req->out.args[0].value = &outentry; 432 req->out.args[0].value = &outentry;
433 req->out.args[1].size = sizeof(outopen); 433 req->out.args[1].size = sizeof(outopen);
434 req->out.args[1].value = &outopen; 434 req->out.args[1].value = &outopen;
435 request_send(fc, req); 435 fuse_request_send(fc, req);
436 err = req->out.h.error; 436 err = req->out.h.error;
437 if (err) { 437 if (err) {
438 if (err == -ENOSYS) 438 if (err == -ENOSYS)
@@ -502,7 +502,7 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
502 else 502 else
503 req->out.args[0].size = sizeof(outarg); 503 req->out.args[0].size = sizeof(outarg);
504 req->out.args[0].value = &outarg; 504 req->out.args[0].value = &outarg;
505 request_send(fc, req); 505 fuse_request_send(fc, req);
506 err = req->out.h.error; 506 err = req->out.h.error;
507 fuse_put_request(fc, req); 507 fuse_put_request(fc, req);
508 if (err) 508 if (err)
@@ -631,15 +631,17 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry)
631 req->in.numargs = 1; 631 req->in.numargs = 1;
632 req->in.args[0].size = entry->d_name.len + 1; 632 req->in.args[0].size = entry->d_name.len + 1;
633 req->in.args[0].value = entry->d_name.name; 633 req->in.args[0].value = entry->d_name.name;
634 request_send(fc, req); 634 fuse_request_send(fc, req);
635 err = req->out.h.error; 635 err = req->out.h.error;
636 fuse_put_request(fc, req); 636 fuse_put_request(fc, req);
637 if (!err) { 637 if (!err) {
638 struct inode *inode = entry->d_inode; 638 struct inode *inode = entry->d_inode;
639 639
640 /* Set nlink to zero so the inode can be cleared, if 640 /*
641 the inode does have more links this will be 641 * Set nlink to zero so the inode can be cleared, if the inode
642 discovered at the next lookup/getattr */ 642 * does have more links this will be discovered at the next
643 * lookup/getattr.
644 */
643 clear_nlink(inode); 645 clear_nlink(inode);
644 fuse_invalidate_attr(inode); 646 fuse_invalidate_attr(inode);
645 fuse_invalidate_attr(dir); 647 fuse_invalidate_attr(dir);
@@ -662,7 +664,7 @@ static int fuse_rmdir(struct inode *dir, struct dentry *entry)
662 req->in.numargs = 1; 664 req->in.numargs = 1;
663 req->in.args[0].size = entry->d_name.len + 1; 665 req->in.args[0].size = entry->d_name.len + 1;
664 req->in.args[0].value = entry->d_name.name; 666 req->in.args[0].value = entry->d_name.name;
665 request_send(fc, req); 667 fuse_request_send(fc, req);
666 err = req->out.h.error; 668 err = req->out.h.error;
667 fuse_put_request(fc, req); 669 fuse_put_request(fc, req);
668 if (!err) { 670 if (!err) {
@@ -695,7 +697,7 @@ static int fuse_rename(struct inode *olddir, struct dentry *oldent,
695 req->in.args[1].value = oldent->d_name.name; 697 req->in.args[1].value = oldent->d_name.name;
696 req->in.args[2].size = newent->d_name.len + 1; 698 req->in.args[2].size = newent->d_name.len + 1;
697 req->in.args[2].value = newent->d_name.name; 699 req->in.args[2].value = newent->d_name.name;
698 request_send(fc, req); 700 fuse_request_send(fc, req);
699 err = req->out.h.error; 701 err = req->out.h.error;
700 fuse_put_request(fc, req); 702 fuse_put_request(fc, req);
701 if (!err) { 703 if (!err) {
@@ -811,7 +813,7 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
811 else 813 else
812 req->out.args[0].size = sizeof(outarg); 814 req->out.args[0].size = sizeof(outarg);
813 req->out.args[0].value = &outarg; 815 req->out.args[0].value = &outarg;
814 request_send(fc, req); 816 fuse_request_send(fc, req);
815 err = req->out.h.error; 817 err = req->out.h.error;
816 fuse_put_request(fc, req); 818 fuse_put_request(fc, req);
817 if (!err) { 819 if (!err) {
@@ -911,7 +913,7 @@ static int fuse_access(struct inode *inode, int mask)
911 req->in.numargs = 1; 913 req->in.numargs = 1;
912 req->in.args[0].size = sizeof(inarg); 914 req->in.args[0].size = sizeof(inarg);
913 req->in.args[0].value = &inarg; 915 req->in.args[0].value = &inarg;
914 request_send(fc, req); 916 fuse_request_send(fc, req);
915 err = req->out.h.error; 917 err = req->out.h.error;
916 fuse_put_request(fc, req); 918 fuse_put_request(fc, req);
917 if (err == -ENOSYS) { 919 if (err == -ENOSYS) {
@@ -1033,7 +1035,7 @@ static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
1033 req->num_pages = 1; 1035 req->num_pages = 1;
1034 req->pages[0] = page; 1036 req->pages[0] = page;
1035 fuse_read_fill(req, file, inode, file->f_pos, PAGE_SIZE, FUSE_READDIR); 1037 fuse_read_fill(req, file, inode, file->f_pos, PAGE_SIZE, FUSE_READDIR);
1036 request_send(fc, req); 1038 fuse_request_send(fc, req);
1037 nbytes = req->out.args[0].size; 1039 nbytes = req->out.args[0].size;
1038 err = req->out.h.error; 1040 err = req->out.h.error;
1039 fuse_put_request(fc, req); 1041 fuse_put_request(fc, req);
@@ -1067,7 +1069,7 @@ static char *read_link(struct dentry *dentry)
1067 req->out.numargs = 1; 1069 req->out.numargs = 1;
1068 req->out.args[0].size = PAGE_SIZE - 1; 1070 req->out.args[0].size = PAGE_SIZE - 1;
1069 req->out.args[0].value = link; 1071 req->out.args[0].value = link;
1070 request_send(fc, req); 1072 fuse_request_send(fc, req);
1071 if (req->out.h.error) { 1073 if (req->out.h.error) {
1072 free_page((unsigned long) link); 1074 free_page((unsigned long) link);
1073 link = ERR_PTR(req->out.h.error); 1075 link = ERR_PTR(req->out.h.error);
@@ -1273,7 +1275,7 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
1273 else 1275 else
1274 req->out.args[0].size = sizeof(outarg); 1276 req->out.args[0].size = sizeof(outarg);
1275 req->out.args[0].value = &outarg; 1277 req->out.args[0].value = &outarg;
1276 request_send(fc, req); 1278 fuse_request_send(fc, req);
1277 err = req->out.h.error; 1279 err = req->out.h.error;
1278 fuse_put_request(fc, req); 1280 fuse_put_request(fc, req);
1279 if (err) { 1281 if (err) {
@@ -1367,7 +1369,7 @@ static int fuse_setxattr(struct dentry *entry, const char *name,
1367 req->in.args[1].value = name; 1369 req->in.args[1].value = name;
1368 req->in.args[2].size = size; 1370 req->in.args[2].size = size;
1369 req->in.args[2].value = value; 1371 req->in.args[2].value = value;
1370 request_send(fc, req); 1372 fuse_request_send(fc, req);
1371 err = req->out.h.error; 1373 err = req->out.h.error;
1372 fuse_put_request(fc, req); 1374 fuse_put_request(fc, req);
1373 if (err == -ENOSYS) { 1375 if (err == -ENOSYS) {
@@ -1413,7 +1415,7 @@ static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
1413 req->out.args[0].size = sizeof(outarg); 1415 req->out.args[0].size = sizeof(outarg);
1414 req->out.args[0].value = &outarg; 1416 req->out.args[0].value = &outarg;
1415 } 1417 }
1416 request_send(fc, req); 1418 fuse_request_send(fc, req);
1417 ret = req->out.h.error; 1419 ret = req->out.h.error;
1418 if (!ret) 1420 if (!ret)
1419 ret = size ? req->out.args[0].size : outarg.size; 1421 ret = size ? req->out.args[0].size : outarg.size;
@@ -1463,7 +1465,7 @@ static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
1463 req->out.args[0].size = sizeof(outarg); 1465 req->out.args[0].size = sizeof(outarg);
1464 req->out.args[0].value = &outarg; 1466 req->out.args[0].value = &outarg;
1465 } 1467 }
1466 request_send(fc, req); 1468 fuse_request_send(fc, req);
1467 ret = req->out.h.error; 1469 ret = req->out.h.error;
1468 if (!ret) 1470 if (!ret)
1469 ret = size ? req->out.args[0].size : outarg.size; 1471 ret = size ? req->out.args[0].size : outarg.size;
@@ -1496,7 +1498,7 @@ static int fuse_removexattr(struct dentry *entry, const char *name)
1496 req->in.numargs = 1; 1498 req->in.numargs = 1;
1497 req->in.args[0].size = strlen(name) + 1; 1499 req->in.args[0].size = strlen(name) + 1;
1498 req->in.args[0].value = name; 1500 req->in.args[0].value = name;
1499 request_send(fc, req); 1501 fuse_request_send(fc, req);
1500 err = req->out.h.error; 1502 err = req->out.h.error;
1501 fuse_put_request(fc, req); 1503 fuse_put_request(fc, req);
1502 if (err == -ENOSYS) { 1504 if (err == -ENOSYS) {
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 4c9ee7011265..e8162646a9b5 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.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.
@@ -39,14 +39,14 @@ static int fuse_send_open(struct inode *inode, struct file *file, int isdir,
39 req->out.numargs = 1; 39 req->out.numargs = 1;
40 req->out.args[0].size = sizeof(*outargp); 40 req->out.args[0].size = sizeof(*outargp);
41 req->out.args[0].value = outargp; 41 req->out.args[0].value = outargp;
42 request_send(fc, req); 42 fuse_request_send(fc, req);
43 err = req->out.h.error; 43 err = req->out.h.error;
44 fuse_put_request(fc, req); 44 fuse_put_request(fc, req);
45 45
46 return err; 46 return err;
47} 47}
48 48
49struct fuse_file *fuse_file_alloc(void) 49struct fuse_file *fuse_file_alloc(struct fuse_conn *fc)
50{ 50{
51 struct fuse_file *ff; 51 struct fuse_file *ff;
52 ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL); 52 ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL);
@@ -58,7 +58,12 @@ struct fuse_file *fuse_file_alloc(void)
58 } else { 58 } else {
59 INIT_LIST_HEAD(&ff->write_entry); 59 INIT_LIST_HEAD(&ff->write_entry);
60 atomic_set(&ff->count, 0); 60 atomic_set(&ff->count, 0);
61 spin_lock(&fc->lock);
62 ff->kh = ++fc->khctr;
63 spin_unlock(&fc->lock);
61 } 64 }
65 RB_CLEAR_NODE(&ff->polled_node);
66 init_waitqueue_head(&ff->poll_wait);
62 } 67 }
63 return ff; 68 return ff;
64} 69}
@@ -79,7 +84,6 @@ static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req)
79{ 84{
80 dput(req->misc.release.dentry); 85 dput(req->misc.release.dentry);
81 mntput(req->misc.release.vfsmount); 86 mntput(req->misc.release.vfsmount);
82 fuse_put_request(fc, req);
83} 87}
84 88
85static void fuse_file_put(struct fuse_file *ff) 89static void fuse_file_put(struct fuse_file *ff)
@@ -89,7 +93,7 @@ static void fuse_file_put(struct fuse_file *ff)
89 struct inode *inode = req->misc.release.dentry->d_inode; 93 struct inode *inode = req->misc.release.dentry->d_inode;
90 struct fuse_conn *fc = get_fuse_conn(inode); 94 struct fuse_conn *fc = get_fuse_conn(inode);
91 req->end = fuse_release_end; 95 req->end = fuse_release_end;
92 request_send_background(fc, req); 96 fuse_request_send_background(fc, req);
93 kfree(ff); 97 kfree(ff);
94 } 98 }
95} 99}
@@ -109,6 +113,7 @@ void fuse_finish_open(struct inode *inode, struct file *file,
109 113
110int fuse_open_common(struct inode *inode, struct file *file, int isdir) 114int fuse_open_common(struct inode *inode, struct file *file, int isdir)
111{ 115{
116 struct fuse_conn *fc = get_fuse_conn(inode);
112 struct fuse_open_out outarg; 117 struct fuse_open_out outarg;
113 struct fuse_file *ff; 118 struct fuse_file *ff;
114 int err; 119 int err;
@@ -121,7 +126,7 @@ int fuse_open_common(struct inode *inode, struct file *file, int isdir)
121 if (err) 126 if (err)
122 return err; 127 return err;
123 128
124 ff = fuse_file_alloc(); 129 ff = fuse_file_alloc(fc);
125 if (!ff) 130 if (!ff)
126 return -ENOMEM; 131 return -ENOMEM;
127 132
@@ -167,7 +172,11 @@ int fuse_release_common(struct inode *inode, struct file *file, int isdir)
167 172
168 spin_lock(&fc->lock); 173 spin_lock(&fc->lock);
169 list_del(&ff->write_entry); 174 list_del(&ff->write_entry);
175 if (!RB_EMPTY_NODE(&ff->polled_node))
176 rb_erase(&ff->polled_node, &fc->polled_files);
170 spin_unlock(&fc->lock); 177 spin_unlock(&fc->lock);
178
179 wake_up_interruptible_sync(&ff->poll_wait);
171 /* 180 /*
172 * Normally this will send the RELEASE request, 181 * Normally this will send the RELEASE request,
173 * however if some asynchronous READ or WRITE requests 182 * however if some asynchronous READ or WRITE requests
@@ -280,7 +289,7 @@ static int fuse_flush(struct file *file, fl_owner_t id)
280 req->in.args[0].size = sizeof(inarg); 289 req->in.args[0].size = sizeof(inarg);
281 req->in.args[0].value = &inarg; 290 req->in.args[0].value = &inarg;
282 req->force = 1; 291 req->force = 1;
283 request_send(fc, req); 292 fuse_request_send(fc, req);
284 err = req->out.h.error; 293 err = req->out.h.error;
285 fuse_put_request(fc, req); 294 fuse_put_request(fc, req);
286 if (err == -ENOSYS) { 295 if (err == -ENOSYS) {
@@ -344,7 +353,7 @@ int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
344 req->in.numargs = 1; 353 req->in.numargs = 1;
345 req->in.args[0].size = sizeof(inarg); 354 req->in.args[0].size = sizeof(inarg);
346 req->in.args[0].value = &inarg; 355 req->in.args[0].value = &inarg;
347 request_send(fc, req); 356 fuse_request_send(fc, req);
348 err = req->out.h.error; 357 err = req->out.h.error;
349 fuse_put_request(fc, req); 358 fuse_put_request(fc, req);
350 if (err == -ENOSYS) { 359 if (err == -ENOSYS) {
@@ -396,7 +405,7 @@ static size_t fuse_send_read(struct fuse_req *req, struct file *file,
396 inarg->read_flags |= FUSE_READ_LOCKOWNER; 405 inarg->read_flags |= FUSE_READ_LOCKOWNER;
397 inarg->lock_owner = fuse_lock_owner_id(fc, owner); 406 inarg->lock_owner = fuse_lock_owner_id(fc, owner);
398 } 407 }
399 request_send(fc, req); 408 fuse_request_send(fc, req);
400 return req->out.args[0].size; 409 return req->out.args[0].size;
401} 410}
402 411
@@ -493,7 +502,6 @@ static void fuse_readpages_end(struct fuse_conn *fc, struct fuse_req *req)
493 } 502 }
494 if (req->ff) 503 if (req->ff)
495 fuse_file_put(req->ff); 504 fuse_file_put(req->ff);
496 fuse_put_request(fc, req);
497} 505}
498 506
499static void fuse_send_readpages(struct fuse_req *req, struct file *file, 507static void fuse_send_readpages(struct fuse_req *req, struct file *file,
@@ -509,10 +517,11 @@ static void fuse_send_readpages(struct fuse_req *req, struct file *file,
509 struct fuse_file *ff = file->private_data; 517 struct fuse_file *ff = file->private_data;
510 req->ff = fuse_file_get(ff); 518 req->ff = fuse_file_get(ff);
511 req->end = fuse_readpages_end; 519 req->end = fuse_readpages_end;
512 request_send_background(fc, req); 520 fuse_request_send_background(fc, req);
513 } else { 521 } else {
514 request_send(fc, req); 522 fuse_request_send(fc, req);
515 fuse_readpages_end(fc, req); 523 fuse_readpages_end(fc, req);
524 fuse_put_request(fc, req);
516 } 525 }
517} 526}
518 527
@@ -543,7 +552,7 @@ static int fuse_readpages_fill(void *_data, struct page *page)
543 } 552 }
544 } 553 }
545 req->pages[req->num_pages] = page; 554 req->pages[req->num_pages] = page;
546 req->num_pages ++; 555 req->num_pages++;
547 return 0; 556 return 0;
548} 557}
549 558
@@ -636,7 +645,7 @@ static size_t fuse_send_write(struct fuse_req *req, struct file *file,
636 inarg->write_flags |= FUSE_WRITE_LOCKOWNER; 645 inarg->write_flags |= FUSE_WRITE_LOCKOWNER;
637 inarg->lock_owner = fuse_lock_owner_id(fc, owner); 646 inarg->lock_owner = fuse_lock_owner_id(fc, owner);
638 } 647 }
639 request_send(fc, req); 648 fuse_request_send(fc, req);
640 return req->misc.write.out.size; 649 return req->misc.write.out.size;
641} 650}
642 651
@@ -1042,7 +1051,6 @@ static void fuse_writepage_free(struct fuse_conn *fc, struct fuse_req *req)
1042{ 1051{
1043 __free_page(req->pages[0]); 1052 __free_page(req->pages[0]);
1044 fuse_file_put(req->ff); 1053 fuse_file_put(req->ff);
1045 fuse_put_request(fc, req);
1046} 1054}
1047 1055
1048static void fuse_writepage_finish(struct fuse_conn *fc, struct fuse_req *req) 1056static void fuse_writepage_finish(struct fuse_conn *fc, struct fuse_req *req)
@@ -1060,6 +1068,8 @@ static void fuse_writepage_finish(struct fuse_conn *fc, struct fuse_req *req)
1060 1068
1061/* Called under fc->lock, may release and reacquire it */ 1069/* Called under fc->lock, may release and reacquire it */
1062static void fuse_send_writepage(struct fuse_conn *fc, struct fuse_req *req) 1070static void fuse_send_writepage(struct fuse_conn *fc, struct fuse_req *req)
1071__releases(&fc->lock)
1072__acquires(&fc->lock)
1063{ 1073{
1064 struct fuse_inode *fi = get_fuse_inode(req->inode); 1074 struct fuse_inode *fi = get_fuse_inode(req->inode);
1065 loff_t size = i_size_read(req->inode); 1075 loff_t size = i_size_read(req->inode);
@@ -1079,13 +1089,14 @@ static void fuse_send_writepage(struct fuse_conn *fc, struct fuse_req *req)
1079 1089
1080 req->in.args[1].size = inarg->size; 1090 req->in.args[1].size = inarg->size;
1081 fi->writectr++; 1091 fi->writectr++;
1082 request_send_background_locked(fc, req); 1092 fuse_request_send_background_locked(fc, req);
1083 return; 1093 return;
1084 1094
1085 out_free: 1095 out_free:
1086 fuse_writepage_finish(fc, req); 1096 fuse_writepage_finish(fc, req);
1087 spin_unlock(&fc->lock); 1097 spin_unlock(&fc->lock);
1088 fuse_writepage_free(fc, req); 1098 fuse_writepage_free(fc, req);
1099 fuse_put_request(fc, req);
1089 spin_lock(&fc->lock); 1100 spin_lock(&fc->lock);
1090} 1101}
1091 1102
@@ -1096,6 +1107,8 @@ static void fuse_send_writepage(struct fuse_conn *fc, struct fuse_req *req)
1096 * Called with fc->lock 1107 * Called with fc->lock
1097 */ 1108 */
1098void fuse_flush_writepages(struct inode *inode) 1109void fuse_flush_writepages(struct inode *inode)
1110__releases(&fc->lock)
1111__acquires(&fc->lock)
1099{ 1112{
1100 struct fuse_conn *fc = get_fuse_conn(inode); 1113 struct fuse_conn *fc = get_fuse_conn(inode);
1101 struct fuse_inode *fi = get_fuse_inode(inode); 1114 struct fuse_inode *fi = get_fuse_inode(inode);
@@ -1325,7 +1338,7 @@ static int fuse_getlk(struct file *file, struct file_lock *fl)
1325 req->out.numargs = 1; 1338 req->out.numargs = 1;
1326 req->out.args[0].size = sizeof(outarg); 1339 req->out.args[0].size = sizeof(outarg);
1327 req->out.args[0].value = &outarg; 1340 req->out.args[0].value = &outarg;
1328 request_send(fc, req); 1341 fuse_request_send(fc, req);
1329 err = req->out.h.error; 1342 err = req->out.h.error;
1330 fuse_put_request(fc, req); 1343 fuse_put_request(fc, req);
1331 if (!err) 1344 if (!err)
@@ -1357,7 +1370,7 @@ static int fuse_setlk(struct file *file, struct file_lock *fl, int flock)
1357 return PTR_ERR(req); 1370 return PTR_ERR(req);
1358 1371
1359 fuse_lk_fill(req, file, fl, opcode, pid, flock); 1372 fuse_lk_fill(req, file, fl, opcode, pid, flock);
1360 request_send(fc, req); 1373 fuse_request_send(fc, req);
1361 err = req->out.h.error; 1374 err = req->out.h.error;
1362 /* locking is restartable */ 1375 /* locking is restartable */
1363 if (err == -EINTR) 1376 if (err == -EINTR)
@@ -1433,7 +1446,7 @@ static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
1433 req->out.numargs = 1; 1446 req->out.numargs = 1;
1434 req->out.args[0].size = sizeof(outarg); 1447 req->out.args[0].size = sizeof(outarg);
1435 req->out.args[0].value = &outarg; 1448 req->out.args[0].value = &outarg;
1436 request_send(fc, req); 1449 fuse_request_send(fc, req);
1437 err = req->out.h.error; 1450 err = req->out.h.error;
1438 fuse_put_request(fc, req); 1451 fuse_put_request(fc, req);
1439 if (err == -ENOSYS) 1452 if (err == -ENOSYS)
@@ -1470,6 +1483,406 @@ static loff_t fuse_file_llseek(struct file *file, loff_t offset, int origin)
1470 return retval; 1483 return retval;
1471} 1484}
1472 1485
1486static int fuse_ioctl_copy_user(struct page **pages, struct iovec *iov,
1487 unsigned int nr_segs, size_t bytes, bool to_user)
1488{
1489 struct iov_iter ii;
1490 int page_idx = 0;
1491
1492 if (!bytes)
1493 return 0;
1494
1495 iov_iter_init(&ii, iov, nr_segs, bytes, 0);
1496
1497 while (iov_iter_count(&ii)) {
1498 struct page *page = pages[page_idx++];
1499 size_t todo = min_t(size_t, PAGE_SIZE, iov_iter_count(&ii));
1500 void *kaddr, *map;
1501
1502 kaddr = map = kmap(page);
1503
1504 while (todo) {
1505 char __user *uaddr = ii.iov->iov_base + ii.iov_offset;
1506 size_t iov_len = ii.iov->iov_len - ii.iov_offset;
1507 size_t copy = min(todo, iov_len);
1508 size_t left;
1509
1510 if (!to_user)
1511 left = copy_from_user(kaddr, uaddr, copy);
1512 else
1513 left = copy_to_user(uaddr, kaddr, copy);
1514
1515 if (unlikely(left))
1516 return -EFAULT;
1517
1518 iov_iter_advance(&ii, copy);
1519 todo -= copy;
1520 kaddr += copy;
1521 }
1522
1523 kunmap(map);
1524 }
1525
1526 return 0;
1527}
1528
1529/*
1530 * For ioctls, there is no generic way to determine how much memory
1531 * needs to be read and/or written. Furthermore, ioctls are allowed
1532 * to dereference the passed pointer, so the parameter requires deep
1533 * copying but FUSE has no idea whatsoever about what to copy in or
1534 * out.
1535 *
1536 * This is solved by allowing FUSE server to retry ioctl with
1537 * necessary in/out iovecs. Let's assume the ioctl implementation
1538 * needs to read in the following structure.
1539 *
1540 * struct a {
1541 * char *buf;
1542 * size_t buflen;
1543 * }
1544 *
1545 * On the first callout to FUSE server, inarg->in_size and
1546 * inarg->out_size will be NULL; then, the server completes the ioctl
1547 * with FUSE_IOCTL_RETRY set in out->flags, out->in_iovs set to 1 and
1548 * the actual iov array to
1549 *
1550 * { { .iov_base = inarg.arg, .iov_len = sizeof(struct a) } }
1551 *
1552 * which tells FUSE to copy in the requested area and retry the ioctl.
1553 * On the second round, the server has access to the structure and
1554 * from that it can tell what to look for next, so on the invocation,
1555 * it sets FUSE_IOCTL_RETRY, out->in_iovs to 2 and iov array to
1556 *
1557 * { { .iov_base = inarg.arg, .iov_len = sizeof(struct a) },
1558 * { .iov_base = a.buf, .iov_len = a.buflen } }
1559 *
1560 * FUSE will copy both struct a and the pointed buffer from the
1561 * process doing the ioctl and retry ioctl with both struct a and the
1562 * buffer.
1563 *
1564 * This time, FUSE server has everything it needs and completes ioctl
1565 * without FUSE_IOCTL_RETRY which finishes the ioctl call.
1566 *
1567 * Copying data out works the same way.
1568 *
1569 * Note that if FUSE_IOCTL_UNRESTRICTED is clear, the kernel
1570 * automatically initializes in and out iovs by decoding @cmd with
1571 * _IOC_* macros and the server is not allowed to request RETRY. This
1572 * limits ioctl data transfers to well-formed ioctls and is the forced
1573 * behavior for all FUSE servers.
1574 */
1575static long fuse_file_do_ioctl(struct file *file, unsigned int cmd,
1576 unsigned long arg, unsigned int flags)
1577{
1578 struct inode *inode = file->f_dentry->d_inode;
1579 struct fuse_file *ff = file->private_data;
1580 struct fuse_conn *fc = get_fuse_conn(inode);
1581 struct fuse_ioctl_in inarg = {
1582 .fh = ff->fh,
1583 .cmd = cmd,
1584 .arg = arg,
1585 .flags = flags
1586 };
1587 struct fuse_ioctl_out outarg;
1588 struct fuse_req *req = NULL;
1589 struct page **pages = NULL;
1590 struct page *iov_page = NULL;
1591 struct iovec *in_iov = NULL, *out_iov = NULL;
1592 unsigned int in_iovs = 0, out_iovs = 0, num_pages = 0, max_pages;
1593 size_t in_size, out_size, transferred;
1594 int err;
1595
1596 /* assume all the iovs returned by client always fits in a page */
1597 BUILD_BUG_ON(sizeof(struct iovec) * FUSE_IOCTL_MAX_IOV > PAGE_SIZE);
1598
1599 if (!fuse_allow_task(fc, current))
1600 return -EACCES;
1601
1602 err = -EIO;
1603 if (is_bad_inode(inode))
1604 goto out;
1605
1606 err = -ENOMEM;
1607 pages = kzalloc(sizeof(pages[0]) * FUSE_MAX_PAGES_PER_REQ, GFP_KERNEL);
1608 iov_page = alloc_page(GFP_KERNEL);
1609 if (!pages || !iov_page)
1610 goto out;
1611
1612 /*
1613 * If restricted, initialize IO parameters as encoded in @cmd.
1614 * RETRY from server is not allowed.
1615 */
1616 if (!(flags & FUSE_IOCTL_UNRESTRICTED)) {
1617 struct iovec *iov = page_address(iov_page);
1618
1619 iov->iov_base = (void __user *)arg;
1620 iov->iov_len = _IOC_SIZE(cmd);
1621
1622 if (_IOC_DIR(cmd) & _IOC_WRITE) {
1623 in_iov = iov;
1624 in_iovs = 1;
1625 }
1626
1627 if (_IOC_DIR(cmd) & _IOC_READ) {
1628 out_iov = iov;
1629 out_iovs = 1;
1630 }
1631 }
1632
1633 retry:
1634 inarg.in_size = in_size = iov_length(in_iov, in_iovs);
1635 inarg.out_size = out_size = iov_length(out_iov, out_iovs);
1636
1637 /*
1638 * Out data can be used either for actual out data or iovs,
1639 * make sure there always is at least one page.
1640 */
1641 out_size = max_t(size_t, out_size, PAGE_SIZE);
1642 max_pages = DIV_ROUND_UP(max(in_size, out_size), PAGE_SIZE);
1643
1644 /* make sure there are enough buffer pages and init request with them */
1645 err = -ENOMEM;
1646 if (max_pages > FUSE_MAX_PAGES_PER_REQ)
1647 goto out;
1648 while (num_pages < max_pages) {
1649 pages[num_pages] = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
1650 if (!pages[num_pages])
1651 goto out;
1652 num_pages++;
1653 }
1654
1655 req = fuse_get_req(fc);
1656 if (IS_ERR(req)) {
1657 err = PTR_ERR(req);
1658 req = NULL;
1659 goto out;
1660 }
1661 memcpy(req->pages, pages, sizeof(req->pages[0]) * num_pages);
1662 req->num_pages = num_pages;
1663
1664 /* okay, let's send it to the client */
1665 req->in.h.opcode = FUSE_IOCTL;
1666 req->in.h.nodeid = get_node_id(inode);
1667 req->in.numargs = 1;
1668 req->in.args[0].size = sizeof(inarg);
1669 req->in.args[0].value = &inarg;
1670 if (in_size) {
1671 req->in.numargs++;
1672 req->in.args[1].size = in_size;
1673 req->in.argpages = 1;
1674
1675 err = fuse_ioctl_copy_user(pages, in_iov, in_iovs, in_size,
1676 false);
1677 if (err)
1678 goto out;
1679 }
1680
1681 req->out.numargs = 2;
1682 req->out.args[0].size = sizeof(outarg);
1683 req->out.args[0].value = &outarg;
1684 req->out.args[1].size = out_size;
1685 req->out.argpages = 1;
1686 req->out.argvar = 1;
1687
1688 fuse_request_send(fc, req);
1689 err = req->out.h.error;
1690 transferred = req->out.args[1].size;
1691 fuse_put_request(fc, req);
1692 req = NULL;
1693 if (err)
1694 goto out;
1695
1696 /* did it ask for retry? */
1697 if (outarg.flags & FUSE_IOCTL_RETRY) {
1698 char *vaddr;
1699
1700 /* no retry if in restricted mode */
1701 err = -EIO;
1702 if (!(flags & FUSE_IOCTL_UNRESTRICTED))
1703 goto out;
1704
1705 in_iovs = outarg.in_iovs;
1706 out_iovs = outarg.out_iovs;
1707
1708 /*
1709 * Make sure things are in boundary, separate checks
1710 * are to protect against overflow.
1711 */
1712 err = -ENOMEM;
1713 if (in_iovs > FUSE_IOCTL_MAX_IOV ||
1714 out_iovs > FUSE_IOCTL_MAX_IOV ||
1715 in_iovs + out_iovs > FUSE_IOCTL_MAX_IOV)
1716 goto out;
1717
1718 err = -EIO;
1719 if ((in_iovs + out_iovs) * sizeof(struct iovec) != transferred)
1720 goto out;
1721
1722 /* okay, copy in iovs and retry */
1723 vaddr = kmap_atomic(pages[0], KM_USER0);
1724 memcpy(page_address(iov_page), vaddr, transferred);
1725 kunmap_atomic(vaddr, KM_USER0);
1726
1727 in_iov = page_address(iov_page);
1728 out_iov = in_iov + in_iovs;
1729
1730 goto retry;
1731 }
1732
1733 err = -EIO;
1734 if (transferred > inarg.out_size)
1735 goto out;
1736
1737 err = fuse_ioctl_copy_user(pages, out_iov, out_iovs, transferred, true);
1738 out:
1739 if (req)
1740 fuse_put_request(fc, req);
1741 if (iov_page)
1742 __free_page(iov_page);
1743 while (num_pages)
1744 __free_page(pages[--num_pages]);
1745 kfree(pages);
1746
1747 return err ? err : outarg.result;
1748}
1749
1750static long fuse_file_ioctl(struct file *file, unsigned int cmd,
1751 unsigned long arg)
1752{
1753 return fuse_file_do_ioctl(file, cmd, arg, 0);
1754}
1755
1756static long fuse_file_compat_ioctl(struct file *file, unsigned int cmd,
1757 unsigned long arg)
1758{
1759 return fuse_file_do_ioctl(file, cmd, arg, FUSE_IOCTL_COMPAT);
1760}
1761
1762/*
1763 * All files which have been polled are linked to RB tree
1764 * fuse_conn->polled_files which is indexed by kh. Walk the tree and
1765 * find the matching one.
1766 */
1767static struct rb_node **fuse_find_polled_node(struct fuse_conn *fc, u64 kh,
1768 struct rb_node **parent_out)
1769{
1770 struct rb_node **link = &fc->polled_files.rb_node;
1771 struct rb_node *last = NULL;
1772
1773 while (*link) {
1774 struct fuse_file *ff;
1775
1776 last = *link;
1777 ff = rb_entry(last, struct fuse_file, polled_node);
1778
1779 if (kh < ff->kh)
1780 link = &last->rb_left;
1781 else if (kh > ff->kh)
1782 link = &last->rb_right;
1783 else
1784 return link;
1785 }
1786
1787 if (parent_out)
1788 *parent_out = last;
1789 return link;
1790}
1791
1792/*
1793 * The file is about to be polled. Make sure it's on the polled_files
1794 * RB tree. Note that files once added to the polled_files tree are
1795 * not removed before the file is released. This is because a file
1796 * polled once is likely to be polled again.
1797 */
1798static void fuse_register_polled_file(struct fuse_conn *fc,
1799 struct fuse_file *ff)
1800{
1801 spin_lock(&fc->lock);
1802 if (RB_EMPTY_NODE(&ff->polled_node)) {
1803 struct rb_node **link, *parent;
1804
1805 link = fuse_find_polled_node(fc, ff->kh, &parent);
1806 BUG_ON(*link);
1807 rb_link_node(&ff->polled_node, parent, link);
1808 rb_insert_color(&ff->polled_node, &fc->polled_files);
1809 }
1810 spin_unlock(&fc->lock);
1811}
1812
1813static unsigned fuse_file_poll(struct file *file, poll_table *wait)
1814{
1815 struct inode *inode = file->f_dentry->d_inode;
1816 struct fuse_file *ff = file->private_data;
1817 struct fuse_conn *fc = get_fuse_conn(inode);
1818 struct fuse_poll_in inarg = { .fh = ff->fh, .kh = ff->kh };
1819 struct fuse_poll_out outarg;
1820 struct fuse_req *req;
1821 int err;
1822
1823 if (fc->no_poll)
1824 return DEFAULT_POLLMASK;
1825
1826 poll_wait(file, &ff->poll_wait, wait);
1827
1828 /*
1829 * Ask for notification iff there's someone waiting for it.
1830 * The client may ignore the flag and always notify.
1831 */
1832 if (waitqueue_active(&ff->poll_wait)) {
1833 inarg.flags |= FUSE_POLL_SCHEDULE_NOTIFY;
1834 fuse_register_polled_file(fc, ff);
1835 }
1836
1837 req = fuse_get_req(fc);
1838 if (IS_ERR(req))
1839 return PTR_ERR(req);
1840
1841 req->in.h.opcode = FUSE_POLL;
1842 req->in.h.nodeid = get_node_id(inode);
1843 req->in.numargs = 1;
1844 req->in.args[0].size = sizeof(inarg);
1845 req->in.args[0].value = &inarg;
1846 req->out.numargs = 1;
1847 req->out.args[0].size = sizeof(outarg);
1848 req->out.args[0].value = &outarg;
1849 fuse_request_send(fc, req);
1850 err = req->out.h.error;
1851 fuse_put_request(fc, req);
1852
1853 if (!err)
1854 return outarg.revents;
1855 if (err == -ENOSYS) {
1856 fc->no_poll = 1;
1857 return DEFAULT_POLLMASK;
1858 }
1859 return POLLERR;
1860}
1861
1862/*
1863 * This is called from fuse_handle_notify() on FUSE_NOTIFY_POLL and
1864 * wakes up the poll waiters.
1865 */
1866int fuse_notify_poll_wakeup(struct fuse_conn *fc,
1867 struct fuse_notify_poll_wakeup_out *outarg)
1868{
1869 u64 kh = outarg->kh;
1870 struct rb_node **link;
1871
1872 spin_lock(&fc->lock);
1873
1874 link = fuse_find_polled_node(fc, kh, NULL);
1875 if (*link) {
1876 struct fuse_file *ff;
1877
1878 ff = rb_entry(*link, struct fuse_file, polled_node);
1879 wake_up_interruptible_sync(&ff->poll_wait);
1880 }
1881
1882 spin_unlock(&fc->lock);
1883 return 0;
1884}
1885
1473static const struct file_operations fuse_file_operations = { 1886static const struct file_operations fuse_file_operations = {
1474 .llseek = fuse_file_llseek, 1887 .llseek = fuse_file_llseek,
1475 .read = do_sync_read, 1888 .read = do_sync_read,
@@ -1484,6 +1897,9 @@ static const struct file_operations fuse_file_operations = {
1484 .lock = fuse_file_lock, 1897 .lock = fuse_file_lock,
1485 .flock = fuse_file_flock, 1898 .flock = fuse_file_flock,
1486 .splice_read = generic_file_splice_read, 1899 .splice_read = generic_file_splice_read,
1900 .unlocked_ioctl = fuse_file_ioctl,
1901 .compat_ioctl = fuse_file_compat_ioctl,
1902 .poll = fuse_file_poll,
1487}; 1903};
1488 1904
1489static const struct file_operations fuse_direct_io_file_operations = { 1905static const struct file_operations fuse_direct_io_file_operations = {
@@ -1496,6 +1912,9 @@ static const struct file_operations fuse_direct_io_file_operations = {
1496 .fsync = fuse_fsync, 1912 .fsync = fuse_fsync,
1497 .lock = fuse_file_lock, 1913 .lock = fuse_file_lock,
1498 .flock = fuse_file_flock, 1914 .flock = fuse_file_flock,
1915 .unlocked_ioctl = fuse_file_ioctl,
1916 .compat_ioctl = fuse_file_compat_ioctl,
1917 .poll = fuse_file_poll,
1499 /* no mmap and splice_read */ 1918 /* no mmap and splice_read */
1500}; 1919};
1501 1920
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 35accfdd747f..5e64b815a5a1 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -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.
@@ -19,6 +19,8 @@
19#include <linux/backing-dev.h> 19#include <linux/backing-dev.h>
20#include <linux/mutex.h> 20#include <linux/mutex.h>
21#include <linux/rwsem.h> 21#include <linux/rwsem.h>
22#include <linux/rbtree.h>
23#include <linux/poll.h>
22 24
23/** Max number of pages that can be used in a single read request */ 25/** Max number of pages that can be used in a single read request */
24#define FUSE_MAX_PAGES_PER_REQ 32 26#define FUSE_MAX_PAGES_PER_REQ 32
@@ -100,6 +102,9 @@ struct fuse_file {
100 /** Request reserved for flush and release */ 102 /** Request reserved for flush and release */
101 struct fuse_req *reserved_req; 103 struct fuse_req *reserved_req;
102 104
105 /** Kernel file handle guaranteed to be unique */
106 u64 kh;
107
103 /** File handle used by userspace */ 108 /** File handle used by userspace */
104 u64 fh; 109 u64 fh;
105 110
@@ -108,6 +113,12 @@ struct fuse_file {
108 113
109 /** Entry on inode's write_files list */ 114 /** Entry on inode's write_files list */
110 struct list_head write_entry; 115 struct list_head write_entry;
116
117 /** RB node to be linked on fuse_conn->polled_files */
118 struct rb_node polled_node;
119
120 /** Wait queue head for poll */
121 wait_queue_head_t poll_wait;
111}; 122};
112 123
113/** One input argument of a request */ 124/** One input argument of a request */
@@ -322,6 +333,12 @@ struct fuse_conn {
322 /** The list of requests under I/O */ 333 /** The list of requests under I/O */
323 struct list_head io; 334 struct list_head io;
324 335
336 /** The next unique kernel file handle */
337 u64 khctr;
338
339 /** rbtree of fuse_files waiting for poll events indexed by ph */
340 struct rb_root polled_files;
341
325 /** Number of requests currently in the background */ 342 /** Number of requests currently in the background */
326 unsigned num_background; 343 unsigned num_background;
327 344
@@ -355,19 +372,19 @@ struct fuse_conn {
355 /** Connection failed (version mismatch). Cannot race with 372 /** Connection failed (version mismatch). Cannot race with
356 setting other bitfields since it is only set once in INIT 373 setting other bitfields since it is only set once in INIT
357 reply, before any other request, and never cleared */ 374 reply, before any other request, and never cleared */
358 unsigned conn_error : 1; 375 unsigned conn_error:1;
359 376
360 /** Connection successful. Only set in INIT */ 377 /** Connection successful. Only set in INIT */
361 unsigned conn_init : 1; 378 unsigned conn_init:1;
362 379
363 /** Do readpages asynchronously? Only set in INIT */ 380 /** Do readpages asynchronously? Only set in INIT */
364 unsigned async_read : 1; 381 unsigned async_read:1;
365 382
366 /** Do not send separate SETATTR request before open(O_TRUNC) */ 383 /** Do not send separate SETATTR request before open(O_TRUNC) */
367 unsigned atomic_o_trunc : 1; 384 unsigned atomic_o_trunc:1;
368 385
369 /** Filesystem supports NFS exporting. Only set in INIT */ 386 /** Filesystem supports NFS exporting. Only set in INIT */
370 unsigned export_support : 1; 387 unsigned export_support:1;
371 388
372 /* 389 /*
373 * The following bitfields are only for optimization purposes 390 * The following bitfields are only for optimization purposes
@@ -375,43 +392,46 @@ struct fuse_conn {
375 */ 392 */
376 393
377 /** Is fsync not implemented by fs? */ 394 /** Is fsync not implemented by fs? */
378 unsigned no_fsync : 1; 395 unsigned no_fsync:1;
379 396
380 /** Is fsyncdir not implemented by fs? */ 397 /** Is fsyncdir not implemented by fs? */
381 unsigned no_fsyncdir : 1; 398 unsigned no_fsyncdir:1;
382 399
383 /** Is flush not implemented by fs? */ 400 /** Is flush not implemented by fs? */
384 unsigned no_flush : 1; 401 unsigned no_flush:1;
385 402
386 /** Is setxattr not implemented by fs? */ 403 /** Is setxattr not implemented by fs? */
387 unsigned no_setxattr : 1; 404 unsigned no_setxattr:1;
388 405
389 /** Is getxattr not implemented by fs? */ 406 /** Is getxattr not implemented by fs? */
390 unsigned no_getxattr : 1; 407 unsigned no_getxattr:1;
391 408
392 /** Is listxattr not implemented by fs? */ 409 /** Is listxattr not implemented by fs? */
393 unsigned no_listxattr : 1; 410 unsigned no_listxattr:1;
394 411
395 /** Is removexattr not implemented by fs? */ 412 /** Is removexattr not implemented by fs? */
396 unsigned no_removexattr : 1; 413 unsigned no_removexattr:1;
397 414
398 /** Are file locking primitives not implemented by fs? */ 415 /** Are file locking primitives not implemented by fs? */
399 unsigned no_lock : 1; 416 unsigned no_lock:1;
400 417
401 /** Is access not implemented by fs? */ 418 /** Is access not implemented by fs? */
402 unsigned no_access : 1; 419 unsigned no_access:1;
403 420
404 /** Is create not implemented by fs? */ 421 /** Is create not implemented by fs? */
405 unsigned no_create : 1; 422 unsigned no_create:1;
406 423
407 /** Is interrupt not implemented by fs? */ 424 /** Is interrupt not implemented by fs? */
408 unsigned no_interrupt : 1; 425 unsigned no_interrupt:1;
409 426
410 /** Is bmap not implemented by fs? */ 427 /** Is bmap not implemented by fs? */
411 unsigned no_bmap : 1; 428 unsigned no_bmap:1;
429
430 /** Is poll not implemented by fs? */
431 unsigned no_poll:1;
412 432
413 /** Do multi-page cached writes */ 433 /** Do multi-page cached writes */
414 unsigned big_writes : 1; 434 unsigned big_writes:1;
415 435
416 /** The number of requests waiting for completion */ 436 /** The number of requests waiting for completion */
417 atomic_t num_waiting; 437 atomic_t num_waiting;
@@ -445,6 +465,9 @@ struct fuse_conn {
445 465
446 /** Version counter for attribute changes */ 466 /** Version counter for attribute changes */
447 u64 attr_version; 467 u64 attr_version;
468
469 /** Called on final put */
470 void (*release)(struct fuse_conn *);
448}; 471};
449 472
450static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 473static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
@@ -499,7 +522,7 @@ void fuse_read_fill(struct fuse_req *req, struct file *file,
499 */ 522 */
500int fuse_open_common(struct inode *inode, struct file *file, int isdir); 523int fuse_open_common(struct inode *inode, struct file *file, int isdir);
501 524
502struct fuse_file *fuse_file_alloc(void); 525struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
503void fuse_file_free(struct fuse_file *ff); 526void fuse_file_free(struct fuse_file *ff);
504void fuse_finish_open(struct inode *inode, struct file *file, 527void fuse_finish_open(struct inode *inode, struct file *file,
505 struct fuse_file *ff, struct fuse_open_out *outarg); 528 struct fuse_file *ff, struct fuse_open_out *outarg);
@@ -519,6 +542,12 @@ int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
519 int isdir); 542 int isdir);
520 543
521/** 544/**
545 * Notify poll wakeup
546 */
547int fuse_notify_poll_wakeup(struct fuse_conn *fc,
548 struct fuse_notify_poll_wakeup_out *outarg);
549
550/**
522 * Initialize file operations on a regular file 551 * Initialize file operations on a regular file
523 */ 552 */
524void fuse_init_file_inode(struct inode *inode); 553void fuse_init_file_inode(struct inode *inode);
@@ -593,19 +622,20 @@ void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
593/** 622/**
594 * Send a request (synchronous) 623 * Send a request (synchronous)
595 */ 624 */
596void request_send(struct fuse_conn *fc, struct fuse_req *req); 625void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
597 626
598/** 627/**
599 * Send a request with no reply 628 * Send a request with no reply
600 */ 629 */
601void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req); 630void fuse_request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
602 631
603/** 632/**
604 * Send a request in the background 633 * Send a request in the background
605 */ 634 */
606void request_send_background(struct fuse_conn *fc, struct fuse_req *req); 635void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
607 636
608void request_send_background_locked(struct fuse_conn *fc, struct fuse_req *req); 637void fuse_request_send_background_locked(struct fuse_conn *fc,
638 struct fuse_req *req);
609 639
610/* Abort all requests */ 640/* Abort all requests */
611void fuse_abort_conn(struct fuse_conn *fc); 641void fuse_abort_conn(struct fuse_conn *fc);
@@ -623,6 +653,11 @@ void fuse_invalidate_entry_cache(struct dentry *entry);
623struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 653struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
624 654
625/** 655/**
656 * Initialize fuse_conn
657 */
658int fuse_conn_init(struct fuse_conn *fc, struct super_block *sb);
659
660/**
626 * Release reference to fuse_conn 661 * Release reference to fuse_conn
627 */ 662 */
628void fuse_conn_put(struct fuse_conn *fc); 663void fuse_conn_put(struct fuse_conn *fc);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 2e99f34b4435..47c96fdca1ac 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.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.
@@ -37,10 +37,10 @@ struct fuse_mount_data {
37 unsigned rootmode; 37 unsigned rootmode;
38 unsigned user_id; 38 unsigned user_id;
39 unsigned group_id; 39 unsigned group_id;
40 unsigned fd_present : 1; 40 unsigned fd_present:1;
41 unsigned rootmode_present : 1; 41 unsigned rootmode_present:1;
42 unsigned user_id_present : 1; 42 unsigned user_id_present:1;
43 unsigned group_id_present : 1; 43 unsigned group_id_present:1;
44 unsigned flags; 44 unsigned flags;
45 unsigned max_read; 45 unsigned max_read;
46 unsigned blksize; 46 unsigned blksize;
@@ -94,7 +94,7 @@ void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
94 req->in.numargs = 1; 94 req->in.numargs = 1;
95 req->in.args[0].size = sizeof(struct fuse_forget_in); 95 req->in.args[0].size = sizeof(struct fuse_forget_in);
96 req->in.args[0].value = inarg; 96 req->in.args[0].value = inarg;
97 request_send_noreply(fc, req); 97 fuse_request_send_noreply(fc, req);
98} 98}
99 99
100static void fuse_clear_inode(struct inode *inode) 100static void fuse_clear_inode(struct inode *inode)
@@ -250,7 +250,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
250 250
251 fi = get_fuse_inode(inode); 251 fi = get_fuse_inode(inode);
252 spin_lock(&fc->lock); 252 spin_lock(&fc->lock);
253 fi->nlookup ++; 253 fi->nlookup++;
254 spin_unlock(&fc->lock); 254 spin_unlock(&fc->lock);
255 fuse_change_attributes(inode, attr, attr_valid, attr_version); 255 fuse_change_attributes(inode, attr, attr_valid, attr_version);
256 256
@@ -269,7 +269,7 @@ static void fuse_send_destroy(struct fuse_conn *fc)
269 fc->destroy_req = NULL; 269 fc->destroy_req = NULL;
270 req->in.h.opcode = FUSE_DESTROY; 270 req->in.h.opcode = FUSE_DESTROY;
271 req->force = 1; 271 req->force = 1;
272 request_send(fc, req); 272 fuse_request_send(fc, req);
273 fuse_put_request(fc, req); 273 fuse_put_request(fc, req);
274 } 274 }
275} 275}
@@ -334,7 +334,7 @@ static int fuse_statfs(struct dentry *dentry, struct kstatfs *buf)
334 req->out.args[0].size = 334 req->out.args[0].size =
335 fc->minor < 4 ? FUSE_COMPAT_STATFS_SIZE : sizeof(outarg); 335 fc->minor < 4 ? FUSE_COMPAT_STATFS_SIZE : sizeof(outarg);
336 req->out.args[0].value = &outarg; 336 req->out.args[0].value = &outarg;
337 request_send(fc, req); 337 fuse_request_send(fc, req);
338 err = req->out.h.error; 338 err = req->out.h.error;
339 if (!err) 339 if (!err)
340 convert_fuse_statfs(buf, &outarg.st); 340 convert_fuse_statfs(buf, &outarg.st);
@@ -462,68 +462,69 @@ static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt)
462 return 0; 462 return 0;
463} 463}
464 464
465static struct fuse_conn *new_conn(struct super_block *sb) 465int fuse_conn_init(struct fuse_conn *fc, struct super_block *sb)
466{ 466{
467 struct fuse_conn *fc;
468 int err; 467 int err;
469 468
470 fc = kzalloc(sizeof(*fc), GFP_KERNEL); 469 memset(fc, 0, sizeof(*fc));
471 if (fc) { 470 spin_lock_init(&fc->lock);
472 spin_lock_init(&fc->lock); 471 mutex_init(&fc->inst_mutex);
473 mutex_init(&fc->inst_mutex); 472 atomic_set(&fc->count, 1);
474 atomic_set(&fc->count, 1); 473 init_waitqueue_head(&fc->waitq);
475 init_waitqueue_head(&fc->waitq); 474 init_waitqueue_head(&fc->blocked_waitq);
476 init_waitqueue_head(&fc->blocked_waitq); 475 init_waitqueue_head(&fc->reserved_req_waitq);
477 init_waitqueue_head(&fc->reserved_req_waitq); 476 INIT_LIST_HEAD(&fc->pending);
478 INIT_LIST_HEAD(&fc->pending); 477 INIT_LIST_HEAD(&fc->processing);
479 INIT_LIST_HEAD(&fc->processing); 478 INIT_LIST_HEAD(&fc->io);
480 INIT_LIST_HEAD(&fc->io); 479 INIT_LIST_HEAD(&fc->interrupts);
481 INIT_LIST_HEAD(&fc->interrupts); 480 INIT_LIST_HEAD(&fc->bg_queue);
482 INIT_LIST_HEAD(&fc->bg_queue); 481 INIT_LIST_HEAD(&fc->entry);
483 atomic_set(&fc->num_waiting, 0); 482 atomic_set(&fc->num_waiting, 0);
484 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; 483 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
485 fc->bdi.unplug_io_fn = default_unplug_io_fn; 484 fc->bdi.unplug_io_fn = default_unplug_io_fn;
486 /* fuse does it's own writeback accounting */ 485 /* fuse does it's own writeback accounting */
487 fc->bdi.capabilities = BDI_CAP_NO_ACCT_WB; 486 fc->bdi.capabilities = BDI_CAP_NO_ACCT_WB;
488 fc->dev = sb->s_dev; 487 fc->khctr = 0;
489 err = bdi_init(&fc->bdi); 488 fc->polled_files = RB_ROOT;
490 if (err) 489 fc->dev = sb->s_dev;
491 goto error_kfree; 490 err = bdi_init(&fc->bdi);
492 if (sb->s_bdev) { 491 if (err)
493 err = bdi_register(&fc->bdi, NULL, "%u:%u-fuseblk", 492 goto error_mutex_destroy;
494 MAJOR(fc->dev), MINOR(fc->dev)); 493 if (sb->s_bdev) {
495 } else { 494 err = bdi_register(&fc->bdi, NULL, "%u:%u-fuseblk",
496 err = bdi_register_dev(&fc->bdi, fc->dev); 495 MAJOR(fc->dev), MINOR(fc->dev));
497 } 496 } else {
498 if (err) 497 err = bdi_register_dev(&fc->bdi, fc->dev);
499 goto error_bdi_destroy;
500 /*
501 * For a single fuse filesystem use max 1% of dirty +
502 * writeback threshold.
503 *
504 * This gives about 1M of write buffer for memory maps on a
505 * machine with 1G and 10% dirty_ratio, which should be more
506 * than enough.
507 *
508 * Privileged users can raise it by writing to
509 *
510 * /sys/class/bdi/<bdi>/max_ratio
511 */
512 bdi_set_max_ratio(&fc->bdi, 1);
513 fc->reqctr = 0;
514 fc->blocked = 1;
515 fc->attr_version = 1;
516 get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
517 } 498 }
518 return fc; 499 if (err)
500 goto error_bdi_destroy;
501 /*
502 * For a single fuse filesystem use max 1% of dirty +
503 * writeback threshold.
504 *
505 * This gives about 1M of write buffer for memory maps on a
506 * machine with 1G and 10% dirty_ratio, which should be more
507 * than enough.
508 *
509 * Privileged users can raise it by writing to
510 *
511 * /sys/class/bdi/<bdi>/max_ratio
512 */
513 bdi_set_max_ratio(&fc->bdi, 1);
514 fc->reqctr = 0;
515 fc->blocked = 1;
516 fc->attr_version = 1;
517 get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
519 518
520error_bdi_destroy: 519 return 0;
520
521 error_bdi_destroy:
521 bdi_destroy(&fc->bdi); 522 bdi_destroy(&fc->bdi);
522error_kfree: 523 error_mutex_destroy:
523 mutex_destroy(&fc->inst_mutex); 524 mutex_destroy(&fc->inst_mutex);
524 kfree(fc); 525 return err;
525 return NULL;
526} 526}
527EXPORT_SYMBOL_GPL(fuse_conn_init);
527 528
528void fuse_conn_put(struct fuse_conn *fc) 529void fuse_conn_put(struct fuse_conn *fc)
529{ 530{
@@ -532,7 +533,7 @@ void fuse_conn_put(struct fuse_conn *fc)
532 fuse_request_free(fc->destroy_req); 533 fuse_request_free(fc->destroy_req);
533 mutex_destroy(&fc->inst_mutex); 534 mutex_destroy(&fc->inst_mutex);
534 bdi_destroy(&fc->bdi); 535 bdi_destroy(&fc->bdi);
535 kfree(fc); 536 fc->release(fc);
536 } 537 }
537} 538}
538 539
@@ -542,7 +543,7 @@ struct fuse_conn *fuse_conn_get(struct fuse_conn *fc)
542 return fc; 543 return fc;
543} 544}
544 545
545static struct inode *get_root_inode(struct super_block *sb, unsigned mode) 546static struct inode *fuse_get_root_inode(struct super_block *sb, unsigned mode)
546{ 547{
547 struct fuse_attr attr; 548 struct fuse_attr attr;
548 memset(&attr, 0, sizeof(attr)); 549 memset(&attr, 0, sizeof(attr));
@@ -553,8 +554,7 @@ static struct inode *get_root_inode(struct super_block *sb, unsigned mode)
553 return fuse_iget(sb, 1, 0, &attr, 0, 0); 554 return fuse_iget(sb, 1, 0, &attr, 0, 0);
554} 555}
555 556
556struct fuse_inode_handle 557struct fuse_inode_handle {
557{
558 u64 nodeid; 558 u64 nodeid;
559 u32 generation; 559 u32 generation;
560}; 560};
@@ -761,7 +761,6 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
761 fc->max_write = max_t(unsigned, 4096, fc->max_write); 761 fc->max_write = max_t(unsigned, 4096, fc->max_write);
762 fc->conn_init = 1; 762 fc->conn_init = 1;
763 } 763 }
764 fuse_put_request(fc, req);
765 fc->blocked = 0; 764 fc->blocked = 0;
766 wake_up_all(&fc->blocked_waitq); 765 wake_up_all(&fc->blocked_waitq);
767} 766}
@@ -787,7 +786,12 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req)
787 req->out.args[0].size = sizeof(struct fuse_init_out); 786 req->out.args[0].size = sizeof(struct fuse_init_out);
788 req->out.args[0].value = &req->misc.init_out; 787 req->out.args[0].value = &req->misc.init_out;
789 req->end = process_init_reply; 788 req->end = process_init_reply;
790 request_send_background(fc, req); 789 fuse_request_send_background(fc, req);
790}
791
792static void fuse_free_conn(struct fuse_conn *fc)
793{
794 kfree(fc);
791} 795}
792 796
793static int fuse_fill_super(struct super_block *sb, void *data, int silent) 797static int fuse_fill_super(struct super_block *sb, void *data, int silent)
@@ -828,10 +832,17 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
828 if (file->f_op != &fuse_dev_operations) 832 if (file->f_op != &fuse_dev_operations)
829 return -EINVAL; 833 return -EINVAL;
830 834
831 fc = new_conn(sb); 835 fc = kmalloc(sizeof(*fc), GFP_KERNEL);
832 if (!fc) 836 if (!fc)
833 return -ENOMEM; 837 return -ENOMEM;
834 838
839 err = fuse_conn_init(fc, sb);
840 if (err) {
841 kfree(fc);
842 return err;
843 }
844
845 fc->release = fuse_free_conn;
835 fc->flags = d.flags; 846 fc->flags = d.flags;
836 fc->user_id = d.user_id; 847 fc->user_id = d.user_id;
837 fc->group_id = d.group_id; 848 fc->group_id = d.group_id;
@@ -841,7 +852,7 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
841 sb->s_fs_info = fc; 852 sb->s_fs_info = fc;
842 853
843 err = -ENOMEM; 854 err = -ENOMEM;
844 root = get_root_inode(sb, d.rootmode); 855 root = fuse_get_root_inode(sb, d.rootmode);
845 if (!root) 856 if (!root)
846 goto err; 857 goto err;
847 858
@@ -952,7 +963,7 @@ static inline void unregister_fuseblk(void)
952 963
953static void fuse_inode_init_once(void *foo) 964static void fuse_inode_init_once(void *foo)
954{ 965{
955 struct inode * inode = foo; 966 struct inode *inode = foo;
956 967
957 inode_init_once(inode); 968 inode_init_once(inode);
958} 969}
@@ -1031,7 +1042,7 @@ static int __init fuse_init(void)
1031{ 1042{
1032 int res; 1043 int res;
1033 1044
1034 printk("fuse init (API version %i.%i)\n", 1045 printk(KERN_INFO "fuse init (API version %i.%i)\n",
1035 FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); 1046 FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
1036 1047
1037 INIT_LIST_HEAD(&fuse_conn_list); 1048 INIT_LIST_HEAD(&fuse_conn_list);
diff --git a/include/linux/fuse.h b/include/linux/fuse.h
index 350fe9767bbc..162e5defe683 100644
--- a/include/linux/fuse.h
+++ b/include/linux/fuse.h
@@ -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.
@@ -20,29 +20,27 @@
20 * 20 *
21 * 7.10 21 * 7.10
22 * - add nonseekable open flag 22 * - add nonseekable open flag
23 *
24 * 7.11
25 * - add IOCTL message
26 * - add unsolicited notification support
27 * - add POLL message and NOTIFY_POLL notification
23 */ 28 */
24 29
25#ifndef _LINUX_FUSE_H 30#ifndef _LINUX_FUSE_H
26#define _LINUX_FUSE_H 31#define _LINUX_FUSE_H
27 32
28#include <asm/types.h> 33#include <linux/types.h>
29#include <linux/major.h>
30 34
31/** Version number of this interface */ 35/** Version number of this interface */
32#define FUSE_KERNEL_VERSION 7 36#define FUSE_KERNEL_VERSION 7
33 37
34/** Minor version number of this interface */ 38/** Minor version number of this interface */
35#define FUSE_KERNEL_MINOR_VERSION 10 39#define FUSE_KERNEL_MINOR_VERSION 11
36 40
37/** The node ID of the root inode */ 41/** The node ID of the root inode */
38#define FUSE_ROOT_ID 1 42#define FUSE_ROOT_ID 1
39 43
40/** The major number of the fuse character device */
41#define FUSE_MAJOR MISC_MAJOR
42
43/** The minor number of the fuse character device */
44#define FUSE_MINOR 229
45
46/* Make sure all structures are padded to 64bit boundary, so 32bit 44/* Make sure all structures are padded to 64bit boundary, so 32bit
47 userspace works under 64bit kernels */ 45 userspace works under 64bit kernels */
48 46
@@ -151,6 +149,28 @@ struct fuse_file_lock {
151 */ 149 */
152#define FUSE_READ_LOCKOWNER (1 << 1) 150#define FUSE_READ_LOCKOWNER (1 << 1)
153 151
152/**
153 * Ioctl flags
154 *
155 * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
156 * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
157 * FUSE_IOCTL_RETRY: retry with new iovecs
158 *
159 * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
160 */
161#define FUSE_IOCTL_COMPAT (1 << 0)
162#define FUSE_IOCTL_UNRESTRICTED (1 << 1)
163#define FUSE_IOCTL_RETRY (1 << 2)
164
165#define FUSE_IOCTL_MAX_IOV 256
166
167/**
168 * Poll flags
169 *
170 * FUSE_POLL_SCHEDULE_NOTIFY: request poll notify
171 */
172#define FUSE_POLL_SCHEDULE_NOTIFY (1 << 0)
173
154enum fuse_opcode { 174enum fuse_opcode {
155 FUSE_LOOKUP = 1, 175 FUSE_LOOKUP = 1,
156 FUSE_FORGET = 2, /* no reply */ 176 FUSE_FORGET = 2, /* no reply */
@@ -188,6 +208,13 @@ enum fuse_opcode {
188 FUSE_INTERRUPT = 36, 208 FUSE_INTERRUPT = 36,
189 FUSE_BMAP = 37, 209 FUSE_BMAP = 37,
190 FUSE_DESTROY = 38, 210 FUSE_DESTROY = 38,
211 FUSE_IOCTL = 39,
212 FUSE_POLL = 40,
213};
214
215enum fuse_notify_code {
216 FUSE_NOTIFY_POLL = 1,
217 FUSE_NOTIFY_CODE_MAX,
191}; 218};
192 219
193/* The read buffer is required to be at least 8k, but may be much larger */ 220/* The read buffer is required to be at least 8k, but may be much larger */
@@ -388,6 +415,38 @@ struct fuse_bmap_out {
388 __u64 block; 415 __u64 block;
389}; 416};
390 417
418struct fuse_ioctl_in {
419 __u64 fh;
420 __u32 flags;
421 __u32 cmd;
422 __u64 arg;
423 __u32 in_size;
424 __u32 out_size;
425};
426
427struct fuse_ioctl_out {
428 __s32 result;
429 __u32 flags;
430 __u32 in_iovs;
431 __u32 out_iovs;
432};
433
434struct fuse_poll_in {
435 __u64 fh;
436 __u64 kh;
437 __u32 flags;
438 __u32 padding;
439};
440
441struct fuse_poll_out {
442 __u32 revents;
443 __u32 padding;
444};
445
446struct fuse_notify_poll_wakeup_out {
447 __u64 kh;
448};
449
391struct fuse_in_header { 450struct fuse_in_header {
392 __u32 len; 451 __u32 len;
393 __u32 opcode; 452 __u32 opcode;
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 26433ec520b3..a820f816a49e 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -3,33 +3,33 @@
3#include <linux/module.h> 3#include <linux/module.h>
4#include <linux/major.h> 4#include <linux/major.h>
5 5
6#define PSMOUSE_MINOR 1 6#define PSMOUSE_MINOR 1
7#define MS_BUSMOUSE_MINOR 2 7#define MS_BUSMOUSE_MINOR 2
8#define ATIXL_BUSMOUSE_MINOR 3 8#define ATIXL_BUSMOUSE_MINOR 3
9/*#define AMIGAMOUSE_MINOR 4 FIXME OBSOLETE */ 9/*#define AMIGAMOUSE_MINOR 4 FIXME OBSOLETE */
10#define ATARIMOUSE_MINOR 5 10#define ATARIMOUSE_MINOR 5
11#define SUN_MOUSE_MINOR 6 11#define SUN_MOUSE_MINOR 6
12#define APOLLO_MOUSE_MINOR 7 12#define APOLLO_MOUSE_MINOR 7
13#define PC110PAD_MINOR 9 13#define PC110PAD_MINOR 9
14/*#define ADB_MOUSE_MINOR 10 FIXME OBSOLETE */ 14/*#define ADB_MOUSE_MINOR 10 FIXME OBSOLETE */
15#define WATCHDOG_MINOR 130 /* Watchdog timer */ 15#define WATCHDOG_MINOR 130 /* Watchdog timer */
16#define TEMP_MINOR 131 /* Temperature Sensor */ 16#define TEMP_MINOR 131 /* Temperature Sensor */
17#define RTC_MINOR 135 17#define RTC_MINOR 135
18#define EFI_RTC_MINOR 136 /* EFI Time services */ 18#define EFI_RTC_MINOR 136 /* EFI Time services */
19#define SUN_OPENPROM_MINOR 139 19#define SUN_OPENPROM_MINOR 139
20#define DMAPI_MINOR 140 /* DMAPI */ 20#define DMAPI_MINOR 140 /* DMAPI */
21#define NVRAM_MINOR 144 21#define NVRAM_MINOR 144
22#define SGI_MMTIMER 153 22#define SGI_MMTIMER 153
23#define STORE_QUEUE_MINOR 155 23#define STORE_QUEUE_MINOR 155
24#define I2O_MINOR 166 24#define I2O_MINOR 166
25#define MICROCODE_MINOR 184 25#define MICROCODE_MINOR 184
26#define MWAVE_MINOR 219 /* ACP/Mwave Modem */ 26#define TUN_MINOR 200
27#define MPT_MINOR 220 27#define MWAVE_MINOR 219 /* ACP/Mwave Modem */
28#define MISC_DYNAMIC_MINOR 255 28#define MPT_MINOR 220
29 29#define HPET_MINOR 228
30#define TUN_MINOR 200 30#define FUSE_MINOR 229
31#define HPET_MINOR 228 31#define KVM_MINOR 232
32#define KVM_MINOR 232 32#define MISC_DYNAMIC_MINOR 255
33 33
34struct device; 34struct device;
35 35