]>
Commit | Line | Data |
---|---|---|
d5afabcb SL |
1 | From 58e9060ef80221da9887c99a190f06486930f7ae Mon Sep 17 00:00:00 2001 |
2 | From: Sasha Levin <sashal@kernel.org> | |
3 | Date: Mon, 20 Apr 2020 17:59:34 +0200 | |
4 | Subject: fuse: drop fuse_conn parameter where possible | |
5 | ||
6 | From: Max Reitz <mreitz@redhat.com> | |
7 | ||
8 | [ Upstream commit 8f622e9497bbbd5df4675edf782500cd9fe961ba ] | |
9 | ||
10 | With the last commit, all functions that handle some existing fuse_req | |
11 | no longer need to be given the associated fuse_conn, because they can | |
12 | get it from the fuse_req object. | |
13 | ||
14 | Signed-off-by: Max Reitz <mreitz@redhat.com> | |
15 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | |
16 | Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> | |
17 | Stable-dep-of: b1fe686a765e ("fuse: don't unhash root") | |
18 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
19 | --- | |
20 | fs/fuse/dev.c | 70 +++++++++++++++++++++++++-------------------- | |
21 | fs/fuse/fuse_i.h | 2 +- | |
22 | fs/fuse/virtio_fs.c | 8 ++---- | |
23 | 3 files changed, 43 insertions(+), 37 deletions(-) | |
24 | ||
25 | diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c | |
26 | index 185cae8a7ce11..96fcb004190e2 100644 | |
27 | --- a/fs/fuse/dev.c | |
28 | +++ b/fs/fuse/dev.c | |
29 | @@ -101,7 +101,7 @@ static void fuse_drop_waiting(struct fuse_conn *fc) | |
30 | } | |
31 | } | |
32 | ||
33 | -static void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); | |
34 | +static void fuse_put_request(struct fuse_req *req); | |
35 | ||
36 | static struct fuse_req *fuse_get_req(struct fuse_conn *fc, bool for_background) | |
37 | { | |
38 | @@ -144,7 +144,7 @@ static struct fuse_req *fuse_get_req(struct fuse_conn *fc, bool for_background) | |
39 | ||
40 | if (unlikely(req->in.h.uid == ((uid_t)-1) || | |
41 | req->in.h.gid == ((gid_t)-1))) { | |
42 | - fuse_put_request(fc, req); | |
43 | + fuse_put_request(req); | |
44 | return ERR_PTR(-EOVERFLOW); | |
45 | } | |
46 | return req; | |
47 | @@ -154,8 +154,10 @@ static struct fuse_req *fuse_get_req(struct fuse_conn *fc, bool for_background) | |
48 | return ERR_PTR(err); | |
49 | } | |
50 | ||
51 | -static void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req) | |
52 | +static void fuse_put_request(struct fuse_req *req) | |
53 | { | |
54 | + struct fuse_conn *fc = req->fc; | |
55 | + | |
56 | if (refcount_dec_and_test(&req->count)) { | |
57 | if (test_bit(FR_BACKGROUND, &req->flags)) { | |
58 | /* | |
59 | @@ -274,8 +276,9 @@ static void flush_bg_queue(struct fuse_conn *fc) | |
60 | * the 'end' callback is called if given, else the reference to the | |
61 | * request is released | |
62 | */ | |
63 | -void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req) | |
64 | +void fuse_request_end(struct fuse_req *req) | |
65 | { | |
66 | + struct fuse_conn *fc = req->fc; | |
67 | struct fuse_iqueue *fiq = &fc->iq; | |
68 | ||
69 | if (test_and_set_bit(FR_FINISHED, &req->flags)) | |
70 | @@ -326,12 +329,14 @@ void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req) | |
71 | if (test_bit(FR_ASYNC, &req->flags)) | |
72 | req->args->end(fc, req->args, req->out.h.error); | |
73 | put_request: | |
74 | - fuse_put_request(fc, req); | |
75 | + fuse_put_request(req); | |
76 | } | |
77 | EXPORT_SYMBOL_GPL(fuse_request_end); | |
78 | ||
79 | -static int queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req) | |
80 | +static int queue_interrupt(struct fuse_req *req) | |
81 | { | |
82 | + struct fuse_iqueue *fiq = &req->fc->iq; | |
83 | + | |
84 | spin_lock(&fiq->lock); | |
85 | /* Check for we've sent request to interrupt this req */ | |
86 | if (unlikely(!test_bit(FR_INTERRUPTED, &req->flags))) { | |
87 | @@ -358,8 +363,9 @@ static int queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req) | |
88 | return 0; | |
89 | } | |
90 | ||
91 | -static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req) | |
92 | +static void request_wait_answer(struct fuse_req *req) | |
93 | { | |
94 | + struct fuse_conn *fc = req->fc; | |
95 | struct fuse_iqueue *fiq = &fc->iq; | |
96 | int err; | |
97 | ||
98 | @@ -374,7 +380,7 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req) | |
99 | /* matches barrier in fuse_dev_do_read() */ | |
100 | smp_mb__after_atomic(); | |
101 | if (test_bit(FR_SENT, &req->flags)) | |
102 | - queue_interrupt(fiq, req); | |
103 | + queue_interrupt(req); | |
104 | } | |
105 | ||
106 | if (!test_bit(FR_FORCE, &req->flags)) { | |
107 | @@ -403,9 +409,9 @@ static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req) | |
108 | wait_event(req->waitq, test_bit(FR_FINISHED, &req->flags)); | |
109 | } | |
110 | ||
111 | -static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req) | |
112 | +static void __fuse_request_send(struct fuse_req *req) | |
113 | { | |
114 | - struct fuse_iqueue *fiq = &fc->iq; | |
115 | + struct fuse_iqueue *fiq = &req->fc->iq; | |
116 | ||
117 | BUG_ON(test_bit(FR_BACKGROUND, &req->flags)); | |
118 | spin_lock(&fiq->lock); | |
119 | @@ -419,7 +425,7 @@ static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req) | |
120 | __fuse_get_request(req); | |
121 | queue_request_and_unlock(fiq, req); | |
122 | ||
123 | - request_wait_answer(fc, req); | |
124 | + request_wait_answer(req); | |
125 | /* Pairs with smp_wmb() in fuse_request_end() */ | |
126 | smp_rmb(); | |
127 | } | |
128 | @@ -458,8 +464,10 @@ static void fuse_adjust_compat(struct fuse_conn *fc, struct fuse_args *args) | |
129 | } | |
130 | } | |
131 | ||
132 | -static void fuse_force_creds(struct fuse_conn *fc, struct fuse_req *req) | |
133 | +static void fuse_force_creds(struct fuse_req *req) | |
134 | { | |
135 | + struct fuse_conn *fc = req->fc; | |
136 | + | |
137 | req->in.h.uid = from_kuid_munged(fc->user_ns, current_fsuid()); | |
138 | req->in.h.gid = from_kgid_munged(fc->user_ns, current_fsgid()); | |
139 | req->in.h.pid = pid_nr_ns(task_pid(current), fc->pid_ns); | |
140 | @@ -484,7 +492,7 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args) | |
141 | req = fuse_request_alloc(fc, GFP_KERNEL | __GFP_NOFAIL); | |
142 | ||
143 | if (!args->nocreds) | |
144 | - fuse_force_creds(fc, req); | |
145 | + fuse_force_creds(req); | |
146 | ||
147 | __set_bit(FR_WAITING, &req->flags); | |
148 | __set_bit(FR_FORCE, &req->flags); | |
149 | @@ -501,20 +509,20 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args) | |
150 | ||
151 | if (!args->noreply) | |
152 | __set_bit(FR_ISREPLY, &req->flags); | |
153 | - __fuse_request_send(fc, req); | |
154 | + __fuse_request_send(req); | |
155 | ret = req->out.h.error; | |
156 | if (!ret && args->out_argvar) { | |
157 | BUG_ON(args->out_numargs == 0); | |
158 | ret = args->out_args[args->out_numargs - 1].size; | |
159 | } | |
160 | - fuse_put_request(fc, req); | |
161 | + fuse_put_request(req); | |
162 | ||
163 | return ret; | |
164 | } | |
165 | ||
166 | -static bool fuse_request_queue_background(struct fuse_conn *fc, | |
167 | - struct fuse_req *req) | |
168 | +static bool fuse_request_queue_background(struct fuse_req *req) | |
169 | { | |
170 | + struct fuse_conn *fc = req->fc; | |
171 | bool queued = false; | |
172 | ||
173 | WARN_ON(!test_bit(FR_BACKGROUND, &req->flags)); | |
174 | @@ -561,8 +569,8 @@ int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args, | |
175 | ||
176 | fuse_args_to_req(req, args); | |
177 | ||
178 | - if (!fuse_request_queue_background(fc, req)) { | |
179 | - fuse_put_request(fc, req); | |
180 | + if (!fuse_request_queue_background(req)) { | |
181 | + fuse_put_request(req); | |
182 | return -ENOTCONN; | |
183 | } | |
184 | ||
185 | @@ -592,7 +600,7 @@ static int fuse_simple_notify_reply(struct fuse_conn *fc, | |
186 | } else { | |
187 | err = -ENODEV; | |
188 | spin_unlock(&fiq->lock); | |
189 | - fuse_put_request(fc, req); | |
190 | + fuse_put_request(req); | |
191 | } | |
192 | ||
193 | return err; | |
194 | @@ -1277,7 +1285,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, | |
195 | /* SETXATTR is special, since it may contain too large data */ | |
196 | if (args->opcode == FUSE_SETXATTR) | |
197 | req->out.h.error = -E2BIG; | |
198 | - fuse_request_end(fc, req); | |
199 | + fuse_request_end(req); | |
200 | goto restart; | |
201 | } | |
202 | spin_lock(&fpq->lock); | |
203 | @@ -1320,8 +1328,8 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, | |
204 | /* matches barrier in request_wait_answer() */ | |
205 | smp_mb__after_atomic(); | |
206 | if (test_bit(FR_INTERRUPTED, &req->flags)) | |
207 | - queue_interrupt(fiq, req); | |
208 | - fuse_put_request(fc, req); | |
209 | + queue_interrupt(req); | |
210 | + fuse_put_request(req); | |
211 | ||
212 | return reqsize; | |
213 | ||
214 | @@ -1329,7 +1337,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, | |
215 | if (!test_bit(FR_PRIVATE, &req->flags)) | |
216 | list_del_init(&req->list); | |
217 | spin_unlock(&fpq->lock); | |
218 | - fuse_request_end(fc, req); | |
219 | + fuse_request_end(req); | |
220 | return err; | |
221 | ||
222 | err_unlock: | |
223 | @@ -1911,9 +1919,9 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, | |
224 | else if (oh.error == -ENOSYS) | |
225 | fc->no_interrupt = 1; | |
226 | else if (oh.error == -EAGAIN) | |
227 | - err = queue_interrupt(&fc->iq, req); | |
228 | + err = queue_interrupt(req); | |
229 | ||
230 | - fuse_put_request(fc, req); | |
231 | + fuse_put_request(req); | |
232 | ||
233 | goto copy_finish; | |
234 | } | |
235 | @@ -1943,7 +1951,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, | |
236 | list_del_init(&req->list); | |
237 | spin_unlock(&fpq->lock); | |
238 | ||
239 | - fuse_request_end(fc, req); | |
240 | + fuse_request_end(req); | |
241 | out: | |
242 | return err ? err : nbytes; | |
243 | ||
244 | @@ -2079,7 +2087,7 @@ static __poll_t fuse_dev_poll(struct file *file, poll_table *wait) | |
245 | } | |
246 | ||
247 | /* Abort all requests on the given list (pending or processing) */ | |
248 | -static void end_requests(struct fuse_conn *fc, struct list_head *head) | |
249 | +static void end_requests(struct list_head *head) | |
250 | { | |
251 | while (!list_empty(head)) { | |
252 | struct fuse_req *req; | |
253 | @@ -2087,7 +2095,7 @@ static void end_requests(struct fuse_conn *fc, struct list_head *head) | |
254 | req->out.h.error = -ECONNABORTED; | |
255 | clear_bit(FR_SENT, &req->flags); | |
256 | list_del_init(&req->list); | |
257 | - fuse_request_end(fc, req); | |
258 | + fuse_request_end(req); | |
259 | } | |
260 | } | |
261 | ||
262 | @@ -2182,7 +2190,7 @@ void fuse_abort_conn(struct fuse_conn *fc) | |
263 | wake_up_all(&fc->blocked_waitq); | |
264 | spin_unlock(&fc->lock); | |
265 | ||
266 | - end_requests(fc, &to_end); | |
267 | + end_requests(&to_end); | |
268 | } else { | |
269 | spin_unlock(&fc->lock); | |
270 | } | |
271 | @@ -2212,7 +2220,7 @@ int fuse_dev_release(struct inode *inode, struct file *file) | |
272 | list_splice_init(&fpq->processing[i], &to_end); | |
273 | spin_unlock(&fpq->lock); | |
274 | ||
275 | - end_requests(fc, &to_end); | |
276 | + end_requests(&to_end); | |
277 | ||
278 | /* Are we the last open device? */ | |
279 | if (atomic_dec_and_test(&fc->dev_count)) { | |
280 | diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h | |
281 | index 7138b780c9abd..b7bd2e623c3f3 100644 | |
282 | --- a/fs/fuse/fuse_i.h | |
283 | +++ b/fs/fuse/fuse_i.h | |
284 | @@ -941,7 +941,7 @@ int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args, | |
285 | /** | |
286 | * End a finished request | |
287 | */ | |
288 | -void fuse_request_end(struct fuse_conn *fc, struct fuse_req *req); | |
289 | +void fuse_request_end(struct fuse_req *req); | |
290 | ||
291 | /* Abort all requests */ | |
292 | void fuse_abort_conn(struct fuse_conn *fc); | |
293 | diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c | |
294 | index fadf6fb90fe22..8865ab961abfe 100644 | |
295 | --- a/fs/fuse/virtio_fs.c | |
296 | +++ b/fs/fuse/virtio_fs.c | |
297 | @@ -268,7 +268,6 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work) | |
298 | struct fuse_req *req; | |
299 | struct virtio_fs_vq *fsvq = container_of(work, struct virtio_fs_vq, | |
300 | dispatch_work.work); | |
301 | - struct fuse_conn *fc = fsvq->fud->fc; | |
302 | int ret; | |
303 | ||
304 | pr_debug("virtio-fs: worker %s called.\n", __func__); | |
305 | @@ -283,7 +282,7 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work) | |
306 | ||
307 | list_del_init(&req->list); | |
308 | spin_unlock(&fsvq->lock); | |
309 | - fuse_request_end(fc, req); | |
310 | + fuse_request_end(req); | |
311 | } | |
312 | ||
313 | /* Dispatch pending requests */ | |
314 | @@ -314,7 +313,7 @@ static void virtio_fs_request_dispatch_work(struct work_struct *work) | |
315 | spin_unlock(&fsvq->lock); | |
316 | pr_err("virtio-fs: virtio_fs_enqueue_req() failed %d\n", | |
317 | ret); | |
318 | - fuse_request_end(fc, req); | |
319 | + fuse_request_end(req); | |
320 | } | |
321 | } | |
322 | } | |
323 | @@ -453,7 +452,6 @@ static void virtio_fs_request_complete(struct fuse_req *req, | |
324 | struct virtio_fs_vq *fsvq) | |
325 | { | |
326 | struct fuse_pqueue *fpq = &fsvq->fud->pq; | |
327 | - struct fuse_conn *fc = fsvq->fud->fc; | |
328 | struct fuse_args *args; | |
329 | struct fuse_args_pages *ap; | |
330 | unsigned int len, i, thislen; | |
331 | @@ -486,7 +484,7 @@ static void virtio_fs_request_complete(struct fuse_req *req, | |
332 | clear_bit(FR_SENT, &req->flags); | |
333 | spin_unlock(&fpq->lock); | |
334 | ||
335 | - fuse_request_end(fc, req); | |
336 | + fuse_request_end(req); | |
337 | spin_lock(&fsvq->lock); | |
338 | dec_in_flight_req(fsvq); | |
339 | spin_unlock(&fsvq->lock); | |
340 | -- | |
341 | 2.43.0 | |
342 |