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) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) #include <linux/sunrpc/addr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) #include <linux/sunrpc/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/nfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/nfs3.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/nfs4.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/nfs_xdr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include "nfs4_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include "nfs42.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include "iostat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include "pnfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include "nfs4session.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include "delegation.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "nfs4trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #define NFSDBG_FACILITY NFSDBG_PROC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) static int nfs42_do_offload_cancel_async(struct file *dst, nfs4_stateid *std);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) static void nfs42_set_netaddr(struct file *filep, struct nfs42_netaddr *naddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 	struct nfs_client *clp = (NFS_SERVER(file_inode(filep)))->nfs_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 	unsigned short port = 2049;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 	naddr->netid_len = scnprintf(naddr->netid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 					sizeof(naddr->netid), "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 					rpc_peeraddr2str(clp->cl_rpcclient,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 					RPC_DISPLAY_NETID));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 	naddr->addr_len = scnprintf(naddr->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 					sizeof(naddr->addr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 					"%s.%u.%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 					rpc_peeraddr2str(clp->cl_rpcclient,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 					RPC_DISPLAY_ADDR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 					port >> 8, port & 255);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 		struct nfs_lock_context *lock, loff_t offset, loff_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	struct inode *inode = file_inode(filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	u32 bitmask[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	struct nfs42_falloc_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 		.falloc_fh	= NFS_FH(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 		.falloc_offset	= offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 		.falloc_length	= len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 		.falloc_bitmask	= bitmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	struct nfs42_falloc_res res = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 		.falloc_server	= server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	msg->rpc_argp = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	msg->rpc_resp = &res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	status = nfs4_set_rw_stateid(&args.falloc_stateid, lock->open_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 			lock, FMODE_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 		if (status == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 			status = -NFS4ERR_BAD_STATEID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	memcpy(bitmask, server->cache_consistency_bitmask, sizeof(bitmask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	if (server->attr_bitmask[1] & FATTR4_WORD1_SPACE_USED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 		bitmask[1] |= FATTR4_WORD1_SPACE_USED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	res.falloc_fattr = nfs_alloc_fattr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	if (!res.falloc_fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	status = nfs4_call_sync(server->client, server, msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 				&args.seq_args, &res.seq_res, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	if (status == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 		status = nfs_post_op_update_inode_force_wcc(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 							    res.falloc_fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	kfree(res.falloc_fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 				loff_t offset, loff_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	struct inode *inode = file_inode(filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	struct nfs4_exception exception = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	struct nfs_lock_context *lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	lock = nfs_get_lock_context(nfs_file_open_context(filep));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	if (IS_ERR(lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 		return PTR_ERR(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	exception.inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	exception.state = lock->open_context->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	err = nfs_sync_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		err = _nfs42_proc_fallocate(msg, filep, lock, offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 		if (err == -ENOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 			err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 		err = nfs4_handle_exception(server, err, &exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	} while (exception.retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	nfs_put_lock_context(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	return err;
^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) int nfs42_proc_allocate(struct file *filep, loff_t offset, loff_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	struct inode *inode = file_inode(filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	if (!nfs_server_capable(inode, NFS_CAP_ALLOCATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	err = nfs42_proc_fallocate(&msg, filep, offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	if (err == -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 		NFS_SERVER(inode)->caps &= ~NFS_CAP_ALLOCATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DEALLOCATE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	struct inode *inode = file_inode(filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	if (!nfs_server_capable(inode, NFS_CAP_DEALLOCATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	err = nfs42_proc_fallocate(&msg, filep, offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	if (err == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		truncate_pagecache_range(inode, offset, (offset + len) -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	if (err == -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) static int handle_async_copy(struct nfs42_copy_res *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 			     struct nfs_server *dst_server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 			     struct nfs_server *src_server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 			     struct file *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 			     struct file *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 			     nfs4_stateid *src_stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 			     bool *restart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	struct nfs4_copy_state *copy, *tmp_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	int status = NFS4_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	bool found_pending = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	struct nfs_open_context *dst_ctx = nfs_file_open_context(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	struct nfs_open_context *src_ctx = nfs_file_open_context(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	if (!copy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	spin_lock(&dst_server->nfs_client->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	list_for_each_entry(tmp_copy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 				&dst_server->nfs_client->pending_cb_stateids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 				copies) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 		if (memcmp(&res->write_res.stateid, &tmp_copy->stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 				NFS4_STATEID_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 		found_pending = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 		list_del(&tmp_copy->copies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	if (found_pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		spin_unlock(&dst_server->nfs_client->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		kfree(copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 		copy = tmp_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	memcpy(&copy->stateid, &res->write_res.stateid, NFS4_STATEID_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	init_completion(&copy->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	copy->parent_dst_state = dst_ctx->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	copy->parent_src_state = src_ctx->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	list_add_tail(&copy->copies, &dst_server->ss_copies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	spin_unlock(&dst_server->nfs_client->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	if (dst_server != src_server) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 		spin_lock(&src_server->nfs_client->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		list_add_tail(&copy->src_copies, &src_server->ss_copies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		spin_unlock(&src_server->nfs_client->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	status = wait_for_completion_interruptible(&copy->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	spin_lock(&dst_server->nfs_client->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	list_del_init(&copy->copies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	spin_unlock(&dst_server->nfs_client->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	if (dst_server != src_server) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		spin_lock(&src_server->nfs_client->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		list_del_init(&copy->src_copies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		spin_unlock(&src_server->nfs_client->cl_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	if (status == -ERESTARTSYS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		goto out_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	} else if (copy->flags || copy->error == NFS4ERR_PARTNER_NO_AUTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		status = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 		*restart = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		goto out_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	res->write_res.count = copy->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	memcpy(&res->write_res.verifier, &copy->verf, sizeof(copy->verf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	status = -copy->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	kfree(copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) out_cancel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	nfs42_do_offload_cancel_async(dst, &copy->stateid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	if (!nfs42_files_from_same_server(src, dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		nfs42_do_offload_cancel_async(src, src_stateid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) static int process_copy_commit(struct file *dst, loff_t pos_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 			       struct nfs42_copy_res *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	struct nfs_commitres cres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	int status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	cres.verf = kzalloc(sizeof(struct nfs_writeverf), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	if (!cres.verf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	status = nfs4_proc_commit(dst, pos_dst, res->write_res.count, &cres);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	if (nfs_write_verifier_cmp(&res->write_res.verifier.verifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 				    &cres.verf->verifier)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		dprintk("commit verf differs from copy verf\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		status = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	kfree(cres.verf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) static ssize_t _nfs42_proc_copy(struct file *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 				struct nfs_lock_context *src_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 				struct file *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 				struct nfs_lock_context *dst_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 				struct nfs42_copy_args *args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 				struct nfs42_copy_res *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 				struct nl4_server *nss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 				nfs4_stateid *cnr_stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 				bool *restart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COPY],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		.rpc_argp = args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		.rpc_resp = res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	struct inode *dst_inode = file_inode(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	struct inode *src_inode = file_inode(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	struct nfs_server *dst_server = NFS_SERVER(dst_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	struct nfs_server *src_server = NFS_SERVER(src_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	loff_t pos_src = args->src_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	loff_t pos_dst = args->dst_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	size_t count = args->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	ssize_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	if (nss) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		args->cp_src = nss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		nfs4_stateid_copy(&args->src_stateid, cnr_stateid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		status = nfs4_set_rw_stateid(&args->src_stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 				src_lock->open_context, src_lock, FMODE_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 			if (status == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 				status = -NFS4ERR_BAD_STATEID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 			return status;
^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) 	status = nfs_filemap_write_and_wait_range(file_inode(src)->i_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 			pos_src, pos_src + (loff_t)count - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	status = nfs4_set_rw_stateid(&args->dst_stateid, dst_lock->open_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 				     dst_lock, FMODE_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		if (status == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 			status = -NFS4ERR_BAD_STATEID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	status = nfs_sync_inode(dst_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	res->commit_res.verf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	if (args->sync) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		res->commit_res.verf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 			kzalloc(sizeof(struct nfs_writeverf), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		if (!res->commit_res.verf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	set_bit(NFS_CLNT_SRC_SSC_COPY_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		&src_lock->open_context->state->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	set_bit(NFS_CLNT_DST_SSC_COPY_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		&dst_lock->open_context->state->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	status = nfs4_call_sync(dst_server->client, dst_server, &msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 				&args->seq_args, &res->seq_res, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	if (status == -ENOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		dst_server->caps &= ~NFS_CAP_COPY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	if (args->sync &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		nfs_write_verifier_cmp(&res->write_res.verifier.verifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 				    &res->commit_res.verf->verifier)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		status = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	if (!res->synchronous) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		status = handle_async_copy(res, dst_server, src_server, src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 				dst, &args->src_stateid, restart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	if ((!res->synchronous || !args->sync) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			res->write_res.verifier.committed != NFS_FILE_SYNC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		status = process_copy_commit(dst, pos_dst, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	WARN_ON_ONCE(invalidate_inode_pages2_range(dst_inode->i_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 					pos_dst >> PAGE_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 					(pos_dst + res->write_res.count - 1) >> PAGE_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	spin_lock(&dst_inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	NFS_I(dst_inode)->cache_validity |= (NFS_INO_REVAL_PAGECACHE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 			NFS_INO_REVAL_FORCED | NFS_INO_INVALID_SIZE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			NFS_INO_INVALID_ATTR | NFS_INO_INVALID_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	spin_unlock(&dst_inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	spin_lock(&src_inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	NFS_I(src_inode)->cache_validity |= (NFS_INO_REVAL_PAGECACHE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 			NFS_INO_REVAL_FORCED | NFS_INO_INVALID_ATIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	spin_unlock(&src_inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	status = res->write_res.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	if (args->sync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		kfree(res->commit_res.verf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			struct file *dst, loff_t pos_dst, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 			struct nl4_server *nss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			nfs4_stateid *cnr_stateid, bool sync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	struct nfs_server *server = NFS_SERVER(file_inode(dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	struct nfs_lock_context *src_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	struct nfs_lock_context *dst_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	struct nfs42_copy_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		.src_fh		= NFS_FH(file_inode(src)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		.src_pos	= pos_src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		.dst_fh		= NFS_FH(file_inode(dst)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		.dst_pos	= pos_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		.count		= count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		.sync		= sync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	struct nfs42_copy_res res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	struct nfs4_exception src_exception = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		.inode		= file_inode(src),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		.stateid	= &args.src_stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	struct nfs4_exception dst_exception = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		.inode		= file_inode(dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		.stateid	= &args.dst_stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	ssize_t err, err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	bool restart = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	src_lock = nfs_get_lock_context(nfs_file_open_context(src));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	if (IS_ERR(src_lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		return PTR_ERR(src_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	src_exception.state = src_lock->open_context->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	dst_lock = nfs_get_lock_context(nfs_file_open_context(dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	if (IS_ERR(dst_lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		err = PTR_ERR(dst_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		goto out_put_src_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	dst_exception.state = dst_lock->open_context->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		inode_lock(file_inode(dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		err = _nfs42_proc_copy(src, src_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 				dst, dst_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 				&args, &res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 				nss, cnr_stateid, &restart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		inode_unlock(file_inode(dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		if (err >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		if (err == -ENOTSUPP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 				nfs42_files_from_same_server(src, dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 			err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		} else if (err == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 			if (!restart) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 				dst_exception.retry = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		} else if (err == -NFS4ERR_OFFLOAD_NO_REQS && !args.sync) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 			args.sync = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 			dst_exception.retry = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		} else if ((err == -ESTALE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 				err == -NFS4ERR_OFFLOAD_DENIED ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 				err == -ENOTSUPP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 				!nfs42_files_from_same_server(src, dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 			nfs42_do_offload_cancel_async(src, &args.src_stateid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		err2 = nfs4_handle_exception(server, err, &src_exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		err  = nfs4_handle_exception(server, err, &dst_exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 			err = err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	} while (src_exception.retry || dst_exception.retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	nfs_put_lock_context(dst_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) out_put_src_lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	nfs_put_lock_context(src_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) struct nfs42_offloadcancel_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	struct nfs_server *seq_server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	struct nfs42_offload_status_args args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	struct nfs42_offload_status_res res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) static void nfs42_offload_cancel_prepare(struct rpc_task *task, void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	struct nfs42_offloadcancel_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	nfs4_setup_sequence(data->seq_server->nfs_client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 				&data->args.osa_seq_args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 				&data->res.osr_seq_res, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) static void nfs42_offload_cancel_done(struct rpc_task *task, void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	struct nfs42_offloadcancel_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	nfs41_sequence_done(task, &data->res.osr_seq_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	if (task->tk_status &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		nfs4_async_handle_error(task, data->seq_server, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 			NULL) == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		rpc_restart_call_prepare(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) static void nfs42_free_offloadcancel_data(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) static const struct rpc_call_ops nfs42_offload_cancel_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	.rpc_call_prepare = nfs42_offload_cancel_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	.rpc_call_done = nfs42_offload_cancel_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	.rpc_release = nfs42_free_offloadcancel_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) static int nfs42_do_offload_cancel_async(struct file *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 					 nfs4_stateid *stateid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	struct nfs_server *dst_server = NFS_SERVER(file_inode(dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	struct nfs42_offloadcancel_data *data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	struct nfs_open_context *ctx = nfs_file_open_context(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	struct rpc_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OFFLOAD_CANCEL],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 		.rpc_cred = ctx->cred,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	struct rpc_task_setup task_setup_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		.rpc_client = dst_server->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		.rpc_message = &msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		.callback_ops = &nfs42_offload_cancel_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		.workqueue = nfsiod_workqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		.flags = RPC_TASK_ASYNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	if (!(dst_server->caps & NFS_CAP_OFFLOAD_CANCEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	data = kzalloc(sizeof(struct nfs42_offloadcancel_data), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	if (data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	data->seq_server = dst_server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	data->args.osa_src_fh = NFS_FH(file_inode(dst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	memcpy(&data->args.osa_stateid, stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		sizeof(data->args.osa_stateid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	msg.rpc_argp = &data->args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	msg.rpc_resp = &data->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	task_setup_data.callback_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	nfs4_init_sequence(&data->args.osa_seq_args, &data->res.osr_seq_res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			   1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	task = rpc_run_task(&task_setup_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	if (IS_ERR(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		return PTR_ERR(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	status = rpc_wait_for_completion_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	if (status == -ENOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		dst_server->caps &= ~NFS_CAP_OFFLOAD_CANCEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	rpc_put_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) static int _nfs42_proc_copy_notify(struct file *src, struct file *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 				   struct nfs42_copy_notify_args *args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 				   struct nfs42_copy_notify_res *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	struct nfs_server *src_server = NFS_SERVER(file_inode(src));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COPY_NOTIFY],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		.rpc_argp = args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		.rpc_resp = res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	struct nfs_open_context *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	struct nfs_lock_context *l_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	ctx = get_nfs_open_context(nfs_file_open_context(src));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	l_ctx = nfs_get_lock_context(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	if (IS_ERR(l_ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		return PTR_ERR(l_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	status = nfs4_set_rw_stateid(&args->cna_src_stateid, ctx, l_ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 				     FMODE_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	nfs_put_lock_context(l_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		if (status == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 			status = -NFS4ERR_BAD_STATEID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	status = nfs4_call_sync(src_server->client, src_server, &msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 				&args->cna_seq_args, &res->cnr_seq_res, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	if (status == -ENOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 		src_server->caps &= ~NFS_CAP_COPY_NOTIFY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	put_nfs_open_context(nfs_file_open_context(src));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	return status;
^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) int nfs42_proc_copy_notify(struct file *src, struct file *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 				struct nfs42_copy_notify_res *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	struct nfs_server *src_server = NFS_SERVER(file_inode(src));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	struct nfs42_copy_notify_args *args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	struct nfs4_exception exception = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		.inode = file_inode(src),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	if (!(src_server->caps & NFS_CAP_COPY_NOTIFY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	args = kzalloc(sizeof(struct nfs42_copy_notify_args), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	if (args == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	args->cna_src_fh  = NFS_FH(file_inode(src)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	args->cna_dst.nl4_type = NL4_NETADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	nfs42_set_netaddr(dst, &args->cna_dst.u.nl4_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	exception.stateid = &args->cna_src_stateid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		status = _nfs42_proc_copy_notify(src, dst, args, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 		if (status == -ENOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			status = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		status = nfs4_handle_exception(src_server, status, &exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	} while (exception.retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	kfree(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) static loff_t _nfs42_proc_llseek(struct file *filep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		struct nfs_lock_context *lock, loff_t offset, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	struct inode *inode = file_inode(filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	struct nfs42_seek_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		.sa_fh		= NFS_FH(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		.sa_offset	= offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		.sa_what	= (whence == SEEK_HOLE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 					NFS4_CONTENT_HOLE : NFS4_CONTENT_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	struct nfs42_seek_res res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEEK],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		.rpc_argp = &args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		.rpc_resp = &res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	if (!nfs_server_capable(inode, NFS_CAP_SEEK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	status = nfs4_set_rw_stateid(&args.sa_stateid, lock->open_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 			lock, FMODE_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		if (status == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 			status = -NFS4ERR_BAD_STATEID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	status = nfs_filemap_write_and_wait_range(inode->i_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 			offset, LLONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	status = nfs4_call_sync(server->client, server, &msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 				&args.seq_args, &res.seq_res, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	if (status == -ENOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		server->caps &= ~NFS_CAP_SEEK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	if (whence == SEEK_DATA && res.sr_eof)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		return -NFS4ERR_NXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		return vfs_setpos(filep, res.sr_offset, inode->i_sb->s_maxbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	struct nfs_server *server = NFS_SERVER(file_inode(filep));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	struct nfs4_exception exception = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	struct nfs_lock_context *lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	loff_t err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	lock = nfs_get_lock_context(nfs_file_open_context(filep));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	if (IS_ERR(lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		return PTR_ERR(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	exception.inode = file_inode(filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	exception.state = lock->open_context->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		err = _nfs42_proc_llseek(filep, lock, offset, whence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		if (err >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		if (err == -ENOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		err = nfs4_handle_exception(server, err, &exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	} while (exception.retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	nfs_put_lock_context(lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) nfs42_layoutstat_prepare(struct rpc_task *task, void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	struct nfs42_layoutstat_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	struct inode *inode = data->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	struct pnfs_layout_hdr *lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	lo = NFS_I(inode)->layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	if (!pnfs_layout_is_valid(lo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		rpc_exit(task, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	nfs4_stateid_copy(&data->args.stateid, &lo->plh_stateid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	nfs4_setup_sequence(server->nfs_client, &data->args.seq_args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 			    &data->res.seq_res, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) nfs42_layoutstat_done(struct rpc_task *task, void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	struct nfs42_layoutstat_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	struct inode *inode = data->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	struct pnfs_layout_hdr *lo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	if (!nfs4_sequence_done(task, &data->res.seq_res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	switch (task->tk_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	case -NFS4ERR_BADHANDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	case -ESTALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		pnfs_destroy_layout(NFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	case -NFS4ERR_EXPIRED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	case -NFS4ERR_ADMIN_REVOKED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	case -NFS4ERR_DELEG_REVOKED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	case -NFS4ERR_STALE_STATEID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	case -NFS4ERR_BAD_STATEID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		lo = NFS_I(inode)->layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		if (pnfs_layout_is_valid(lo) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		    nfs4_stateid_match(&data->args.stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 					     &lo->plh_stateid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 			LIST_HEAD(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 			 * Mark the bad layout state as invalid, then retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 			 * with the current stateid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 			pnfs_mark_layout_stateid_invalid(lo, &head);
^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) 			pnfs_free_lseg_list(&head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 			nfs_commit_inode(inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 			spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	case -NFS4ERR_OLD_STATEID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		lo = NFS_I(inode)->layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		if (pnfs_layout_is_valid(lo) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		    nfs4_stateid_match_other(&data->args.stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 					&lo->plh_stateid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 			/* Do we need to delay before resending? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 			if (!nfs4_stateid_is_newer(&lo->plh_stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 						&data->args.stateid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 				rpc_delay(task, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 			rpc_restart_call_prepare(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	case -ENOTSUPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	case -EOPNOTSUPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		NFS_SERVER(inode)->caps &= ~NFS_CAP_LAYOUTSTATS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	trace_nfs4_layoutstats(inode, &data->args.stateid, task->tk_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) nfs42_layoutstat_release(void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	struct nfs42_layoutstat_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	struct nfs42_layoutstat_devinfo *devinfo = data->args.devinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	for (i = 0; i < data->args.num_dev; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		if (devinfo[i].ld_private.ops && devinfo[i].ld_private.ops->free)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 			devinfo[i].ld_private.ops->free(&devinfo[i].ld_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	pnfs_put_layout_hdr(NFS_I(data->args.inode)->layout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	smp_mb__before_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	clear_bit(NFS_INO_LAYOUTSTATS, &NFS_I(data->args.inode)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	nfs_iput_and_deactive(data->inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	kfree(data->args.devinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) static const struct rpc_call_ops nfs42_layoutstat_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	.rpc_call_prepare = nfs42_layoutstat_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	.rpc_call_done = nfs42_layoutstat_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	.rpc_release = nfs42_layoutstat_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) int nfs42_proc_layoutstats_generic(struct nfs_server *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 				   struct nfs42_layoutstat_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTSTATS],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		.rpc_argp = &data->args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		.rpc_resp = &data->res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	struct rpc_task_setup task_setup = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		.rpc_client = server->client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		.rpc_message = &msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		.callback_ops = &nfs42_layoutstat_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		.callback_data = data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		.flags = RPC_TASK_ASYNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	struct rpc_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	data->inode = nfs_igrab_and_active(data->args.inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	if (!data->inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		nfs42_layoutstat_release(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	task = rpc_run_task(&task_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	if (IS_ERR(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		return PTR_ERR(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	rpc_put_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) static struct nfs42_layouterror_data *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) nfs42_alloc_layouterror_data(struct pnfs_layout_segment *lseg, gfp_t gfp_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	struct nfs42_layouterror_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	struct inode *inode = lseg->pls_layout->plh_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	data = kzalloc(sizeof(*data), gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	if (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		data->args.inode = data->inode = nfs_igrab_and_active(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		if (data->inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 			data->lseg = pnfs_get_lseg(lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 			if (data->lseg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 				return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 			nfs_iput_and_deactive(data->inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) nfs42_free_layouterror_data(struct nfs42_layouterror_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	pnfs_put_lseg(data->lseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	nfs_iput_and_deactive(data->inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) nfs42_layouterror_prepare(struct rpc_task *task, void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	struct nfs42_layouterror_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	struct inode *inode = data->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	struct pnfs_layout_hdr *lo = data->lseg->pls_layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	if (!pnfs_layout_is_valid(lo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		rpc_exit(task, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	for (i = 0; i < data->args.num_errors; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		nfs4_stateid_copy(&data->args.errors[i].stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 				&lo->plh_stateid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	nfs4_setup_sequence(server->nfs_client, &data->args.seq_args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 			    &data->res.seq_res, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) nfs42_layouterror_done(struct rpc_task *task, void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	struct nfs42_layouterror_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	struct inode *inode = data->inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	struct pnfs_layout_hdr *lo = data->lseg->pls_layout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	if (!nfs4_sequence_done(task, &data->res.seq_res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	switch (task->tk_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	case -NFS4ERR_BADHANDLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	case -ESTALE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		pnfs_destroy_layout(NFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	case -NFS4ERR_EXPIRED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	case -NFS4ERR_ADMIN_REVOKED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	case -NFS4ERR_DELEG_REVOKED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	case -NFS4ERR_STALE_STATEID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	case -NFS4ERR_BAD_STATEID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		if (pnfs_layout_is_valid(lo) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		    nfs4_stateid_match(&data->args.errors[0].stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 					     &lo->plh_stateid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 			LIST_HEAD(head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 			 * Mark the bad layout state as invalid, then retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 			 * with the current stateid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 			pnfs_mark_layout_stateid_invalid(lo, &head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 			spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 			pnfs_free_lseg_list(&head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 			nfs_commit_inode(inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 			spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	case -NFS4ERR_OLD_STATEID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		if (pnfs_layout_is_valid(lo) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		    nfs4_stateid_match_other(&data->args.errors[0].stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 					&lo->plh_stateid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 			/* Do we need to delay before resending? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 			if (!nfs4_stateid_is_newer(&lo->plh_stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 						&data->args.errors[0].stateid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 				rpc_delay(task, HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 			rpc_restart_call_prepare(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	case -ENOTSUPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	case -EOPNOTSUPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		NFS_SERVER(inode)->caps &= ~NFS_CAP_LAYOUTERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	trace_nfs4_layouterror(inode, &data->args.errors[0].stateid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 			       task->tk_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) nfs42_layouterror_release(void *calldata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	struct nfs42_layouterror_data *data = calldata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	nfs42_free_layouterror_data(data);
^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 const struct rpc_call_ops nfs42_layouterror_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	.rpc_call_prepare = nfs42_layouterror_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	.rpc_call_done = nfs42_layouterror_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	.rpc_release = nfs42_layouterror_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) int nfs42_proc_layouterror(struct pnfs_layout_segment *lseg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		const struct nfs42_layout_error *errors, size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	struct inode *inode = lseg->pls_layout->plh_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	struct nfs42_layouterror_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	struct rpc_task *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTERROR],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	struct rpc_task_setup task_setup = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		.rpc_message = &msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		.callback_ops = &nfs42_layouterror_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		.flags = RPC_TASK_ASYNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	if (!nfs_server_capable(inode, NFS_CAP_LAYOUTERROR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	if (n > NFS42_LAYOUTERROR_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	data = nfs42_alloc_layouterror_data(lseg, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	for (i = 0; i < n; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		data->args.errors[i] = errors[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		data->args.num_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		data->res.num_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	msg.rpc_argp = &data->args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	msg.rpc_resp = &data->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	task_setup.callback_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	task_setup.rpc_client = NFS_SERVER(inode)->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	task = rpc_run_task(&task_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	if (IS_ERR(task))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		return PTR_ERR(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	rpc_put_task(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) EXPORT_SYMBOL_GPL(nfs42_proc_layouterror);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) static int _nfs42_proc_clone(struct rpc_message *msg, struct file *src_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		struct file *dst_f, struct nfs_lock_context *src_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		struct nfs_lock_context *dst_lock, loff_t src_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		loff_t dst_offset, loff_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	struct inode *src_inode = file_inode(src_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	struct inode *dst_inode = file_inode(dst_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	struct nfs_server *server = NFS_SERVER(dst_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	struct nfs42_clone_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		.src_fh = NFS_FH(src_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		.dst_fh = NFS_FH(dst_inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		.src_offset = src_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 		.dst_offset = dst_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 		.count = count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		.dst_bitmask = server->cache_consistency_bitmask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	struct nfs42_clone_res res = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		.server	= server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	msg->rpc_argp = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	msg->rpc_resp = &res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	status = nfs4_set_rw_stateid(&args.src_stateid, src_lock->open_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 			src_lock, FMODE_READ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		if (status == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 			status = -NFS4ERR_BAD_STATEID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	status = nfs4_set_rw_stateid(&args.dst_stateid, dst_lock->open_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 			dst_lock, FMODE_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		if (status == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 			status = -NFS4ERR_BAD_STATEID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	res.dst_fattr = nfs_alloc_fattr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	if (!res.dst_fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	status = nfs4_call_sync(server->client, server, msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 				&args.seq_args, &res.seq_res, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	if (status == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		status = nfs_post_op_update_inode(dst_inode, res.dst_fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	kfree(res.dst_fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) int nfs42_proc_clone(struct file *src_f, struct file *dst_f,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		     loff_t src_offset, loff_t dst_offset, loff_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLONE],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	struct inode *inode = file_inode(src_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	struct nfs_server *server = NFS_SERVER(file_inode(src_f));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	struct nfs_lock_context *src_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	struct nfs_lock_context *dst_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	struct nfs4_exception src_exception = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	struct nfs4_exception dst_exception = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	int err, err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	if (!nfs_server_capable(inode, NFS_CAP_CLONE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	src_lock = nfs_get_lock_context(nfs_file_open_context(src_f));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	if (IS_ERR(src_lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		return PTR_ERR(src_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	src_exception.inode = file_inode(src_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	src_exception.state = src_lock->open_context->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	dst_lock = nfs_get_lock_context(nfs_file_open_context(dst_f));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	if (IS_ERR(dst_lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 		err = PTR_ERR(dst_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		goto out_put_src_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	dst_exception.inode = file_inode(dst_f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	dst_exception.state = dst_lock->open_context->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		err = _nfs42_proc_clone(&msg, src_f, dst_f, src_lock, dst_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 					src_offset, dst_offset, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		if (err == -ENOTSUPP || err == -EOPNOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 			NFS_SERVER(inode)->caps &= ~NFS_CAP_CLONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 			err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		err2 = nfs4_handle_exception(server, err, &src_exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		err = nfs4_handle_exception(server, err, &dst_exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 			err = err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	} while (src_exception.retry || dst_exception.retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	nfs_put_lock_context(dst_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) out_put_src_lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	nfs_put_lock_context(src_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) #define NFS4XATTR_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) static int _nfs42_proc_removexattr(struct inode *inode, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	struct nfs42_removexattrargs args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		.fh = NFS_FH(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		.xattr_name = name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	struct nfs42_removexattrres res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVEXATTR],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		.rpc_argp = &args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		.rpc_resp = &res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	unsigned long timestamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	ret = nfs4_call_sync(server->client, server, &msg, &args.seq_args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	    &res.seq_res, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		nfs4_update_changeattr(inode, &res.cinfo, timestamp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	return ret;
^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) static int _nfs42_proc_setxattr(struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 				const void *buf, size_t buflen, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	struct page *pages[NFS4XATTR_MAXPAGES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	struct nfs42_setxattrargs arg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		.fh		= NFS_FH(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		.xattr_pages	= pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		.xattr_len	= buflen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		.xattr_name	= name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 		.xattr_flags	= flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	struct nfs42_setxattrres res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_SETXATTR],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		.rpc_argp	= &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 		.rpc_resp	= &res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	int ret, np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	unsigned long timestamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	if (buflen > server->sxasize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 		return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	if (buflen > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		np = nfs4_buf_to_pages_noslab(buf, buflen, arg.xattr_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 		if (np < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 			return np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 		np = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	    &res.seq_res, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	for (; np > 0; np--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 		put_page(pages[np - 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 		nfs4_update_changeattr(inode, &res.cinfo, timestamp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) static ssize_t _nfs42_proc_getxattr(struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 				void *buf, size_t buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	struct page *pages[NFS4XATTR_MAXPAGES] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	struct nfs42_getxattrargs arg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		.fh		= NFS_FH(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		.xattr_pages	= pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		.xattr_len	= buflen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 		.xattr_name	= name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	struct nfs42_getxattrres res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_GETXATTR],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		.rpc_argp	= &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 		.rpc_resp	= &res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	int ret, np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	    &res.seq_res, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	 * Normally, the caching is done one layer up, but for successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	 * RPCS, always cache the result here, even if the caller was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	 * just querying the length, or if the reply was too big for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	 * the caller. This avoids a second RPC in the case of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	 * common query-alloc-retrieve cycle for xattrs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	 * Note that xattr_len is always capped to XATTR_SIZE_MAX.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	nfs4_xattr_cache_add(inode, name, NULL, pages, res.xattr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	if (buflen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 		if (res.xattr_len > buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 			return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		_copy_from_pages(buf, pages, 0, res.xattr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	np = DIV_ROUND_UP(res.xattr_len, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	while (--np >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 		__free_page(pages[np]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	return res.xattr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) static ssize_t _nfs42_proc_listxattrs(struct inode *inode, void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 				 size_t buflen, u64 *cookiep, bool *eofp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	struct nfs_server *server = NFS_SERVER(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	struct page **pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	struct nfs42_listxattrsargs arg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		.fh		= NFS_FH(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 		.cookie		= *cookiep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	struct nfs42_listxattrsres res = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 		.eof = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		.xattr_buf = buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		.xattr_len = buflen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	struct rpc_message msg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_LISTXATTRS],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		.rpc_argp	= &arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		.rpc_resp	= &res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	u32 xdrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	int ret, np, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	res.scratch = alloc_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	if (!res.scratch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	xdrlen = nfs42_listxattr_xdrsize(buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	if (xdrlen > server->lxasize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 		xdrlen = server->lxasize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	np = xdrlen / PAGE_SIZE + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	pages = kcalloc(np, sizeof(struct page *), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	if (!pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 		goto out_free_scratch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	for (i = 0; i < np; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		pages[i] = alloc_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		if (!pages[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 			goto out_free_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 	arg.xattr_pages = pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	arg.count = xdrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	    &res.seq_res, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		ret = res.copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		*cookiep = res.cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		*eofp = res.eof;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) out_free_pages:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	while (--np >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 		if (pages[np])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 			__free_page(pages[np]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	kfree(pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) out_free_scratch:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	__free_page(res.scratch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) ssize_t nfs42_proc_getxattr(struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 			      void *buf, size_t buflen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	struct nfs4_exception exception = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	ssize_t err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		err = _nfs42_proc_getxattr(inode, name, buf, buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		if (err >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		err = nfs4_handle_exception(NFS_SERVER(inode), err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 				&exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 	} while (exception.retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) int nfs42_proc_setxattr(struct inode *inode, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 			      const void *buf, size_t buflen, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	struct nfs4_exception exception = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 		err = _nfs42_proc_setxattr(inode, name, buf, buflen, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 		err = nfs4_handle_exception(NFS_SERVER(inode), err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 				&exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	} while (exception.retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) ssize_t nfs42_proc_listxattrs(struct inode *inode, void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 			      size_t buflen, u64 *cookiep, bool *eofp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	struct nfs4_exception exception = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	ssize_t err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		err = _nfs42_proc_listxattrs(inode, buf, buflen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		    cookiep, eofp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		if (err >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		err = nfs4_handle_exception(NFS_SERVER(inode), err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 				&exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	} while (exception.retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) int nfs42_proc_removexattr(struct inode *inode, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	struct nfs4_exception exception = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		err = _nfs42_proc_removexattr(inode, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		err = nfs4_handle_exception(NFS_SERVER(inode), err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 				&exception);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	} while (exception.retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) }