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.
7 * The Regents of the University of Michigan
10 * Dean Hildebrand <dhildebz@umich.edu>
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.
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
32 #include <linux/nfs_fs.h>
35 #include "nfs4filelayout.h"
37 #define NFSDBG_FACILITY NFSDBG_PNFS_LD
39 MODULE_LICENSE("GPL");
40 MODULE_AUTHOR("Dean Hildebrand <dhildebz@umich.edu>");
41 MODULE_DESCRIPTION("The NFSv4 file layout driver");
43 #define FILELAYOUT_POLL_RETRY_MAX (15*HZ)
46 filelayout_get_dense_offset(struct nfs4_filelayout_segment *flseg,
49 u32 stripe_width = flseg->stripe_unit * flseg->dsaddr->stripe_count;
52 offset -= flseg->pattern_offset;
54 do_div(tmp, stripe_width);
56 return tmp * flseg->stripe_unit + do_div(offset, flseg->stripe_unit);
59 /* This function is used by the layout driver to calculate the
60 * offset of the file on the dserver based on whether the
61 * layout type is STRIPE_DENSE or STRIPE_SPARSE
64 filelayout_get_dserver_offset(struct pnfs_layout_segment *lseg, loff_t offset)
66 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
68 switch (flseg->stripe_type) {
73 return filelayout_get_dense_offset(flseg, offset);
79 /* For data server errors we don't recover from */
81 filelayout_set_lo_fail(struct pnfs_layout_segment *lseg)
83 if (lseg->pls_range.iomode == IOMODE_RW) {
84 dprintk("%s Setting layout IOMODE_RW fail bit\n", __func__);
85 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
87 dprintk("%s Setting layout IOMODE_READ fail bit\n", __func__);
88 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
92 static int filelayout_async_handle_error(struct rpc_task *task,
93 struct nfs4_state *state,
94 struct nfs_client *clp,
97 if (task->tk_status >= 0)
102 switch (task->tk_status) {
103 case -NFS4ERR_BADSESSION:
104 case -NFS4ERR_BADSLOT:
105 case -NFS4ERR_BAD_HIGH_SLOT:
106 case -NFS4ERR_DEADSESSION:
107 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
108 case -NFS4ERR_SEQ_FALSE_RETRY:
109 case -NFS4ERR_SEQ_MISORDERED:
110 dprintk("%s ERROR %d, Reset session. Exchangeid "
111 "flags 0x%x\n", __func__, task->tk_status,
112 clp->cl_exchange_flags);
113 nfs4_schedule_session_recovery(clp->cl_session);
118 rpc_delay(task, FILELAYOUT_POLL_RETRY_MAX);
121 dprintk("%s DS error. Retry through MDS %d\n", __func__,
130 /* NFS_PROTO call done callback routines */
132 static int filelayout_read_done_cb(struct rpc_task *task,
133 struct nfs_read_data *data)
135 struct nfs_client *clp = data->ds_clp;
138 dprintk("%s DS read\n", __func__);
140 if (filelayout_async_handle_error(task, data->args.context->state,
141 data->ds_clp, &reset) == -EAGAIN) {
142 dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
143 __func__, data->ds_clp, data->ds_clp->cl_session);
145 filelayout_set_lo_fail(data->lseg);
146 nfs4_reset_read(task, data);
147 clp = NFS_SERVER(data->inode)->nfs_client;
149 nfs_restart_rpc(task, clp);
157 * We reference the rpc_cred of the first WRITE that triggers the need for
158 * a LAYOUTCOMMIT, and use it to send the layoutcommit compound.
159 * rfc5661 is not clear about which credential should be used.
162 filelayout_set_layoutcommit(struct nfs_write_data *wdata)
164 if (FILELAYOUT_LSEG(wdata->lseg)->commit_through_mds ||
165 wdata->res.verf->committed == NFS_FILE_SYNC)
168 pnfs_set_layoutcommit(wdata);
169 dprintk("%s ionde %lu pls_end_pos %lu\n", __func__, wdata->inode->i_ino,
170 (unsigned long) wdata->lseg->pls_end_pos);
174 * Call ops for the async read/write cases
175 * In the case of dense layouts, the offset needs to be reset to its
178 static void filelayout_read_prepare(struct rpc_task *task, void *data)
180 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
182 rdata->read_done_cb = filelayout_read_done_cb;
184 if (nfs41_setup_sequence(rdata->ds_clp->cl_session,
185 &rdata->args.seq_args, &rdata->res.seq_res,
189 rpc_call_start(task);
192 static void filelayout_read_call_done(struct rpc_task *task, void *data)
194 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
196 dprintk("--> %s task->tk_status %d\n", __func__, task->tk_status);
198 /* Note this may cause RPC to be resent */
199 rdata->mds_ops->rpc_call_done(task, data);
202 static void filelayout_read_release(void *data)
204 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
206 rdata->mds_ops->rpc_release(data);
209 static int filelayout_write_done_cb(struct rpc_task *task,
210 struct nfs_write_data *data)
214 if (filelayout_async_handle_error(task, data->args.context->state,
215 data->ds_clp, &reset) == -EAGAIN) {
216 struct nfs_client *clp;
218 dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
219 __func__, data->ds_clp, data->ds_clp->cl_session);
221 filelayout_set_lo_fail(data->lseg);
222 nfs4_reset_write(task, data);
223 clp = NFS_SERVER(data->inode)->nfs_client;
226 nfs_restart_rpc(task, clp);
230 filelayout_set_layoutcommit(data);
234 /* Fake up some data that will cause nfs_commit_release to retry the writes. */
235 static void prepare_to_resend_writes(struct nfs_write_data *data)
237 struct nfs_page *first = nfs_list_entry(data->pages.next);
239 data->task.tk_status = 0;
240 memcpy(data->verf.verifier, first->wb_verf.verifier,
241 sizeof(first->wb_verf.verifier));
242 data->verf.verifier[0]++; /* ensure verifier mismatch */
245 static int filelayout_commit_done_cb(struct rpc_task *task,
246 struct nfs_write_data *data)
250 if (filelayout_async_handle_error(task, data->args.context->state,
251 data->ds_clp, &reset) == -EAGAIN) {
252 dprintk("%s calling restart ds_clp %p ds_clp->cl_session %p\n",
253 __func__, data->ds_clp, data->ds_clp->cl_session);
255 prepare_to_resend_writes(data);
256 filelayout_set_lo_fail(data->lseg);
258 nfs_restart_rpc(task, data->ds_clp);
265 static void filelayout_write_prepare(struct rpc_task *task, void *data)
267 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
269 if (nfs41_setup_sequence(wdata->ds_clp->cl_session,
270 &wdata->args.seq_args, &wdata->res.seq_res,
274 rpc_call_start(task);
277 static void filelayout_write_call_done(struct rpc_task *task, void *data)
279 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
281 /* Note this may cause RPC to be resent */
282 wdata->mds_ops->rpc_call_done(task, data);
285 static void filelayout_write_release(void *data)
287 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
289 wdata->mds_ops->rpc_release(data);
292 static void filelayout_commit_release(void *data)
294 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
296 nfs_commit_release_pages(wdata);
297 if (atomic_dec_and_test(&NFS_I(wdata->inode)->commits_outstanding))
298 nfs_commit_clear_lock(NFS_I(wdata->inode));
299 nfs_commitdata_release(wdata);
302 struct rpc_call_ops filelayout_read_call_ops = {
303 .rpc_call_prepare = filelayout_read_prepare,
304 .rpc_call_done = filelayout_read_call_done,
305 .rpc_release = filelayout_read_release,
308 struct rpc_call_ops filelayout_write_call_ops = {
309 .rpc_call_prepare = filelayout_write_prepare,
310 .rpc_call_done = filelayout_write_call_done,
311 .rpc_release = filelayout_write_release,
314 struct rpc_call_ops filelayout_commit_call_ops = {
315 .rpc_call_prepare = filelayout_write_prepare,
316 .rpc_call_done = filelayout_write_call_done,
317 .rpc_release = filelayout_commit_release,
320 static enum pnfs_try_status
321 filelayout_read_pagelist(struct nfs_read_data *data)
323 struct pnfs_layout_segment *lseg = data->lseg;
324 struct nfs4_pnfs_ds *ds;
325 loff_t offset = data->args.offset;
330 dprintk("--> %s ino %lu pgbase %u req %Zu@%llu\n",
331 __func__, data->inode->i_ino,
332 data->args.pgbase, (size_t)data->args.count, offset);
334 /* Retrieve the correct rpc_client for the byte range */
335 j = nfs4_fl_calc_j_index(lseg, offset);
336 idx = nfs4_fl_calc_ds_index(lseg, j);
337 ds = nfs4_fl_prepare_ds(lseg, idx);
339 /* Either layout fh index faulty, or ds connect failed */
340 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
341 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
342 return PNFS_NOT_ATTEMPTED;
344 dprintk("%s USE DS:ip %x %hu\n", __func__,
345 ntohl(ds->ds_ip_addr), ntohs(ds->ds_port));
347 /* No multipath support. Use first DS */
348 data->ds_clp = ds->ds_clp;
349 fh = nfs4_fl_select_ds_fh(lseg, j);
353 data->args.offset = filelayout_get_dserver_offset(lseg, offset);
354 data->mds_offset = offset;
356 /* Perform an asynchronous read to ds */
357 status = nfs_initiate_read(data, ds->ds_clp->cl_rpcclient,
358 &filelayout_read_call_ops);
360 return PNFS_ATTEMPTED;
363 /* Perform async writes. */
364 static enum pnfs_try_status
365 filelayout_write_pagelist(struct nfs_write_data *data, int sync)
367 struct pnfs_layout_segment *lseg = data->lseg;
368 struct nfs4_pnfs_ds *ds;
369 loff_t offset = data->args.offset;
374 /* Retrieve the correct rpc_client for the byte range */
375 j = nfs4_fl_calc_j_index(lseg, offset);
376 idx = nfs4_fl_calc_ds_index(lseg, j);
377 ds = nfs4_fl_prepare_ds(lseg, idx);
379 printk(KERN_ERR "%s: prepare_ds failed, use MDS\n", __func__);
380 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
381 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
382 return PNFS_NOT_ATTEMPTED;
384 dprintk("%s ino %lu sync %d req %Zu@%llu DS:%x:%hu\n", __func__,
385 data->inode->i_ino, sync, (size_t) data->args.count, offset,
386 ntohl(ds->ds_ip_addr), ntohs(ds->ds_port));
388 /* We can't handle commit to ds yet */
389 if (!FILELAYOUT_LSEG(lseg)->commit_through_mds)
390 data->args.stable = NFS_FILE_SYNC;
392 data->write_done_cb = filelayout_write_done_cb;
393 data->ds_clp = ds->ds_clp;
394 fh = nfs4_fl_select_ds_fh(lseg, j);
398 * Get the file offset on the dserver. Set the write offset to
399 * this offset and save the original offset.
401 data->args.offset = filelayout_get_dserver_offset(lseg, offset);
402 data->mds_offset = offset;
404 /* Perform an asynchronous write */
405 status = nfs_initiate_write(data, ds->ds_clp->cl_rpcclient,
406 &filelayout_write_call_ops, sync);
408 return PNFS_ATTEMPTED;
412 * filelayout_check_layout()
414 * Make sure layout segment parameters are sane WRT the device.
415 * At this point no generic layer initialization of the lseg has occurred,
416 * and nothing has been added to the layout_hdr cache.
420 filelayout_check_layout(struct pnfs_layout_hdr *lo,
421 struct nfs4_filelayout_segment *fl,
422 struct nfs4_layoutget_res *lgr,
423 struct nfs4_deviceid *id)
425 struct nfs4_file_layout_dsaddr *dsaddr;
426 int status = -EINVAL;
427 struct nfs_server *nfss = NFS_SERVER(lo->plh_inode);
429 dprintk("--> %s\n", __func__);
431 if (fl->pattern_offset > lgr->range.offset) {
432 dprintk("%s pattern_offset %lld to large\n",
433 __func__, fl->pattern_offset);
437 if (!fl->stripe_unit || fl->stripe_unit % PAGE_SIZE) {
438 dprintk("%s Invalid stripe unit (%u)\n",
439 __func__, fl->stripe_unit);
443 /* find and reference the deviceid */
444 dsaddr = nfs4_fl_find_get_deviceid(id);
445 if (dsaddr == NULL) {
446 dsaddr = get_device_info(lo->plh_inode, id);
452 if (fl->first_stripe_index < 0 ||
453 fl->first_stripe_index >= dsaddr->stripe_count) {
454 dprintk("%s Bad first_stripe_index %d\n",
455 __func__, fl->first_stripe_index);
459 if ((fl->stripe_type == STRIPE_SPARSE &&
460 fl->num_fh > 1 && fl->num_fh != dsaddr->ds_num) ||
461 (fl->stripe_type == STRIPE_DENSE &&
462 fl->num_fh != dsaddr->stripe_count)) {
463 dprintk("%s num_fh %u not valid for given packing\n",
464 __func__, fl->num_fh);
468 if (fl->stripe_unit % nfss->rsize || fl->stripe_unit % nfss->wsize) {
469 dprintk("%s Stripe unit (%u) not aligned with rsize %u "
470 "wsize %u\n", __func__, fl->stripe_unit, nfss->rsize,
476 dprintk("--> %s returns %d\n", __func__, status);
479 nfs4_fl_put_deviceid(dsaddr);
483 static void filelayout_free_fh_array(struct nfs4_filelayout_segment *fl)
487 for (i = 0; i < fl->num_fh; i++) {
488 if (!fl->fh_array[i])
490 kfree(fl->fh_array[i]);
497 _filelayout_free_lseg(struct nfs4_filelayout_segment *fl)
499 filelayout_free_fh_array(fl);
504 filelayout_decode_layout(struct pnfs_layout_hdr *flo,
505 struct nfs4_filelayout_segment *fl,
506 struct nfs4_layoutget_res *lgr,
507 struct nfs4_deviceid *id)
509 uint32_t *p = (uint32_t *)lgr->layout.buf;
513 dprintk("%s: set_layout_map Begin\n", __func__);
515 memcpy(id, p, sizeof(*id));
516 p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE);
519 nfl_util = be32_to_cpup(p++);
520 if (nfl_util & NFL4_UFLG_COMMIT_THRU_MDS)
521 fl->commit_through_mds = 1;
522 if (nfl_util & NFL4_UFLG_DENSE)
523 fl->stripe_type = STRIPE_DENSE;
525 fl->stripe_type = STRIPE_SPARSE;
526 fl->stripe_unit = nfl_util & ~NFL4_UFLG_MASK;
528 fl->first_stripe_index = be32_to_cpup(p++);
529 p = xdr_decode_hyper(p, &fl->pattern_offset);
530 fl->num_fh = be32_to_cpup(p++);
532 dprintk("%s: nfl_util 0x%X num_fh %u fsi %u po %llu\n",
533 __func__, nfl_util, fl->num_fh, fl->first_stripe_index,
536 fl->fh_array = kzalloc(fl->num_fh * sizeof(struct nfs_fh *),
541 for (i = 0; i < fl->num_fh; i++) {
542 /* Do we want to use a mempool here? */
543 fl->fh_array[i] = kmalloc(sizeof(struct nfs_fh), GFP_KERNEL);
544 if (!fl->fh_array[i]) {
545 filelayout_free_fh_array(fl);
548 fl->fh_array[i]->size = be32_to_cpup(p++);
549 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
550 printk(KERN_ERR "Too big fh %d received %d\n",
551 i, fl->fh_array[i]->size);
552 filelayout_free_fh_array(fl);
555 memcpy(fl->fh_array[i]->data, p, fl->fh_array[i]->size);
556 p += XDR_QUADLEN(fl->fh_array[i]->size);
557 dprintk("DEBUG: %s: fh len %d\n", __func__,
558 fl->fh_array[i]->size);
565 filelayout_free_lseg(struct pnfs_layout_segment *lseg)
567 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
569 dprintk("--> %s\n", __func__);
570 nfs4_fl_put_deviceid(fl->dsaddr);
571 kfree(fl->commit_buckets);
572 _filelayout_free_lseg(fl);
575 static struct pnfs_layout_segment *
576 filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
577 struct nfs4_layoutget_res *lgr)
579 struct nfs4_filelayout_segment *fl;
581 struct nfs4_deviceid id;
583 dprintk("--> %s\n", __func__);
584 fl = kzalloc(sizeof(*fl), GFP_KERNEL);
588 rc = filelayout_decode_layout(layoutid, fl, lgr, &id);
589 if (rc != 0 || filelayout_check_layout(layoutid, fl, lgr, &id)) {
590 _filelayout_free_lseg(fl);
594 /* This assumes there is only one IOMODE_RW lseg. What
595 * we really want to do is have a layout_hdr level
596 * dictionary of <multipath_list4, fh> keys, each
597 * associated with a struct list_head, populated by calls
598 * to filelayout_write_pagelist().
600 if ((!fl->commit_through_mds) && (lgr->range.iomode == IOMODE_RW)) {
602 int size = (fl->stripe_type == STRIPE_SPARSE) ?
603 fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
605 fl->commit_buckets = kcalloc(size, sizeof(struct list_head), GFP_KERNEL);
606 if (!fl->commit_buckets) {
607 filelayout_free_lseg(&fl->generic_hdr);
610 fl->number_of_buckets = size;
611 for (i = 0; i < size; i++)
612 INIT_LIST_HEAD(&fl->commit_buckets[i]);
614 return &fl->generic_hdr;
618 * filelayout_pg_test(). Called by nfs_can_coalesce_requests()
620 * return 1 : coalesce page
621 * return 0 : don't coalesce page
624 filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
625 struct nfs_page *req)
627 u64 p_stripe, r_stripe;
632 p_stripe = (u64)prev->wb_index << PAGE_CACHE_SHIFT;
633 r_stripe = (u64)req->wb_index << PAGE_CACHE_SHIFT;
634 stripe_unit = FILELAYOUT_LSEG(pgio->pg_lseg)->stripe_unit;
636 do_div(p_stripe, stripe_unit);
637 do_div(r_stripe, stripe_unit);
639 return (p_stripe == r_stripe);
642 static bool filelayout_mark_pnfs_commit(struct pnfs_layout_segment *lseg)
644 return !FILELAYOUT_LSEG(lseg)->commit_through_mds;
647 static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
649 if (fl->stripe_type == STRIPE_SPARSE)
650 return nfs4_fl_calc_ds_index(&fl->generic_hdr, j);
655 struct list_head *filelayout_choose_commit_list(struct nfs_page *req)
657 struct pnfs_layout_segment *lseg = req->wb_commit_lseg;
658 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
660 struct list_head *list;
662 /* Note that we are calling nfs4_fl_calc_j_index on each page
663 * that ends up being committed to a data server. An attractive
664 * alternative is to add a field to nfs_write_data and nfs_page
665 * to store the value calculated in filelayout_write_pagelist
666 * and just use that here.
668 j = nfs4_fl_calc_j_index(lseg,
669 (loff_t)req->wb_index << PAGE_CACHE_SHIFT);
670 i = select_bucket_index(fl, j);
671 list = &fl->commit_buckets[i];
672 if (list_empty(list)) {
673 /* Non-empty buckets hold a reference on the lseg */
679 static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
681 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
683 if (flseg->stripe_type == STRIPE_SPARSE)
686 return nfs4_fl_calc_ds_index(lseg, i);
689 static struct nfs_fh *
690 select_ds_fh_from_commit(struct pnfs_layout_segment *lseg, u32 i)
692 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
694 if (flseg->stripe_type == STRIPE_SPARSE) {
695 if (flseg->num_fh == 1)
697 else if (flseg->num_fh == 0)
698 /* Use the MDS OPEN fh set in nfs_read_rpcsetup */
701 return flseg->fh_array[i];
704 static int filelayout_initiate_commit(struct nfs_write_data *data, int how)
706 struct pnfs_layout_segment *lseg = data->lseg;
707 struct nfs4_pnfs_ds *ds;
711 idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
712 ds = nfs4_fl_prepare_ds(lseg, idx);
714 printk(KERN_ERR "%s: prepare_ds failed, use MDS\n", __func__);
715 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
716 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
717 prepare_to_resend_writes(data);
718 data->mds_ops->rpc_release(data);
721 dprintk("%s ino %lu, how %d\n", __func__, data->inode->i_ino, how);
722 data->write_done_cb = filelayout_commit_done_cb;
723 data->ds_clp = ds->ds_clp;
724 fh = select_ds_fh_from_commit(lseg, data->ds_commit_index);
727 return nfs_initiate_commit(data, ds->ds_clp->cl_rpcclient,
728 &filelayout_commit_call_ops, how);
732 * This is only useful while we are using whole file layouts.
734 static struct pnfs_layout_segment *find_only_write_lseg(struct inode *inode)
736 struct pnfs_layout_segment *lseg, *rv = NULL;
738 spin_lock(&inode->i_lock);
739 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list)
740 if (lseg->pls_range.iomode == IOMODE_RW)
742 spin_unlock(&inode->i_lock);
746 static int alloc_ds_commits(struct inode *inode, struct list_head *list)
748 struct pnfs_layout_segment *lseg;
749 struct nfs4_filelayout_segment *fl;
750 struct nfs_write_data *data;
753 /* Won't need this when non-whole file layout segments are supported
754 * instead we will use a pnfs_layout_hdr structure */
755 lseg = find_only_write_lseg(inode);
758 fl = FILELAYOUT_LSEG(lseg);
759 for (i = 0; i < fl->number_of_buckets; i++) {
760 if (list_empty(&fl->commit_buckets[i]))
762 data = nfs_commitdata_alloc();
765 data->ds_commit_index = i;
767 list_add(&data->pages, list);
773 for (j = i; j < fl->number_of_buckets; j++) {
774 if (list_empty(&fl->commit_buckets[i]))
776 nfs_retry_commit(&fl->commit_buckets[i], lseg);
777 put_lseg(lseg); /* associated with emptying bucket */
780 /* Caller will clean up entries put on list */
784 /* This follows nfs_commit_list pretty closely */
786 filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
789 struct nfs_write_data *data, *tmp;
792 if (!list_empty(mds_pages)) {
793 data = nfs_commitdata_alloc();
797 list_add(&data->pages, &list);
800 if (alloc_ds_commits(inode, &list))
803 list_for_each_entry_safe(data, tmp, &list, pages) {
804 list_del_init(&data->pages);
805 atomic_inc(&NFS_I(inode)->commits_outstanding);
807 nfs_init_commit(data, mds_pages, NULL);
808 nfs_initiate_commit(data, NFS_CLIENT(inode),
811 nfs_init_commit(data, &FILELAYOUT_LSEG(data->lseg)->commit_buckets[data->ds_commit_index], data->lseg);
812 filelayout_initiate_commit(data, how);
817 list_for_each_entry_safe(data, tmp, &list, pages) {
818 nfs_retry_commit(&data->pages, data->lseg);
819 list_del_init(&data->pages);
820 nfs_commit_free(data);
822 nfs_retry_commit(mds_pages, NULL);
823 nfs_commit_clear_lock(NFS_I(inode));
827 static struct pnfs_layoutdriver_type filelayout_type = {
828 .id = LAYOUT_NFSV4_1_FILES,
829 .name = "LAYOUT_NFSV4_1_FILES",
830 .owner = THIS_MODULE,
831 .alloc_lseg = filelayout_alloc_lseg,
832 .free_lseg = filelayout_free_lseg,
833 .pg_test = filelayout_pg_test,
834 .mark_pnfs_commit = filelayout_mark_pnfs_commit,
835 .choose_commit_list = filelayout_choose_commit_list,
836 .commit_pagelist = filelayout_commit_pagelist,
837 .read_pagelist = filelayout_read_pagelist,
838 .write_pagelist = filelayout_write_pagelist,
841 static int __init nfs4filelayout_init(void)
843 printk(KERN_INFO "%s: NFSv4 File Layout Driver Registering...\n",
845 return pnfs_register_layoutdriver(&filelayout_type);
848 static void __exit nfs4filelayout_exit(void)
850 printk(KERN_INFO "%s: NFSv4 File Layout Driver Unregistering...\n",
852 pnfs_unregister_layoutdriver(&filelayout_type);
855 module_init(nfs4filelayout_init);
856 module_exit(nfs4filelayout_exit);