2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 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 kmem_cache_t
*fuse_req_cachep
;
24 static struct fuse_conn
*fuse_get_conn(struct file
*file
)
27 spin_lock(&fuse_lock
);
28 fc
= file
->private_data
;
29 if (fc
&& !fc
->connected
)
31 spin_unlock(&fuse_lock
);
35 static void fuse_request_init(struct fuse_req
*req
)
37 memset(req
, 0, sizeof(*req
));
38 INIT_LIST_HEAD(&req
->list
);
39 init_waitqueue_head(&req
->waitq
);
40 atomic_set(&req
->count
, 1);
43 struct fuse_req
*fuse_request_alloc(void)
45 struct fuse_req
*req
= kmem_cache_alloc(fuse_req_cachep
, SLAB_KERNEL
);
47 fuse_request_init(req
);
51 void fuse_request_free(struct fuse_req
*req
)
53 kmem_cache_free(fuse_req_cachep
, req
);
56 static void block_sigs(sigset_t
*oldset
)
60 siginitsetinv(&mask
, sigmask(SIGKILL
));
61 sigprocmask(SIG_BLOCK
, &mask
, oldset
);
64 static void restore_sigs(sigset_t
*oldset
)
66 sigprocmask(SIG_SETMASK
, oldset
, NULL
);
69 void fuse_reset_request(struct fuse_req
*req
)
71 int preallocated
= req
->preallocated
;
72 BUG_ON(atomic_read(&req
->count
) != 1);
73 fuse_request_init(req
);
74 req
->preallocated
= preallocated
;
77 static void __fuse_get_request(struct fuse_req
*req
)
79 atomic_inc(&req
->count
);
82 /* Must be called with > 1 refcount */
83 static void __fuse_put_request(struct fuse_req
*req
)
85 BUG_ON(atomic_read(&req
->count
) < 2);
86 atomic_dec(&req
->count
);
89 static struct fuse_req
*do_get_request(struct fuse_conn
*fc
)
93 spin_lock(&fuse_lock
);
94 BUG_ON(list_empty(&fc
->unused_list
));
95 req
= list_entry(fc
->unused_list
.next
, struct fuse_req
, list
);
96 list_del_init(&req
->list
);
97 spin_unlock(&fuse_lock
);
98 fuse_request_init(req
);
99 req
->preallocated
= 1;
100 req
->in
.h
.uid
= current
->fsuid
;
101 req
->in
.h
.gid
= current
->fsgid
;
102 req
->in
.h
.pid
= current
->pid
;
106 /* This can return NULL, but only in case it's interrupted by a SIGKILL */
107 struct fuse_req
*fuse_get_request(struct fuse_conn
*fc
)
112 atomic_inc(&fc
->num_waiting
);
114 intr
= down_interruptible(&fc
->outstanding_sem
);
115 restore_sigs(&oldset
);
117 atomic_dec(&fc
->num_waiting
);
120 return do_get_request(fc
);
123 /* Must be called with fuse_lock held */
124 static void fuse_putback_request(struct fuse_conn
*fc
, struct fuse_req
*req
)
126 if (req
->preallocated
) {
127 atomic_dec(&fc
->num_waiting
);
128 list_add(&req
->list
, &fc
->unused_list
);
130 fuse_request_free(req
);
132 /* If we are in debt decrease that first */
133 if (fc
->outstanding_debt
)
134 fc
->outstanding_debt
--;
136 up(&fc
->outstanding_sem
);
139 void fuse_put_request(struct fuse_conn
*fc
, struct fuse_req
*req
)
141 if (atomic_dec_and_test(&req
->count
)) {
142 spin_lock(&fuse_lock
);
143 fuse_putback_request(fc
, req
);
144 spin_unlock(&fuse_lock
);
148 static void fuse_put_request_locked(struct fuse_conn
*fc
, struct fuse_req
*req
)
150 if (atomic_dec_and_test(&req
->count
))
151 fuse_putback_request(fc
, req
);
154 void fuse_release_background(struct fuse_req
*req
)
160 spin_lock(&fuse_lock
);
161 list_del(&req
->bg_entry
);
162 spin_unlock(&fuse_lock
);
166 * This function is called when a request is finished. Either a reply
167 * has arrived or it was interrupted (and not yet sent) or some error
168 * occurred during communication with userspace, or the device file
169 * was closed. In case of a background request the reference to the
170 * stored objects are released. The requester thread is woken up (if
171 * still waiting), the 'end' callback is called if given, else the
172 * reference to the request is released
174 * Releasing extra reference for foreground requests must be done
175 * within the same locked region as setting state to finished. This
176 * is because fuse_reset_request() may be called after request is
177 * finished and it must be the sole possessor. If request is
178 * interrupted and put in the background, it will return with an error
179 * and hence never be reset and reused.
181 * Called with fuse_lock, unlocks it
183 static void request_end(struct fuse_conn
*fc
, struct fuse_req
*req
)
185 list_del(&req
->list
);
186 req
->state
= FUSE_REQ_FINISHED
;
187 if (!req
->background
) {
188 wake_up(&req
->waitq
);
189 fuse_put_request_locked(fc
, req
);
190 spin_unlock(&fuse_lock
);
192 void (*end
) (struct fuse_conn
*, struct fuse_req
*) = req
->end
;
194 spin_unlock(&fuse_lock
);
195 down_read(&fc
->sbput_sem
);
197 fuse_release_background(req
);
198 up_read(&fc
->sbput_sem
);
202 fuse_put_request(fc
, req
);
207 * Unfortunately request interruption not just solves the deadlock
208 * problem, it causes problems too. These stem from the fact, that an
209 * interrupted request is continued to be processed in userspace,
210 * while all the locks and object references (inode and file) held
211 * during the operation are released.
213 * To release the locks is exactly why there's a need to interrupt the
214 * request, so there's not a lot that can be done about this, except
215 * introduce additional locking in userspace.
217 * More important is to keep inode and file references until userspace
218 * has replied, otherwise FORGET and RELEASE could be sent while the
219 * inode/file is still used by the filesystem.
221 * For this reason the concept of "background" request is introduced.
222 * An interrupted request is backgrounded if it has been already sent
223 * to userspace. Backgrounding involves getting an extra reference to
224 * inode(s) or file used in the request, and adding the request to
225 * fc->background list. When a reply is received for a background
226 * request, the object references are released, and the request is
227 * removed from the list. If the filesystem is unmounted while there
228 * are still background requests, the list is walked and references
229 * are released as if a reply was received.
231 * There's one more use for a background request. The RELEASE message is
232 * always sent as background, since it doesn't return an error or
235 static void background_request(struct fuse_conn
*fc
, struct fuse_req
*req
)
238 list_add(&req
->bg_entry
, &fc
->background
);
240 req
->inode
= igrab(req
->inode
);
242 req
->inode2
= igrab(req
->inode2
);
247 /* Called with fuse_lock held. Releases, and then reacquires it. */
248 static void request_wait_answer(struct fuse_conn
*fc
, struct fuse_req
*req
)
252 spin_unlock(&fuse_lock
);
254 wait_event_interruptible(req
->waitq
, req
->state
== FUSE_REQ_FINISHED
);
255 restore_sigs(&oldset
);
256 spin_lock(&fuse_lock
);
257 if (req
->state
== FUSE_REQ_FINISHED
&& !req
->interrupted
)
260 if (!req
->interrupted
) {
261 req
->out
.h
.error
= -EINTR
;
262 req
->interrupted
= 1;
265 /* This is uninterruptible sleep, because data is
266 being copied to/from the buffers of req. During
267 locked state, there mustn't be any filesystem
268 operation (e.g. page fault), since that could lead
270 spin_unlock(&fuse_lock
);
271 wait_event(req
->waitq
, !req
->locked
);
272 spin_lock(&fuse_lock
);
274 if (req
->state
== FUSE_REQ_PENDING
) {
275 list_del(&req
->list
);
276 __fuse_put_request(req
);
277 } else if (req
->state
== FUSE_REQ_SENT
)
278 background_request(fc
, req
);
281 static unsigned len_args(unsigned numargs
, struct fuse_arg
*args
)
286 for (i
= 0; i
< numargs
; i
++)
287 nbytes
+= args
[i
].size
;
292 static void queue_request(struct fuse_conn
*fc
, struct fuse_req
*req
)
295 /* zero is special */
298 req
->in
.h
.unique
= fc
->reqctr
;
299 req
->in
.h
.len
= sizeof(struct fuse_in_header
) +
300 len_args(req
->in
.numargs
, (struct fuse_arg
*) req
->in
.args
);
301 if (!req
->preallocated
) {
302 /* If request is not preallocated (either FORGET or
303 RELEASE), then still decrease outstanding_sem, so
304 user can't open infinite number of files while not
305 processing the RELEASE requests. However for
306 efficiency do it without blocking, so if down()
307 would block, just increase the debt instead */
308 if (down_trylock(&fc
->outstanding_sem
))
309 fc
->outstanding_debt
++;
311 list_add_tail(&req
->list
, &fc
->pending
);
312 req
->state
= FUSE_REQ_PENDING
;
317 * This can only be interrupted by a SIGKILL
319 void request_send(struct fuse_conn
*fc
, struct fuse_req
*req
)
322 spin_lock(&fuse_lock
);
324 req
->out
.h
.error
= -ENOTCONN
;
325 else if (fc
->conn_error
)
326 req
->out
.h
.error
= -ECONNREFUSED
;
328 queue_request(fc
, req
);
329 /* acquire extra reference, since request is still needed
330 after request_end() */
331 __fuse_get_request(req
);
333 request_wait_answer(fc
, req
);
335 spin_unlock(&fuse_lock
);
338 static void request_send_nowait(struct fuse_conn
*fc
, struct fuse_req
*req
)
340 spin_lock(&fuse_lock
);
342 queue_request(fc
, req
);
343 spin_unlock(&fuse_lock
);
345 req
->out
.h
.error
= -ENOTCONN
;
346 request_end(fc
, req
);
350 void request_send_noreply(struct fuse_conn
*fc
, struct fuse_req
*req
)
353 request_send_nowait(fc
, req
);
356 void request_send_background(struct fuse_conn
*fc
, struct fuse_req
*req
)
359 spin_lock(&fuse_lock
);
360 background_request(fc
, req
);
361 spin_unlock(&fuse_lock
);
362 request_send_nowait(fc
, req
);
366 * Lock the request. Up to the next unlock_request() there mustn't be
367 * anything that could cause a page-fault. If the request was already
368 * interrupted bail out.
370 static int lock_request(struct fuse_req
*req
)
374 spin_lock(&fuse_lock
);
375 if (req
->interrupted
)
379 spin_unlock(&fuse_lock
);
385 * Unlock request. If it was interrupted during being locked, the
386 * requester thread is currently waiting for it to be unlocked, so
389 static void unlock_request(struct fuse_req
*req
)
392 spin_lock(&fuse_lock
);
394 if (req
->interrupted
)
395 wake_up(&req
->waitq
);
396 spin_unlock(&fuse_lock
);
400 struct fuse_copy_state
{
402 struct fuse_req
*req
;
403 const struct iovec
*iov
;
404 unsigned long nr_segs
;
405 unsigned long seglen
;
413 static void fuse_copy_init(struct fuse_copy_state
*cs
, int write
,
414 struct fuse_req
*req
, const struct iovec
*iov
,
415 unsigned long nr_segs
)
417 memset(cs
, 0, sizeof(*cs
));
421 cs
->nr_segs
= nr_segs
;
424 /* Unmap and put previous page of userspace buffer */
425 static void fuse_copy_finish(struct fuse_copy_state
*cs
)
428 kunmap_atomic(cs
->mapaddr
, KM_USER0
);
430 flush_dcache_page(cs
->pg
);
431 set_page_dirty_lock(cs
->pg
);
439 * Get another pagefull of userspace buffer, and map it to kernel
440 * address space, and lock request
442 static int fuse_copy_fill(struct fuse_copy_state
*cs
)
444 unsigned long offset
;
447 unlock_request(cs
->req
);
448 fuse_copy_finish(cs
);
450 BUG_ON(!cs
->nr_segs
);
451 cs
->seglen
= cs
->iov
[0].iov_len
;
452 cs
->addr
= (unsigned long) cs
->iov
[0].iov_base
;
456 down_read(¤t
->mm
->mmap_sem
);
457 err
= get_user_pages(current
, current
->mm
, cs
->addr
, 1, cs
->write
, 0,
459 up_read(¤t
->mm
->mmap_sem
);
463 offset
= cs
->addr
% PAGE_SIZE
;
464 cs
->mapaddr
= kmap_atomic(cs
->pg
, KM_USER0
);
465 cs
->buf
= cs
->mapaddr
+ offset
;
466 cs
->len
= min(PAGE_SIZE
- offset
, cs
->seglen
);
467 cs
->seglen
-= cs
->len
;
470 return lock_request(cs
->req
);
473 /* Do as much copy to/from userspace buffer as we can */
474 static int fuse_copy_do(struct fuse_copy_state
*cs
, void **val
, unsigned *size
)
476 unsigned ncpy
= min(*size
, cs
->len
);
479 memcpy(cs
->buf
, *val
, ncpy
);
481 memcpy(*val
, cs
->buf
, ncpy
);
491 * Copy a page in the request to/from the userspace buffer. Must be
494 static int fuse_copy_page(struct fuse_copy_state
*cs
, struct page
*page
,
495 unsigned offset
, unsigned count
, int zeroing
)
497 if (page
&& zeroing
&& count
< PAGE_SIZE
) {
498 void *mapaddr
= kmap_atomic(page
, KM_USER1
);
499 memset(mapaddr
, 0, PAGE_SIZE
);
500 kunmap_atomic(mapaddr
, KM_USER1
);
504 if (!cs
->len
&& (err
= fuse_copy_fill(cs
)))
507 void *mapaddr
= kmap_atomic(page
, KM_USER1
);
508 void *buf
= mapaddr
+ offset
;
509 offset
+= fuse_copy_do(cs
, &buf
, &count
);
510 kunmap_atomic(mapaddr
, KM_USER1
);
512 offset
+= fuse_copy_do(cs
, NULL
, &count
);
514 if (page
&& !cs
->write
)
515 flush_dcache_page(page
);
519 /* Copy pages in the request to/from userspace buffer */
520 static int fuse_copy_pages(struct fuse_copy_state
*cs
, unsigned nbytes
,
524 struct fuse_req
*req
= cs
->req
;
525 unsigned offset
= req
->page_offset
;
526 unsigned count
= min(nbytes
, (unsigned) PAGE_SIZE
- offset
);
528 for (i
= 0; i
< req
->num_pages
&& (nbytes
|| zeroing
); i
++) {
529 struct page
*page
= req
->pages
[i
];
530 int err
= fuse_copy_page(cs
, page
, offset
, count
, zeroing
);
535 count
= min(nbytes
, (unsigned) PAGE_SIZE
);
541 /* Copy a single argument in the request to/from userspace buffer */
542 static int fuse_copy_one(struct fuse_copy_state
*cs
, void *val
, unsigned size
)
546 if (!cs
->len
&& (err
= fuse_copy_fill(cs
)))
548 fuse_copy_do(cs
, &val
, &size
);
553 /* Copy request arguments to/from userspace buffer */
554 static int fuse_copy_args(struct fuse_copy_state
*cs
, unsigned numargs
,
555 unsigned argpages
, struct fuse_arg
*args
,
561 for (i
= 0; !err
&& i
< numargs
; i
++) {
562 struct fuse_arg
*arg
= &args
[i
];
563 if (i
== numargs
- 1 && argpages
)
564 err
= fuse_copy_pages(cs
, arg
->size
, zeroing
);
566 err
= fuse_copy_one(cs
, arg
->value
, arg
->size
);
571 /* Wait until a request is available on the pending list */
572 static void request_wait(struct fuse_conn
*fc
)
574 DECLARE_WAITQUEUE(wait
, current
);
576 add_wait_queue_exclusive(&fc
->waitq
, &wait
);
577 while (fc
->connected
&& list_empty(&fc
->pending
)) {
578 set_current_state(TASK_INTERRUPTIBLE
);
579 if (signal_pending(current
))
582 spin_unlock(&fuse_lock
);
584 spin_lock(&fuse_lock
);
586 set_current_state(TASK_RUNNING
);
587 remove_wait_queue(&fc
->waitq
, &wait
);
591 * Read a single request into the userspace filesystem's buffer. This
592 * function waits until a request is available, then removes it from
593 * the pending list and copies request data to userspace buffer. If
594 * no reply is needed (FORGET) or request has been interrupted or
595 * there was an error during the copying then it's finished by calling
596 * request_end(). Otherwise add it to the processing list, and set
599 static ssize_t
fuse_dev_readv(struct file
*file
, const struct iovec
*iov
,
600 unsigned long nr_segs
, loff_t
*off
)
603 struct fuse_conn
*fc
;
604 struct fuse_req
*req
;
606 struct fuse_copy_state cs
;
610 spin_lock(&fuse_lock
);
611 fc
= file
->private_data
;
620 if (list_empty(&fc
->pending
))
623 req
= list_entry(fc
->pending
.next
, struct fuse_req
, list
);
624 req
->state
= FUSE_REQ_READING
;
625 list_move(&req
->list
, &fc
->io
);
629 /* If request is too large, reply with an error and restart the read */
630 if (iov_length(iov
, nr_segs
) < reqsize
) {
631 req
->out
.h
.error
= -EIO
;
632 /* SETXATTR is special, since it may contain too large data */
633 if (in
->h
.opcode
== FUSE_SETXATTR
)
634 req
->out
.h
.error
= -E2BIG
;
635 request_end(fc
, req
);
638 spin_unlock(&fuse_lock
);
639 fuse_copy_init(&cs
, 1, req
, iov
, nr_segs
);
640 err
= fuse_copy_one(&cs
, &in
->h
, sizeof(in
->h
));
642 err
= fuse_copy_args(&cs
, in
->numargs
, in
->argpages
,
643 (struct fuse_arg
*) in
->args
, 0);
644 fuse_copy_finish(&cs
);
645 spin_lock(&fuse_lock
);
647 if (!err
&& req
->interrupted
)
650 if (!req
->interrupted
)
651 req
->out
.h
.error
= -EIO
;
652 request_end(fc
, req
);
656 request_end(fc
, req
);
658 req
->state
= FUSE_REQ_SENT
;
659 list_move_tail(&req
->list
, &fc
->processing
);
660 spin_unlock(&fuse_lock
);
665 spin_unlock(&fuse_lock
);
669 static ssize_t
fuse_dev_read(struct file
*file
, char __user
*buf
,
670 size_t nbytes
, loff_t
*off
)
673 iov
.iov_len
= nbytes
;
675 return fuse_dev_readv(file
, &iov
, 1, off
);
678 /* Look up request on processing list by unique ID */
679 static struct fuse_req
*request_find(struct fuse_conn
*fc
, u64 unique
)
681 struct list_head
*entry
;
683 list_for_each(entry
, &fc
->processing
) {
684 struct fuse_req
*req
;
685 req
= list_entry(entry
, struct fuse_req
, list
);
686 if (req
->in
.h
.unique
== unique
)
692 static int copy_out_args(struct fuse_copy_state
*cs
, struct fuse_out
*out
,
695 unsigned reqsize
= sizeof(struct fuse_out_header
);
698 return nbytes
!= reqsize
? -EINVAL
: 0;
700 reqsize
+= len_args(out
->numargs
, out
->args
);
702 if (reqsize
< nbytes
|| (reqsize
> nbytes
&& !out
->argvar
))
704 else if (reqsize
> nbytes
) {
705 struct fuse_arg
*lastarg
= &out
->args
[out
->numargs
-1];
706 unsigned diffsize
= reqsize
- nbytes
;
707 if (diffsize
> lastarg
->size
)
709 lastarg
->size
-= diffsize
;
711 return fuse_copy_args(cs
, out
->numargs
, out
->argpages
, out
->args
,
716 * Write a single reply to a request. First the header is copied from
717 * the write buffer. The request is then searched on the processing
718 * list by the unique ID found in the header. If found, then remove
719 * it from the list and copy the rest of the buffer to the request.
720 * The request is finished by calling request_end()
722 static ssize_t
fuse_dev_writev(struct file
*file
, const struct iovec
*iov
,
723 unsigned long nr_segs
, loff_t
*off
)
726 unsigned nbytes
= iov_length(iov
, nr_segs
);
727 struct fuse_req
*req
;
728 struct fuse_out_header oh
;
729 struct fuse_copy_state cs
;
730 struct fuse_conn
*fc
= fuse_get_conn(file
);
734 fuse_copy_init(&cs
, 0, NULL
, iov
, nr_segs
);
735 if (nbytes
< sizeof(struct fuse_out_header
))
738 err
= fuse_copy_one(&cs
, &oh
, sizeof(oh
));
742 if (!oh
.unique
|| oh
.error
<= -1000 || oh
.error
> 0 ||
746 spin_lock(&fuse_lock
);
751 req
= request_find(fc
, oh
.unique
);
756 if (req
->interrupted
) {
757 spin_unlock(&fuse_lock
);
758 fuse_copy_finish(&cs
);
759 spin_lock(&fuse_lock
);
760 request_end(fc
, req
);
763 list_move(&req
->list
, &fc
->io
);
767 spin_unlock(&fuse_lock
);
769 err
= copy_out_args(&cs
, &req
->out
, nbytes
);
770 fuse_copy_finish(&cs
);
772 spin_lock(&fuse_lock
);
775 if (req
->interrupted
)
777 } else if (!req
->interrupted
)
778 req
->out
.h
.error
= -EIO
;
779 request_end(fc
, req
);
781 return err
? err
: nbytes
;
784 spin_unlock(&fuse_lock
);
786 fuse_copy_finish(&cs
);
790 static ssize_t
fuse_dev_write(struct file
*file
, const char __user
*buf
,
791 size_t nbytes
, loff_t
*off
)
794 iov
.iov_len
= nbytes
;
795 iov
.iov_base
= (char __user
*) buf
;
796 return fuse_dev_writev(file
, &iov
, 1, off
);
799 static unsigned fuse_dev_poll(struct file
*file
, poll_table
*wait
)
801 struct fuse_conn
*fc
= fuse_get_conn(file
);
802 unsigned mask
= POLLOUT
| POLLWRNORM
;
807 poll_wait(file
, &fc
->waitq
, wait
);
809 spin_lock(&fuse_lock
);
810 if (!list_empty(&fc
->pending
))
811 mask
|= POLLIN
| POLLRDNORM
;
812 spin_unlock(&fuse_lock
);
818 * Abort all requests on the given list (pending or processing)
820 * This function releases and reacquires fuse_lock
822 static void end_requests(struct fuse_conn
*fc
, struct list_head
*head
)
824 while (!list_empty(head
)) {
825 struct fuse_req
*req
;
826 req
= list_entry(head
->next
, struct fuse_req
, list
);
827 req
->out
.h
.error
= -ECONNABORTED
;
828 request_end(fc
, req
);
829 spin_lock(&fuse_lock
);
834 * Abort requests under I/O
836 * The requests are set to interrupted and finished, and the request
837 * waiter is woken up. This will make request_wait_answer() wait
838 * until the request is unlocked and then return.
840 * If the request is asynchronous, then the end function needs to be
841 * called after waiting for the request to be unlocked (if it was
844 static void end_io_requests(struct fuse_conn
*fc
)
846 while (!list_empty(&fc
->io
)) {
847 struct fuse_req
*req
=
848 list_entry(fc
->io
.next
, struct fuse_req
, list
);
849 void (*end
) (struct fuse_conn
*, struct fuse_req
*) = req
->end
;
851 req
->interrupted
= 1;
852 req
->out
.h
.error
= -ECONNABORTED
;
853 req
->state
= FUSE_REQ_FINISHED
;
854 list_del_init(&req
->list
);
855 wake_up(&req
->waitq
);
858 /* The end function will consume this reference */
859 __fuse_get_request(req
);
860 spin_unlock(&fuse_lock
);
861 wait_event(req
->waitq
, !req
->locked
);
863 spin_lock(&fuse_lock
);
869 * Abort all requests.
871 * Emergency exit in case of a malicious or accidental deadlock, or
872 * just a hung filesystem.
874 * The same effect is usually achievable through killing the
875 * filesystem daemon and all users of the filesystem. The exception
876 * is the combination of an asynchronous request and the tricky
877 * deadlock (see Documentation/filesystems/fuse.txt).
879 * During the aborting, progression of requests from the pending and
880 * processing lists onto the io list, and progression of new requests
881 * onto the pending list is prevented by req->connected being false.
883 * Progression of requests under I/O to the processing list is
884 * prevented by the req->interrupted flag being true for these
885 * requests. For this reason requests on the io list must be aborted
888 void fuse_abort_conn(struct fuse_conn
*fc
)
890 spin_lock(&fuse_lock
);
894 end_requests(fc
, &fc
->pending
);
895 end_requests(fc
, &fc
->processing
);
896 wake_up_all(&fc
->waitq
);
898 spin_unlock(&fuse_lock
);
901 static int fuse_dev_release(struct inode
*inode
, struct file
*file
)
903 struct fuse_conn
*fc
;
905 spin_lock(&fuse_lock
);
906 fc
= file
->private_data
;
909 end_requests(fc
, &fc
->pending
);
910 end_requests(fc
, &fc
->processing
);
912 spin_unlock(&fuse_lock
);
914 kobject_put(&fc
->kobj
);
919 struct file_operations fuse_dev_operations
= {
920 .owner
= THIS_MODULE
,
922 .read
= fuse_dev_read
,
923 .readv
= fuse_dev_readv
,
924 .write
= fuse_dev_write
,
925 .writev
= fuse_dev_writev
,
926 .poll
= fuse_dev_poll
,
927 .release
= fuse_dev_release
,
930 static struct miscdevice fuse_miscdevice
= {
933 .fops
= &fuse_dev_operations
,
936 int __init
fuse_dev_init(void)
939 fuse_req_cachep
= kmem_cache_create("fuse_request",
940 sizeof(struct fuse_req
),
942 if (!fuse_req_cachep
)
945 err
= misc_register(&fuse_miscdevice
);
947 goto out_cache_clean
;
952 kmem_cache_destroy(fuse_req_cachep
);
957 void fuse_dev_cleanup(void)
959 misc_deregister(&fuse_miscdevice
);
960 kmem_cache_destroy(fuse_req_cachep
);