~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/nfs/filelayout/filelayout.c

Version: ~ [ linux-5.15-rc5 ] ~ [ linux-5.14.11 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.72 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.152 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.210 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.250 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.286 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.288 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  Module for the pnfs nfs4 file layout driver.
  3  *  Defines all I/O and Policy interface operations, plus code
  4  *  to register itself with the pNFS client.
  5  *
  6  *  Copyright (c) 2002
  7  *  The Regents of the University of Michigan
  8  *  All Rights Reserved
  9  *
 10  *  Dean Hildebrand <dhildebz@umich.edu>
 11  *
 12  *  Permission is granted to use, copy, create derivative works, and
 13  *  redistribute this software and such derivative works for any purpose,
 14  *  so long as the name of the University of Michigan is not used in
 15  *  any advertising or publicity pertaining to the use or distribution
 16  *  of this software without specific, written prior authorization. If
 17  *  the above copyright notice or any other identification of the
 18  *  University of Michigan is included in any copy of any portion of
 19  *  this software, then the disclaimer below must also be included.
 20  *
 21  *  This software is provided as is, without representation or warranty
 22  *  of any kind either express or implied, including without limitation
 23  *  the implied warranties of merchantability, fitness for a particular
 24  *  purpose, or noninfringement.  The Regents of the University of
 25  *  Michigan shall not be liable for any damages, including special,
 26  *  indirect, incidental, or consequential damages, with respect to any
 27  *  claim arising out of or in connection with the use of the software,
 28  *  even if it has been or is hereafter advised of the possibility of
 29  *  such damages.
 30  */
 31 
 32 #include <linux/nfs_fs.h>
 33 #include <linux/nfs_page.h>
 34 #include <linux/module.h>
 35 #include <linux/backing-dev.h>
 36 
 37 #include <linux/sunrpc/metrics.h>
 38 
 39 #include "../nfs4session.h"
 40 #include "../internal.h"
 41 #include "../delegation.h"
 42 #include "filelayout.h"
 43 #include "../nfs4trace.h"
 44 
 45 #define NFSDBG_FACILITY         NFSDBG_PNFS_LD
 46 
 47 MODULE_LICENSE("GPL");
 48 MODULE_AUTHOR("Dean Hildebrand <dhildebz@umich.edu>");
 49 MODULE_DESCRIPTION("The NFSv4 file layout driver");
 50 
 51 #define FILELAYOUT_POLL_RETRY_MAX     (15*HZ)
 52 
 53 static loff_t
 54 filelayout_get_dense_offset(struct nfs4_filelayout_segment *flseg,
 55                             loff_t offset)
 56 {
 57         u32 stripe_width = flseg->stripe_unit * flseg->dsaddr->stripe_count;
 58         u64 stripe_no;
 59         u32 rem;
 60 
 61         offset -= flseg->pattern_offset;
 62         stripe_no = div_u64(offset, stripe_width);
 63         div_u64_rem(offset, flseg->stripe_unit, &rem);
 64 
 65         return stripe_no * flseg->stripe_unit + rem;
 66 }
 67 
 68 /* This function is used by the layout driver to calculate the
 69  * offset of the file on the dserver based on whether the
 70  * layout type is STRIPE_DENSE or STRIPE_SPARSE
 71  */
 72 static loff_t
 73 filelayout_get_dserver_offset(struct pnfs_layout_segment *lseg, loff_t offset)
 74 {
 75         struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
 76 
 77         switch (flseg->stripe_type) {
 78         case STRIPE_SPARSE:
 79                 return offset;
 80 
 81         case STRIPE_DENSE:
 82                 return filelayout_get_dense_offset(flseg, offset);
 83         }
 84 
 85         BUG();
 86 }
 87 
 88 static void filelayout_reset_write(struct nfs_pgio_header *hdr)
 89 {
 90         struct rpc_task *task = &hdr->task;
 91 
 92         if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
 93                 dprintk("%s Reset task %5u for i/o through MDS "
 94                         "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
 95                         hdr->task.tk_pid,
 96                         hdr->inode->i_sb->s_id,
 97                         (unsigned long long)NFS_FILEID(hdr->inode),
 98                         hdr->args.count,
 99                         (unsigned long long)hdr->args.offset);
100 
101                 task->tk_status = pnfs_write_done_resend_to_mds(hdr);
102         }
103 }
104 
105 static void filelayout_reset_read(struct nfs_pgio_header *hdr)
106 {
107         struct rpc_task *task = &hdr->task;
108 
109         if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
110                 dprintk("%s Reset task %5u for i/o through MDS "
111                         "(req %s/%llu, %u bytes @ offset %llu)\n", __func__,
112                         hdr->task.tk_pid,
113                         hdr->inode->i_sb->s_id,
114                         (unsigned long long)NFS_FILEID(hdr->inode),
115                         hdr->args.count,
116                         (unsigned long long)hdr->args.offset);
117 
118                 task->tk_status = pnfs_read_done_resend_to_mds(hdr);
119         }
120 }
121 
122 static int filelayout_async_handle_error(struct rpc_task *task,
123                                          struct nfs4_state *state,
124                                          struct nfs_client *clp,
125                                          struct pnfs_layout_segment *lseg)
126 {
127         struct pnfs_layout_hdr *lo = lseg->pls_layout;
128         struct inode *inode = lo->plh_inode;
129         struct nfs_server *mds_server = NFS_SERVER(inode);
130         struct nfs4_deviceid_node *devid = FILELAYOUT_DEVID_NODE(lseg);
131         struct nfs_client *mds_client = mds_server->nfs_client;
132         struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table;
133 
134         if (task->tk_status >= 0)
135                 return 0;
136 
137         switch (task->tk_status) {
138         /* MDS state errors */
139         case -NFS4ERR_DELEG_REVOKED:
140         case -NFS4ERR_ADMIN_REVOKED:
141         case -NFS4ERR_BAD_STATEID:
142         case -NFS4ERR_OPENMODE:
143                 if (state == NULL)
144                         break;
145                 if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
146                         goto out_bad_stateid;
147                 goto wait_on_recovery;
148         case -NFS4ERR_EXPIRED:
149                 if (state != NULL) {
150                         if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
151                                 goto out_bad_stateid;
152                 }
153                 nfs4_schedule_lease_recovery(mds_client);
154                 goto wait_on_recovery;
155         /* DS session errors */
156         case -NFS4ERR_BADSESSION:
157         case -NFS4ERR_BADSLOT:
158         case -NFS4ERR_BAD_HIGH_SLOT:
159         case -NFS4ERR_DEADSESSION:
160         case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
161         case -NFS4ERR_SEQ_FALSE_RETRY:
162         case -NFS4ERR_SEQ_MISORDERED:
163                 dprintk("%s ERROR %d, Reset session. Exchangeid "
164                         "flags 0x%x\n", __func__, task->tk_status,
165                         clp->cl_exchange_flags);
166                 nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
167                 break;
168         case -NFS4ERR_DELAY:
169         case -NFS4ERR_GRACE:
170                 rpc_delay(task, FILELAYOUT_POLL_RETRY_MAX);
171                 break;
172         case -NFS4ERR_RETRY_UNCACHED_REP:
173                 break;
174         /* Invalidate Layout errors */
175         case -NFS4ERR_ACCESS:
176         case -NFS4ERR_PNFS_NO_LAYOUT:
177         case -ESTALE:           /* mapped NFS4ERR_STALE */
178         case -EBADHANDLE:       /* mapped NFS4ERR_BADHANDLE */
179         case -EISDIR:           /* mapped NFS4ERR_ISDIR */
180         case -NFS4ERR_FHEXPIRED:
181         case -NFS4ERR_WRONG_TYPE:
182                 dprintk("%s Invalid layout error %d\n", __func__,
183                         task->tk_status);
184                 /*
185                  * Destroy layout so new i/o will get a new layout.
186                  * Layout will not be destroyed until all current lseg
187                  * references are put. Mark layout as invalid to resend failed
188                  * i/o and all i/o waiting on the slot table to the MDS until
189                  * layout is destroyed and a new valid layout is obtained.
190                  */
191                 pnfs_destroy_layout(NFS_I(inode));
192                 rpc_wake_up(&tbl->slot_tbl_waitq);
193                 goto reset;
194         /* RPC connection errors */
195         case -ECONNREFUSED:
196         case -EHOSTDOWN:
197         case -EHOSTUNREACH:
198         case -ENETUNREACH:
199         case -EIO:
200         case -ETIMEDOUT:
201         case -EPIPE:
202                 dprintk("%s DS connection error %d\n", __func__,
203                         task->tk_status);
204                 nfs4_mark_deviceid_unavailable(devid);
205                 pnfs_error_mark_layout_for_return(inode, lseg);
206                 pnfs_set_lo_fail(lseg);
207                 rpc_wake_up(&tbl->slot_tbl_waitq);
208                 /* fall through */
209         default:
210 reset:
211                 dprintk("%s Retry through MDS. Error %d\n", __func__,
212                         task->tk_status);
213                 return -NFS4ERR_RESET_TO_MDS;
214         }
215 out:
216         task->tk_status = 0;
217         return -EAGAIN;
218 out_bad_stateid:
219         task->tk_status = -EIO;
220         return 0;
221 wait_on_recovery:
222         rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
223         if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
224                 rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task);
225         goto out;
226 }
227 
228 /* NFS_PROTO call done callback routines */
229 
230 static int filelayout_read_done_cb(struct rpc_task *task,
231                                 struct nfs_pgio_header *hdr)
232 {
233         int err;
234 
235         trace_nfs4_pnfs_read(hdr, task->tk_status);
236         err = filelayout_async_handle_error(task, hdr->args.context->state,
237                                             hdr->ds_clp, hdr->lseg);
238 
239         switch (err) {
240         case -NFS4ERR_RESET_TO_MDS:
241                 filelayout_reset_read(hdr);
242                 return task->tk_status;
243         case -EAGAIN:
244                 rpc_restart_call_prepare(task);
245                 return -EAGAIN;
246         }
247 
248         return 0;
249 }
250 
251 /*
252  * We reference the rpc_cred of the first WRITE that triggers the need for
253  * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
254  * rfc5661 is not clear about which credential should be used.
255  */
256 static void
257 filelayout_set_layoutcommit(struct nfs_pgio_header *hdr)
258 {
259         loff_t end_offs = 0;
260 
261         if (FILELAYOUT_LSEG(hdr->lseg)->commit_through_mds ||
262             hdr->res.verf->committed == NFS_FILE_SYNC)
263                 return;
264         if (hdr->res.verf->committed == NFS_DATA_SYNC)
265                 end_offs = hdr->mds_offset + (loff_t)hdr->res.count;
266 
267         /* Note: if the write is unstable, don't set end_offs until commit */
268         pnfs_set_layoutcommit(hdr->inode, hdr->lseg, end_offs);
269         dprintk("%s inode %lu pls_end_pos %lu\n", __func__, hdr->inode->i_ino,
270                 (unsigned long) NFS_I(hdr->inode)->layout->plh_lwb);
271 }
272 
273 bool
274 filelayout_test_devid_unavailable(struct nfs4_deviceid_node *node)
275 {
276         return filelayout_test_devid_invalid(node) ||
277                 nfs4_test_deviceid_unavailable(node);
278 }
279 
280 static bool
281 filelayout_reset_to_mds(struct pnfs_layout_segment *lseg)
282 {
283         struct nfs4_deviceid_node *node = FILELAYOUT_DEVID_NODE(lseg);
284 
285         return filelayout_test_devid_unavailable(node);
286 }
287 
288 /*
289  * Call ops for the async read/write cases
290  * In the case of dense layouts, the offset needs to be reset to its
291  * original value.
292  */
293 static void filelayout_read_prepare(struct rpc_task *task, void *data)
294 {
295         struct nfs_pgio_header *hdr = data;
296 
297         if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
298                 rpc_exit(task, -EIO);
299                 return;
300         }
301         if (filelayout_reset_to_mds(hdr->lseg)) {
302                 dprintk("%s task %u reset io to MDS\n", __func__, task->tk_pid);
303                 filelayout_reset_read(hdr);
304                 rpc_exit(task, 0);
305                 return;
306         }
307         hdr->pgio_done_cb = filelayout_read_done_cb;
308 
309         if (nfs4_setup_sequence(hdr->ds_clp,
310                         &hdr->args.seq_args,
311                         &hdr->res.seq_res,
312                         task))
313                 return;
314         if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
315                         hdr->args.lock_context, FMODE_READ) == -EIO)
316                 rpc_exit(task, -EIO); /* lost lock, terminate I/O */
317 }
318 
319 static void filelayout_read_call_done(struct rpc_task *task, void *data)
320 {
321         struct nfs_pgio_header *hdr = data;
322 
323         dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
324 
325         if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
326             task->tk_status == 0) {
327                 nfs41_sequence_done(task, &hdr->res.seq_res);
328                 return;
329         }
330 
331         /* Note this may cause RPC to be resent */
332         hdr->mds_ops->rpc_call_done(task, data);
333 }
334 
335 static void filelayout_read_count_stats(struct rpc_task *task, void *data)
336 {
337         struct nfs_pgio_header *hdr = data;
338 
339         rpc_count_iostats(task, NFS_SERVER(hdr->inode)->client->cl_metrics);
340 }
341 
342 static int filelayout_write_done_cb(struct rpc_task *task,
343                                 struct nfs_pgio_header *hdr)
344 {
345         int err;
346 
347         trace_nfs4_pnfs_write(hdr, task->tk_status);
348         err = filelayout_async_handle_error(task, hdr->args.context->state,
349                                             hdr->ds_clp, hdr->lseg);
350 
351         switch (err) {
352         case -NFS4ERR_RESET_TO_MDS:
353                 filelayout_reset_write(hdr);
354                 return task->tk_status;
355         case -EAGAIN:
356                 rpc_restart_call_prepare(task);
357                 return -EAGAIN;
358         }
359 
360         filelayout_set_layoutcommit(hdr);
361 
362         /* zero out the fattr */
363         hdr->fattr.valid = 0;
364         if (task->tk_status >= 0)
365                 nfs_writeback_update_inode(hdr);
366 
367         return 0;
368 }
369 
370 static int filelayout_commit_done_cb(struct rpc_task *task,
371                                      struct nfs_commit_data *data)
372 {
373         int err;
374 
375         trace_nfs4_pnfs_commit_ds(data, task->tk_status);
376         err = filelayout_async_handle_error(task, NULL, data->ds_clp,
377                                             data->lseg);
378 
379         switch (err) {
380         case -NFS4ERR_RESET_TO_MDS:
381                 pnfs_generic_prepare_to_resend_writes(data);
382                 return -EAGAIN;
383         case -EAGAIN:
384                 rpc_restart_call_prepare(task);
385                 return -EAGAIN;
386         }
387 
388         pnfs_set_layoutcommit(data->inode, data->lseg, data->lwb);
389 
390         return 0;
391 }
392 
393 static void filelayout_write_prepare(struct rpc_task *task, void *data)
394 {
395         struct nfs_pgio_header *hdr = data;
396 
397         if (unlikely(test_bit(NFS_CONTEXT_BAD, &hdr->args.context->flags))) {
398                 rpc_exit(task, -EIO);
399                 return;
400         }
401         if (filelayout_reset_to_mds(hdr->lseg)) {
402                 dprintk("%s task %u reset io to MDS\n", __func__, task->tk_pid);
403                 filelayout_reset_write(hdr);
404                 rpc_exit(task, 0);
405                 return;
406         }
407         if (nfs4_setup_sequence(hdr->ds_clp,
408                         &hdr->args.seq_args,
409                         &hdr->res.seq_res,
410                         task))
411                 return;
412         if (nfs4_set_rw_stateid(&hdr->args.stateid, hdr->args.context,
413                         hdr->args.lock_context, FMODE_WRITE) == -EIO)
414                 rpc_exit(task, -EIO); /* lost lock, terminate I/O */
415 }
416 
417 static void filelayout_write_call_done(struct rpc_task *task, void *data)
418 {
419         struct nfs_pgio_header *hdr = data;
420 
421         if (test_bit(NFS_IOHDR_REDO, &hdr->flags) &&
422             task->tk_status == 0) {
423                 nfs41_sequence_done(task, &hdr->res.seq_res);
424                 return;
425         }
426 
427         /* Note this may cause RPC to be resent */
428         hdr->mds_ops->rpc_call_done(task, data);
429 }
430 
431 static void filelayout_write_count_stats(struct rpc_task *task, void *data)
432 {
433         struct nfs_pgio_header *hdr = data;
434 
435         rpc_count_iostats(task, NFS_SERVER(hdr->inode)->client->cl_metrics);
436 }
437 
438 static void filelayout_commit_prepare(struct rpc_task *task, void *data)
439 {
440         struct nfs_commit_data *wdata = data;
441 
442         nfs4_setup_sequence(wdata->ds_clp,
443                         &wdata->args.seq_args,
444                         &wdata->res.seq_res,
445                         task);
446 }
447 
448 static void filelayout_commit_count_stats(struct rpc_task *task, void *data)
449 {
450         struct nfs_commit_data *cdata = data;
451 
452         rpc_count_iostats(task, NFS_SERVER(cdata->inode)->client->cl_metrics);
453 }
454 
455 static const struct rpc_call_ops filelayout_read_call_ops = {
456         .rpc_call_prepare = filelayout_read_prepare,
457         .rpc_call_done = filelayout_read_call_done,
458         .rpc_count_stats = filelayout_read_count_stats,
459         .rpc_release = pnfs_generic_rw_release,
460 };
461 
462 static const struct rpc_call_ops filelayout_write_call_ops = {
463         .rpc_call_prepare = filelayout_write_prepare,
464         .rpc_call_done = filelayout_write_call_done,
465         .rpc_count_stats = filelayout_write_count_stats,
466         .rpc_release = pnfs_generic_rw_release,
467 };
468 
469 static const struct rpc_call_ops filelayout_commit_call_ops = {
470         .rpc_call_prepare = filelayout_commit_prepare,
471         .rpc_call_done = pnfs_generic_write_commit_done,
472         .rpc_count_stats = filelayout_commit_count_stats,
473         .rpc_release = pnfs_generic_commit_release,
474 };
475 
476 static enum pnfs_try_status
477 filelayout_read_pagelist(struct nfs_pgio_header *hdr)
478 {
479         struct pnfs_layout_segment *lseg = hdr->lseg;
480         struct nfs4_pnfs_ds *ds;
481         struct rpc_clnt *ds_clnt;
482         loff_t offset = hdr->args.offset;
483         u32 j, idx;
484         struct nfs_fh *fh;
485 
486         dprintk("--> %s ino %lu pgbase %u req %zu@%llu\n",
487                 __func__, hdr->inode->i_ino,
488                 hdr->args.pgbase, (size_t)hdr->args.count, offset);
489 
490         /* Retrieve the correct rpc_client for the byte range */
491         j = nfs4_fl_calc_j_index(lseg, offset);
492         idx = nfs4_fl_calc_ds_index(lseg, j);
493         ds = nfs4_fl_prepare_ds(lseg, idx);
494         if (!ds)
495                 return PNFS_NOT_ATTEMPTED;
496 
497         ds_clnt = nfs4_find_or_create_ds_client(ds->ds_clp, hdr->inode);
498         if (IS_ERR(ds_clnt))
499                 return PNFS_NOT_ATTEMPTED;
500 
501         dprintk("%s USE DS: %s cl_count %d\n", __func__,
502                 ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count));
503 
504         /* No multipath support. Use first DS */
505         atomic_inc(&ds->ds_clp->cl_count);
506         hdr->ds_clp = ds->ds_clp;
507         hdr->ds_commit_idx = idx;
508         fh = nfs4_fl_select_ds_fh(lseg, j);
509         if (fh)
510                 hdr->args.fh = fh;
511 
512         hdr->args.offset = filelayout_get_dserver_offset(lseg, offset);
513         hdr->mds_offset = offset;
514 
515         /* Perform an asynchronous read to ds */
516         nfs_initiate_pgio(ds_clnt, hdr, hdr->cred,
517                           NFS_PROTO(hdr->inode), &filelayout_read_call_ops,
518                           0, RPC_TASK_SOFTCONN);
519         return PNFS_ATTEMPTED;
520 }
521 
522 /* Perform async writes. */
523 static enum pnfs_try_status
524 filelayout_write_pagelist(struct nfs_pgio_header *hdr, int sync)
525 {
526         struct pnfs_layout_segment *lseg = hdr->lseg;
527         struct nfs4_pnfs_ds *ds;
528         struct rpc_clnt *ds_clnt;
529         loff_t offset = hdr->args.offset;
530         u32 j, idx;
531         struct nfs_fh *fh;
532 
533         /* Retrieve the correct rpc_client for the byte range */
534         j = nfs4_fl_calc_j_index(lseg, offset);
535         idx = nfs4_fl_calc_ds_index(lseg, j);
536         ds = nfs4_fl_prepare_ds(lseg, idx);
537         if (!ds)
538                 return PNFS_NOT_ATTEMPTED;
539 
540         ds_clnt = nfs4_find_or_create_ds_client(ds->ds_clp, hdr->inode);
541         if (IS_ERR(ds_clnt))
542                 return PNFS_NOT_ATTEMPTED;
543 
544         dprintk("%s ino %lu sync %d req %zu@%llu DS: %s cl_count %d\n",
545                 __func__, hdr->inode->i_ino, sync, (size_t) hdr->args.count,
546                 offset, ds->ds_remotestr, atomic_read(&ds->ds_clp->cl_count));
547 
548         hdr->pgio_done_cb = filelayout_write_done_cb;
549         atomic_inc(&ds->ds_clp->cl_count);
550         hdr->ds_clp = ds->ds_clp;
551         hdr->ds_commit_idx = idx;
552         fh = nfs4_fl_select_ds_fh(lseg, j);
553         if (fh)
554                 hdr->args.fh = fh;
555         hdr->args.offset = filelayout_get_dserver_offset(lseg, offset);
556 
557         /* Perform an asynchronous write */
558         nfs_initiate_pgio(ds_clnt, hdr, hdr->cred,
559                           NFS_PROTO(hdr->inode), &filelayout_write_call_ops,
560                           sync, RPC_TASK_SOFTCONN);
561         return PNFS_ATTEMPTED;
562 }
563 
564 static int
565 filelayout_check_deviceid(struct pnfs_layout_hdr *lo,
566                           struct nfs4_filelayout_segment *fl,
567                           gfp_t gfp_flags)
568 {
569         struct nfs4_deviceid_node *d;
570         struct nfs4_file_layout_dsaddr *dsaddr;
571         int status = -EINVAL;
572 
573         /* find and reference the deviceid */
574         d = nfs4_find_get_deviceid(NFS_SERVER(lo->plh_inode), &fl->deviceid,
575                         lo->plh_lc_cred, gfp_flags);
576         if (d == NULL)
577                 goto out;
578 
579         dsaddr = container_of(d, struct nfs4_file_layout_dsaddr, id_node);
580         /* Found deviceid is unavailable */
581         if (filelayout_test_devid_unavailable(&dsaddr->id_node))
582                 goto out_put;
583 
584         fl->dsaddr = dsaddr;
585 
586         if (fl->first_stripe_index >= dsaddr->stripe_count) {
587                 dprintk("%s Bad first_stripe_index %u\n",
588                                 __func__, fl->first_stripe_index);
589                 goto out_put;
590         }
591 
592         if ((fl->stripe_type == STRIPE_SPARSE &&
593             fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) ||
594             (fl->stripe_type == STRIPE_DENSE &&
595             fl->num_fh != dsaddr->stripe_count)) {
596                 dprintk("%s num_fh %u not valid for given packing\n",
597                         __func__, fl->num_fh);
598                 goto out_put;
599         }
600         status = 0;
601 out:
602         return status;
603 out_put:
604         nfs4_fl_put_deviceid(dsaddr);
605         goto out;
606 }
607 
608 /*
609  * filelayout_check_layout()
610  *
611  * Make sure layout segment parameters are sane WRT the device.
612  * At this point no generic layer initialization of the lseg has occurred,
613  * and nothing has been added to the layout_hdr cache.
614  *
615  */
616 static int
617 filelayout_check_layout(struct pnfs_layout_hdr *lo,
618                         struct nfs4_filelayout_segment *fl,
619                         struct nfs4_layoutget_res *lgr,
620                         gfp_t gfp_flags)
621 {
622         int status = -EINVAL;
623 
624         dprintk("--> %s\n", __func__);
625 
626         /* FIXME: remove this check when layout segment support is added */
627         if (lgr->range.offset != 0 ||
628             lgr->range.length != NFS4_MAX_UINT64) {
629                 dprintk("%s Only whole file layouts supported. Use MDS i/o\n",
630                         __func__);
631                 goto out;
632         }
633 
634         if (fl->pattern_offset > lgr->range.offset) {
635                 dprintk("%s pattern_offset %lld too large\n",
636                                 __func__, fl->pattern_offset);
637                 goto out;
638         }
639 
640         if (!fl->stripe_unit) {
641                 dprintk("%s Invalid stripe unit (%u)\n",
642                         __func__, fl->stripe_unit);
643                 goto out;
644         }
645 
646         status = 0;
647 out:
648         dprintk("--> %s returns %d\n", __func__, status);
649         return status;
650 }
651 
652 static void _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
653 {
654         int i;
655 
656         if (fl->fh_array) {
657                 for (i = 0; i < fl->num_fh; i++) {
658                         if (!fl->fh_array[i])
659                                 break;
660                         kfree(fl->fh_array[i]);
661                 }
662                 kfree(fl->fh_array);
663         }
664         kfree(fl);
665 }
666 
667 static int
668 filelayout_decode_layout(struct pnfs_layout_hdr *flo,
669                          struct nfs4_filelayout_segment *fl,
670                          struct nfs4_layoutget_res *lgr,
671                          gfp_t gfp_flags)
672 {
673         struct xdr_stream stream;
674         struct xdr_buf buf;
675         struct page *scratch;
676         __be32 *p;
677         uint32_t nfl_util;
678         int i;
679 
680         dprintk("%s: set_layout_map Begin\n", __func__);
681 
682         scratch = alloc_page(gfp_flags);
683         if (!scratch)
684                 return -ENOMEM;
685 
686         xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len);
687         xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
688 
689         /* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8),
690          * num_fh (4) */
691         p = xdr_inline_decode(&stream, NFS4_DEVICEID4_SIZE + 20);
692         if (unlikely(!p))
693                 goto out_err;
694 
695         memcpy(&fl->deviceid, p, sizeof(fl->deviceid));
696         p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
697         nfs4_print_deviceid(&fl->deviceid);
698 
699         nfl_util = be32_to_cpup(p++);
700         if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS)
701                 fl->commit_through_mds = 1;
702         if (nfl_util & NFL4_UFLG_DENSE)
703                 fl->stripe_type = STRIPE_DENSE;
704         else
705                 fl->stripe_type = STRIPE_SPARSE;
706         fl->stripe_unit = nfl_util & ~NFL4_UFLG_MASK;
707 
708         fl->first_stripe_index = be32_to_cpup(p++);
709         p = xdr_decode_hyper(p, &fl->pattern_offset);
710         fl->num_fh = be32_to_cpup(p++);
711 
712         dprintk("%s: nfl_util 0x%X num_fh %u fsi %u po %llu\n",
713                 __func__, nfl_util, fl->num_fh, fl->first_stripe_index,
714                 fl->pattern_offset);
715 
716         /* Note that a zero value for num_fh is legal for STRIPE_SPARSE.
717          * Futher checking is done in filelayout_check_layout */
718         if (fl->num_fh >
719             max(NFS4_PNFS_MAX_STRIPE_CNT, NFS4_PNFS_MAX_MULTI_CNT))
720                 goto out_err;
721 
722         if (fl->num_fh > 0) {
723                 fl->fh_array = kcalloc(fl->num_fh, sizeof(fl->fh_array[0]),
724                                        gfp_flags);
725                 if (!fl->fh_array)
726                         goto out_err;
727         }
728 
729         for (i = 0; i < fl->num_fh; i++) {
730                 /* Do we want to use a mempool here? */
731                 fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), gfp_flags);
732                 if (!fl->fh_array[i])
733                         goto out_err;
734 
735                 p = xdr_inline_decode(&stream, 4);
736                 if (unlikely(!p))
737                         goto out_err;
738                 fl->fh_array[i]->size = be32_to_cpup(p++);
739                 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
740                         printk(KERN_ERR "NFS: Too big fh %d received %d\n",
741                                i, fl->fh_array[i]->size);
742                         goto out_err;
743                 }
744 
745                 p = xdr_inline_decode(&stream, fl->fh_array[i]->size);
746                 if (unlikely(!p))
747                         goto out_err;
748                 memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size);
749                 dprintk("DEBUG: %s: fh len %d\n", __func__,
750                         fl->fh_array[i]->size);
751         }
752 
753         __free_page(scratch);
754         return 0;
755 
756 out_err:
757         __free_page(scratch);
758         return -EIO;
759 }
760 
761 static void
762 filelayout_free_lseg(struct pnfs_layout_segment *lseg)
763 {
764         struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
765 
766         dprintk("--> %s\n", __func__);
767         nfs4_fl_put_deviceid(fl->dsaddr);
768         /* This assumes a single RW lseg */
769         if (lseg->pls_range.iomode == IOMODE_RW) {
770                 struct nfs4_filelayout *flo;
771 
772                 flo = FILELAYOUT_FROM_HDR(lseg->pls_layout);
773                 flo->commit_info.nbuckets = 0;
774                 kfree(flo->commit_info.buckets);
775                 flo->commit_info.buckets = NULL;
776         }
777         _filelayout_free_lseg(fl);
778 }
779 
780 static int
781 filelayout_alloc_commit_info(struct pnfs_layout_segment *lseg,
782                              struct nfs_commit_info *cinfo,
783                              gfp_t gfp_flags)
784 {
785         struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
786         struct pnfs_commit_bucket *buckets;
787         int size, i;
788 
789         if (fl->commit_through_mds)
790                 return 0;
791 
792         size = (fl->stripe_type == STRIPE_SPARSE) ?
793                 fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
794 
795         if (cinfo->ds->nbuckets >= size) {
796                 /* This assumes there is only one IOMODE_RW lseg.  What
797                  * we really want to do is have a layout_hdr level
798                  * dictionary of <multipath_list4, fh> keys, each
799                  * associated with a struct list_head, populated by calls
800                  * to filelayout_write_pagelist().
801                  * */
802                 return 0;
803         }
804 
805         buckets = kcalloc(size, sizeof(struct pnfs_commit_bucket),
806                           gfp_flags);
807         if (!buckets)
808                 return -ENOMEM;
809         for (i = 0; i < size; i++) {
810                 INIT_LIST_HEAD(&buckets[i].written);
811                 INIT_LIST_HEAD(&buckets[i].committing);
812                 /* mark direct verifier as unset */
813                 buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
814         }
815 
816         spin_lock(&cinfo->inode->i_lock);
817         if (cinfo->ds->nbuckets >= size)
818                 goto out;
819         for (i = 0; i < cinfo->ds->nbuckets; i++) {
820                 list_splice(&cinfo->ds->buckets[i].written,
821                             &buckets[i].written);
822                 list_splice(&cinfo->ds->buckets[i].committing,
823                             &buckets[i].committing);
824                 buckets[i].direct_verf.committed =
825                         cinfo->ds->buckets[i].direct_verf.committed;
826                 buckets[i].wlseg = cinfo->ds->buckets[i].wlseg;
827                 buckets[i].clseg = cinfo->ds->buckets[i].clseg;
828         }
829         swap(cinfo->ds->buckets, buckets);
830         cinfo->ds->nbuckets = size;
831 out:
832         spin_unlock(&cinfo->inode->i_lock);
833         kfree(buckets);
834         return 0;
835 }
836 
837 static struct pnfs_layout_segment *
838 filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
839                       struct nfs4_layoutget_res *lgr,
840                       gfp_t gfp_flags)
841 {
842         struct nfs4_filelayout_segment *fl;
843         int rc;
844 
845         dprintk("--> %s\n", __func__);
846         fl = kzalloc(sizeof(*fl), gfp_flags);
847         if (!fl)
848                 return NULL;
849 
850         rc = filelayout_decode_layout(layoutid, fl, lgr, gfp_flags);
851         if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, gfp_flags)) {
852                 _filelayout_free_lseg(fl);
853                 return NULL;
854         }
855         return &fl->generic_hdr;
856 }
857 
858 /*
859  * filelayout_pg_test(). Called by nfs_can_coalesce_requests()
860  *
861  * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
862  * of bytes (maximum @req->wb_bytes) that can be coalesced.
863  */
864 static size_t
865 filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
866                    struct nfs_page *req)
867 {
868         unsigned int size;
869         u64 p_stripe, r_stripe;
870         u32 stripe_offset;
871         u64 segment_offset = pgio->pg_lseg->pls_range.offset;
872         u32 stripe_unit = FILELAYOUT_LSEG(pgio->pg_lseg)->stripe_unit;
873 
874         /* calls nfs_generic_pg_test */
875         size = pnfs_generic_pg_test(pgio, prev, req);
876         if (!size)
877                 return 0;
878 
879         /* see if req and prev are in the same stripe */
880         if (prev) {
881                 p_stripe = (u64)req_offset(prev) - segment_offset;
882                 r_stripe = (u64)req_offset(req) - segment_offset;
883                 do_div(p_stripe, stripe_unit);
884                 do_div(r_stripe, stripe_unit);
885 
886                 if (p_stripe != r_stripe)
887                         return 0;
888         }
889 
890         /* calculate remaining bytes in the current stripe */
891         div_u64_rem((u64)req_offset(req) - segment_offset,
892                         stripe_unit,
893                         &stripe_offset);
894         WARN_ON_ONCE(stripe_offset > stripe_unit);
895         if (stripe_offset >= stripe_unit)
896                 return 0;
897         return min(stripe_unit - (unsigned int)stripe_offset, size);
898 }
899 
900 static struct pnfs_layout_segment *
901 fl_pnfs_update_layout(struct inode *ino,
902                       struct nfs_open_context *ctx,
903                       loff_t pos,
904                       u64 count,
905                       enum pnfs_iomode iomode,
906                       bool strict_iomode,
907                       gfp_t gfp_flags)
908 {
909         struct pnfs_layout_segment *lseg = NULL;
910         struct pnfs_layout_hdr *lo;
911         struct nfs4_filelayout_segment *fl;
912         int status;
913 
914         lseg = pnfs_update_layout(ino, ctx, pos, count, iomode, strict_iomode,
915                                   gfp_flags);
916         if (!lseg)
917                 lseg = ERR_PTR(-ENOMEM);
918         if (IS_ERR(lseg))
919                 goto out;
920 
921         lo = NFS_I(ino)->layout;
922         fl = FILELAYOUT_LSEG(lseg);
923 
924         status = filelayout_check_deviceid(lo, fl, gfp_flags);
925         if (status) {
926                 pnfs_put_lseg(lseg);
927                 lseg = ERR_PTR(status);
928         }
929 out:
930         return lseg;
931 }
932 
933 static void
934 filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
935                         struct nfs_page *req)
936 {
937         pnfs_generic_pg_check_layout(pgio);
938         if (!pgio->pg_lseg) {
939                 pgio->pg_lseg = fl_pnfs_update_layout(pgio->pg_inode,
940                                                       req->wb_context,
941                                                       0,
942                                                       NFS4_MAX_UINT64,
943                                                       IOMODE_READ,
944                                                       false,
945                                                       GFP_KERNEL);
946                 if (IS_ERR(pgio->pg_lseg)) {
947                         pgio->pg_error = PTR_ERR(pgio->pg_lseg);
948                         pgio->pg_lseg = NULL;
949                         return;
950                 }
951         }
952         /* If no lseg, fall back to read through mds */
953         if (pgio->pg_lseg == NULL)
954                 nfs_pageio_reset_read_mds(pgio);
955 }
956 
957 static void
958 filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,
959                          struct nfs_page *req)
960 {
961         struct nfs_commit_info cinfo;
962         int status;
963 
964         pnfs_generic_pg_check_layout(pgio);
965         if (!pgio->pg_lseg) {
966                 pgio->pg_lseg = fl_pnfs_update_layout(pgio->pg_inode,
967                                                       req->wb_context,
968                                                       0,
969                                                       NFS4_MAX_UINT64,
970                                                       IOMODE_RW,
971                                                       false,
972                                                       GFP_NOFS);
973                 if (IS_ERR(pgio->pg_lseg)) {
974                         pgio->pg_error = PTR_ERR(pgio->pg_lseg);
975                         pgio->pg_lseg = NULL;
976                         return;
977                 }
978         }
979 
980         /* If no lseg, fall back to write through mds */
981         if (pgio->pg_lseg == NULL)
982                 goto out_mds;
983         nfs_init_cinfo(&cinfo, pgio->pg_inode, pgio->pg_dreq);
984         status = filelayout_alloc_commit_info(pgio->pg_lseg, &cinfo, GFP_NOFS);
985         if (status < 0) {
986                 pnfs_put_lseg(pgio->pg_lseg);
987                 pgio->pg_lseg = NULL;
988                 goto out_mds;
989         }
990         return;
991 out_mds:
992         nfs_pageio_reset_write_mds(pgio);
993 }
994 
995 static const struct nfs_pageio_ops filelayout_pg_read_ops = {
996         .pg_init = filelayout_pg_init_read,
997         .pg_test = filelayout_pg_test,
998         .pg_doio = pnfs_generic_pg_readpages,
999         .pg_cleanup = pnfs_generic_pg_cleanup,
1000 };
1001 
1002 static const struct nfs_pageio_ops filelayout_pg_write_ops = {
1003         .pg_init = filelayout_pg_init_write,
1004         .pg_test = filelayout_pg_test,
1005         .pg_doio = pnfs_generic_pg_writepages,
1006         .pg_cleanup = pnfs_generic_pg_cleanup,
1007 };
1008 
1009 static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
1010 {
1011         if (fl->stripe_type == STRIPE_SPARSE)
1012                 return nfs4_fl_calc_ds_index(&fl->generic_hdr, j);
1013         else
1014                 return j;
1015 }
1016 
1017 static void
1018 filelayout_mark_request_commit(struct nfs_page *req,
1019                                struct pnfs_layout_segment *lseg,
1020                                struct nfs_commit_info *cinfo,
1021                                u32 ds_commit_idx)
1022 
1023 {
1024         struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
1025         u32 i, j;
1026 
1027         if (fl->commit_through_mds) {
1028                 nfs_request_add_commit_list(req, cinfo);
1029         } else {
1030                 /* Note that we are calling nfs4_fl_calc_j_index on each page
1031                  * that ends up being committed to a data server.  An attractive
1032                  * alternative is to add a field to nfs_write_data and nfs_page
1033                  * to store the value calculated in filelayout_write_pagelist
1034                  * and just use that here.
1035                  */
1036                 j = nfs4_fl_calc_j_index(lseg, req_offset(req));
1037                 i = select_bucket_index(fl, j);
1038                 pnfs_layout_mark_request_commit(req, lseg, cinfo, i);
1039         }
1040 }
1041 
1042 static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
1043 {
1044         struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
1045 
1046         if (flseg->stripe_type == STRIPE_SPARSE)
1047                 return i;
1048         else
1049                 return nfs4_fl_calc_ds_index(lseg, i);
1050 }
1051 
1052 static struct nfs_fh *
1053 select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i)
1054 {
1055         struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
1056 
1057         if (flseg->stripe_type == STRIPE_SPARSE) {
1058                 if (flseg->num_fh == 1)
1059                         i = 0;
1060                 else if (flseg->num_fh == 0)
1061                         /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
1062                         return NULL;
1063         }
1064         return flseg->fh_array[i];
1065 }
1066 
1067 static int filelayout_initiate_commit(struct nfs_commit_data *data, int how)
1068 {
1069         struct pnfs_layout_segment *lseg = data->lseg;
1070         struct nfs4_pnfs_ds *ds;
1071         struct rpc_clnt *ds_clnt;
1072         u32 idx;
1073         struct nfs_fh *fh;
1074 
1075         idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
1076         ds = nfs4_fl_prepare_ds(lseg, idx);
1077         if (!ds)
1078                 goto out_err;
1079 
1080         ds_clnt = nfs4_find_or_create_ds_client(ds->ds_clp, data->inode);
1081         if (IS_ERR(ds_clnt))
1082                 goto out_err;
1083 
1084         dprintk("%s ino %lu, how %d cl_count %d\n", __func__,
1085                 data->inode->i_ino, how, atomic_read(&ds->ds_clp->cl_count));
1086         data->commit_done_cb = filelayout_commit_done_cb;
1087         atomic_inc(&ds->ds_clp->cl_count);
1088         data->ds_clp = ds->ds_clp;
1089         fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
1090         if (fh)
1091                 data->args.fh = fh;
1092         return nfs_initiate_commit(ds_clnt, data, NFS_PROTO(data->inode),
1093                                    &filelayout_commit_call_ops, how,
1094                                    RPC_TASK_SOFTCONN);
1095 out_err:
1096         pnfs_generic_prepare_to_resend_writes(data);
1097         pnfs_generic_commit_release(data);
1098         return -EAGAIN;
1099 }
1100 
1101 /* filelayout_search_commit_reqs - Search lists in @cinfo for the head reqest
1102  *                                 for @page
1103  * @cinfo - commit info for current inode
1104  * @page - page to search for matching head request
1105  *
1106  * Returns a the head request if one is found, otherwise returns NULL.
1107  */
1108 static struct nfs_page *
1109 filelayout_search_commit_reqs(struct nfs_commit_info *cinfo, struct page *page)
1110 {
1111         struct nfs_page *freq, *t;
1112         struct pnfs_commit_bucket *b;
1113         int i;
1114 
1115         /* Linearly search the commit lists for each bucket until a matching
1116          * request is found */
1117         for (i = 0, b = cinfo->ds->buckets; i < cinfo->ds->nbuckets; i++, b++) {
1118                 list_for_each_entry_safe(freq, t, &b->written, wb_list) {
1119                         if (freq->wb_page == page)
1120                                 return freq->wb_head;
1121                 }
1122                 list_for_each_entry_safe(freq, t, &b->committing, wb_list) {
1123                         if (freq->wb_page == page)
1124                                 return freq->wb_head;
1125                 }
1126         }
1127 
1128         return NULL;
1129 }
1130 
1131 static int
1132 filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
1133                            int how, struct nfs_commit_info *cinfo)
1134 {
1135         return pnfs_generic_commit_pagelist(inode, mds_pages, how, cinfo,
1136                                             filelayout_initiate_commit);
1137 }
1138 
1139 static struct nfs4_deviceid_node *
1140 filelayout_alloc_deviceid_node(struct nfs_server *server,
1141                 struct pnfs_device *pdev, gfp_t gfp_flags)
1142 {
1143         struct nfs4_file_layout_dsaddr *dsaddr;
1144 
1145         dsaddr = nfs4_fl_alloc_deviceid_node(server, pdev, gfp_flags);
1146         if (!dsaddr)
1147                 return NULL;
1148         return &dsaddr->id_node;
1149 }
1150 
1151 static void
1152 filelayout_free_deviceid_node(struct nfs4_deviceid_node *d)
1153 {
1154         nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node));
1155 }
1156 
1157 static struct pnfs_layout_hdr *
1158 filelayout_alloc_layout_hdr(struct inode *inode, gfp_t gfp_flags)
1159 {
1160         struct nfs4_filelayout *flo;
1161 
1162         flo = kzalloc(sizeof(*flo), gfp_flags);
1163         return flo != NULL ? &flo->generic_hdr : NULL;
1164 }
1165 
1166 static void
1167 filelayout_free_layout_hdr(struct pnfs_layout_hdr *lo)
1168 {
1169         kfree(FILELAYOUT_FROM_HDR(lo));
1170 }
1171 
1172 static struct pnfs_ds_commit_info *
1173 filelayout_get_ds_info(struct inode *inode)
1174 {
1175         struct pnfs_layout_hdr *layout = NFS_I(inode)->layout;
1176 
1177         if (layout == NULL)
1178                 return NULL;
1179         else
1180                 return &FILELAYOUT_FROM_HDR(layout)->commit_info;
1181 }
1182 
1183 static struct pnfs_layoutdriver_type filelayout_type = {
1184         .id                     = LAYOUT_NFSV4_1_FILES,
1185         .name                   = "LAYOUT_NFSV4_1_FILES",
1186         .owner                  = THIS_MODULE,
1187         .alloc_layout_hdr       = filelayout_alloc_layout_hdr,
1188         .free_layout_hdr        = filelayout_free_layout_hdr,
1189         .alloc_lseg             = filelayout_alloc_lseg,
1190         .free_lseg              = filelayout_free_lseg,
1191         .pg_read_ops            = &filelayout_pg_read_ops,
1192         .pg_write_ops           = &filelayout_pg_write_ops,
1193         .get_ds_info            = &filelayout_get_ds_info,
1194         .mark_request_commit    = filelayout_mark_request_commit,
1195         .clear_request_commit   = pnfs_generic_clear_request_commit,
1196         .scan_commit_lists      = pnfs_generic_scan_commit_lists,
1197         .recover_commit_reqs    = pnfs_generic_recover_commit_reqs,
1198         .search_commit_reqs     = filelayout_search_commit_reqs,
1199         .commit_pagelist        = filelayout_commit_pagelist,
1200         .read_pagelist          = filelayout_read_pagelist,
1201         .write_pagelist         = filelayout_write_pagelist,
1202         .alloc_deviceid_node    = filelayout_alloc_deviceid_node,
1203         .free_deviceid_node     = filelayout_free_deviceid_node,
1204         .sync                   = pnfs_nfs_generic_sync,
1205 };
1206 
1207 static int __init nfs4filelayout_init(void)
1208 {
1209         printk(KERN_INFO "%s: NFSv4 File Layout Driver Registering...\n",
1210                __func__);
1211         return pnfs_register_layoutdriver(&filelayout_type);
1212 }
1213 
1214 static void __exit nfs4filelayout_exit(void)
1215 {
1216         printk(KERN_INFO "%s: NFSv4 File Layout Driver Unregistering...\n",
1217                __func__);
1218         pnfs_unregister_layoutdriver(&filelayout_type);
1219 }
1220 
1221 MODULE_ALIAS("nfs-layouttype4-1");
1222 
1223 module_init(nfs4filelayout_init);
1224 module_exit(nfs4filelayout_exit);
1225 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp