Skip to content

Commit 5fec8bd

Browse files
committed
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
2 parents 59e3af2 + 5d9ec85 commit 5fec8bd

8 files changed

Lines changed: 783 additions & 202 deletions

File tree

‎fs/fuse/control.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
FUSE: Filesystem in Userspace
3-
Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
3+
Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
44
55
This program can be distributed under the terms of the GNU GPL.
66
See the file COPYING.
@@ -48,11 +48,13 @@ static ssize_t fuse_conn_waiting_read(struct file *file, char __user *buf,
4848
size_t size;
4949

5050
if (!*ppos) {
51+
long value;
5152
struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
5253
if (!fc)
5354
return 0;
5455

55-
file->private_data=(void *)(long)atomic_read(&fc->num_waiting);
56+
value = atomic_read(&fc->num_waiting);
57+
file->private_data = (void *)value;
5658
fuse_conn_put(fc);
5759
}
5860
size = sprintf(tmp, "%ld\n", (long)file->private_data);

‎fs/fuse/dev.c‎

Lines changed: 83 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
FUSE: Filesystem in Userspace
3-
Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
3+
Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
44
55
This program can be distributed under the terms of the GNU GPL.
66
See the file COPYING.
@@ -269,7 +269,7 @@ static void flush_bg_queue(struct fuse_conn *fc)
269269
* Called with fc->lock, unlocks it
270270
*/
271271
static void request_end(struct fuse_conn *fc, struct fuse_req *req)
272-
__releases(fc->lock)
272+
__releases(&fc->lock)
273273
{
274274
void (*end) (struct fuse_conn *, struct fuse_req *) = req->end;
275275
req->end = NULL;
@@ -293,13 +293,13 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
293293
wake_up(&req->waitq);
294294
if (end)
295295
end(fc, req);
296-
else
297-
fuse_put_request(fc, req);
296+
fuse_put_request(fc, req);
298297
}
299298

300299
static void wait_answer_interruptible(struct fuse_conn *fc,
301300
struct fuse_req *req)
302-
__releases(fc->lock) __acquires(fc->lock)
301+
__releases(&fc->lock)
302+
__acquires(&fc->lock)
303303
{
304304
if (signal_pending(current))
305305
return;
@@ -317,7 +317,8 @@ static void queue_interrupt(struct fuse_conn *fc, struct fuse_req *req)
317317
}
318318

319319
static 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)
321322
{
322323
if (!fc->no_interrupt) {
323324
/* Any signal may interrupt this */
@@ -380,7 +381,7 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
380381
}
381382
}
382383

383-
void request_send(struct fuse_conn *fc, struct fuse_req *req)
384+
void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
384385
{
385386
req->isreply = 1;
386387
spin_lock(&fc->lock);
@@ -399,8 +400,8 @@ void request_send(struct fuse_conn *fc, struct fuse_req *req)
399400
spin_unlock(&fc->lock);
400401
}
401402

402-
static void request_send_nowait_locked(struct fuse_conn *fc,
403-
struct fuse_req *req)
403+
static void fuse_request_send_nowait_locked(struct fuse_conn *fc,
404+
struct fuse_req *req)
404405
{
405406
req->background = 1;
406407
fc->num_background++;
@@ -414,39 +415,40 @@ static void request_send_nowait_locked(struct fuse_conn *fc,
414415
flush_bg_queue(fc);
415416
}
416417

417-
static void request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
418+
static void fuse_request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
418419
{
419420
spin_lock(&fc->lock);
420421
if (fc->connected) {
421-
request_send_nowait_locked(fc, req);
422+
fuse_request_send_nowait_locked(fc, req);
422423
spin_unlock(&fc->lock);
423424
} else {
424425
req->out.h.error = -ENOTCONN;
425426
request_end(fc, req);
426427
}
427428
}
428429

429-
void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req)
430+
void fuse_request_send_noreply(struct fuse_conn *fc, struct fuse_req *req)
430431
{
431432
req->isreply = 0;
432-
request_send_nowait(fc, req);
433+
fuse_request_send_nowait(fc, req);
433434
}
434435

435-
void request_send_background(struct fuse_conn *fc, struct fuse_req *req)
436+
void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req)
436437
{
437438
req->isreply = 1;
438-
request_send_nowait(fc, req);
439+
fuse_request_send_nowait(fc, req);
439440
}
440441

441442
/*
442443
* Called under fc->lock
443444
*
444445
* fc->connected must have been checked previously
445446
*/
446-
void request_send_background_locked(struct fuse_conn *fc, struct fuse_req *req)
447+
void fuse_request_send_background_locked(struct fuse_conn *fc,
448+
struct fuse_req *req)
447449
{
448450
req->isreply = 1;
449-
request_send_nowait_locked(fc, req);
451+
fuse_request_send_nowait_locked(fc, req);
450452
}
451453

452454
/*
@@ -539,8 +541,8 @@ static int fuse_copy_fill(struct fuse_copy_state *cs)
539541
BUG_ON(!cs->nr_segs);
540542
cs->seglen = cs->iov[0].iov_len;
541543
cs->addr = (unsigned long) cs->iov[0].iov_base;
542-
cs->iov ++;
543-
cs->nr_segs --;
544+
cs->iov++;
545+
cs->nr_segs--;
544546
}
545547
down_read(&current->mm->mmap_sem);
546548
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,
589591
kunmap_atomic(mapaddr, KM_USER1);
590592
}
591593
while (count) {
592-
int err;
593-
if (!cs->len && (err = fuse_copy_fill(cs)))
594-
return err;
594+
if (!cs->len) {
595+
int err = fuse_copy_fill(cs);
596+
if (err)
597+
return err;
598+
}
595599
if (page) {
596600
void *mapaddr = kmap_atomic(page, KM_USER1);
597601
void *buf = mapaddr + offset;
@@ -631,9 +635,11 @@ static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes,
631635
static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size)
632636
{
633637
while (size) {
634-
int err;
635-
if (!cs->len && (err = fuse_copy_fill(cs)))
636-
return err;
638+
if (!cs->len) {
639+
int err = fuse_copy_fill(cs);
640+
if (err)
641+
return err;
642+
}
637643
fuse_copy_do(cs, &val, &size);
638644
}
639645
return 0;
@@ -664,6 +670,8 @@ static int request_pending(struct fuse_conn *fc)
664670

665671
/* Wait until a request is available on the pending list */
666672
static void request_wait(struct fuse_conn *fc)
673+
__releases(&fc->lock)
674+
__acquires(&fc->lock)
667675
{
668676
DECLARE_WAITQUEUE(wait, current);
669677

@@ -691,7 +699,7 @@ static void request_wait(struct fuse_conn *fc)
691699
*/
692700
static int fuse_read_interrupt(struct fuse_conn *fc, struct fuse_req *req,
693701
const struct iovec *iov, unsigned long nr_segs)
694-
__releases(fc->lock)
702+
__releases(&fc->lock)
695703
{
696704
struct fuse_copy_state cs;
697705
struct fuse_in_header ih;
@@ -813,6 +821,34 @@ static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
813821
return err;
814822
}
815823

824+
static 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+
840+
static 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+
816852
/* Look up request on processing list by unique ID */
817853
static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique)
818854
{
@@ -876,9 +912,23 @@ static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
876912
err = fuse_copy_one(&cs, &oh, sizeof(oh));
877913
if (err)
878914
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+
879930
err = -EINVAL;
880-
if (!oh.unique || oh.error <= -1000 || oh.error > 0 ||
881-
oh.len != nbytes)
931+
if (oh.error <= -1000 || oh.error > 0)
882932
goto err_finish;
883933

884934
spin_lock(&fc->lock);
@@ -966,6 +1016,8 @@ static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
9661016
* This function releases and reacquires fc->lock
9671017
*/
9681018
static void end_requests(struct fuse_conn *fc, struct list_head *head)
1019+
__releases(&fc->lock)
1020+
__acquires(&fc->lock)
9691021
{
9701022
while (!list_empty(head)) {
9711023
struct fuse_req *req;
@@ -988,7 +1040,8 @@ static void end_requests(struct fuse_conn *fc, struct list_head *head)
9881040
* locked).
9891041
*/
9901042
static void end_io_requests(struct fuse_conn *fc)
991-
__releases(fc->lock) __acquires(fc->lock)
1043+
__releases(&fc->lock)
1044+
__acquires(&fc->lock)
9921045
{
9931046
while (!list_empty(&fc->io)) {
9941047
struct fuse_req *req =
@@ -1002,11 +1055,11 @@ static void end_io_requests(struct fuse_conn *fc)
10021055
wake_up(&req->waitq);
10031056
if (end) {
10041057
req->end = NULL;
1005-
/* The end function will consume this reference */
10061058
__fuse_get_request(req);
10071059
spin_unlock(&fc->lock);
10081060
wait_event(req->waitq, !req->locked);
10091061
end(fc, req);
1062+
fuse_put_request(fc, req);
10101063
spin_lock(&fc->lock);
10111064
}
10121065
}

0 commit comments

Comments
 (0)