Skip to content

Commit 8f622e9

Browse files
XanClicMiklos Szeredi
authored andcommitted
fuse: drop fuse_conn parameter where possible
With the last commit, all functions that handle some existing fuse_req no longer need to be given the associated fuse_conn, because they can get it from the fuse_req object. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 24754db commit 8f622e9

3 files changed

Lines changed: 43 additions & 37 deletions

File tree

fs/fuse/dev.c

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static void fuse_drop_waiting(struct fuse_conn *fc)
101101
}
102102
}
103103

104-
static void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
104+
static void fuse_put_request(struct fuse_req *req);
105105

106106
static struct fuse_req *fuse_get_req(struct fuse_conn *fc, bool for_background)
107107
{
@@ -144,7 +144,7 @@ static struct fuse_req *fuse_get_req(struct fuse_conn *fc, bool for_background)
144144

145145
if (unlikely(req->in.h.uid == ((uid_t)-1) ||
146146
req->in.h.gid == ((gid_t)-1))) {
147-
fuse_put_request(fc, req);
147+
fuse_put_request(req);
148148
return ERR_PTR(-EOVERFLOW);
149149
}
150150
return req;
@@ -154,8 +154,10 @@ static struct fuse_req *fuse_get_req(struct fuse_conn *fc, bool for_background)
154154
return ERR_PTR(err);
155155
}
156156

157-
static void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
157+
static void fuse_put_request(struct fuse_req *req)
158158
{
159+
struct fuse_conn *fc = req->fc;
160+
159161
if (refcount_dec_and_test(&req->count)) {
160162
if (test_bit(FR_BACKGROUND, &req->flags)) {
161163
/*
@@ -274,8 +276,9 @@ static void flush_bg_queue(struct fuse_conn *fc)
274276
* the 'end' callback is called if given, else the reference to the
275277
* request is released
276278
*/
277-
void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req)
279+
void fuse_request_end(struct fuse_req *req)
278280
{
281+
struct fuse_conn *fc = req->fc;
279282
struct fuse_iqueue *fiq = &fc->iq;
280283

281284
if (test_and_set_bit(FR_FINISHED, &req->flags))
@@ -326,12 +329,14 @@ void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req)
326329
if (test_bit(FR_ASYNC, &req->flags))
327330
req->args->end(fc, req->args, req->out.h.error);
328331
put_request:
329-
fuse_put_request(fc, req);
332+
fuse_put_request(req);
330333
}
331334
EXPORT_SYMBOL_GPL(fuse_request_end);
332335

333-
static int queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req)
336+
static int queue_interrupt(struct fuse_req *req)
334337
{
338+
struct fuse_iqueue *fiq = &req->fc->iq;
339+
335340
spin_lock(&fiq->lock);
336341
/* Check for we've sent request to interrupt this req */
337342
if (unlikely(!test_bit(FR_INTERRUPTED, &req->flags))) {
@@ -358,8 +363,9 @@ static int queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req)
358363
return 0;
359364
}
360365

361-
static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
366+
static void request_wait_answer(struct fuse_req *req)
362367
{
368+
struct fuse_conn *fc = req->fc;
363369
struct fuse_iqueue *fiq = &fc->iq;
364370
int err;
365371

@@ -374,7 +380,7 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
374380
/* matches barrier in fuse_dev_do_read() */
375381
smp_mb__after_atomic();
376382
if (test_bit(FR_SENT, &req->flags))
377-
queue_interrupt(fiq, req);
383+
queue_interrupt(req);
378384
}
379385

380386
if (!test_bit(FR_FORCE, &req->flags)) {
@@ -403,9 +409,9 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
403409
wait_event(req->waitq, test_bit(FR_FINISHED, &req->flags));
404410
}
405411

406-
static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
412+
static void __fuse_request_send(struct fuse_req *req)
407413
{
408-
struct fuse_iqueue *fiq = &fc->iq;
414+
struct fuse_iqueue *fiq = &req->fc->iq;
409415

410416
BUG_ON(test_bit(FR_BACKGROUND, &req->flags));
411417
spin_lock(&fiq->lock);
@@ -419,7 +425,7 @@ static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
419425
__fuse_get_request(req);
420426
queue_request_and_unlock(fiq, req);
421427

422-
request_wait_answer(fc, req);
428+
request_wait_answer(req);
423429
/* Pairs with smp_wmb() in fuse_request_end() */
424430
smp_rmb();
425431
}
@@ -458,8 +464,10 @@ static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args)
458464
}
459465
}
460466

461-
static void fuse_force_creds(struct fuse_conn *fc, struct fuse_req *req)
467+
static void fuse_force_creds(struct fuse_req *req)
462468
{
469+
struct fuse_conn *fc = req->fc;
470+
463471
req->in.h.uid = from_kuid_munged(fc->user_ns, current_fsuid());
464472
req->in.h.gid = from_kgid_munged(fc->user_ns, current_fsgid());
465473
req->in.h.pid = pid_nr_ns(task_pid(current), fc->pid_ns);
@@ -484,7 +492,7 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args)
484492
req = fuse_request_alloc(fc, GFP_KERNEL | __GFP_NOFAIL);
485493

486494
if (!args->nocreds)
487-
fuse_force_creds(fc, req);
495+
fuse_force_creds(req);
488496

489497
__set_bit(FR_WAITING, &req->flags);
490498
__set_bit(FR_FORCE, &req->flags);
@@ -501,20 +509,20 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args)
501509

502510
if (!args->noreply)
503511
__set_bit(FR_ISREPLY, &req->flags);
504-
__fuse_request_send(fc, req);
512+
__fuse_request_send(req);
505513
ret = req->out.h.error;
506514
if (!ret && args->out_argvar) {
507515
BUG_ON(args->out_numargs == 0);
508516
ret = args->out_args[args->out_numargs - 1].size;
509517
}
510-
fuse_put_request(fc, req);
518+
fuse_put_request(req);
511519

512520
return ret;
513521
}
514522

515-
static bool fuse_request_queue_background(struct fuse_conn *fc,
516-
struct fuse_req *req)
523+
static bool fuse_request_queue_background(struct fuse_req *req)
517524
{
525+
struct fuse_conn *fc = req->fc;
518526
bool queued = false;
519527

520528
WARN_ON(!test_bit(FR_BACKGROUND, &req->flags));
@@ -561,8 +569,8 @@ int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args,
561569

562570
fuse_args_to_req(req, args);
563571

564-
if (!fuse_request_queue_background(fc, req)) {
565-
fuse_put_request(fc, req);
572+
if (!fuse_request_queue_background(req)) {
573+
fuse_put_request(req);
566574
return -ENOTCONN;
567575
}
568576

@@ -592,7 +600,7 @@ static int fuse_simple_notify_reply(struct fuse_conn *fc,
592600
} else {
593601
err = -ENODEV;
594602
spin_unlock(&fiq->lock);
595-
fuse_put_request(fc, req);
603+
fuse_put_request(req);
596604
}
597605

598606
return err;
@@ -1259,7 +1267,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
12591267
/* SETXATTR is special, since it may contain too large data */
12601268
if (args->opcode == FUSE_SETXATTR)
12611269
req->out.h.error = -E2BIG;
1262-
fuse_request_end(fc, req);
1270+
fuse_request_end(req);
12631271
goto restart;
12641272
}
12651273
spin_lock(&fpq->lock);
@@ -1293,16 +1301,16 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
12931301
/* matches barrier in request_wait_answer() */
12941302
smp_mb__after_atomic();
12951303
if (test_bit(FR_INTERRUPTED, &req->flags))
1296-
queue_interrupt(fiq, req);
1297-
fuse_put_request(fc, req);
1304+
queue_interrupt(req);
1305+
fuse_put_request(req);
12981306

12991307
return reqsize;
13001308

13011309
out_end:
13021310
if (!test_bit(FR_PRIVATE, &req->flags))
13031311
list_del_init(&req->list);
13041312
spin_unlock(&fpq->lock);
1305-
fuse_request_end(fc, req);
1313+
fuse_request_end(req);
13061314
return err;
13071315

13081316
err_unlock:
@@ -1884,9 +1892,9 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
18841892
else if (oh.error == -ENOSYS)
18851893
fc->no_interrupt = 1;
18861894
else if (oh.error == -EAGAIN)
1887-
err = queue_interrupt(&fc->iq, req);
1895+
err = queue_interrupt(req);
18881896

1889-
fuse_put_request(fc, req);
1897+
fuse_put_request(req);
18901898

18911899
goto copy_finish;
18921900
}
@@ -1916,7 +1924,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
19161924
list_del_init(&req->list);
19171925
spin_unlock(&fpq->lock);
19181926

1919-
fuse_request_end(fc, req);
1927+
fuse_request_end(req);
19201928
out:
19211929
return err ? err : nbytes;
19221930

@@ -2054,15 +2062,15 @@ static __poll_t fuse_dev_poll(struct file *file, poll_table *wait)
20542062
}
20552063

20562064
/* Abort all requests on the given list (pending or processing) */
2057-
static void end_requests(struct fuse_conn *fc, struct list_head *head)
2065+
static void end_requests(struct list_head *head)
20582066
{
20592067
while (!list_empty(head)) {
20602068
struct fuse_req *req;
20612069
req = list_entry(head->next, struct fuse_req, list);
20622070
req->out.h.error = -ECONNABORTED;
20632071
clear_bit(FR_SENT, &req->flags);
20642072
list_del_init(&req->list);
2065-
fuse_request_end(fc, req);
2073+
fuse_request_end(req);
20662074
}
20672075
}
20682076

@@ -2157,7 +2165,7 @@ void fuse_abort_conn(struct fuse_conn *fc)
21572165
wake_up_all(&fc->blocked_waitq);
21582166
spin_unlock(&fc->lock);
21592167

2160-
end_requests(fc, &to_end);
2168+
end_requests(&to_end);
21612169
} else {
21622170
spin_unlock(&fc->lock);
21632171
}
@@ -2187,7 +2195,7 @@ int fuse_dev_release(struct inode *inode, struct file *file)
21872195
list_splice_init(&fpq->processing[i], &to_end);
21882196
spin_unlock(&fpq->lock);
21892197

2190-
end_requests(fc, &to_end);
2198+
end_requests(&to_end);
21912199

21922200
/* Are we the last open device? */
21932201
if (atomic_dec_and_test(&fc->dev_count)) {

fs/fuse/fuse_i.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args,
949949
/**
950950
* End a finished request
951951
*/
952-
void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req);
952+
void fuse_request_end(struct fuse_req *req);
953953

954954
/* Abort all requests */
955955
void fuse_abort_conn(struct fuse_conn *fc);

fs/fuse/virtio_fs.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work)
340340
struct fuse_req *req;
341341
struct virtio_fs_vq *fsvq = container_of(work, struct virtio_fs_vq,
342342
dispatch_work.work);
343-
struct fuse_conn *fc = fsvq->fud->fc;
344343
int ret;
345344

346345
pr_debug("virtio-fs: worker %s called.\n", __func__);
@@ -355,7 +354,7 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work)
355354

356355
list_del_init(&req->list);
357356
spin_unlock(&fsvq->lock);
358-
fuse_request_end(fc, req);
357+
fuse_request_end(req);
359358
}
360359

361360
/* Dispatch pending requests */
@@ -386,7 +385,7 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work)
386385
spin_unlock(&fsvq->lock);
387386
pr_err("virtio-fs: virtio_fs_enqueue_req() failed %d\n",
388387
ret);
389-
fuse_request_end(fc, req);
388+
fuse_request_end(req);
390389
}
391390
}
392391
}
@@ -546,7 +545,6 @@ static void virtio_fs_request_complete(struct fuse_req *req,
546545
struct virtio_fs_vq *fsvq)
547546
{
548547
struct fuse_pqueue *fpq = &fsvq->fud->pq;
549-
struct fuse_conn *fc = fsvq->fud->fc;
550548
struct fuse_args *args;
551549
struct fuse_args_pages *ap;
552550
unsigned int len, i, thislen;
@@ -579,7 +577,7 @@ static void virtio_fs_request_complete(struct fuse_req *req,
579577
clear_bit(FR_SENT, &req->flags);
580578
spin_unlock(&fpq->lock);
581579

582-
fuse_request_end(fc, req);
580+
fuse_request_end(req);
583581
spin_lock(&fsvq->lock);
584582
dec_in_flight_req(fsvq);
585583
spin_unlock(&fsvq->lock);

0 commit comments

Comments
 (0)