Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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