]>
Commit | Line | Data |
---|---|---|
d67ae825 TH |
1 | /* |
2 | * Module for pnfs flexfile layout driver. | |
3 | * | |
4 | * Copyright (c) 2014, Primary Data, Inc. All rights reserved. | |
5 | * | |
6 | * Tao Peng <bergwolf@primarydata.com> | |
7 | */ | |
8 | ||
9 | #include <linux/nfs_fs.h> | |
10 | #include <linux/nfs_page.h> | |
11 | #include <linux/module.h> | |
12 | ||
13 | #include <linux/sunrpc/metrics.h> | |
d67ae825 TH |
14 | |
15 | #include "flexfilelayout.h" | |
16 | #include "../nfs4session.h" | |
40c64c26 | 17 | #include "../nfs4idmap.h" |
d67ae825 TH |
18 | #include "../internal.h" |
19 | #include "../delegation.h" | |
20 | #include "../nfs4trace.h" | |
21 | #include "../iostat.h" | |
22 | #include "../nfs.h" | |
23 | ||
24 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD | |
25 | ||
26 | #define FF_LAYOUT_POLL_RETRY_MAX (15*HZ) | |
27 | ||
28 | static struct pnfs_layout_hdr * | |
29 | ff_layout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags) | |
30 | { | |
31 | struct nfs4_flexfile_layout *ffl; | |
32 | ||
33 | ffl = kzalloc(sizeof(*ffl), gfp_flags); | |
34 | if (ffl) { | |
35 | INIT_LIST_HEAD(&ffl->error_list); | |
36 | return &ffl->generic_hdr; | |
37 | } else | |
38 | return NULL; | |
39 | } | |
40 | ||
41 | static void | |
42 | ff_layout_free_layout_hdr(struct pnfs_layout_hdr *lo) | |
43 | { | |
44 | struct nfs4_ff_layout_ds_err *err, *n; | |
45 | ||
46 | list_for_each_entry_safe(err, n, &FF_LAYOUT_FROM_HDR(lo)->error_list, | |
47 | list) { | |
48 | list_del(&err->list); | |
49 | kfree(err); | |
50 | } | |
51 | kfree(FF_LAYOUT_FROM_HDR(lo)); | |
52 | } | |
53 | ||
54 | static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) | |
55 | { | |
56 | __be32 *p; | |
57 | ||
58 | p = xdr_inline_decode(xdr, NFS4_STATEID_SIZE); | |
59 | if (unlikely(p == NULL)) | |
60 | return -ENOBUFS; | |
61 | memcpy(stateid, p, NFS4_STATEID_SIZE); | |
62 | dprintk("%s: stateid id= [%x%x%x%x]\n", __func__, | |
63 | p[0], p[1], p[2], p[3]); | |
64 | return 0; | |
65 | } | |
66 | ||
67 | static int decode_deviceid(struct xdr_stream *xdr, struct nfs4_deviceid *devid) | |
68 | { | |
69 | __be32 *p; | |
70 | ||
71 | p = xdr_inline_decode(xdr, NFS4_DEVICEID4_SIZE); | |
72 | if (unlikely(!p)) | |
73 | return -ENOBUFS; | |
74 | memcpy(devid, p, NFS4_DEVICEID4_SIZE); | |
75 | nfs4_print_deviceid(devid); | |
76 | return 0; | |
77 | } | |
78 | ||
79 | static int decode_nfs_fh(struct xdr_stream *xdr, struct nfs_fh *fh) | |
80 | { | |
81 | __be32 *p; | |
82 | ||
83 | p = xdr_inline_decode(xdr, 4); | |
84 | if (unlikely(!p)) | |
85 | return -ENOBUFS; | |
86 | fh->size = be32_to_cpup(p++); | |
87 | if (fh->size > sizeof(struct nfs_fh)) { | |
88 | printk(KERN_ERR "NFS flexfiles: Too big fh received %d\n", | |
89 | fh->size); | |
90 | return -EOVERFLOW; | |
91 | } | |
92 | /* fh.data */ | |
93 | p = xdr_inline_decode(xdr, fh->size); | |
94 | if (unlikely(!p)) | |
95 | return -ENOBUFS; | |
96 | memcpy(&fh->data, p, fh->size); | |
97 | dprintk("%s: fh len %d\n", __func__, fh->size); | |
98 | ||
99 | return 0; | |
100 | } | |
101 | ||
102 | /* | |
103 | * Currently only stringified uids and gids are accepted. | |
104 | * I.e., kerberos is not supported to the DSes, so no pricipals. | |
105 | * | |
106 | * That means that one common function will suffice, but when | |
107 | * principals are added, this should be split to accomodate | |
108 | * calls to both nfs_map_name_to_uid() and nfs_map_group_to_gid(). | |
109 | */ | |
110 | static int | |
111 | decode_name(struct xdr_stream *xdr, u32 *id) | |
112 | { | |
113 | __be32 *p; | |
114 | int len; | |
115 | ||
116 | /* opaque_length(4)*/ | |
117 | p = xdr_inline_decode(xdr, 4); | |
118 | if (unlikely(!p)) | |
119 | return -ENOBUFS; | |
120 | len = be32_to_cpup(p++); | |
121 | if (len < 0) | |
122 | return -EINVAL; | |
123 | ||
124 | dprintk("%s: len %u\n", __func__, len); | |
125 | ||
126 | /* opaque body */ | |
127 | p = xdr_inline_decode(xdr, len); | |
128 | if (unlikely(!p)) | |
129 | return -ENOBUFS; | |
130 | ||
131 | if (!nfs_map_string_to_numeric((char *)p, len, id)) | |
132 | return -EINVAL; | |
133 | ||
134 | return 0; | |
135 | } | |
136 | ||
137 | static void ff_layout_free_mirror_array(struct nfs4_ff_layout_segment *fls) | |
138 | { | |
139 | int i; | |
140 | ||
141 | if (fls->mirror_array) { | |
142 | for (i = 0; i < fls->mirror_array_cnt; i++) { | |
143 | /* normally mirror_ds is freed in | |
144 | * .free_deviceid_node but we still do it here | |
145 | * for .alloc_lseg error path */ | |
146 | if (fls->mirror_array[i]) { | |
147 | kfree(fls->mirror_array[i]->fh_versions); | |
148 | nfs4_ff_layout_put_deviceid(fls->mirror_array[i]->mirror_ds); | |
149 | kfree(fls->mirror_array[i]); | |
150 | } | |
151 | } | |
152 | kfree(fls->mirror_array); | |
153 | fls->mirror_array = NULL; | |
154 | } | |
155 | } | |
156 | ||
157 | static int ff_layout_check_layout(struct nfs4_layoutget_res *lgr) | |
158 | { | |
159 | int ret = 0; | |
160 | ||
161 | dprintk("--> %s\n", __func__); | |
162 | ||
163 | /* FIXME: remove this check when layout segment support is added */ | |
164 | if (lgr->range.offset != 0 || | |
165 | lgr->range.length != NFS4_MAX_UINT64) { | |
166 | dprintk("%s Only whole file layouts supported. Use MDS i/o\n", | |
167 | __func__); | |
168 | ret = -EINVAL; | |
169 | } | |
170 | ||
171 | dprintk("--> %s returns %d\n", __func__, ret); | |
172 | return ret; | |
173 | } | |
174 | ||
175 | static void _ff_layout_free_lseg(struct nfs4_ff_layout_segment *fls) | |
176 | { | |
177 | if (fls) { | |
178 | ff_layout_free_mirror_array(fls); | |
179 | kfree(fls); | |
180 | } | |
181 | } | |
182 | ||
183 | static void ff_layout_sort_mirrors(struct nfs4_ff_layout_segment *fls) | |
184 | { | |
d67ae825 TH |
185 | int i, j; |
186 | ||
187 | for (i = 0; i < fls->mirror_array_cnt - 1; i++) { | |
188 | for (j = i + 1; j < fls->mirror_array_cnt; j++) | |
189 | if (fls->mirror_array[i]->efficiency < | |
455b6ee6 FF |
190 | fls->mirror_array[j]->efficiency) |
191 | swap(fls->mirror_array[i], | |
192 | fls->mirror_array[j]); | |
d67ae825 TH |
193 | } |
194 | } | |
195 | ||
196 | static struct pnfs_layout_segment * | |
197 | ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh, | |
198 | struct nfs4_layoutget_res *lgr, | |
199 | gfp_t gfp_flags) | |
200 | { | |
201 | struct pnfs_layout_segment *ret; | |
202 | struct nfs4_ff_layout_segment *fls = NULL; | |
203 | struct xdr_stream stream; | |
204 | struct xdr_buf buf; | |
205 | struct page *scratch; | |
206 | u64 stripe_unit; | |
207 | u32 mirror_array_cnt; | |
208 | __be32 *p; | |
209 | int i, rc; | |
210 | ||
211 | dprintk("--> %s\n", __func__); | |
212 | scratch = alloc_page(gfp_flags); | |
213 | if (!scratch) | |
214 | return ERR_PTR(-ENOMEM); | |
215 | ||
216 | xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, | |
217 | lgr->layoutp->len); | |
218 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); | |
219 | ||
220 | /* stripe unit and mirror_array_cnt */ | |
221 | rc = -EIO; | |
222 | p = xdr_inline_decode(&stream, 8 + 4); | |
223 | if (!p) | |
224 | goto out_err_free; | |
225 | ||
226 | p = xdr_decode_hyper(p, &stripe_unit); | |
227 | mirror_array_cnt = be32_to_cpup(p++); | |
228 | dprintk("%s: stripe_unit=%llu mirror_array_cnt=%u\n", __func__, | |
229 | stripe_unit, mirror_array_cnt); | |
230 | ||
231 | if (mirror_array_cnt > NFS4_FLEXFILE_LAYOUT_MAX_MIRROR_CNT || | |
232 | mirror_array_cnt == 0) | |
233 | goto out_err_free; | |
234 | ||
235 | rc = -ENOMEM; | |
236 | fls = kzalloc(sizeof(*fls), gfp_flags); | |
237 | if (!fls) | |
238 | goto out_err_free; | |
239 | ||
240 | fls->mirror_array_cnt = mirror_array_cnt; | |
241 | fls->stripe_unit = stripe_unit; | |
242 | fls->mirror_array = kcalloc(fls->mirror_array_cnt, | |
243 | sizeof(fls->mirror_array[0]), gfp_flags); | |
244 | if (fls->mirror_array == NULL) | |
245 | goto out_err_free; | |
246 | ||
247 | for (i = 0; i < fls->mirror_array_cnt; i++) { | |
248 | struct nfs4_deviceid devid; | |
249 | struct nfs4_deviceid_node *idnode; | |
250 | u32 ds_count; | |
251 | u32 fh_count; | |
252 | int j; | |
253 | ||
254 | rc = -EIO; | |
255 | p = xdr_inline_decode(&stream, 4); | |
256 | if (!p) | |
257 | goto out_err_free; | |
258 | ds_count = be32_to_cpup(p); | |
259 | ||
260 | /* FIXME: allow for striping? */ | |
261 | if (ds_count != 1) | |
262 | goto out_err_free; | |
263 | ||
264 | fls->mirror_array[i] = | |
265 | kzalloc(sizeof(struct nfs4_ff_layout_mirror), | |
266 | gfp_flags); | |
267 | if (fls->mirror_array[i] == NULL) { | |
268 | rc = -ENOMEM; | |
269 | goto out_err_free; | |
270 | } | |
271 | ||
272 | spin_lock_init(&fls->mirror_array[i]->lock); | |
273 | fls->mirror_array[i]->ds_count = ds_count; | |
274 | ||
275 | /* deviceid */ | |
276 | rc = decode_deviceid(&stream, &devid); | |
277 | if (rc) | |
278 | goto out_err_free; | |
279 | ||
280 | idnode = nfs4_find_get_deviceid(NFS_SERVER(lh->plh_inode), | |
281 | &devid, lh->plh_lc_cred, | |
282 | gfp_flags); | |
283 | /* | |
284 | * upon success, mirror_ds is allocated by previous | |
285 | * getdeviceinfo, or newly by .alloc_deviceid_node | |
286 | * nfs4_find_get_deviceid failure is indeed getdeviceinfo falure | |
287 | */ | |
288 | if (idnode) | |
289 | fls->mirror_array[i]->mirror_ds = | |
290 | FF_LAYOUT_MIRROR_DS(idnode); | |
291 | else | |
292 | goto out_err_free; | |
293 | ||
294 | /* efficiency */ | |
295 | rc = -EIO; | |
296 | p = xdr_inline_decode(&stream, 4); | |
297 | if (!p) | |
298 | goto out_err_free; | |
299 | fls->mirror_array[i]->efficiency = be32_to_cpup(p); | |
300 | ||
301 | /* stateid */ | |
302 | rc = decode_stateid(&stream, &fls->mirror_array[i]->stateid); | |
303 | if (rc) | |
304 | goto out_err_free; | |
305 | ||
306 | /* fh */ | |
307 | p = xdr_inline_decode(&stream, 4); | |
308 | if (!p) | |
309 | goto out_err_free; | |
310 | fh_count = be32_to_cpup(p); | |
311 | ||
312 | fls->mirror_array[i]->fh_versions = | |
313 | kzalloc(fh_count * sizeof(struct nfs_fh), | |
314 | gfp_flags); | |
315 | if (fls->mirror_array[i]->fh_versions == NULL) { | |
316 | rc = -ENOMEM; | |
317 | goto out_err_free; | |
318 | } | |
319 | ||
320 | for (j = 0; j < fh_count; j++) { | |
321 | rc = decode_nfs_fh(&stream, | |
322 | &fls->mirror_array[i]->fh_versions[j]); | |
323 | if (rc) | |
324 | goto out_err_free; | |
325 | } | |
326 | ||
327 | fls->mirror_array[i]->fh_versions_cnt = fh_count; | |
328 | ||
329 | /* user */ | |
330 | rc = decode_name(&stream, &fls->mirror_array[i]->uid); | |
331 | if (rc) | |
332 | goto out_err_free; | |
333 | ||
334 | /* group */ | |
335 | rc = decode_name(&stream, &fls->mirror_array[i]->gid); | |
336 | if (rc) | |
337 | goto out_err_free; | |
338 | ||
339 | dprintk("%s: uid %d gid %d\n", __func__, | |
340 | fls->mirror_array[i]->uid, | |
341 | fls->mirror_array[i]->gid); | |
342 | } | |
343 | ||
344 | ff_layout_sort_mirrors(fls); | |
345 | rc = ff_layout_check_layout(lgr); | |
346 | if (rc) | |
347 | goto out_err_free; | |
348 | ||
349 | ret = &fls->generic_hdr; | |
350 | dprintk("<-- %s (success)\n", __func__); | |
351 | out_free_page: | |
352 | __free_page(scratch); | |
353 | return ret; | |
354 | out_err_free: | |
355 | _ff_layout_free_lseg(fls); | |
356 | ret = ERR_PTR(rc); | |
357 | dprintk("<-- %s (%d)\n", __func__, rc); | |
358 | goto out_free_page; | |
359 | } | |
360 | ||
361 | static bool ff_layout_has_rw_segments(struct pnfs_layout_hdr *layout) | |
362 | { | |
363 | struct pnfs_layout_segment *lseg; | |
364 | ||
365 | list_for_each_entry(lseg, &layout->plh_segs, pls_list) | |
366 | if (lseg->pls_range.iomode == IOMODE_RW) | |
367 | return true; | |
368 | ||
369 | return false; | |
370 | } | |
371 | ||
372 | static void | |
373 | ff_layout_free_lseg(struct pnfs_layout_segment *lseg) | |
374 | { | |
375 | struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg); | |
376 | int i; | |
377 | ||
378 | dprintk("--> %s\n", __func__); | |
379 | ||
380 | for (i = 0; i < fls->mirror_array_cnt; i++) { | |
381 | if (fls->mirror_array[i]) { | |
382 | nfs4_ff_layout_put_deviceid(fls->mirror_array[i]->mirror_ds); | |
383 | fls->mirror_array[i]->mirror_ds = NULL; | |
384 | if (fls->mirror_array[i]->cred) { | |
385 | put_rpccred(fls->mirror_array[i]->cred); | |
386 | fls->mirror_array[i]->cred = NULL; | |
387 | } | |
388 | } | |
389 | } | |
390 | ||
391 | if (lseg->pls_range.iomode == IOMODE_RW) { | |
392 | struct nfs4_flexfile_layout *ffl; | |
393 | struct inode *inode; | |
394 | ||
395 | ffl = FF_LAYOUT_FROM_HDR(lseg->pls_layout); | |
396 | inode = ffl->generic_hdr.plh_inode; | |
397 | spin_lock(&inode->i_lock); | |
398 | if (!ff_layout_has_rw_segments(lseg->pls_layout)) { | |
399 | ffl->commit_info.nbuckets = 0; | |
400 | kfree(ffl->commit_info.buckets); | |
401 | ffl->commit_info.buckets = NULL; | |
402 | } | |
403 | spin_unlock(&inode->i_lock); | |
404 | } | |
405 | _ff_layout_free_lseg(fls); | |
406 | } | |
407 | ||
408 | /* Return 1 until we have multiple lsegs support */ | |
409 | static int | |
410 | ff_layout_get_lseg_count(struct nfs4_ff_layout_segment *fls) | |
411 | { | |
412 | return 1; | |
413 | } | |
414 | ||
abcb7bfc TM |
415 | static void |
416 | nfs4_ff_start_busy_timer(struct nfs4_ff_busy_timer *timer) | |
417 | { | |
418 | ktime_t old, new; | |
419 | ||
420 | /* | |
421 | * Note: careful here! | |
422 | * If the counter is zero, then we must not increment it until after | |
423 | * we've set the start_time. | |
424 | * If we were instead to use atomic_inc_return(), then another | |
425 | * request might come in, bump, and then call end_busy_timer() | |
426 | * before we've set the timer->start_time. | |
427 | */ | |
428 | old = timer->start_time; | |
429 | if (atomic_inc_not_zero(&timer->n_ops) == 0) { | |
430 | new = ktime_get(); | |
431 | cmpxchg(&timer->start_time.tv64, old.tv64, new.tv64); | |
432 | atomic_inc(&timer->n_ops); | |
433 | } | |
434 | } | |
435 | ||
436 | static ktime_t | |
437 | nfs4_ff_end_busy_timer(struct nfs4_ff_busy_timer *timer) | |
438 | { | |
439 | ktime_t start, now; | |
440 | ||
441 | now = ktime_get(); | |
442 | start.tv64 = xchg(&timer->start_time.tv64, now.tv64); | |
443 | atomic_dec(&timer->n_ops); | |
444 | return ktime_sub(now, start); | |
445 | } | |
446 | ||
447 | static ktime_t | |
448 | nfs4_ff_layout_calc_completion_time(struct rpc_task *task) | |
449 | { | |
450 | return ktime_sub(ktime_get(), task->tk_start); | |
451 | } | |
452 | ||
453 | static void | |
d983803d PT |
454 | nfs4_ff_layoutstat_start_io(struct nfs4_ff_layout_mirror *mirror, |
455 | struct nfs4_ff_layoutstat *layoutstat) | |
abcb7bfc | 456 | { |
d983803d PT |
457 | static const ktime_t notime = {0}; |
458 | ||
abcb7bfc | 459 | nfs4_ff_start_busy_timer(&layoutstat->busy_timer); |
d983803d | 460 | cmpxchg(&mirror->start_time, notime, ktime_get()); |
abcb7bfc TM |
461 | } |
462 | ||
463 | static void | |
464 | nfs4_ff_layout_stat_io_update_requested(struct nfs4_ff_layoutstat *layoutstat, | |
465 | __u64 requested) | |
466 | { | |
467 | struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat; | |
468 | ||
469 | iostat->ops_requested++; | |
470 | iostat->bytes_requested += requested; | |
471 | } | |
472 | ||
473 | static void | |
474 | nfs4_ff_layout_stat_io_update_completed(struct nfs4_ff_layoutstat *layoutstat, | |
475 | __u64 requested, | |
476 | __u64 completed, | |
477 | ktime_t time_completed) | |
478 | { | |
479 | struct nfs4_ff_io_stat *iostat = &layoutstat->io_stat; | |
480 | ktime_t timer; | |
481 | ||
482 | iostat->ops_completed++; | |
483 | iostat->bytes_completed += completed; | |
484 | iostat->bytes_not_delivered += requested - completed; | |
485 | ||
486 | timer = nfs4_ff_end_busy_timer(&layoutstat->busy_timer); | |
487 | iostat->total_busy_time = | |
488 | ktime_add(iostat->total_busy_time, timer); | |
489 | iostat->aggregate_completion_time = | |
490 | ktime_add(iostat->aggregate_completion_time, time_completed); | |
491 | } | |
492 | ||
493 | static void | |
494 | nfs4_ff_layout_stat_io_start_read(struct nfs4_ff_layout_mirror *mirror, | |
495 | __u64 requested) | |
496 | { | |
497 | spin_lock(&mirror->lock); | |
d983803d | 498 | nfs4_ff_layoutstat_start_io(mirror, &mirror->read_stat); |
abcb7bfc TM |
499 | nfs4_ff_layout_stat_io_update_requested(&mirror->read_stat, requested); |
500 | spin_unlock(&mirror->lock); | |
501 | } | |
502 | ||
503 | static void | |
504 | nfs4_ff_layout_stat_io_end_read(struct rpc_task *task, | |
505 | struct nfs4_ff_layout_mirror *mirror, | |
506 | __u64 requested, | |
507 | __u64 completed) | |
508 | { | |
509 | spin_lock(&mirror->lock); | |
510 | nfs4_ff_layout_stat_io_update_completed(&mirror->read_stat, | |
511 | requested, completed, | |
512 | nfs4_ff_layout_calc_completion_time(task)); | |
513 | spin_unlock(&mirror->lock); | |
514 | } | |
515 | ||
516 | static void | |
517 | nfs4_ff_layout_stat_io_start_write(struct nfs4_ff_layout_mirror *mirror, | |
518 | __u64 requested) | |
519 | { | |
520 | spin_lock(&mirror->lock); | |
d983803d | 521 | nfs4_ff_layoutstat_start_io(mirror, &mirror->write_stat); |
abcb7bfc TM |
522 | nfs4_ff_layout_stat_io_update_requested(&mirror->write_stat, requested); |
523 | spin_unlock(&mirror->lock); | |
524 | } | |
525 | ||
526 | static void | |
527 | nfs4_ff_layout_stat_io_end_write(struct rpc_task *task, | |
528 | struct nfs4_ff_layout_mirror *mirror, | |
529 | __u64 requested, | |
530 | __u64 completed, | |
531 | enum nfs3_stable_how committed) | |
532 | { | |
533 | if (committed == NFS_UNSTABLE) | |
534 | requested = completed = 0; | |
535 | ||
536 | spin_lock(&mirror->lock); | |
537 | nfs4_ff_layout_stat_io_update_completed(&mirror->write_stat, | |
538 | requested, completed, | |
539 | nfs4_ff_layout_calc_completion_time(task)); | |
540 | spin_unlock(&mirror->lock); | |
541 | } | |
542 | ||
d67ae825 TH |
543 | static int |
544 | ff_layout_alloc_commit_info(struct pnfs_layout_segment *lseg, | |
545 | struct nfs_commit_info *cinfo, | |
546 | gfp_t gfp_flags) | |
547 | { | |
548 | struct nfs4_ff_layout_segment *fls = FF_LAYOUT_LSEG(lseg); | |
549 | struct pnfs_commit_bucket *buckets; | |
550 | int size; | |
551 | ||
552 | if (cinfo->ds->nbuckets != 0) { | |
553 | /* This assumes there is only one RW lseg per file. | |
554 | * To support multiple lseg per file, we need to | |
555 | * change struct pnfs_commit_bucket to allow dynamic | |
556 | * increasing nbuckets. | |
557 | */ | |
558 | return 0; | |
559 | } | |
560 | ||
561 | size = ff_layout_get_lseg_count(fls) * FF_LAYOUT_MIRROR_COUNT(lseg); | |
562 | ||
563 | buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket), | |
564 | gfp_flags); | |
565 | if (!buckets) | |
566 | return -ENOMEM; | |
567 | else { | |
568 | int i; | |
569 | ||
570 | spin_lock(cinfo->lock); | |
571 | if (cinfo->ds->nbuckets != 0) | |
572 | kfree(buckets); | |
573 | else { | |
574 | cinfo->ds->buckets = buckets; | |
575 | cinfo->ds->nbuckets = size; | |
576 | for (i = 0; i < size; i++) { | |
577 | INIT_LIST_HEAD(&buckets[i].written); | |
578 | INIT_LIST_HEAD(&buckets[i].committing); | |
579 | /* mark direct verifier as unset */ | |
580 | buckets[i].direct_verf.committed = | |
581 | NFS_INVALID_STABLE_HOW; | |
582 | } | |
583 | } | |
584 | spin_unlock(cinfo->lock); | |
585 | return 0; | |
586 | } | |
587 | } | |
588 | ||
589 | static struct nfs4_pnfs_ds * | |
590 | ff_layout_choose_best_ds_for_read(struct nfs_pageio_descriptor *pgio, | |
591 | int *best_idx) | |
592 | { | |
593 | struct nfs4_ff_layout_segment *fls; | |
594 | struct nfs4_pnfs_ds *ds; | |
595 | int idx; | |
596 | ||
597 | fls = FF_LAYOUT_LSEG(pgio->pg_lseg); | |
598 | /* mirrors are sorted by efficiency */ | |
599 | for (idx = 0; idx < fls->mirror_array_cnt; idx++) { | |
600 | ds = nfs4_ff_layout_prepare_ds(pgio->pg_lseg, idx, false); | |
601 | if (ds) { | |
602 | *best_idx = idx; | |
603 | return ds; | |
604 | } | |
605 | } | |
606 | ||
607 | return NULL; | |
608 | } | |
609 | ||
610 | static void | |
611 | ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio, | |
612 | struct nfs_page *req) | |
613 | { | |
614 | struct nfs_pgio_mirror *pgm; | |
615 | struct nfs4_ff_layout_mirror *mirror; | |
616 | struct nfs4_pnfs_ds *ds; | |
617 | int ds_idx; | |
618 | ||
619 | /* Use full layout for now */ | |
620 | if (!pgio->pg_lseg) | |
621 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | |
622 | req->wb_context, | |
623 | 0, | |
624 | NFS4_MAX_UINT64, | |
625 | IOMODE_READ, | |
626 | GFP_KERNEL); | |
627 | /* If no lseg, fall back to read through mds */ | |
628 | if (pgio->pg_lseg == NULL) | |
629 | goto out_mds; | |
630 | ||
631 | ds = ff_layout_choose_best_ds_for_read(pgio, &ds_idx); | |
632 | if (!ds) | |
633 | goto out_mds; | |
634 | mirror = FF_LAYOUT_COMP(pgio->pg_lseg, ds_idx); | |
635 | ||
636 | pgio->pg_mirror_idx = ds_idx; | |
637 | ||
638 | /* read always uses only one mirror - idx 0 for pgio layer */ | |
639 | pgm = &pgio->pg_mirrors[0]; | |
640 | pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].rsize; | |
641 | ||
642 | return; | |
643 | out_mds: | |
644 | pnfs_put_lseg(pgio->pg_lseg); | |
645 | pgio->pg_lseg = NULL; | |
646 | nfs_pageio_reset_read_mds(pgio); | |
647 | } | |
648 | ||
649 | static void | |
650 | ff_layout_pg_init_write(struct nfs_pageio_descriptor *pgio, | |
651 | struct nfs_page *req) | |
652 | { | |
653 | struct nfs4_ff_layout_mirror *mirror; | |
654 | struct nfs_pgio_mirror *pgm; | |
655 | struct nfs_commit_info cinfo; | |
656 | struct nfs4_pnfs_ds *ds; | |
657 | int i; | |
658 | int status; | |
659 | ||
660 | if (!pgio->pg_lseg) | |
661 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | |
662 | req->wb_context, | |
663 | 0, | |
664 | NFS4_MAX_UINT64, | |
665 | IOMODE_RW, | |
666 | GFP_NOFS); | |
667 | /* If no lseg, fall back to write through mds */ | |
668 | if (pgio->pg_lseg == NULL) | |
669 | goto out_mds; | |
670 | ||
671 | nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq); | |
672 | status = ff_layout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS); | |
673 | if (status < 0) | |
674 | goto out_mds; | |
675 | ||
676 | /* Use a direct mapping of ds_idx to pgio mirror_idx */ | |
677 | if (WARN_ON_ONCE(pgio->pg_mirror_count != | |
678 | FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg))) | |
679 | goto out_mds; | |
680 | ||
681 | for (i = 0; i < pgio->pg_mirror_count; i++) { | |
682 | ds = nfs4_ff_layout_prepare_ds(pgio->pg_lseg, i, true); | |
683 | if (!ds) | |
684 | goto out_mds; | |
685 | pgm = &pgio->pg_mirrors[i]; | |
686 | mirror = FF_LAYOUT_COMP(pgio->pg_lseg, i); | |
687 | pgm->pg_bsize = mirror->mirror_ds->ds_versions[0].wsize; | |
688 | } | |
689 | ||
690 | return; | |
691 | ||
692 | out_mds: | |
693 | pnfs_put_lseg(pgio->pg_lseg); | |
694 | pgio->pg_lseg = NULL; | |
695 | nfs_pageio_reset_write_mds(pgio); | |
696 | } | |
697 | ||
698 | static unsigned int | |
699 | ff_layout_pg_get_mirror_count_write(struct nfs_pageio_descriptor *pgio, | |
700 | struct nfs_page *req) | |
701 | { | |
702 | if (!pgio->pg_lseg) | |
703 | pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode, | |
704 | req->wb_context, | |
705 | 0, | |
706 | NFS4_MAX_UINT64, | |
707 | IOMODE_RW, | |
708 | GFP_NOFS); | |
709 | if (pgio->pg_lseg) | |
710 | return FF_LAYOUT_MIRROR_COUNT(pgio->pg_lseg); | |
711 | ||
712 | /* no lseg means that pnfs is not in use, so no mirroring here */ | |
713 | pnfs_put_lseg(pgio->pg_lseg); | |
714 | pgio->pg_lseg = NULL; | |
715 | nfs_pageio_reset_write_mds(pgio); | |
716 | return 1; | |
717 | } | |
718 | ||
719 | static const struct nfs_pageio_ops ff_layout_pg_read_ops = { | |
720 | .pg_init = ff_layout_pg_init_read, | |
721 | .pg_test = pnfs_generic_pg_test, | |
722 | .pg_doio = pnfs_generic_pg_readpages, | |
723 | .pg_cleanup = pnfs_generic_pg_cleanup, | |
724 | }; | |
725 | ||
726 | static const struct nfs_pageio_ops ff_layout_pg_write_ops = { | |
727 | .pg_init = ff_layout_pg_init_write, | |
728 | .pg_test = pnfs_generic_pg_test, | |
729 | .pg_doio = pnfs_generic_pg_writepages, | |
730 | .pg_get_mirror_count = ff_layout_pg_get_mirror_count_write, | |
731 | .pg_cleanup = pnfs_generic_pg_cleanup, | |
732 | }; | |
733 | ||
734 | static void ff_layout_reset_write(struct nfs_pgio_header *hdr, bool retry_pnfs) | |
735 | { | |
736 | struct rpc_task *task = &hdr->task; | |
737 | ||
738 | pnfs_layoutcommit_inode(hdr->inode, false); | |
739 | ||
740 | if (retry_pnfs) { | |
741 | dprintk("%s Reset task %5u for i/o through pNFS " | |
742 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__, | |
743 | hdr->task.tk_pid, | |
744 | hdr->inode->i_sb->s_id, | |
745 | (unsigned long long)NFS_FILEID(hdr->inode), | |
746 | hdr->args.count, | |
747 | (unsigned long long)hdr->args.offset); | |
748 | ||
749 | if (!hdr->dreq) { | |
750 | struct nfs_open_context *ctx; | |
751 | ||
752 | ctx = nfs_list_entry(hdr->pages.next)->wb_context; | |
753 | set_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags); | |
754 | hdr->completion_ops->error_cleanup(&hdr->pages); | |
755 | } else { | |
756 | nfs_direct_set_resched_writes(hdr->dreq); | |
757 | /* fake unstable write to let common nfs resend pages */ | |
758 | hdr->verf.committed = NFS_UNSTABLE; | |
759 | hdr->good_bytes = 0; | |
760 | } | |
761 | return; | |
762 | } | |
763 | ||
764 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { | |
765 | dprintk("%s Reset task %5u for i/o through MDS " | |
766 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__, | |
767 | hdr->task.tk_pid, | |
768 | hdr->inode->i_sb->s_id, | |
769 | (unsigned long long)NFS_FILEID(hdr->inode), | |
770 | hdr->args.count, | |
771 | (unsigned long long)hdr->args.offset); | |
772 | ||
773 | task->tk_status = pnfs_write_done_resend_to_mds(hdr); | |
774 | } | |
775 | } | |
776 | ||
777 | static void ff_layout_reset_read(struct nfs_pgio_header *hdr) | |
778 | { | |
779 | struct rpc_task *task = &hdr->task; | |
780 | ||
781 | pnfs_layoutcommit_inode(hdr->inode, false); | |
782 | ||
783 | if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) { | |
784 | dprintk("%s Reset task %5u for i/o through MDS " | |
785 | "(req %s/%llu, %u bytes @ offset %llu)\n", __func__, | |
786 | hdr->task.tk_pid, | |
787 | hdr->inode->i_sb->s_id, | |
788 | (unsigned long long)NFS_FILEID(hdr->inode), | |
789 | hdr->args.count, | |
790 | (unsigned long long)hdr->args.offset); | |
791 | ||
792 | task->tk_status = pnfs_read_done_resend_to_mds(hdr); | |
793 | } | |
794 | } | |
795 | ||
796 | static int ff_layout_async_handle_error_v4(struct rpc_task *task, | |
797 | struct nfs4_state *state, | |
798 | struct nfs_client *clp, | |
799 | struct pnfs_layout_segment *lseg, | |
800 | int idx) | |
801 | { | |
802 | struct pnfs_layout_hdr *lo = lseg->pls_layout; | |
803 | struct inode *inode = lo->plh_inode; | |
804 | struct nfs_server *mds_server = NFS_SERVER(inode); | |
805 | ||
806 | struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx); | |
807 | struct nfs_client *mds_client = mds_server->nfs_client; | |
808 | struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table; | |
809 | ||
810 | if (task->tk_status >= 0) | |
811 | return 0; | |
812 | ||
813 | switch (task->tk_status) { | |
814 | /* MDS state errors */ | |
815 | case -NFS4ERR_DELEG_REVOKED: | |
816 | case -NFS4ERR_ADMIN_REVOKED: | |
817 | case -NFS4ERR_BAD_STATEID: | |
818 | if (state == NULL) | |
819 | break; | |
820 | nfs_remove_bad_delegation(state->inode); | |
821 | case -NFS4ERR_OPENMODE: | |
822 | if (state == NULL) | |
823 | break; | |
824 | if (nfs4_schedule_stateid_recovery(mds_server, state) < 0) | |
825 | goto out_bad_stateid; | |
826 | goto wait_on_recovery; | |
827 | case -NFS4ERR_EXPIRED: | |
828 | if (state != NULL) { | |
829 | if (nfs4_schedule_stateid_recovery(mds_server, state) < 0) | |
830 | goto out_bad_stateid; | |
831 | } | |
832 | nfs4_schedule_lease_recovery(mds_client); | |
833 | goto wait_on_recovery; | |
834 | /* DS session errors */ | |
835 | case -NFS4ERR_BADSESSION: | |
836 | case -NFS4ERR_BADSLOT: | |
837 | case -NFS4ERR_BAD_HIGH_SLOT: | |
838 | case -NFS4ERR_DEADSESSION: | |
839 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | |
840 | case -NFS4ERR_SEQ_FALSE_RETRY: | |
841 | case -NFS4ERR_SEQ_MISORDERED: | |
842 | dprintk("%s ERROR %d, Reset session. Exchangeid " | |
843 | "flags 0x%x\n", __func__, task->tk_status, | |
844 | clp->cl_exchange_flags); | |
845 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); | |
846 | break; | |
847 | case -NFS4ERR_DELAY: | |
848 | case -NFS4ERR_GRACE: | |
849 | rpc_delay(task, FF_LAYOUT_POLL_RETRY_MAX); | |
850 | break; | |
851 | case -NFS4ERR_RETRY_UNCACHED_REP: | |
852 | break; | |
853 | /* Invalidate Layout errors */ | |
854 | case -NFS4ERR_PNFS_NO_LAYOUT: | |
855 | case -ESTALE: /* mapped NFS4ERR_STALE */ | |
856 | case -EBADHANDLE: /* mapped NFS4ERR_BADHANDLE */ | |
857 | case -EISDIR: /* mapped NFS4ERR_ISDIR */ | |
858 | case -NFS4ERR_FHEXPIRED: | |
859 | case -NFS4ERR_WRONG_TYPE: | |
860 | dprintk("%s Invalid layout error %d\n", __func__, | |
861 | task->tk_status); | |
862 | /* | |
863 | * Destroy layout so new i/o will get a new layout. | |
864 | * Layout will not be destroyed until all current lseg | |
865 | * references are put. Mark layout as invalid to resend failed | |
866 | * i/o and all i/o waiting on the slot table to the MDS until | |
867 | * layout is destroyed and a new valid layout is obtained. | |
868 | */ | |
869 | pnfs_destroy_layout(NFS_I(inode)); | |
870 | rpc_wake_up(&tbl->slot_tbl_waitq); | |
871 | goto reset; | |
872 | /* RPC connection errors */ | |
873 | case -ECONNREFUSED: | |
874 | case -EHOSTDOWN: | |
875 | case -EHOSTUNREACH: | |
876 | case -ENETUNREACH: | |
877 | case -EIO: | |
878 | case -ETIMEDOUT: | |
879 | case -EPIPE: | |
880 | dprintk("%s DS connection error %d\n", __func__, | |
881 | task->tk_status); | |
882 | nfs4_mark_deviceid_unavailable(devid); | |
883 | rpc_wake_up(&tbl->slot_tbl_waitq); | |
884 | /* fall through */ | |
885 | default: | |
886 | if (ff_layout_has_available_ds(lseg)) | |
887 | return -NFS4ERR_RESET_TO_PNFS; | |
888 | reset: | |
889 | dprintk("%s Retry through MDS. Error %d\n", __func__, | |
890 | task->tk_status); | |
891 | return -NFS4ERR_RESET_TO_MDS; | |
892 | } | |
893 | out: | |
894 | task->tk_status = 0; | |
895 | return -EAGAIN; | |
896 | out_bad_stateid: | |
897 | task->tk_status = -EIO; | |
898 | return 0; | |
899 | wait_on_recovery: | |
900 | rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL); | |
901 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0) | |
902 | rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task); | |
903 | goto out; | |
904 | } | |
905 | ||
906 | /* Retry all errors through either pNFS or MDS except for -EJUKEBOX */ | |
907 | static int ff_layout_async_handle_error_v3(struct rpc_task *task, | |
908 | struct pnfs_layout_segment *lseg, | |
909 | int idx) | |
910 | { | |
911 | struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx); | |
912 | ||
913 | if (task->tk_status >= 0) | |
914 | return 0; | |
915 | ||
916 | if (task->tk_status != -EJUKEBOX) { | |
917 | dprintk("%s DS connection error %d\n", __func__, | |
918 | task->tk_status); | |
919 | nfs4_mark_deviceid_unavailable(devid); | |
920 | if (ff_layout_has_available_ds(lseg)) | |
921 | return -NFS4ERR_RESET_TO_PNFS; | |
922 | else | |
923 | return -NFS4ERR_RESET_TO_MDS; | |
924 | } | |
925 | ||
926 | if (task->tk_status == -EJUKEBOX) | |
927 | nfs_inc_stats(lseg->pls_layout->plh_inode, NFSIOS_DELAY); | |
928 | task->tk_status = 0; | |
929 | rpc_restart_call(task); | |
930 | rpc_delay(task, NFS_JUKEBOX_RETRY_TIME); | |
931 | return -EAGAIN; | |
932 | } | |
933 | ||
934 | static int ff_layout_async_handle_error(struct rpc_task *task, | |
935 | struct nfs4_state *state, | |
936 | struct nfs_client *clp, | |
937 | struct pnfs_layout_segment *lseg, | |
938 | int idx) | |
939 | { | |
940 | int vers = clp->cl_nfs_mod->rpc_vers->number; | |
941 | ||
942 | switch (vers) { | |
943 | case 3: | |
944 | return ff_layout_async_handle_error_v3(task, lseg, idx); | |
945 | case 4: | |
946 | return ff_layout_async_handle_error_v4(task, state, clp, | |
947 | lseg, idx); | |
948 | default: | |
949 | /* should never happen */ | |
950 | WARN_ON_ONCE(1); | |
951 | return 0; | |
952 | } | |
953 | } | |
954 | ||
955 | static void ff_layout_io_track_ds_error(struct pnfs_layout_segment *lseg, | |
956 | int idx, u64 offset, u64 length, | |
957 | u32 status, int opnum) | |
958 | { | |
959 | struct nfs4_ff_layout_mirror *mirror; | |
960 | int err; | |
961 | ||
962 | mirror = FF_LAYOUT_COMP(lseg, idx); | |
963 | err = ff_layout_track_ds_error(FF_LAYOUT_FROM_HDR(lseg->pls_layout), | |
964 | mirror, offset, length, status, opnum, | |
965 | GFP_NOIO); | |
966 | dprintk("%s: err %d op %d status %u\n", __func__, err, opnum, status); | |
967 | } | |
968 | ||
969 | /* NFS_PROTO call done callback routines */ | |
970 | ||
971 | static int ff_layout_read_done_cb(struct rpc_task *task, | |
972 | struct nfs_pgio_header *hdr) | |
973 | { | |
974 | struct inode *inode; | |
975 | int err; | |
976 | ||
977 | trace_nfs4_pnfs_read(hdr, task->tk_status); | |
978 | if (task->tk_status == -ETIMEDOUT && !hdr->res.op_status) | |
979 | hdr->res.op_status = NFS4ERR_NXIO; | |
980 | if (task->tk_status < 0 && hdr->res.op_status) | |
981 | ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx, | |
982 | hdr->args.offset, hdr->args.count, | |
983 | hdr->res.op_status, OP_READ); | |
984 | err = ff_layout_async_handle_error(task, hdr->args.context->state, | |
985 | hdr->ds_clp, hdr->lseg, | |
986 | hdr->pgio_mirror_idx); | |
987 | ||
988 | switch (err) { | |
989 | case -NFS4ERR_RESET_TO_PNFS: | |
990 | set_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE, | |
991 | &hdr->lseg->pls_layout->plh_flags); | |
992 | pnfs_read_resend_pnfs(hdr); | |
993 | return task->tk_status; | |
994 | case -NFS4ERR_RESET_TO_MDS: | |
995 | inode = hdr->lseg->pls_layout->plh_inode; | |
996 | pnfs_error_mark_layout_for_return(inode, hdr->lseg); | |
997 | ff_layout_reset_read(hdr); | |
998 | return task->tk_status; | |
999 | case -EAGAIN: | |
1000 | rpc_restart_call_prepare(task); | |
1001 | return -EAGAIN; | |
1002 | } | |
1003 | ||
1004 | return 0; | |
1005 | } | |
1006 | ||
1007 | /* | |
1008 | * We reference the rpc_cred of the first WRITE that triggers the need for | |
1009 | * a LAYOUTCOMMIT, and use it to send the layoutcommit compound. | |
1010 | * rfc5661 is not clear about which credential should be used. | |
1011 | * | |
1012 | * Flexlayout client should treat DS replied FILE_SYNC as DATA_SYNC, so | |
1013 | * to follow http://www.rfc-editor.org/errata_search.php?rfc=5661&eid=2751 | |
1014 | * we always send layoutcommit after DS writes. | |
1015 | */ | |
1016 | static void | |
1017 | ff_layout_set_layoutcommit(struct nfs_pgio_header *hdr) | |
1018 | { | |
67af7611 TM |
1019 | pnfs_set_layoutcommit(hdr->inode, hdr->lseg, |
1020 | hdr->mds_offset + hdr->res.count); | |
d67ae825 TH |
1021 | dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino, |
1022 | (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb); | |
1023 | } | |
1024 | ||
1025 | static bool | |
1026 | ff_layout_reset_to_mds(struct pnfs_layout_segment *lseg, int idx) | |
1027 | { | |
1028 | /* No mirroring for now */ | |
1029 | struct nfs4_deviceid_node *node = FF_LAYOUT_DEVID_NODE(lseg, idx); | |
1030 | ||
1031 | return ff_layout_test_devid_unavailable(node); | |
1032 | } | |
1033 | ||
1034 | static int ff_layout_read_prepare_common(struct rpc_task *task, | |
1035 | struct nfs_pgio_header *hdr) | |
1036 | { | |
abcb7bfc TM |
1037 | nfs4_ff_layout_stat_io_start_read( |
1038 | FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx), | |
1039 | hdr->args.count); | |
1040 | ||
d67ae825 TH |
1041 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) { |
1042 | rpc_exit(task, -EIO); | |
1043 | return -EIO; | |
1044 | } | |
1045 | if (ff_layout_reset_to_mds(hdr->lseg, hdr->pgio_mirror_idx)) { | |
1046 | dprintk("%s task %u reset io to MDS\n", __func__, task->tk_pid); | |
1047 | if (ff_layout_has_available_ds(hdr->lseg)) | |
1048 | pnfs_read_resend_pnfs(hdr); | |
1049 | else | |
1050 | ff_layout_reset_read(hdr); | |
1051 | rpc_exit(task, 0); | |
1052 | return -EAGAIN; | |
1053 | } | |
1054 | hdr->pgio_done_cb = ff_layout_read_done_cb; | |
1055 | ||
1056 | return 0; | |
1057 | } | |
1058 | ||
1059 | /* | |
1060 | * Call ops for the async read/write cases | |
1061 | * In the case of dense layouts, the offset needs to be reset to its | |
1062 | * original value. | |
1063 | */ | |
1064 | static void ff_layout_read_prepare_v3(struct rpc_task *task, void *data) | |
1065 | { | |
1066 | struct nfs_pgio_header *hdr = data; | |
1067 | ||
1068 | if (ff_layout_read_prepare_common(task, hdr)) | |
1069 | return; | |
1070 | ||
1071 | rpc_call_start(task); | |
1072 | } | |
1073 | ||
1074 | static int ff_layout_setup_sequence(struct nfs_client *ds_clp, | |
1075 | struct nfs4_sequence_args *args, | |
1076 | struct nfs4_sequence_res *res, | |
1077 | struct rpc_task *task) | |
1078 | { | |
1079 | if (ds_clp->cl_session) | |
1080 | return nfs41_setup_sequence(ds_clp->cl_session, | |
1081 | args, | |
1082 | res, | |
1083 | task); | |
1084 | return nfs40_setup_sequence(ds_clp->cl_slot_tbl, | |
1085 | args, | |
1086 | res, | |
1087 | task); | |
1088 | } | |
1089 | ||
1090 | static void ff_layout_read_prepare_v4(struct rpc_task *task, void *data) | |
1091 | { | |
1092 | struct nfs_pgio_header *hdr = data; | |
1093 | ||
d67ae825 TH |
1094 | if (ff_layout_setup_sequence(hdr->ds_clp, |
1095 | &hdr->args.seq_args, | |
1096 | &hdr->res.seq_res, | |
1097 | task)) | |
1098 | return; | |
1099 | ||
abcb7bfc TM |
1100 | if (ff_layout_read_prepare_common(task, hdr)) |
1101 | return; | |
1102 | ||
d67ae825 TH |
1103 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
1104 | hdr->args.lock_context, FMODE_READ) == -EIO) | |
1105 | rpc_exit(task, -EIO); /* lost lock, terminate I/O */ | |
1106 | } | |
1107 | ||
1108 | static void ff_layout_read_call_done(struct rpc_task *task, void *data) | |
1109 | { | |
1110 | struct nfs_pgio_header *hdr = data; | |
1111 | ||
1112 | dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status); | |
1113 | ||
abcb7bfc TM |
1114 | nfs4_ff_layout_stat_io_end_read(task, |
1115 | FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx), | |
1116 | hdr->args.count, hdr->res.count); | |
1117 | ||
d67ae825 TH |
1118 | if (test_bit(NFS_IOHDR_REDO, &hdr->flags) && |
1119 | task->tk_status == 0) { | |
1120 | nfs4_sequence_done(task, &hdr->res.seq_res); | |
1121 | return; | |
1122 | } | |
1123 | ||
1124 | /* Note this may cause RPC to be resent */ | |
1125 | hdr->mds_ops->rpc_call_done(task, hdr); | |
1126 | } | |
1127 | ||
1128 | static void ff_layout_read_count_stats(struct rpc_task *task, void *data) | |
1129 | { | |
1130 | struct nfs_pgio_header *hdr = data; | |
1131 | ||
1132 | rpc_count_iostats_metrics(task, | |
1133 | &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_READ]); | |
1134 | } | |
1135 | ||
1136 | static int ff_layout_write_done_cb(struct rpc_task *task, | |
1137 | struct nfs_pgio_header *hdr) | |
1138 | { | |
1139 | struct inode *inode; | |
1140 | int err; | |
1141 | ||
1142 | trace_nfs4_pnfs_write(hdr, task->tk_status); | |
1143 | if (task->tk_status == -ETIMEDOUT && !hdr->res.op_status) | |
1144 | hdr->res.op_status = NFS4ERR_NXIO; | |
1145 | if (task->tk_status < 0 && hdr->res.op_status) | |
1146 | ff_layout_io_track_ds_error(hdr->lseg, hdr->pgio_mirror_idx, | |
1147 | hdr->args.offset, hdr->args.count, | |
1148 | hdr->res.op_status, OP_WRITE); | |
1149 | err = ff_layout_async_handle_error(task, hdr->args.context->state, | |
1150 | hdr->ds_clp, hdr->lseg, | |
1151 | hdr->pgio_mirror_idx); | |
1152 | ||
1153 | switch (err) { | |
1154 | case -NFS4ERR_RESET_TO_PNFS: | |
1155 | case -NFS4ERR_RESET_TO_MDS: | |
1156 | inode = hdr->lseg->pls_layout->plh_inode; | |
1157 | pnfs_error_mark_layout_for_return(inode, hdr->lseg); | |
1158 | if (err == -NFS4ERR_RESET_TO_PNFS) { | |
1159 | pnfs_set_retry_layoutget(hdr->lseg->pls_layout); | |
1160 | ff_layout_reset_write(hdr, true); | |
1161 | } else { | |
1162 | pnfs_clear_retry_layoutget(hdr->lseg->pls_layout); | |
1163 | ff_layout_reset_write(hdr, false); | |
1164 | } | |
1165 | return task->tk_status; | |
1166 | case -EAGAIN: | |
1167 | rpc_restart_call_prepare(task); | |
1168 | return -EAGAIN; | |
1169 | } | |
1170 | ||
1171 | if (hdr->res.verf->committed == NFS_FILE_SYNC || | |
1172 | hdr->res.verf->committed == NFS_DATA_SYNC) | |
1173 | ff_layout_set_layoutcommit(hdr); | |
1174 | ||
1175 | return 0; | |
1176 | } | |
1177 | ||
1178 | static int ff_layout_commit_done_cb(struct rpc_task *task, | |
1179 | struct nfs_commit_data *data) | |
1180 | { | |
1181 | struct inode *inode; | |
1182 | int err; | |
1183 | ||
1184 | trace_nfs4_pnfs_commit_ds(data, task->tk_status); | |
1185 | if (task->tk_status == -ETIMEDOUT && !data->res.op_status) | |
1186 | data->res.op_status = NFS4ERR_NXIO; | |
1187 | if (task->tk_status < 0 && data->res.op_status) | |
1188 | ff_layout_io_track_ds_error(data->lseg, data->ds_commit_index, | |
1189 | data->args.offset, data->args.count, | |
1190 | data->res.op_status, OP_COMMIT); | |
1191 | err = ff_layout_async_handle_error(task, NULL, data->ds_clp, | |
1192 | data->lseg, data->ds_commit_index); | |
1193 | ||
1194 | switch (err) { | |
1195 | case -NFS4ERR_RESET_TO_PNFS: | |
1196 | case -NFS4ERR_RESET_TO_MDS: | |
1197 | inode = data->lseg->pls_layout->plh_inode; | |
1198 | pnfs_error_mark_layout_for_return(inode, data->lseg); | |
1199 | if (err == -NFS4ERR_RESET_TO_PNFS) | |
1200 | pnfs_set_retry_layoutget(data->lseg->pls_layout); | |
1201 | else | |
1202 | pnfs_clear_retry_layoutget(data->lseg->pls_layout); | |
1203 | pnfs_generic_prepare_to_resend_writes(data); | |
1204 | return -EAGAIN; | |
1205 | case -EAGAIN: | |
1206 | rpc_restart_call_prepare(task); | |
1207 | return -EAGAIN; | |
1208 | } | |
1209 | ||
1210 | if (data->verf.committed == NFS_UNSTABLE) | |
67af7611 | 1211 | pnfs_set_layoutcommit(data->inode, data->lseg, data->lwb); |
d67ae825 TH |
1212 | |
1213 | return 0; | |
1214 | } | |
1215 | ||
1216 | static int ff_layout_write_prepare_common(struct rpc_task *task, | |
1217 | struct nfs_pgio_header *hdr) | |
1218 | { | |
abcb7bfc TM |
1219 | nfs4_ff_layout_stat_io_start_write( |
1220 | FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx), | |
1221 | hdr->args.count); | |
1222 | ||
d67ae825 TH |
1223 | if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) { |
1224 | rpc_exit(task, -EIO); | |
1225 | return -EIO; | |
1226 | } | |
1227 | ||
1228 | if (ff_layout_reset_to_mds(hdr->lseg, hdr->pgio_mirror_idx)) { | |
1229 | bool retry_pnfs; | |
1230 | ||
1231 | retry_pnfs = ff_layout_has_available_ds(hdr->lseg); | |
1232 | dprintk("%s task %u reset io to %s\n", __func__, | |
1233 | task->tk_pid, retry_pnfs ? "pNFS" : "MDS"); | |
1234 | ff_layout_reset_write(hdr, retry_pnfs); | |
1235 | rpc_exit(task, 0); | |
1236 | return -EAGAIN; | |
1237 | } | |
1238 | ||
1239 | return 0; | |
1240 | } | |
1241 | ||
1242 | static void ff_layout_write_prepare_v3(struct rpc_task *task, void *data) | |
1243 | { | |
1244 | struct nfs_pgio_header *hdr = data; | |
1245 | ||
1246 | if (ff_layout_write_prepare_common(task, hdr)) | |
1247 | return; | |
1248 | ||
1249 | rpc_call_start(task); | |
1250 | } | |
1251 | ||
1252 | static void ff_layout_write_prepare_v4(struct rpc_task *task, void *data) | |
1253 | { | |
1254 | struct nfs_pgio_header *hdr = data; | |
1255 | ||
d67ae825 TH |
1256 | if (ff_layout_setup_sequence(hdr->ds_clp, |
1257 | &hdr->args.seq_args, | |
1258 | &hdr->res.seq_res, | |
1259 | task)) | |
1260 | return; | |
1261 | ||
abcb7bfc TM |
1262 | if (ff_layout_write_prepare_common(task, hdr)) |
1263 | return; | |
1264 | ||
d67ae825 TH |
1265 | if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context, |
1266 | hdr->args.lock_context, FMODE_WRITE) == -EIO) | |
1267 | rpc_exit(task, -EIO); /* lost lock, terminate I/O */ | |
1268 | } | |
1269 | ||
1270 | static void ff_layout_write_call_done(struct rpc_task *task, void *data) | |
1271 | { | |
1272 | struct nfs_pgio_header *hdr = data; | |
1273 | ||
abcb7bfc TM |
1274 | nfs4_ff_layout_stat_io_end_write(task, |
1275 | FF_LAYOUT_COMP(hdr->lseg, hdr->pgio_mirror_idx), | |
1276 | hdr->args.count, hdr->res.count, | |
1277 | hdr->res.verf->committed); | |
1278 | ||
d67ae825 TH |
1279 | if (test_bit(NFS_IOHDR_REDO, &hdr->flags) && |
1280 | task->tk_status == 0) { | |
1281 | nfs4_sequence_done(task, &hdr->res.seq_res); | |
1282 | return; | |
1283 | } | |
1284 | ||
1285 | /* Note this may cause RPC to be resent */ | |
1286 | hdr->mds_ops->rpc_call_done(task, hdr); | |
1287 | } | |
1288 | ||
1289 | static void ff_layout_write_count_stats(struct rpc_task *task, void *data) | |
1290 | { | |
1291 | struct nfs_pgio_header *hdr = data; | |
1292 | ||
1293 | rpc_count_iostats_metrics(task, | |
1294 | &NFS_CLIENT(hdr->inode)->cl_metrics[NFSPROC4_CLNT_WRITE]); | |
1295 | } | |
1296 | ||
abcb7bfc TM |
1297 | static void ff_layout_commit_prepare_common(struct rpc_task *task, |
1298 | struct nfs_commit_data *cdata) | |
1299 | { | |
1300 | nfs4_ff_layout_stat_io_start_write( | |
1301 | FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index), | |
1302 | 0); | |
1303 | } | |
1304 | ||
d67ae825 TH |
1305 | static void ff_layout_commit_prepare_v3(struct rpc_task *task, void *data) |
1306 | { | |
abcb7bfc | 1307 | ff_layout_commit_prepare_common(task, data); |
d67ae825 TH |
1308 | rpc_call_start(task); |
1309 | } | |
1310 | ||
1311 | static void ff_layout_commit_prepare_v4(struct rpc_task *task, void *data) | |
1312 | { | |
1313 | struct nfs_commit_data *wdata = data; | |
1314 | ||
abcb7bfc | 1315 | if (ff_layout_setup_sequence(wdata->ds_clp, |
d67ae825 TH |
1316 | &wdata->args.seq_args, |
1317 | &wdata->res.seq_res, | |
abcb7bfc TM |
1318 | task)) |
1319 | return; | |
1320 | ff_layout_commit_prepare_common(task, data); | |
1321 | } | |
1322 | ||
1323 | static void ff_layout_commit_done(struct rpc_task *task, void *data) | |
1324 | { | |
1325 | struct nfs_commit_data *cdata = data; | |
1326 | struct nfs_page *req; | |
1327 | __u64 count = 0; | |
1328 | ||
1329 | if (task->tk_status == 0) { | |
1330 | list_for_each_entry(req, &cdata->pages, wb_list) | |
1331 | count += req->wb_bytes; | |
1332 | } | |
1333 | ||
1334 | nfs4_ff_layout_stat_io_end_write(task, | |
1335 | FF_LAYOUT_COMP(cdata->lseg, cdata->ds_commit_index), | |
1336 | count, count, NFS_FILE_SYNC); | |
1337 | ||
1338 | pnfs_generic_write_commit_done(task, data); | |
d67ae825 TH |
1339 | } |
1340 | ||
1341 | static void ff_layout_commit_count_stats(struct rpc_task *task, void *data) | |
1342 | { | |
1343 | struct nfs_commit_data *cdata = data; | |
1344 | ||
1345 | rpc_count_iostats_metrics(task, | |
1346 | &NFS_CLIENT(cdata->inode)->cl_metrics[NFSPROC4_CLNT_COMMIT]); | |
1347 | } | |
1348 | ||
1349 | static const struct rpc_call_ops ff_layout_read_call_ops_v3 = { | |
1350 | .rpc_call_prepare = ff_layout_read_prepare_v3, | |
1351 | .rpc_call_done = ff_layout_read_call_done, | |
1352 | .rpc_count_stats = ff_layout_read_count_stats, | |
1353 | .rpc_release = pnfs_generic_rw_release, | |
1354 | }; | |
1355 | ||
1356 | static const struct rpc_call_ops ff_layout_read_call_ops_v4 = { | |
1357 | .rpc_call_prepare = ff_layout_read_prepare_v4, | |
1358 | .rpc_call_done = ff_layout_read_call_done, | |
1359 | .rpc_count_stats = ff_layout_read_count_stats, | |
1360 | .rpc_release = pnfs_generic_rw_release, | |
1361 | }; | |
1362 | ||
1363 | static const struct rpc_call_ops ff_layout_write_call_ops_v3 = { | |
1364 | .rpc_call_prepare = ff_layout_write_prepare_v3, | |
1365 | .rpc_call_done = ff_layout_write_call_done, | |
1366 | .rpc_count_stats = ff_layout_write_count_stats, | |
1367 | .rpc_release = pnfs_generic_rw_release, | |
1368 | }; | |
1369 | ||
1370 | static const struct rpc_call_ops ff_layout_write_call_ops_v4 = { | |
1371 | .rpc_call_prepare = ff_layout_write_prepare_v4, | |
1372 | .rpc_call_done = ff_layout_write_call_done, | |
1373 | .rpc_count_stats = ff_layout_write_count_stats, | |
1374 | .rpc_release = pnfs_generic_rw_release, | |
1375 | }; | |
1376 | ||
1377 | static const struct rpc_call_ops ff_layout_commit_call_ops_v3 = { | |
1378 | .rpc_call_prepare = ff_layout_commit_prepare_v3, | |
abcb7bfc | 1379 | .rpc_call_done = ff_layout_commit_done, |
d67ae825 TH |
1380 | .rpc_count_stats = ff_layout_commit_count_stats, |
1381 | .rpc_release = pnfs_generic_commit_release, | |
1382 | }; | |
1383 | ||
1384 | static const struct rpc_call_ops ff_layout_commit_call_ops_v4 = { | |
1385 | .rpc_call_prepare = ff_layout_commit_prepare_v4, | |
abcb7bfc | 1386 | .rpc_call_done = ff_layout_commit_done, |
d67ae825 TH |
1387 | .rpc_count_stats = ff_layout_commit_count_stats, |
1388 | .rpc_release = pnfs_generic_commit_release, | |
1389 | }; | |
1390 | ||
1391 | static enum pnfs_try_status | |
1392 | ff_layout_read_pagelist(struct nfs_pgio_header *hdr) | |
1393 | { | |
1394 | struct pnfs_layout_segment *lseg = hdr->lseg; | |
1395 | struct nfs4_pnfs_ds *ds; | |
1396 | struct rpc_clnt *ds_clnt; | |
1397 | struct rpc_cred *ds_cred; | |
1398 | loff_t offset = hdr->args.offset; | |
1399 | u32 idx = hdr->pgio_mirror_idx; | |
1400 | int vers; | |
1401 | struct nfs_fh *fh; | |
1402 | ||
1403 | dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n", | |
1404 | __func__, hdr->inode->i_ino, | |
1405 | hdr->args.pgbase, (size_t)hdr->args.count, offset); | |
1406 | ||
1407 | ds = nfs4_ff_layout_prepare_ds(lseg, idx, false); | |
1408 | if (!ds) | |
1409 | goto out_failed; | |
1410 | ||
1411 | ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp, | |
1412 | hdr->inode); | |
1413 | if (IS_ERR(ds_clnt)) | |
1414 | goto out_failed; | |
1415 | ||
1416 | ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred); | |
1417 | if (IS_ERR(ds_cred)) | |
1418 | goto out_failed; | |
1419 | ||
1420 | vers = nfs4_ff_layout_ds_version(lseg, idx); | |
1421 | ||
1422 | dprintk("%s USE DS: %s cl_count %d vers %d\n", __func__, | |
1423 | ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count), vers); | |
1424 | ||
1425 | atomic_inc(&ds->ds_clp->cl_count); | |
1426 | hdr->ds_clp = ds->ds_clp; | |
1427 | fh = nfs4_ff_layout_select_ds_fh(lseg, idx); | |
1428 | if (fh) | |
1429 | hdr->args.fh = fh; | |
d67ae825 TH |
1430 | /* |
1431 | * Note that if we ever decide to split across DSes, | |
1432 | * then we may need to handle dense-like offsets. | |
1433 | */ | |
1434 | hdr->args.offset = offset; | |
1435 | hdr->mds_offset = offset; | |
1436 | ||
1437 | /* Perform an asynchronous read to ds */ | |
1438 | nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, | |
1439 | vers == 3 ? &ff_layout_read_call_ops_v3 : | |
1440 | &ff_layout_read_call_ops_v4, | |
1441 | 0, RPC_TASK_SOFTCONN); | |
1442 | ||
1443 | return PNFS_ATTEMPTED; | |
1444 | ||
1445 | out_failed: | |
1446 | if (ff_layout_has_available_ds(lseg)) | |
1447 | return PNFS_TRY_AGAIN; | |
1448 | return PNFS_NOT_ATTEMPTED; | |
1449 | } | |
1450 | ||
1451 | /* Perform async writes. */ | |
1452 | static enum pnfs_try_status | |
1453 | ff_layout_write_pagelist(struct nfs_pgio_header *hdr, int sync) | |
1454 | { | |
1455 | struct pnfs_layout_segment *lseg = hdr->lseg; | |
1456 | struct nfs4_pnfs_ds *ds; | |
1457 | struct rpc_clnt *ds_clnt; | |
1458 | struct rpc_cred *ds_cred; | |
1459 | loff_t offset = hdr->args.offset; | |
1460 | int vers; | |
1461 | struct nfs_fh *fh; | |
1462 | int idx = hdr->pgio_mirror_idx; | |
1463 | ||
1464 | ds = nfs4_ff_layout_prepare_ds(lseg, idx, true); | |
1465 | if (!ds) | |
1466 | return PNFS_NOT_ATTEMPTED; | |
1467 | ||
1468 | ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp, | |
1469 | hdr->inode); | |
1470 | if (IS_ERR(ds_clnt)) | |
1471 | return PNFS_NOT_ATTEMPTED; | |
1472 | ||
1473 | ds_cred = ff_layout_get_ds_cred(lseg, idx, hdr->cred); | |
1474 | if (IS_ERR(ds_cred)) | |
1475 | return PNFS_NOT_ATTEMPTED; | |
1476 | ||
1477 | vers = nfs4_ff_layout_ds_version(lseg, idx); | |
1478 | ||
1479 | dprintk("%s ino %lu sync %d req %Zu@%llu DS: %s cl_count %d vers %d\n", | |
1480 | __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count, | |
1481 | offset, ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count), | |
1482 | vers); | |
1483 | ||
1484 | hdr->pgio_done_cb = ff_layout_write_done_cb; | |
1485 | atomic_inc(&ds->ds_clp->cl_count); | |
1486 | hdr->ds_clp = ds->ds_clp; | |
1487 | hdr->ds_commit_idx = idx; | |
1488 | fh = nfs4_ff_layout_select_ds_fh(lseg, idx); | |
1489 | if (fh) | |
1490 | hdr->args.fh = fh; | |
1491 | ||
1492 | /* | |
1493 | * Note that if we ever decide to split across DSes, | |
1494 | * then we may need to handle dense-like offsets. | |
1495 | */ | |
1496 | hdr->args.offset = offset; | |
1497 | ||
1498 | /* Perform an asynchronous write */ | |
1499 | nfs_initiate_pgio(ds_clnt, hdr, ds_cred, ds->ds_clp->rpc_ops, | |
1500 | vers == 3 ? &ff_layout_write_call_ops_v3 : | |
1501 | &ff_layout_write_call_ops_v4, | |
1502 | sync, RPC_TASK_SOFTCONN); | |
1503 | return PNFS_ATTEMPTED; | |
1504 | } | |
1505 | ||
d67ae825 TH |
1506 | static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i) |
1507 | { | |
1508 | return i; | |
1509 | } | |
1510 | ||
1511 | static struct nfs_fh * | |
1512 | select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i) | |
1513 | { | |
1514 | struct nfs4_ff_layout_segment *flseg = FF_LAYOUT_LSEG(lseg); | |
1515 | ||
1516 | /* FIXME: Assume that there is only one NFS version available | |
1517 | * for the DS. | |
1518 | */ | |
1519 | return &flseg->mirror_array[i]->fh_versions[0]; | |
1520 | } | |
1521 | ||
1522 | static int ff_layout_initiate_commit(struct nfs_commit_data *data, int how) | |
1523 | { | |
1524 | struct pnfs_layout_segment *lseg = data->lseg; | |
1525 | struct nfs4_pnfs_ds *ds; | |
1526 | struct rpc_clnt *ds_clnt; | |
1527 | struct rpc_cred *ds_cred; | |
1528 | u32 idx; | |
1529 | int vers; | |
1530 | struct nfs_fh *fh; | |
1531 | ||
1532 | idx = calc_ds_index_from_commit(lseg, data->ds_commit_index); | |
1533 | ds = nfs4_ff_layout_prepare_ds(lseg, idx, true); | |
1534 | if (!ds) | |
1535 | goto out_err; | |
1536 | ||
1537 | ds_clnt = nfs4_ff_find_or_create_ds_client(lseg, idx, ds->ds_clp, | |
1538 | data->inode); | |
1539 | if (IS_ERR(ds_clnt)) | |
1540 | goto out_err; | |
1541 | ||
1542 | ds_cred = ff_layout_get_ds_cred(lseg, idx, data->cred); | |
1543 | if (IS_ERR(ds_cred)) | |
1544 | goto out_err; | |
1545 | ||
1546 | vers = nfs4_ff_layout_ds_version(lseg, idx); | |
1547 | ||
1548 | dprintk("%s ino %lu, how %d cl_count %d vers %d\n", __func__, | |
1549 | data->inode->i_ino, how, atomic_read(&ds->ds_clp->cl_count), | |
1550 | vers); | |
1551 | data->commit_done_cb = ff_layout_commit_done_cb; | |
1552 | data->cred = ds_cred; | |
1553 | atomic_inc(&ds->ds_clp->cl_count); | |
1554 | data->ds_clp = ds->ds_clp; | |
1555 | fh = select_ds_fh_from_commit(lseg, data->ds_commit_index); | |
1556 | if (fh) | |
1557 | data->args.fh = fh; | |
abcb7bfc | 1558 | |
d67ae825 TH |
1559 | return nfs_initiate_commit(ds_clnt, data, ds->ds_clp->rpc_ops, |
1560 | vers == 3 ? &ff_layout_commit_call_ops_v3 : | |
1561 | &ff_layout_commit_call_ops_v4, | |
1562 | how, RPC_TASK_SOFTCONN); | |
1563 | out_err: | |
1564 | pnfs_generic_prepare_to_resend_writes(data); | |
1565 | pnfs_generic_commit_release(data); | |
1566 | return -EAGAIN; | |
1567 | } | |
1568 | ||
1569 | static int | |
1570 | ff_layout_commit_pagelist(struct inode *inode, struct list_head *mds_pages, | |
1571 | int how, struct nfs_commit_info *cinfo) | |
1572 | { | |
1573 | return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo, | |
1574 | ff_layout_initiate_commit); | |
1575 | } | |
1576 | ||
1577 | static struct pnfs_ds_commit_info * | |
1578 | ff_layout_get_ds_info(struct inode *inode) | |
1579 | { | |
1580 | struct pnfs_layout_hdr *layout = NFS_I(inode)->layout; | |
1581 | ||
1582 | if (layout == NULL) | |
1583 | return NULL; | |
1584 | ||
1585 | return &FF_LAYOUT_FROM_HDR(layout)->commit_info; | |
1586 | } | |
1587 | ||
1588 | static void | |
fc87701b | 1589 | ff_layout_free_deviceid_node(struct nfs4_deviceid_node *d) |
d67ae825 TH |
1590 | { |
1591 | nfs4_ff_layout_free_deviceid(container_of(d, struct nfs4_ff_layout_ds, | |
1592 | id_node)); | |
1593 | } | |
1594 | ||
1595 | static int ff_layout_encode_ioerr(struct nfs4_flexfile_layout *flo, | |
1596 | struct xdr_stream *xdr, | |
1597 | const struct nfs4_layoutreturn_args *args) | |
1598 | { | |
1599 | struct pnfs_layout_hdr *hdr = &flo->generic_hdr; | |
1600 | __be32 *start; | |
1601 | int count = 0, ret = 0; | |
1602 | ||
1603 | start = xdr_reserve_space(xdr, 4); | |
1604 | if (unlikely(!start)) | |
1605 | return -E2BIG; | |
1606 | ||
1607 | /* This assume we always return _ALL_ layouts */ | |
1608 | spin_lock(&hdr->plh_inode->i_lock); | |
1609 | ret = ff_layout_encode_ds_ioerr(flo, xdr, &count, &args->range); | |
1610 | spin_unlock(&hdr->plh_inode->i_lock); | |
1611 | ||
1612 | *start = cpu_to_be32(count); | |
1613 | ||
1614 | return ret; | |
1615 | } | |
1616 | ||
1617 | /* report nothing for now */ | |
1618 | static void ff_layout_encode_iostats(struct nfs4_flexfile_layout *flo, | |
1619 | struct xdr_stream *xdr, | |
1620 | const struct nfs4_layoutreturn_args *args) | |
1621 | { | |
1622 | __be32 *p; | |
1623 | ||
1624 | p = xdr_reserve_space(xdr, 4); | |
1625 | if (likely(p)) | |
1626 | *p = cpu_to_be32(0); | |
1627 | } | |
1628 | ||
1629 | static struct nfs4_deviceid_node * | |
1630 | ff_layout_alloc_deviceid_node(struct nfs_server *server, | |
1631 | struct pnfs_device *pdev, gfp_t gfp_flags) | |
1632 | { | |
1633 | struct nfs4_ff_layout_ds *dsaddr; | |
1634 | ||
1635 | dsaddr = nfs4_ff_alloc_deviceid_node(server, pdev, gfp_flags); | |
1636 | if (!dsaddr) | |
1637 | return NULL; | |
1638 | return &dsaddr->id_node; | |
1639 | } | |
1640 | ||
1641 | static void | |
1642 | ff_layout_encode_layoutreturn(struct pnfs_layout_hdr *lo, | |
1643 | struct xdr_stream *xdr, | |
1644 | const struct nfs4_layoutreturn_args *args) | |
1645 | { | |
1646 | struct nfs4_flexfile_layout *flo = FF_LAYOUT_FROM_HDR(lo); | |
1647 | __be32 *start; | |
1648 | ||
1649 | dprintk("%s: Begin\n", __func__); | |
1650 | start = xdr_reserve_space(xdr, 4); | |
1651 | BUG_ON(!start); | |
1652 | ||
1653 | if (ff_layout_encode_ioerr(flo, xdr, args)) | |
1654 | goto out; | |
1655 | ||
1656 | ff_layout_encode_iostats(flo, xdr, args); | |
1657 | out: | |
1658 | *start = cpu_to_be32((xdr->p - start - 1) * 4); | |
1659 | dprintk("%s: Return\n", __func__); | |
1660 | } | |
1661 | ||
1662 | static struct pnfs_layoutdriver_type flexfilelayout_type = { | |
1663 | .id = LAYOUT_FLEX_FILES, | |
1664 | .name = "LAYOUT_FLEX_FILES", | |
1665 | .owner = THIS_MODULE, | |
1666 | .alloc_layout_hdr = ff_layout_alloc_layout_hdr, | |
1667 | .free_layout_hdr = ff_layout_free_layout_hdr, | |
1668 | .alloc_lseg = ff_layout_alloc_lseg, | |
1669 | .free_lseg = ff_layout_free_lseg, | |
1670 | .pg_read_ops = &ff_layout_pg_read_ops, | |
1671 | .pg_write_ops = &ff_layout_pg_write_ops, | |
1672 | .get_ds_info = ff_layout_get_ds_info, | |
fc87701b | 1673 | .free_deviceid_node = ff_layout_free_deviceid_node, |
338d00cf | 1674 | .mark_request_commit = pnfs_layout_mark_request_commit, |
d67ae825 TH |
1675 | .clear_request_commit = pnfs_generic_clear_request_commit, |
1676 | .scan_commit_lists = pnfs_generic_scan_commit_lists, | |
1677 | .recover_commit_reqs = pnfs_generic_recover_commit_reqs, | |
1678 | .commit_pagelist = ff_layout_commit_pagelist, | |
1679 | .read_pagelist = ff_layout_read_pagelist, | |
1680 | .write_pagelist = ff_layout_write_pagelist, | |
1681 | .alloc_deviceid_node = ff_layout_alloc_deviceid_node, | |
1682 | .encode_layoutreturn = ff_layout_encode_layoutreturn, | |
5bb89b47 | 1683 | .sync = pnfs_nfs_generic_sync, |
d67ae825 TH |
1684 | }; |
1685 | ||
1686 | static int __init nfs4flexfilelayout_init(void) | |
1687 | { | |
1688 | printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Registering...\n", | |
1689 | __func__); | |
1690 | return pnfs_register_layoutdriver(&flexfilelayout_type); | |
1691 | } | |
1692 | ||
1693 | static void __exit nfs4flexfilelayout_exit(void) | |
1694 | { | |
1695 | printk(KERN_INFO "%s: NFSv4 Flexfile Layout Driver Unregistering...\n", | |
1696 | __func__); | |
1697 | pnfs_unregister_layoutdriver(&flexfilelayout_type); | |
1698 | } | |
1699 | ||
1700 | MODULE_ALIAS("nfs-layouttype4-4"); | |
1701 | ||
1702 | MODULE_LICENSE("GPL"); | |
1703 | MODULE_DESCRIPTION("The NFSv4 flexfile layout driver"); | |
1704 | ||
1705 | module_init(nfs4flexfilelayout_init); | |
1706 | module_exit(nfs4flexfilelayout_exit); |