Skip to content

Commit ae3aad7

Browse files
stefanhaRHMiklos Szeredi
authored andcommitted
fuse: add fuse_iqueue_ops callbacks
The /dev/fuse device uses fiq->waitq and fasync to signal that requests are available. These mechanisms do not apply to virtio-fs. This patch introduces callbacks so alternative behavior can be used. Note that queue_interrupt() changes along these lines: spin_lock(&fiq->waitq.lock); wake_up_locked(&fiq->waitq); + kill_fasync(&fiq->fasync, SIGIO, POLL_IN); spin_unlock(&fiq->waitq.lock); - kill_fasync(&fiq->fasync, SIGIO, POLL_IN); Since queue_request() and queue_forget() also call kill_fasync() inside the spinlock this should be safe. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 0cc2656 commit ae3aad7

4 files changed

Lines changed: 81 additions & 22 deletions

File tree

‎fs/fuse/cuse.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)
506506
* Limit the cuse channel to requests that can
507507
* be represented in file->f_cred->user_ns.
508508
*/
509-
fuse_conn_init(&cc->fc, file->f_cred->user_ns);
509+
fuse_conn_init(&cc->fc, file->f_cred->user_ns, &fuse_dev_fiq_ops, NULL);
510510

511511
fud = fuse_dev_alloc(&cc->fc);
512512
if (!fud) {

‎fs/fuse/dev.c‎

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,33 @@ static unsigned int fuse_req_hash(u64 unique)
201201
return hash_long(unique & ~FUSE_INT_REQ_BIT, FUSE_PQ_HASH_BITS);
202202
}
203203

204-
static void queue_request(struct fuse_iqueue *fiq, struct fuse_req *req)
204+
/**
205+
* A new request is available, wake fiq->waitq
206+
*/
207+
static void fuse_dev_wake_and_unlock(struct fuse_iqueue *fiq)
208+
__releases(fiq->lock)
209+
{
210+
wake_up(&fiq->waitq);
211+
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
212+
spin_unlock(&fiq->lock);
213+
}
214+
215+
const struct fuse_iqueue_ops fuse_dev_fiq_ops = {
216+
.wake_forget_and_unlock = fuse_dev_wake_and_unlock,
217+
.wake_interrupt_and_unlock = fuse_dev_wake_and_unlock,
218+
.wake_pending_and_unlock = fuse_dev_wake_and_unlock,
219+
};
220+
EXPORT_SYMBOL_GPL(fuse_dev_fiq_ops);
221+
222+
static void queue_request_and_unlock(struct fuse_iqueue *fiq,
223+
struct fuse_req *req)
224+
__releases(fiq->lock)
205225
{
206226
req->in.h.len = sizeof(struct fuse_in_header) +
207227
fuse_len_args(req->args->in_numargs,
208228
(struct fuse_arg *) req->args->in_args);
209229
list_add_tail(&req->list, &fiq->pending);
210-
wake_up(&fiq->waitq);
211-
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
230+
fiq->ops->wake_pending_and_unlock(fiq);
212231
}
213232

214233
void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
@@ -223,12 +242,11 @@ void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
223242
if (fiq->connected) {
224243
fiq->forget_list_tail->next = forget;
225244
fiq->forget_list_tail = forget;
226-
wake_up(&fiq->waitq);
227-
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
245+
fiq->ops->wake_forget_and_unlock(fiq);
228246
} else {
229247
kfree(forget);
248+
spin_unlock(&fiq->lock);
230249
}
231-
spin_unlock(&fiq->lock);
232250
}
233251

234252
static void flush_bg_queue(struct fuse_conn *fc)
@@ -244,8 +262,7 @@ static void flush_bg_queue(struct fuse_conn *fc)
244262
fc->active_background++;
245263
spin_lock(&fiq->lock);
246264
req->in.h.unique = fuse_get_unique(fiq);
247-
queue_request(fiq, req);
248-
spin_unlock(&fiq->lock);
265+
queue_request_and_unlock(fiq, req);
249266
}
250267
}
251268

@@ -334,10 +351,10 @@ static int queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req)
334351
spin_unlock(&fiq->lock);
335352
return 0;
336353
}
337-
wake_up(&fiq->waitq);
338-
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
354+
fiq->ops->wake_interrupt_and_unlock(fiq);
355+
} else {
356+
spin_unlock(&fiq->lock);
339357
}
340-
spin_unlock(&fiq->lock);
341358
return 0;
342359
}
343360

@@ -397,11 +414,10 @@ static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
397414
req->out.h.error = -ENOTCONN;
398415
} else {
399416
req->in.h.unique = fuse_get_unique(fiq);
400-
queue_request(fiq, req);
401417
/* acquire extra reference, since request is still needed
402418
after fuse_request_end() */
403419
__fuse_get_request(req);
404-
spin_unlock(&fiq->lock);
420+
queue_request_and_unlock(fiq, req);
405421

406422
request_wait_answer(fc, req);
407423
/* Pairs with smp_wmb() in fuse_request_end() */
@@ -570,14 +586,12 @@ static int fuse_simple_notify_reply(struct fuse_conn *fc,
570586

571587
spin_lock(&fiq->lock);
572588
if (fiq->connected) {
573-
queue_request(fiq, req);
574-
spin_unlock(&fiq->lock);
589+
queue_request_and_unlock(fiq, req);
575590
} else {
576591
err = -ENODEV;
577592
spin_unlock(&fiq->lock);
578593
fuse_put_request(fc, req);
579594
}
580-
spin_unlock(&fiq->lock);
581595

582596
return err;
583597
}

‎fs/fuse/fuse_i.h‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,39 @@ struct fuse_req {
355355

356356
};
357357

358+
struct fuse_iqueue;
359+
360+
/**
361+
* Input queue callbacks
362+
*
363+
* Input queue signalling is device-specific. For example, the /dev/fuse file
364+
* uses fiq->waitq and fasync to wake processes that are waiting on queue
365+
* readiness. These callbacks allow other device types to respond to input
366+
* queue activity.
367+
*/
368+
struct fuse_iqueue_ops {
369+
/**
370+
* Signal that a forget has been queued
371+
*/
372+
void (*wake_forget_and_unlock)(struct fuse_iqueue *fiq)
373+
__releases(fiq->lock);
374+
375+
/**
376+
* Signal that an INTERRUPT request has been queued
377+
*/
378+
void (*wake_interrupt_and_unlock)(struct fuse_iqueue *fiq)
379+
__releases(fiq->lock);
380+
381+
/**
382+
* Signal that a request has been queued
383+
*/
384+
void (*wake_pending_and_unlock)(struct fuse_iqueue *fiq)
385+
__releases(fiq->lock);
386+
};
387+
388+
/** /dev/fuse input queue operations */
389+
extern const struct fuse_iqueue_ops fuse_dev_fiq_ops;
390+
358391
struct fuse_iqueue {
359392
/** Connection established */
360393
unsigned connected;
@@ -383,6 +416,12 @@ struct fuse_iqueue {
383416

384417
/** O_ASYNC requests */
385418
struct fasync_struct *fasync;
419+
420+
/** Device-specific callbacks */
421+
const struct fuse_iqueue_ops *ops;
422+
423+
/** Device-specific state */
424+
void *priv;
386425
};
387426

388427
#define FUSE_PQ_HASH_BITS 8
@@ -882,7 +921,8 @@ struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
882921
/**
883922
* Initialize fuse_conn
884923
*/
885-
void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns);
924+
void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns,
925+
const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv);
886926

887927
/**
888928
* Release reference to fuse_conn

‎fs/fuse/inode.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,9 @@ static int fuse_show_options(struct seq_file *m, struct dentry *root)
568568
return 0;
569569
}
570570

571-
static void fuse_iqueue_init(struct fuse_iqueue *fiq)
571+
static void fuse_iqueue_init(struct fuse_iqueue *fiq,
572+
const struct fuse_iqueue_ops *ops,
573+
void *priv)
572574
{
573575
memset(fiq, 0, sizeof(struct fuse_iqueue));
574576
spin_lock_init(&fiq->lock);
@@ -577,6 +579,8 @@ static void fuse_iqueue_init(struct fuse_iqueue *fiq)
577579
INIT_LIST_HEAD(&fiq->interrupts);
578580
fiq->forget_list_tail = &fiq->forget_list_head;
579581
fiq->connected = 1;
582+
fiq->ops = ops;
583+
fiq->priv = priv;
580584
}
581585

582586
static void fuse_pqueue_init(struct fuse_pqueue *fpq)
@@ -590,7 +594,8 @@ static void fuse_pqueue_init(struct fuse_pqueue *fpq)
590594
fpq->connected = 1;
591595
}
592596

593-
void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns)
597+
void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns,
598+
const struct fuse_iqueue_ops *fiq_ops, void *fiq_priv)
594599
{
595600
memset(fc, 0, sizeof(*fc));
596601
spin_lock_init(&fc->lock);
@@ -599,7 +604,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns)
599604
refcount_set(&fc->count, 1);
600605
atomic_set(&fc->dev_count, 1);
601606
init_waitqueue_head(&fc->blocked_waitq);
602-
fuse_iqueue_init(&fc->iq);
607+
fuse_iqueue_init(&fc->iq, fiq_ops, fiq_priv);
603608
INIT_LIST_HEAD(&fc->bg_queue);
604609
INIT_LIST_HEAD(&fc->entry);
605610
INIT_LIST_HEAD(&fc->devices);
@@ -1209,7 +1214,7 @@ static int fuse_fill_super(struct super_block *sb, struct fs_context *fsc)
12091214
if (!fc)
12101215
goto err_fput;
12111216

1212-
fuse_conn_init(fc, sb->s_user_ns);
1217+
fuse_conn_init(fc, sb->s_user_ns, &fuse_dev_fiq_ops, NULL);
12131218
fc->release = fuse_free_conn;
12141219
sb->s_fs_info = fc;
12151220

0 commit comments

Comments
 (0)