2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU GPL.
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/poll.h>
14 #include <linux/uio.h>
15 #include <linux/miscdevice.h>
16 #include <linux/pagemap.h>
17 #include <linux/file.h>
18 #include <linux/slab.h>
20 MODULE_ALIAS_MISCDEV(FUSE_MINOR);
22 static struct kmem_cache *fuse_req_cachep;
24 static struct fuse_conn *fuse_get_conn(struct file *file)
27 * Lockless access is OK, because file->private data is set
28 * once during mount and is valid until the file is released.
30 return file->private_data;
33 static void fuse_request_init(struct fuse_req *req)
35 memset(req, 0, sizeof(*req));
36 INIT_LIST_HEAD(&req->list);
37 INIT_LIST_HEAD(&req->intr_entry);
38 init_waitqueue_head(&req->waitq);
39 atomic_set(&req->count, 1);
42 struct fuse_req *fuse_request_alloc(void)
44 struct fuse_req *req = kmem_cache_alloc(fuse_req_cachep, GFP_KERNEL);
46 fuse_request_init(req);
50 void fuse_request_free(struct fuse_req *req)
52 kmem_cache_free(fuse_req_cachep, req);
55 static void block_sigs(sigset_t *oldset)
59 siginitsetinv(&mask, sigmask(SIGKILL));
60 sigprocmask(SIG_BLOCK, &mask, oldset);
63 static void restore_sigs(sigset_t *oldset)
65 sigprocmask(SIG_SETMASK, oldset, NULL);
68 static void __fuse_get_request(struct fuse_req *req)
70 atomic_inc(&req->count);
73 /* Must be called with > 1 refcount */
74 static void __fuse_put_request(struct fuse_req *req)
76 BUG_ON(atomic_read(&req->count) < 2);
77 atomic_dec(&req->count);
80 static void fuse_req_init_context(struct fuse_req *req)
82 req->in.h.uid = current->fsuid;
83 req->in.h.gid = current->fsgid;
84 req->in.h.pid = current->pid;
87 struct fuse_req *fuse_get_req(struct fuse_conn *fc)
94 atomic_inc(&fc->num_waiting);
96 intr = wait_event_interruptible(fc->blocked_waitq, !fc->blocked);
97 restore_sigs(&oldset);
106 req = fuse_request_alloc();
111 fuse_req_init_context(req);
116 atomic_dec(&fc->num_waiting);
121 * Return request in fuse_file->reserved_req. However that may
122 * currently be in use. If that is the case, wait for it to become
125 static struct fuse_req *get_reserved_req(struct fuse_conn *fc,
128 struct fuse_req *req = NULL;
129 struct fuse_file *ff = file->private_data;
132 wait_event(fc->reserved_req_waitq, ff->reserved_req);
133 spin_lock(&fc->lock);
134 if (ff->reserved_req) {
135 req = ff->reserved_req;
136 ff->reserved_req = NULL;
138 req->stolen_file = file;
140 spin_unlock(&fc->lock);
147 * Put stolen request back into fuse_file->reserved_req
149 static void put_reserved_req(struct fuse_conn *fc, struct fuse_req *req)
151 struct file *file = req->stolen_file;
152 struct fuse_file *ff = file->private_data;
154 spin_lock(&fc->lock);
155 fuse_request_init(req);
156 BUG_ON(ff->reserved_req);
157 ff->reserved_req = req;
158 wake_up_all(&fc->reserved_req_waitq);
159 spin_unlock(&fc->lock);
164 * Gets a requests for a file operation, always succeeds
166 * This is used for sending the FLUSH request, which must get to
167 * userspace, due to POSIX locks which may need to be unlocked.
169 * If allocation fails due to OOM, use the reserved request in
172 * This is very unlikely to deadlock accidentally, since the
173 * filesystem should not have it's own file open. If deadlock is
174 * intentional, it can still be broken by "aborting" the filesystem.
176 struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file)
178 struct fuse_req *req;
180 atomic_inc(&fc->num_waiting);
181 wait_event(fc->blocked_waitq, !fc->blocked);
182 req = fuse_request_alloc();
184 req = get_reserved_req(fc, file);
186 fuse_req_init_context(req);
191 void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
193 if (atomic_dec_and_test(&req->count)) {
195 atomic_dec(&fc->num_waiting);
197 if (req->stolen_file)
198 put_reserved_req(fc, req);
200 fuse_request_free(req);
205 * This function is called when a request is finished. Either a reply
206 * has arrived or it was aborted (and not yet sent) or some error
207 * occurred during communication with userspace, or the device file
208 * was closed. The requester thread is woken up (if still waiting),
209 * the 'end' callback is called if given, else the reference to the
210 * request is released
212 * Called with fc->lock, unlocks it
214 static void request_end(struct fuse_conn *fc, struct fuse_req *req)
217 void (*end) (struct fuse_conn *, struct fuse_req *) = req->end;
219 list_del(&req->list);
220 list_del(&req->intr_entry);
221 req->state = FUSE_REQ_FINISHED;
222 if (req->background) {
223 if (fc->num_background == FUSE_MAX_BACKGROUND) {
225 wake_up_all(&fc->blocked_waitq);
227 if (fc->num_background == FUSE_CONGESTION_THRESHOLD) {
228 clear_bdi_congested(&fc->bdi, READ);
229 clear_bdi_congested(&fc->bdi, WRITE);
231 fc->num_background--;
233 spin_unlock(&fc->lock);
234 wake_up(&req->waitq);
238 fuse_put_request(fc, req);
241 static void wait_answer_interruptible(struct fuse_conn *fc,
242 struct fuse_req *req)
244 if (signal_pending(current))
247 spin_unlock(&fc->lock);
248 wait_event_interruptible(req->waitq, req->state == FUSE_REQ_FINISHED);
249 spin_lock(&fc->lock);
252 static void queue_interrupt(struct fuse_conn *fc, struct fuse_req *req)
254 list_add_tail(&req->intr_entry, &fc->interrupts);
256 kill_fasync(&fc->fasync, SIGIO, POLL_IN);
259 /* Called with fc->lock held. Releases, and then reacquires it. */
260 static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
262 if (!fc->no_interrupt) {
263 /* Any signal may interrupt this */
264 wait_answer_interruptible(fc, req);
268 if (req->state == FUSE_REQ_FINISHED)
271 req->interrupted = 1;
272 if (req->state == FUSE_REQ_SENT)
273 queue_interrupt(fc, req);
277 spin_unlock(&fc->lock);
278 wait_event(req->waitq, req->state == FUSE_REQ_FINISHED);
279 spin_lock(&fc->lock);
283 /* Only fatal signals may interrupt this */
285 wait_answer_interruptible(fc, req);
286 restore_sigs(&oldset);
291 if (req->state == FUSE_REQ_FINISHED)
294 req->out.h.error = -EINTR;
299 /* This is uninterruptible sleep, because data is
300 being copied to/from the buffers of req. During
301 locked state, there mustn't be any filesystem
302 operation (e.g. page fault), since that could lead
304 spin_unlock(&fc->lock);
305 wait_event(req->waitq, !req->locked);
306 spin_lock(&fc->lock);
308 if (req->state == FUSE_REQ_PENDING) {
309 list_del(&req->list);
310 __fuse_put_request(req);
311 } else if (req->state == FUSE_REQ_SENT) {
312 spin_unlock(&fc->lock);
313 wait_event(req->waitq, req->state == FUSE_REQ_FINISHED);
314 spin_lock(&fc->lock);
318 static unsigned len_args(unsigned numargs, struct fuse_arg *args)
323 for (i = 0; i < numargs; i++)
324 nbytes += args[i].size;
329 static u64 fuse_get_unique(struct fuse_conn *fc)
332 /* zero is special */
339 static void queue_request(struct fuse_conn *fc, struct fuse_req *req)
341 req->in.h.unique = fuse_get_unique(fc);
342 req->in.h.len = sizeof(struct fuse_in_header) +
343 len_args(req->in.numargs, (struct fuse_arg *) req->in.args);
344 list_add_tail(&req->list, &fc->pending);
345 req->state = FUSE_REQ_PENDING;
348 atomic_inc(&fc->num_waiting);
351 kill_fasync(&fc->fasync, SIGIO, POLL_IN);
354 void request_send(struct fuse_conn *fc, struct fuse_req *req)
357 spin_lock(&fc->lock);
359 req->out.h.error = -ENOTCONN;
360 else if (fc->conn_error)
361 req->out.h.error = -ECONNREFUSED;
363 queue_request(fc, req);
364 /* acquire extra reference, since request is still needed
365 after request_end() */
366 __fuse_get_request(req);
368 request_wait_answer(fc, req);
370 spin_unlock(&fc->lock);
373 static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
375 spin_lock(&fc->lock);
378 fc->num_background++;
379 if (fc->num_background == FUSE_MAX_BACKGROUND)
381 if (fc->num_background == FUSE_CONGESTION_THRESHOLD) {
382 set_bdi_congested(&fc->bdi, READ);
383 set_bdi_congested(&fc->bdi, WRITE);
386 queue_request(fc, req);
387 spin_unlock(&fc->lock);
389 req->out.h.error = -ENOTCONN;
390 request_end(fc, req);
394 void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req)
397 request_send_nowait(fc, req);
400 void request_send_background(struct fuse_conn *fc, struct fuse_req *req)
403 request_send_nowait(fc, req);
407 * Lock the request. Up to the next unlock_request() there mustn't be
408 * anything that could cause a page-fault. If the request was already
411 static int lock_request(struct fuse_conn *fc, struct fuse_req *req)
415 spin_lock(&fc->lock);
420 spin_unlock(&fc->lock);
426 * Unlock request. If it was aborted during being locked, the
427 * requester thread is currently waiting for it to be unlocked, so
430 static void unlock_request(struct fuse_conn *fc, struct fuse_req *req)
433 spin_lock(&fc->lock);
436 wake_up(&req->waitq);
437 spin_unlock(&fc->lock);
441 struct fuse_copy_state {
442 struct fuse_conn *fc;
444 struct fuse_req *req;
445 const struct iovec *iov;
446 unsigned long nr_segs;
447 unsigned long seglen;
455 static void fuse_copy_init(struct fuse_copy_state *cs, struct fuse_conn *fc,
456 int write, struct fuse_req *req,
457 const struct iovec *iov, unsigned long nr_segs)
459 memset(cs, 0, sizeof(*cs));
464 cs->nr_segs = nr_segs;
467 /* Unmap and put previous page of userspace buffer */
468 static void fuse_copy_finish(struct fuse_copy_state *cs)
471 kunmap_atomic(cs->mapaddr, KM_USER0);
473 flush_dcache_page(cs->pg);
474 set_page_dirty_lock(cs->pg);
482 * Get another pagefull of userspace buffer, and map it to kernel
483 * address space, and lock request
485 static int fuse_copy_fill(struct fuse_copy_state *cs)
487 unsigned long offset;
490 unlock_request(cs->fc, cs->req);
491 fuse_copy_finish(cs);
493 BUG_ON(!cs->nr_segs);
494 cs->seglen = cs->iov[0].iov_len;
495 cs->addr = (unsigned long) cs->iov[0].iov_base;
499 down_read(¤t->mm->mmap_sem);
500 err = get_user_pages(current, current->mm, cs->addr, 1, cs->write, 0,
502 up_read(¤t->mm->mmap_sem);
506 offset = cs->addr % PAGE_SIZE;
507 cs->mapaddr = kmap_atomic(cs->pg, KM_USER0);
508 cs->buf = cs->mapaddr + offset;
509 cs->len = min(PAGE_SIZE - offset, cs->seglen);
510 cs->seglen -= cs->len;
513 return lock_request(cs->fc, cs->req);
516 /* Do as much copy to/from userspace buffer as we can */
517 static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size)
519 unsigned ncpy = min(*size, cs->len);
522 memcpy(cs->buf, *val, ncpy);
524 memcpy(*val, cs->buf, ncpy);
534 * Copy a page in the request to/from the userspace buffer. Must be
537 static int fuse_copy_page(struct fuse_copy_state *cs, struct page *page,
538 unsigned offset, unsigned count, int zeroing)
540 if (page && zeroing && count < PAGE_SIZE) {
541 void *mapaddr = kmap_atomic(page, KM_USER1);
542 memset(mapaddr, 0, PAGE_SIZE);
543 kunmap_atomic(mapaddr, KM_USER1);
547 if (!cs->len && (err = fuse_copy_fill(cs)))
550 void *mapaddr = kmap_atomic(page, KM_USER1);
551 void *buf = mapaddr + offset;
552 offset += fuse_copy_do(cs, &buf, &count);
553 kunmap_atomic(mapaddr, KM_USER1);
555 offset += fuse_copy_do(cs, NULL, &count);
557 if (page && !cs->write)
558 flush_dcache_page(page);
562 /* Copy pages in the request to/from userspace buffer */
563 static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes,
567 struct fuse_req *req = cs->req;
568 unsigned offset = req->page_offset;
569 unsigned count = min(nbytes, (unsigned) PAGE_SIZE - offset);
571 for (i = 0; i < req->num_pages && (nbytes || zeroing); i++) {
572 struct page *page = req->pages[i];
573 int err = fuse_copy_page(cs, page, offset, count, zeroing);
578 count = min(nbytes, (unsigned) PAGE_SIZE);
584 /* Copy a single argument in the request to/from userspace buffer */
585 static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size)
589 if (!cs->len && (err = fuse_copy_fill(cs)))
591 fuse_copy_do(cs, &val, &size);
596 /* Copy request arguments to/from userspace buffer */
597 static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs,
598 unsigned argpages, struct fuse_arg *args,
604 for (i = 0; !err && i < numargs; i++) {
605 struct fuse_arg *arg = &args[i];
606 if (i == numargs - 1 && argpages)
607 err = fuse_copy_pages(cs, arg->size, zeroing);
609 err = fuse_copy_one(cs, arg->value, arg->size);
614 static int request_pending(struct fuse_conn *fc)
616 return !list_empty(&fc->pending) || !list_empty(&fc->interrupts);
619 /* Wait until a request is available on the pending list */
620 static void request_wait(struct fuse_conn *fc)
622 DECLARE_WAITQUEUE(wait, current);
624 add_wait_queue_exclusive(&fc->waitq, &wait);
625 while (fc->connected && !request_pending(fc)) {
626 set_current_state(TASK_INTERRUPTIBLE);
627 if (signal_pending(current))
630 spin_unlock(&fc->lock);
632 spin_lock(&fc->lock);
634 set_current_state(TASK_RUNNING);
635 remove_wait_queue(&fc->waitq, &wait);
639 * Transfer an interrupt request to userspace
641 * Unlike other requests this is assembled on demand, without a need
642 * to allocate a separate fuse_req structure.
644 * Called with fc->lock held, releases it
646 static int fuse_read_interrupt(struct fuse_conn *fc, struct fuse_req *req,
647 const struct iovec *iov, unsigned long nr_segs)
650 struct fuse_copy_state cs;
651 struct fuse_in_header ih;
652 struct fuse_interrupt_in arg;
653 unsigned reqsize = sizeof(ih) + sizeof(arg);
656 list_del_init(&req->intr_entry);
657 req->intr_unique = fuse_get_unique(fc);
658 memset(&ih, 0, sizeof(ih));
659 memset(&arg, 0, sizeof(arg));
661 ih.opcode = FUSE_INTERRUPT;
662 ih.unique = req->intr_unique;
663 arg.unique = req->in.h.unique;
665 spin_unlock(&fc->lock);
666 if (iov_length(iov, nr_segs) < reqsize)
669 fuse_copy_init(&cs, fc, 1, NULL, iov, nr_segs);
670 err = fuse_copy_one(&cs, &ih, sizeof(ih));
672 err = fuse_copy_one(&cs, &arg, sizeof(arg));
673 fuse_copy_finish(&cs);
675 return err ? err : reqsize;
679 * Read a single request into the userspace filesystem's buffer. This
680 * function waits until a request is available, then removes it from
681 * the pending list and copies request data to userspace buffer. If
682 * no reply is needed (FORGET) or request has been aborted or there
683 * was an error during the copying then it's finished by calling
684 * request_end(). Otherwise add it to the processing list, and set
687 static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
688 unsigned long nr_segs, loff_t pos)
691 struct fuse_req *req;
693 struct fuse_copy_state cs;
695 struct file *file = iocb->ki_filp;
696 struct fuse_conn *fc = fuse_get_conn(file);
701 spin_lock(&fc->lock);
703 if ((file->f_flags & O_NONBLOCK) && fc->connected &&
704 !request_pending(fc))
712 if (!request_pending(fc))
715 if (!list_empty(&fc->interrupts)) {
716 req = list_entry(fc->interrupts.next, struct fuse_req,
718 return fuse_read_interrupt(fc, req, iov, nr_segs);
721 req = list_entry(fc->pending.next, struct fuse_req, list);
722 req->state = FUSE_REQ_READING;
723 list_move(&req->list, &fc->io);
727 /* If request is too large, reply with an error and restart the read */
728 if (iov_length(iov, nr_segs) < reqsize) {
729 req->out.h.error = -EIO;
730 /* SETXATTR is special, since it may contain too large data */
731 if (in->h.opcode == FUSE_SETXATTR)
732 req->out.h.error = -E2BIG;
733 request_end(fc, req);
736 spin_unlock(&fc->lock);
737 fuse_copy_init(&cs, fc, 1, req, iov, nr_segs);
738 err = fuse_copy_one(&cs, &in->h, sizeof(in->h));
740 err = fuse_copy_args(&cs, in->numargs, in->argpages,
741 (struct fuse_arg *) in->args, 0);
742 fuse_copy_finish(&cs);
743 spin_lock(&fc->lock);
745 if (!err && req->aborted)
749 req->out.h.error = -EIO;
750 request_end(fc, req);
754 request_end(fc, req);
756 req->state = FUSE_REQ_SENT;
757 list_move_tail(&req->list, &fc->processing);
758 if (req->interrupted)
759 queue_interrupt(fc, req);
760 spin_unlock(&fc->lock);
765 spin_unlock(&fc->lock);
769 /* Look up request on processing list by unique ID */
770 static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique)
772 struct list_head *entry;
774 list_for_each(entry, &fc->processing) {
775 struct fuse_req *req;
776 req = list_entry(entry, struct fuse_req, list);
777 if (req->in.h.unique == unique || req->intr_unique == unique)
783 static int copy_out_args(struct fuse_copy_state *cs, struct fuse_out *out,
786 unsigned reqsize = sizeof(struct fuse_out_header);
789 return nbytes != reqsize ? -EINVAL : 0;
791 reqsize += len_args(out->numargs, out->args);
793 if (reqsize < nbytes || (reqsize > nbytes && !out->argvar))
795 else if (reqsize > nbytes) {
796 struct fuse_arg *lastarg = &out->args[out->numargs-1];
797 unsigned diffsize = reqsize - nbytes;
798 if (diffsize > lastarg->size)
800 lastarg->size -= diffsize;
802 return fuse_copy_args(cs, out->numargs, out->argpages, out->args,
807 * Write a single reply to a request. First the header is copied from
808 * the write buffer. The request is then searched on the processing
809 * list by the unique ID found in the header. If found, then remove
810 * it from the list and copy the rest of the buffer to the request.
811 * The request is finished by calling request_end()
813 static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
814 unsigned long nr_segs, loff_t pos)
817 unsigned nbytes = iov_length(iov, nr_segs);
818 struct fuse_req *req;
819 struct fuse_out_header oh;
820 struct fuse_copy_state cs;
821 struct fuse_conn *fc = fuse_get_conn(iocb->ki_filp);
825 fuse_copy_init(&cs, fc, 0, NULL, iov, nr_segs);
826 if (nbytes < sizeof(struct fuse_out_header))
829 err = fuse_copy_one(&cs, &oh, sizeof(oh));
833 if (!oh.unique || oh.error <= -1000 || oh.error > 0 ||
837 spin_lock(&fc->lock);
842 req = request_find(fc, oh.unique);
847 spin_unlock(&fc->lock);
848 fuse_copy_finish(&cs);
849 spin_lock(&fc->lock);
850 request_end(fc, req);
853 /* Is it an interrupt reply? */
854 if (req->intr_unique == oh.unique) {
856 if (nbytes != sizeof(struct fuse_out_header))
859 if (oh.error == -ENOSYS)
860 fc->no_interrupt = 1;
861 else if (oh.error == -EAGAIN)
862 queue_interrupt(fc, req);
864 spin_unlock(&fc->lock);
865 fuse_copy_finish(&cs);
869 req->state = FUSE_REQ_WRITING;
870 list_move(&req->list, &fc->io);
874 spin_unlock(&fc->lock);
876 err = copy_out_args(&cs, &req->out, nbytes);
877 fuse_copy_finish(&cs);
879 spin_lock(&fc->lock);
884 } else if (!req->aborted)
885 req->out.h.error = -EIO;
886 request_end(fc, req);
888 return err ? err : nbytes;
891 spin_unlock(&fc->lock);
893 fuse_copy_finish(&cs);
897 static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
899 unsigned mask = POLLOUT | POLLWRNORM;
900 struct fuse_conn *fc = fuse_get_conn(file);
904 poll_wait(file, &fc->waitq, wait);
906 spin_lock(&fc->lock);
909 else if (request_pending(fc))
910 mask |= POLLIN | POLLRDNORM;
911 spin_unlock(&fc->lock);
917 * Abort all requests on the given list (pending or processing)
919 * This function releases and reacquires fc->lock
921 static void end_requests(struct fuse_conn *fc, struct list_head *head)
923 while (!list_empty(head)) {
924 struct fuse_req *req;
925 req = list_entry(head->next, struct fuse_req, list);
926 req->out.h.error = -ECONNABORTED;
927 request_end(fc, req);
928 spin_lock(&fc->lock);
933 * Abort requests under I/O
935 * The requests are set to aborted and finished, and the request
936 * waiter is woken up. This will make request_wait_answer() wait
937 * until the request is unlocked and then return.
939 * If the request is asynchronous, then the end function needs to be
940 * called after waiting for the request to be unlocked (if it was
943 static void end_io_requests(struct fuse_conn *fc)
945 while (!list_empty(&fc->io)) {
946 struct fuse_req *req =
947 list_entry(fc->io.next, struct fuse_req, list);
948 void (*end) (struct fuse_conn *, struct fuse_req *) = req->end;
951 req->out.h.error = -ECONNABORTED;
952 req->state = FUSE_REQ_FINISHED;
953 list_del_init(&req->list);
954 wake_up(&req->waitq);
957 /* The end function will consume this reference */
958 __fuse_get_request(req);
959 spin_unlock(&fc->lock);
960 wait_event(req->waitq, !req->locked);
962 spin_lock(&fc->lock);
968 * Abort all requests.
970 * Emergency exit in case of a malicious or accidental deadlock, or
971 * just a hung filesystem.
973 * The same effect is usually achievable through killing the
974 * filesystem daemon and all users of the filesystem. The exception
975 * is the combination of an asynchronous request and the tricky
976 * deadlock (see Documentation/filesystems/fuse.txt).
978 * During the aborting, progression of requests from the pending and
979 * processing lists onto the io list, and progression of new requests
980 * onto the pending list is prevented by req->connected being false.
982 * Progression of requests under I/O to the processing list is
983 * prevented by the req->aborted flag being true for these requests.
984 * For this reason requests on the io list must be aborted first.
986 void fuse_abort_conn(struct fuse_conn *fc)
988 spin_lock(&fc->lock);
993 end_requests(fc, &fc->pending);
994 end_requests(fc, &fc->processing);
995 wake_up_all(&fc->waitq);
996 wake_up_all(&fc->blocked_waitq);
997 kill_fasync(&fc->fasync, SIGIO, POLL_IN);
999 spin_unlock(&fc->lock);
1002 static int fuse_dev_release(struct inode *inode, struct file *file)
1004 struct fuse_conn *fc = fuse_get_conn(file);
1006 spin_lock(&fc->lock);
1008 end_requests(fc, &fc->pending);
1009 end_requests(fc, &fc->processing);
1010 spin_unlock(&fc->lock);
1011 fasync_helper(-1, file, 0, &fc->fasync);
1018 static int fuse_dev_fasync(int fd, struct file *file, int on)
1020 struct fuse_conn *fc = fuse_get_conn(file);
1024 /* No locking - fasync_helper does its own locking */
1025 return fasync_helper(fd, file, on, &fc->fasync);
1028 const struct file_operations fuse_dev_operations = {
1029 .owner = THIS_MODULE,
1030 .llseek = no_llseek,
1031 .read = do_sync_read,
1032 .aio_read = fuse_dev_read,
1033 .write = do_sync_write,
1034 .aio_write = fuse_dev_write,
1035 .poll = fuse_dev_poll,
1036 .release = fuse_dev_release,
1037 .fasync = fuse_dev_fasync,
1040 static struct miscdevice fuse_miscdevice = {
1041 .minor = FUSE_MINOR,
1043 .fops = &fuse_dev_operations,
1046 int __init fuse_dev_init(void)
1049 fuse_req_cachep = kmem_cache_create("fuse_request",
1050 sizeof(struct fuse_req),
1052 if (!fuse_req_cachep)
1055 err = misc_register(&fuse_miscdevice);
1057 goto out_cache_clean;
1062 kmem_cache_destroy(fuse_req_cachep);
1067 void fuse_dev_cleanup(void)
1069 misc_deregister(&fuse_miscdevice);
1070 kmem_cache_destroy(fuse_req_cachep);