| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *  fs/nfs/nfs4proc.c | 
 | 3 |  * | 
 | 4 |  *  Client-side procedure declarations for NFSv4. | 
 | 5 |  * | 
 | 6 |  *  Copyright (c) 2002 The Regents of the University of Michigan. | 
 | 7 |  *  All rights reserved. | 
 | 8 |  * | 
 | 9 |  *  Kendrick Smith <kmsmith@umich.edu> | 
 | 10 |  *  Andy Adamson   <andros@umich.edu> | 
 | 11 |  * | 
 | 12 |  *  Redistribution and use in source and binary forms, with or without | 
 | 13 |  *  modification, are permitted provided that the following conditions | 
 | 14 |  *  are met: | 
 | 15 |  * | 
 | 16 |  *  1. Redistributions of source code must retain the above copyright | 
 | 17 |  *     notice, this list of conditions and the following disclaimer. | 
 | 18 |  *  2. Redistributions in binary form must reproduce the above copyright | 
 | 19 |  *     notice, this list of conditions and the following disclaimer in the | 
 | 20 |  *     documentation and/or other materials provided with the distribution. | 
 | 21 |  *  3. Neither the name of the University nor the names of its | 
 | 22 |  *     contributors may be used to endorse or promote products derived | 
 | 23 |  *     from this software without specific prior written permission. | 
 | 24 |  * | 
 | 25 |  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | 
 | 26 |  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 
 | 27 |  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
 | 28 |  *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 
 | 29 |  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 
 | 30 |  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 
 | 31 |  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | 
 | 32 |  *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | 
 | 33 |  *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | 
 | 34 |  *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 
 | 35 |  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
 | 36 |  */ | 
 | 37 |  | 
 | 38 | #include <linux/mm.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> | 
 | 40 | #include <linux/errno.h> | 
 | 41 | #include <linux/string.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/sunrpc/clnt.h> | 
 | 44 | #include <linux/nfs.h> | 
 | 45 | #include <linux/nfs4.h> | 
 | 46 | #include <linux/nfs_fs.h> | 
 | 47 | #include <linux/nfs_page.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/namei.h> | 
| Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 49 | #include <linux/mount.h> | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 50 | #include <linux/module.h> | 
| Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 51 | #include <linux/sunrpc/bc_xprt.h> | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 52 | #include <linux/xattr.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 |  | 
| Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 54 | #include "nfs4_fs.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include "delegation.h" | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 56 | #include "internal.h" | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 57 | #include "iostat.h" | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 58 | #include "callback.h" | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 59 | #include "pnfs.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 |  | 
 | 61 | #define NFSDBG_FACILITY		NFSDBG_PROC | 
 | 62 |  | 
| Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 63 | #define NFS4_POLL_RETRY_MIN	(HZ/10) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #define NFS4_POLL_RETRY_MAX	(15*HZ) | 
 | 65 |  | 
| Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 66 | #define NFS4_MAX_LOOP_ON_RECOVER (10) | 
 | 67 |  | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 68 | struct nfs4_opendata; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 69 | static int _nfs4_proc_open(struct nfs4_opendata *data); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 70 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 72 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); | 
| Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 73 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); | 
 | 74 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); | 
| Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 75 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, | 
 | 76 | 			    struct nfs_fattr *fattr, struct iattr *sattr, | 
 | 77 | 			    struct nfs4_state *state); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* Prevent leaks of NFSv4 errors into userland */ | 
| WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 80 | static int nfs4_map_errors(int err) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 82 | 	if (err >= -1000) | 
 | 83 | 		return err; | 
 | 84 | 	switch (err) { | 
 | 85 | 	case -NFS4ERR_RESOURCE: | 
 | 86 | 		return -EREMOTEIO; | 
 | 87 | 	default: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | 		dprintk("%s could not handle NFSv4 error %d\n", | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 89 | 				__func__, -err); | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 90 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | 	} | 
| Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 92 | 	return -EIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } | 
 | 94 |  | 
 | 95 | /* | 
 | 96 |  * This is our standard bitmap for GETATTR requests. | 
 | 97 |  */ | 
 | 98 | const u32 nfs4_fattr_bitmap[2] = { | 
 | 99 | 	FATTR4_WORD0_TYPE | 
 | 100 | 	| FATTR4_WORD0_CHANGE | 
 | 101 | 	| FATTR4_WORD0_SIZE | 
 | 102 | 	| FATTR4_WORD0_FSID | 
 | 103 | 	| FATTR4_WORD0_FILEID, | 
 | 104 | 	FATTR4_WORD1_MODE | 
 | 105 | 	| FATTR4_WORD1_NUMLINKS | 
 | 106 | 	| FATTR4_WORD1_OWNER | 
 | 107 | 	| FATTR4_WORD1_OWNER_GROUP | 
 | 108 | 	| FATTR4_WORD1_RAWDEV | 
 | 109 | 	| FATTR4_WORD1_SPACE_USED | 
 | 110 | 	| FATTR4_WORD1_TIME_ACCESS | 
 | 111 | 	| FATTR4_WORD1_TIME_METADATA | 
 | 112 | 	| FATTR4_WORD1_TIME_MODIFY | 
 | 113 | }; | 
 | 114 |  | 
 | 115 | const u32 nfs4_statfs_bitmap[2] = { | 
 | 116 | 	FATTR4_WORD0_FILES_AVAIL | 
 | 117 | 	| FATTR4_WORD0_FILES_FREE | 
 | 118 | 	| FATTR4_WORD0_FILES_TOTAL, | 
 | 119 | 	FATTR4_WORD1_SPACE_AVAIL | 
 | 120 | 	| FATTR4_WORD1_SPACE_FREE | 
 | 121 | 	| FATTR4_WORD1_SPACE_TOTAL | 
 | 122 | }; | 
 | 123 |  | 
| Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 124 | const u32 nfs4_pathconf_bitmap[2] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | 	FATTR4_WORD0_MAXLINK | 
 | 126 | 	| FATTR4_WORD0_MAXNAME, | 
 | 127 | 	0 | 
 | 128 | }; | 
 | 129 |  | 
 | 130 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE | 
 | 131 | 			| FATTR4_WORD0_MAXREAD | 
 | 132 | 			| FATTR4_WORD0_MAXWRITE | 
 | 133 | 			| FATTR4_WORD0_LEASE_TIME, | 
| Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 134 | 			FATTR4_WORD1_TIME_DELTA | 
| Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 135 | 			| FATTR4_WORD1_FS_LAYOUT_TYPES | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | }; | 
 | 137 |  | 
| Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 138 | const u32 nfs4_fs_locations_bitmap[2] = { | 
 | 139 | 	FATTR4_WORD0_TYPE | 
 | 140 | 	| FATTR4_WORD0_CHANGE | 
 | 141 | 	| FATTR4_WORD0_SIZE | 
 | 142 | 	| FATTR4_WORD0_FSID | 
 | 143 | 	| FATTR4_WORD0_FILEID | 
 | 144 | 	| FATTR4_WORD0_FS_LOCATIONS, | 
 | 145 | 	FATTR4_WORD1_MODE | 
 | 146 | 	| FATTR4_WORD1_NUMLINKS | 
 | 147 | 	| FATTR4_WORD1_OWNER | 
 | 148 | 	| FATTR4_WORD1_OWNER_GROUP | 
 | 149 | 	| FATTR4_WORD1_RAWDEV | 
 | 150 | 	| FATTR4_WORD1_SPACE_USED | 
 | 151 | 	| FATTR4_WORD1_TIME_ACCESS | 
 | 152 | 	| FATTR4_WORD1_TIME_METADATA | 
 | 153 | 	| FATTR4_WORD1_TIME_MODIFY | 
 | 154 | 	| FATTR4_WORD1_MOUNTED_ON_FILEID | 
 | 155 | }; | 
 | 156 |  | 
| Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 157 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | 		struct nfs4_readdir_arg *readdir) | 
 | 159 | { | 
| Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 160 | 	__be32 *start, *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 |  | 
 | 162 | 	BUG_ON(readdir->count < 80); | 
 | 163 | 	if (cookie > 2) { | 
| Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 164 | 		readdir->cookie = cookie; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | 		memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); | 
 | 166 | 		return; | 
 | 167 | 	} | 
 | 168 |  | 
 | 169 | 	readdir->cookie = 0; | 
 | 170 | 	memset(&readdir->verifier, 0, sizeof(readdir->verifier)); | 
 | 171 | 	if (cookie == 2) | 
 | 172 | 		return; | 
 | 173 | 	 | 
 | 174 | 	/* | 
 | 175 | 	 * NFSv4 servers do not return entries for '.' and '..' | 
 | 176 | 	 * Therefore, we fake these entries here.  We let '.' | 
 | 177 | 	 * have cookie 0 and '..' have cookie 1.  Note that | 
 | 178 | 	 * when talking to the server, we always send cookie 0 | 
 | 179 | 	 * instead of 1 or 2. | 
 | 180 | 	 */ | 
| Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 181 | 	start = p = kmap_atomic(*readdir->pages, KM_USER0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | 	 | 
 | 183 | 	if (cookie == 0) { | 
 | 184 | 		*p++ = xdr_one;                                  /* next */ | 
 | 185 | 		*p++ = xdr_zero;                   /* cookie, first word */ | 
 | 186 | 		*p++ = xdr_one;                   /* cookie, second word */ | 
 | 187 | 		*p++ = xdr_one;                             /* entry len */ | 
 | 188 | 		memcpy(p, ".\0\0\0", 4);                        /* entry */ | 
 | 189 | 		p++; | 
 | 190 | 		*p++ = xdr_one;                         /* bitmap length */ | 
 | 191 | 		*p++ = htonl(FATTR4_WORD0_FILEID);             /* bitmap */ | 
 | 192 | 		*p++ = htonl(8);              /* attribute buffer length */ | 
| Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 193 | 		p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | 	} | 
 | 195 | 	 | 
 | 196 | 	*p++ = xdr_one;                                  /* next */ | 
 | 197 | 	*p++ = xdr_zero;                   /* cookie, first word */ | 
 | 198 | 	*p++ = xdr_two;                   /* cookie, second word */ | 
 | 199 | 	*p++ = xdr_two;                             /* entry len */ | 
 | 200 | 	memcpy(p, "..\0\0", 4);                         /* entry */ | 
 | 201 | 	p++; | 
 | 202 | 	*p++ = xdr_one;                         /* bitmap length */ | 
 | 203 | 	*p++ = htonl(FATTR4_WORD0_FILEID);             /* bitmap */ | 
 | 204 | 	*p++ = htonl(8);              /* attribute buffer length */ | 
| Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 205 | 	p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 |  | 
 | 207 | 	readdir->pgbase = (char *)p - (char *)start; | 
 | 208 | 	readdir->count -= readdir->pgbase; | 
 | 209 | 	kunmap_atomic(start, KM_USER0); | 
 | 210 | } | 
 | 211 |  | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 212 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) | 
 | 213 | { | 
 | 214 | 	int res; | 
 | 215 |  | 
 | 216 | 	might_sleep(); | 
 | 217 |  | 
| Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 218 | 	res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, | 
| Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 219 | 			nfs_wait_bit_killable, TASK_KILLABLE); | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 220 | 	return res; | 
 | 221 | } | 
 | 222 |  | 
 | 223 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) | 
 | 224 | { | 
 | 225 | 	int res = 0; | 
 | 226 |  | 
 | 227 | 	might_sleep(); | 
 | 228 |  | 
 | 229 | 	if (*timeout <= 0) | 
 | 230 | 		*timeout = NFS4_POLL_RETRY_MIN; | 
 | 231 | 	if (*timeout > NFS4_POLL_RETRY_MAX) | 
 | 232 | 		*timeout = NFS4_POLL_RETRY_MAX; | 
 | 233 | 	schedule_timeout_killable(*timeout); | 
 | 234 | 	if (fatal_signal_pending(current)) | 
 | 235 | 		res = -ERESTARTSYS; | 
 | 236 | 	*timeout <<= 1; | 
 | 237 | 	return res; | 
 | 238 | } | 
 | 239 |  | 
 | 240 | /* This is the error handling routine for processes that are allowed | 
 | 241 |  * to sleep. | 
 | 242 |  */ | 
 | 243 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) | 
 | 244 | { | 
 | 245 | 	struct nfs_client *clp = server->nfs_client; | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 246 | 	struct nfs4_state *state = exception->state; | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 247 | 	int ret = errorcode; | 
 | 248 |  | 
 | 249 | 	exception->retry = 0; | 
 | 250 | 	switch(errorcode) { | 
 | 251 | 		case 0: | 
 | 252 | 			return 0; | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 253 | 		case -NFS4ERR_ADMIN_REVOKED: | 
 | 254 | 		case -NFS4ERR_BAD_STATEID: | 
 | 255 | 		case -NFS4ERR_OPENMODE: | 
 | 256 | 			if (state == NULL) | 
 | 257 | 				break; | 
 | 258 | 			nfs4_state_mark_reclaim_nograce(clp, state); | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 259 | 			goto do_state_recovery; | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 260 | 		case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 261 | 		case -NFS4ERR_STALE_CLIENTID: | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 262 | 		case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 263 | 			goto do_state_recovery; | 
| Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 264 | #if defined(CONFIG_NFS_V4_1) | 
| Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 265 | 		case -NFS4ERR_BADSESSION: | 
 | 266 | 		case -NFS4ERR_BADSLOT: | 
 | 267 | 		case -NFS4ERR_BAD_HIGH_SLOT: | 
 | 268 | 		case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
 | 269 | 		case -NFS4ERR_DEADSESSION: | 
 | 270 | 		case -NFS4ERR_SEQ_FALSE_RETRY: | 
 | 271 | 		case -NFS4ERR_SEQ_MISORDERED: | 
 | 272 | 			dprintk("%s ERROR: %d Reset session\n", __func__, | 
 | 273 | 				errorcode); | 
| Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 274 | 			nfs4_schedule_state_recovery(clp); | 
| Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 275 | 			exception->retry = 1; | 
| Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 276 | 			break; | 
| Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 277 | #endif /* defined(CONFIG_NFS_V4_1) */ | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 278 | 		case -NFS4ERR_FILE_OPEN: | 
| NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 279 | 			if (exception->timeout > HZ) { | 
 | 280 | 				/* We have retried a decent amount, time to | 
 | 281 | 				 * fail | 
 | 282 | 				 */ | 
 | 283 | 				ret = -EBUSY; | 
 | 284 | 				break; | 
 | 285 | 			} | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 286 | 		case -NFS4ERR_GRACE: | 
 | 287 | 		case -NFS4ERR_DELAY: | 
| Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 288 | 		case -EKEYEXPIRED: | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 289 | 			ret = nfs4_delay(server->client, &exception->timeout); | 
 | 290 | 			if (ret != 0) | 
 | 291 | 				break; | 
 | 292 | 		case -NFS4ERR_OLD_STATEID: | 
 | 293 | 			exception->retry = 1; | 
 | 294 | 	} | 
 | 295 | 	/* We failed to handle the error */ | 
 | 296 | 	return nfs4_map_errors(ret); | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 297 | do_state_recovery: | 
 | 298 | 	nfs4_schedule_state_recovery(clp); | 
 | 299 | 	ret = nfs4_wait_clnt_recover(clp); | 
 | 300 | 	if (ret == 0) | 
 | 301 | 		exception->retry = 1; | 
 | 302 | 	return ret; | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 303 | } | 
 | 304 |  | 
 | 305 |  | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 306 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | 	spin_lock(&clp->cl_lock); | 
 | 309 | 	if (time_before(clp->cl_last_renewal,timestamp)) | 
 | 310 | 		clp->cl_last_renewal = timestamp; | 
 | 311 | 	spin_unlock(&clp->cl_lock); | 
 | 312 | } | 
 | 313 |  | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 314 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) | 
 | 315 | { | 
 | 316 | 	do_renew_lease(server->nfs_client, timestamp); | 
 | 317 | } | 
 | 318 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 319 | #if defined(CONFIG_NFS_V4_1) | 
 | 320 |  | 
| Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 321 | /* | 
| Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 322 |  * nfs4_free_slot - free a slot and efficiently update slot table. | 
 | 323 |  * | 
 | 324 |  * freeing a slot is trivially done by clearing its respective bit | 
 | 325 |  * in the bitmap. | 
 | 326 |  * If the freed slotid equals highest_used_slotid we want to update it | 
 | 327 |  * so that the server would be able to size down the slot table if needed, | 
 | 328 |  * otherwise we know that the highest_used_slotid is still in use. | 
 | 329 |  * When updating highest_used_slotid there may be "holes" in the bitmap | 
 | 330 |  * so we need to scan down from highest_used_slotid to 0 looking for the now | 
 | 331 |  * highest slotid in use. | 
 | 332 |  * If none found, highest_used_slotid is set to -1. | 
| Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 333 |  * | 
 | 334 |  * Must be called while holding tbl->slot_tbl_lock | 
| Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 335 |  */ | 
 | 336 | static void | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 337 | nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *free_slot) | 
| Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 338 | { | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 339 | 	int free_slotid = free_slot - tbl->slots; | 
| Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 340 | 	int slotid = free_slotid; | 
 | 341 |  | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 342 | 	BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); | 
| Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 343 | 	/* clear used bit in bitmap */ | 
 | 344 | 	__clear_bit(slotid, tbl->used_slots); | 
 | 345 |  | 
 | 346 | 	/* update highest_used_slotid when it is freed */ | 
 | 347 | 	if (slotid == tbl->highest_used_slotid) { | 
 | 348 | 		slotid = find_last_bit(tbl->used_slots, tbl->max_slots); | 
| Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 349 | 		if (slotid < tbl->max_slots) | 
| Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 350 | 			tbl->highest_used_slotid = slotid; | 
 | 351 | 		else | 
 | 352 | 			tbl->highest_used_slotid = -1; | 
 | 353 | 	} | 
| Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 354 | 	dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, | 
 | 355 | 		free_slotid, tbl->highest_used_slotid); | 
 | 356 | } | 
 | 357 |  | 
| Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 358 | /* | 
| Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 359 |  * Signal state manager thread if session fore channel is drained | 
| Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 360 |  */ | 
| Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 361 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) | 
| Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 362 | { | 
| Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 363 | 	struct rpc_task *task; | 
 | 364 |  | 
| Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 365 | 	if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { | 
| Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 366 | 		task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); | 
 | 367 | 		if (task) | 
 | 368 | 			rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); | 
| Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 369 | 		return; | 
 | 370 | 	} | 
 | 371 |  | 
 | 372 | 	if (ses->fc_slot_table.highest_used_slotid != -1) | 
 | 373 | 		return; | 
 | 374 |  | 
| Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 375 | 	dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); | 
 | 376 | 	complete(&ses->fc_slot_table.complete); | 
 | 377 | } | 
 | 378 |  | 
 | 379 | /* | 
 | 380 |  * Signal state manager thread if session back channel is drained | 
 | 381 |  */ | 
 | 382 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) | 
 | 383 | { | 
 | 384 | 	if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || | 
 | 385 | 	    ses->bc_slot_table.highest_used_slotid != -1) | 
 | 386 | 		return; | 
 | 387 | 	dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); | 
 | 388 | 	complete(&ses->bc_slot_table.complete); | 
| Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 389 | } | 
 | 390 |  | 
| Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 391 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 392 | { | 
 | 393 | 	struct nfs4_slot_table *tbl; | 
 | 394 |  | 
| Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 395 | 	tbl = &res->sr_session->fc_slot_table; | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 396 | 	if (!res->sr_slot) { | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 397 | 		/* just wake up the next guy waiting since | 
 | 398 | 		 * we may have not consumed a slot after all */ | 
| Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 399 | 		dprintk("%s: No slot\n", __func__); | 
| Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 400 | 		return; | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 401 | 	} | 
| Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 402 |  | 
| Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 403 | 	spin_lock(&tbl->slot_tbl_lock); | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 404 | 	nfs4_free_slot(tbl, res->sr_slot); | 
| Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 405 | 	nfs4_check_drain_fc_complete(res->sr_session); | 
| Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 406 | 	spin_unlock(&tbl->slot_tbl_lock); | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 407 | 	res->sr_slot = NULL; | 
| Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 408 | } | 
 | 409 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 410 | static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 411 | { | 
 | 412 | 	unsigned long timestamp; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 413 | 	struct nfs_client *clp; | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 414 |  | 
 | 415 | 	/* | 
 | 416 | 	 * sr_status remains 1 if an RPC level error occurred. The server | 
 | 417 | 	 * may or may not have processed the sequence operation.. | 
 | 418 | 	 * Proceed as if the server received and processed the sequence | 
 | 419 | 	 * operation. | 
 | 420 | 	 */ | 
 | 421 | 	if (res->sr_status == 1) | 
 | 422 | 		res->sr_status = NFS_OK; | 
 | 423 |  | 
 | 424 | 	/* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 425 | 	if (!res->sr_slot) | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 426 | 		goto out; | 
 | 427 |  | 
| Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 428 | 	/* Check the SEQUENCE operation status */ | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 429 | 	switch (res->sr_status) { | 
 | 430 | 	case 0: | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 431 | 		/* Update the slot's sequence and clientid lease timer */ | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 432 | 		++res->sr_slot->seq_nr; | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 433 | 		timestamp = res->sr_renewal_time; | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 434 | 		clp = res->sr_session->clp; | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 435 | 		do_renew_lease(clp, timestamp); | 
| Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 436 | 		/* Check sequence flags */ | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 437 | 		if (atomic_read(&clp->cl_count) > 1) | 
 | 438 | 			nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 439 | 		break; | 
 | 440 | 	case -NFS4ERR_DELAY: | 
 | 441 | 		/* The server detected a resend of the RPC call and | 
 | 442 | 		 * returned NFS4ERR_DELAY as per Section 2.10.6.2 | 
 | 443 | 		 * of RFC5661. | 
 | 444 | 		 */ | 
| Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 445 | 		dprintk("%s: slot=%td seq=%d: Operation in progress\n", | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 446 | 			__func__, | 
 | 447 | 			res->sr_slot - res->sr_session->fc_slot_table.slots, | 
 | 448 | 			res->sr_slot->seq_nr); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 449 | 		goto out_retry; | 
 | 450 | 	default: | 
 | 451 | 		/* Just update the slot sequence no. */ | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 452 | 		++res->sr_slot->seq_nr; | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 453 | 	} | 
 | 454 | out: | 
 | 455 | 	/* The session may be reset by one of the error handlers. */ | 
 | 456 | 	dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); | 
| Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 457 | 	nfs41_sequence_free_slot(res); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 458 | 	return 1; | 
 | 459 | out_retry: | 
| Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 460 | 	if (!rpc_restart_call(task)) | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 461 | 		goto out; | 
 | 462 | 	rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
 | 463 | 	return 0; | 
| Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 464 | } | 
 | 465 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 466 | static int nfs4_sequence_done(struct rpc_task *task, | 
 | 467 | 			       struct nfs4_sequence_res *res) | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 468 | { | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 469 | 	if (res->sr_session == NULL) | 
 | 470 | 		return 1; | 
 | 471 | 	return nfs41_sequence_done(task, res); | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 472 | } | 
 | 473 |  | 
| Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 474 | /* | 
| Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 475 |  * nfs4_find_slot - efficiently look for a free slot | 
 | 476 |  * | 
 | 477 |  * nfs4_find_slot looks for an unset bit in the used_slots bitmap. | 
 | 478 |  * If found, we mark the slot as used, update the highest_used_slotid, | 
 | 479 |  * and respectively set up the sequence operation args. | 
 | 480 |  * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise. | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 481 |  * | 
 | 482 |  * Note: must be called with under the slot_tbl_lock. | 
| Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 483 |  */ | 
 | 484 | static u8 | 
| Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 485 | nfs4_find_slot(struct nfs4_slot_table *tbl) | 
| Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 486 | { | 
 | 487 | 	int slotid; | 
 | 488 | 	u8 ret_id = NFS4_MAX_SLOT_TABLE; | 
 | 489 | 	BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); | 
 | 490 |  | 
| Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 491 | 	dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", | 
 | 492 | 		__func__, tbl->used_slots[0], tbl->highest_used_slotid, | 
 | 493 | 		tbl->max_slots); | 
 | 494 | 	slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); | 
 | 495 | 	if (slotid >= tbl->max_slots) | 
 | 496 | 		goto out; | 
 | 497 | 	__set_bit(slotid, tbl->used_slots); | 
 | 498 | 	if (slotid > tbl->highest_used_slotid) | 
 | 499 | 		tbl->highest_used_slotid = slotid; | 
 | 500 | 	ret_id = slotid; | 
 | 501 | out: | 
 | 502 | 	dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", | 
 | 503 | 		__func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); | 
| Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 504 | 	return ret_id; | 
 | 505 | } | 
 | 506 |  | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 507 | static int nfs41_setup_sequence(struct nfs4_session *session, | 
 | 508 | 				struct nfs4_sequence_args *args, | 
 | 509 | 				struct nfs4_sequence_res *res, | 
 | 510 | 				int cache_reply, | 
 | 511 | 				struct rpc_task *task) | 
 | 512 | { | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 513 | 	struct nfs4_slot *slot; | 
 | 514 | 	struct nfs4_slot_table *tbl; | 
 | 515 | 	u8 slotid; | 
 | 516 |  | 
 | 517 | 	dprintk("--> %s\n", __func__); | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 518 | 	/* slot already allocated? */ | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 519 | 	if (res->sr_slot != NULL) | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 520 | 		return 0; | 
 | 521 |  | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 522 | 	tbl = &session->fc_slot_table; | 
 | 523 |  | 
 | 524 | 	spin_lock(&tbl->slot_tbl_lock); | 
| Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 525 | 	if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && | 
| Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 526 | 	    !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { | 
| Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 527 | 		/* | 
 | 528 | 		 * The state manager will wait until the slot table is empty. | 
 | 529 | 		 * Schedule the reset thread | 
 | 530 | 		 */ | 
| Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 531 | 		rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); | 
| Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 532 | 		spin_unlock(&tbl->slot_tbl_lock); | 
| Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 533 | 		dprintk("%s Schedule Session Reset\n", __func__); | 
| Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 534 | 		return -EAGAIN; | 
| Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 535 | 	} | 
 | 536 |  | 
| Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 537 | 	if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && | 
 | 538 | 	    !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { | 
 | 539 | 		rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); | 
 | 540 | 		spin_unlock(&tbl->slot_tbl_lock); | 
 | 541 | 		dprintk("%s enforce FIFO order\n", __func__); | 
 | 542 | 		return -EAGAIN; | 
 | 543 | 	} | 
 | 544 |  | 
| Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 545 | 	slotid = nfs4_find_slot(tbl); | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 546 | 	if (slotid == NFS4_MAX_SLOT_TABLE) { | 
 | 547 | 		rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); | 
 | 548 | 		spin_unlock(&tbl->slot_tbl_lock); | 
 | 549 | 		dprintk("<-- %s: no free slots\n", __func__); | 
 | 550 | 		return -EAGAIN; | 
 | 551 | 	} | 
 | 552 | 	spin_unlock(&tbl->slot_tbl_lock); | 
 | 553 |  | 
| Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 554 | 	rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 555 | 	slot = tbl->slots + slotid; | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 556 | 	args->sa_session = session; | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 557 | 	args->sa_slotid = slotid; | 
 | 558 | 	args->sa_cache_this = cache_reply; | 
 | 559 |  | 
 | 560 | 	dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); | 
 | 561 |  | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 562 | 	res->sr_session = session; | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 563 | 	res->sr_slot = slot; | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 564 | 	res->sr_renewal_time = jiffies; | 
| Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 565 | 	res->sr_status_flags = 0; | 
| Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 566 | 	/* | 
 | 567 | 	 * sr_status is only set in decode_sequence, and so will remain | 
 | 568 | 	 * set to 1 if an rpc level failure occurs. | 
 | 569 | 	 */ | 
 | 570 | 	res->sr_status = 1; | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 571 | 	return 0; | 
 | 572 | } | 
 | 573 |  | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 574 | int nfs4_setup_sequence(const struct nfs_server *server, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 575 | 			struct nfs4_sequence_args *args, | 
 | 576 | 			struct nfs4_sequence_res *res, | 
 | 577 | 			int cache_reply, | 
 | 578 | 			struct rpc_task *task) | 
 | 579 | { | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 580 | 	struct nfs4_session *session = nfs4_get_session(server); | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 581 | 	int ret = 0; | 
 | 582 |  | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 583 | 	if (session == NULL) { | 
 | 584 | 		args->sa_session = NULL; | 
 | 585 | 		res->sr_session = NULL; | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 586 | 		goto out; | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 587 | 	} | 
 | 588 |  | 
| Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 589 | 	dprintk("--> %s clp %p session %p sr_slot %td\n", | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 590 | 		__func__, session->clp, session, res->sr_slot ? | 
 | 591 | 			res->sr_slot - session->fc_slot_table.slots : -1); | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 592 |  | 
 | 593 | 	ret = nfs41_setup_sequence(session, args, res, cache_reply, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 594 | 				   task); | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 595 | out: | 
 | 596 | 	dprintk("<-- %s status=%d\n", __func__, ret); | 
 | 597 | 	return ret; | 
 | 598 | } | 
 | 599 |  | 
 | 600 | struct nfs41_call_sync_data { | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 601 | 	const struct nfs_server *seq_server; | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 602 | 	struct nfs4_sequence_args *seq_args; | 
 | 603 | 	struct nfs4_sequence_res *seq_res; | 
 | 604 | 	int cache_reply; | 
 | 605 | }; | 
 | 606 |  | 
 | 607 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) | 
 | 608 | { | 
 | 609 | 	struct nfs41_call_sync_data *data = calldata; | 
 | 610 |  | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 611 | 	dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); | 
 | 612 |  | 
 | 613 | 	if (nfs4_setup_sequence(data->seq_server, data->seq_args, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 614 | 				data->seq_res, data->cache_reply, task)) | 
 | 615 | 		return; | 
 | 616 | 	rpc_call_start(task); | 
 | 617 | } | 
 | 618 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 619 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) | 
 | 620 | { | 
 | 621 | 	rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); | 
 | 622 | 	nfs41_call_sync_prepare(task, calldata); | 
 | 623 | } | 
 | 624 |  | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 625 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) | 
 | 626 | { | 
 | 627 | 	struct nfs41_call_sync_data *data = calldata; | 
 | 628 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 629 | 	nfs41_sequence_done(task, data->seq_res); | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 630 | } | 
 | 631 |  | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 632 | struct rpc_call_ops nfs41_call_sync_ops = { | 
 | 633 | 	.rpc_call_prepare = nfs41_call_sync_prepare, | 
| Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 634 | 	.rpc_call_done = nfs41_call_sync_done, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 635 | }; | 
 | 636 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 637 | struct rpc_call_ops nfs41_call_priv_sync_ops = { | 
 | 638 | 	.rpc_call_prepare = nfs41_call_priv_sync_prepare, | 
 | 639 | 	.rpc_call_done = nfs41_call_sync_done, | 
 | 640 | }; | 
 | 641 |  | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 642 | static int nfs4_call_sync_sequence(struct nfs_server *server, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 643 | 				   struct rpc_message *msg, | 
 | 644 | 				   struct nfs4_sequence_args *args, | 
 | 645 | 				   struct nfs4_sequence_res *res, | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 646 | 				   int cache_reply, | 
 | 647 | 				   int privileged) | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 648 | { | 
 | 649 | 	int ret; | 
 | 650 | 	struct rpc_task *task; | 
 | 651 | 	struct nfs41_call_sync_data data = { | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 652 | 		.seq_server = server, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 653 | 		.seq_args = args, | 
 | 654 | 		.seq_res = res, | 
 | 655 | 		.cache_reply = cache_reply, | 
 | 656 | 	}; | 
 | 657 | 	struct rpc_task_setup task_setup = { | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 658 | 		.rpc_client = server->client, | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 659 | 		.rpc_message = msg, | 
 | 660 | 		.callback_ops = &nfs41_call_sync_ops, | 
 | 661 | 		.callback_data = &data | 
 | 662 | 	}; | 
 | 663 |  | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 664 | 	res->sr_slot = NULL; | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 665 | 	if (privileged) | 
 | 666 | 		task_setup.callback_ops = &nfs41_call_priv_sync_ops; | 
| Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 667 | 	task = rpc_run_task(&task_setup); | 
 | 668 | 	if (IS_ERR(task)) | 
 | 669 | 		ret = PTR_ERR(task); | 
 | 670 | 	else { | 
 | 671 | 		ret = task->tk_status; | 
 | 672 | 		rpc_put_task(task); | 
 | 673 | 	} | 
 | 674 | 	return ret; | 
 | 675 | } | 
 | 676 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 677 | int _nfs4_call_sync_session(struct nfs_server *server, | 
 | 678 | 			    struct rpc_message *msg, | 
 | 679 | 			    struct nfs4_sequence_args *args, | 
 | 680 | 			    struct nfs4_sequence_res *res, | 
 | 681 | 			    int cache_reply) | 
 | 682 | { | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 683 | 	return nfs4_call_sync_sequence(server, msg, args, res, cache_reply, 0); | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 684 | } | 
 | 685 |  | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 686 | #else | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 687 | static int nfs4_sequence_done(struct rpc_task *task, | 
 | 688 | 			       struct nfs4_sequence_res *res) | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 689 | { | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 690 | 	return 1; | 
| Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 691 | } | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 692 | #endif /* CONFIG_NFS_V4_1 */ | 
 | 693 |  | 
 | 694 | int _nfs4_call_sync(struct nfs_server *server, | 
 | 695 | 		    struct rpc_message *msg, | 
 | 696 | 		    struct nfs4_sequence_args *args, | 
 | 697 | 		    struct nfs4_sequence_res *res, | 
 | 698 | 		    int cache_reply) | 
 | 699 | { | 
| Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 700 | 	args->sa_session = res->sr_session = NULL; | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 701 | 	return rpc_call_sync(server->client, msg, 0); | 
 | 702 | } | 
 | 703 |  | 
 | 704 | #define nfs4_call_sync(server, msg, args, res, cache_reply) \ | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 705 | 	(server)->nfs_client->cl_mvops->call_sync((server), (msg), &(args)->seq_args, \ | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 706 | 			&(res)->seq_res, (cache_reply)) | 
 | 707 |  | 
| Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 708 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | { | 
| Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 710 | 	struct nfs_inode *nfsi = NFS_I(dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 |  | 
| Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 712 | 	spin_lock(&dir->i_lock); | 
| Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 713 | 	nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; | 
 | 714 | 	if (!cinfo->atomic || cinfo->before != nfsi->change_attr) | 
| Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 715 | 		nfs_force_lookup_revalidate(dir); | 
| Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 716 | 	nfsi->change_attr = cinfo->after; | 
| Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 717 | 	spin_unlock(&dir->i_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | } | 
 | 719 |  | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 720 | struct nfs4_opendata { | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 721 | 	struct kref kref; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 722 | 	struct nfs_openargs o_arg; | 
 | 723 | 	struct nfs_openres o_res; | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 724 | 	struct nfs_open_confirmargs c_arg; | 
 | 725 | 	struct nfs_open_confirmres c_res; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 726 | 	struct nfs_fattr f_attr; | 
 | 727 | 	struct nfs_fattr dir_attr; | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 728 | 	struct path path; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 729 | 	struct dentry *dir; | 
 | 730 | 	struct nfs4_state_owner *owner; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 731 | 	struct nfs4_state *state; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 732 | 	struct iattr attrs; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 733 | 	unsigned long timestamp; | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 734 | 	unsigned int rpc_done : 1; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 735 | 	int rpc_status; | 
 | 736 | 	int cancelled; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 737 | }; | 
 | 738 |  | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 739 |  | 
 | 740 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) | 
 | 741 | { | 
 | 742 | 	p->o_res.f_attr = &p->f_attr; | 
 | 743 | 	p->o_res.dir_attr = &p->dir_attr; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 744 | 	p->o_res.seqid = p->o_arg.seqid; | 
 | 745 | 	p->c_res.seqid = p->c_arg.seqid; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 746 | 	p->o_res.server = p->o_arg.server; | 
 | 747 | 	nfs_fattr_init(&p->f_attr); | 
 | 748 | 	nfs_fattr_init(&p->dir_attr); | 
 | 749 | } | 
 | 750 |  | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 751 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 752 | 		struct nfs4_state_owner *sp, fmode_t fmode, int flags, | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 753 | 		const struct iattr *attrs, | 
 | 754 | 		gfp_t gfp_mask) | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 755 | { | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 756 | 	struct dentry *parent = dget_parent(path->dentry); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 757 | 	struct inode *dir = parent->d_inode; | 
 | 758 | 	struct nfs_server *server = NFS_SERVER(dir); | 
 | 759 | 	struct nfs4_opendata *p; | 
 | 760 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 761 | 	p = kzalloc(sizeof(*p), gfp_mask); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 762 | 	if (p == NULL) | 
 | 763 | 		goto err; | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 764 | 	p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 765 | 	if (p->o_arg.seqid == NULL) | 
 | 766 | 		goto err_free; | 
| Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 767 | 	path_get(path); | 
 | 768 | 	p->path = *path; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 769 | 	p->dir = parent; | 
 | 770 | 	p->owner = sp; | 
 | 771 | 	atomic_inc(&sp->so_count); | 
 | 772 | 	p->o_arg.fh = NFS_FH(dir); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 773 | 	p->o_arg.open_flags = flags; | 
 | 774 | 	p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 775 | 	p->o_arg.clientid = server->nfs_client->cl_clientid; | 
| Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 776 | 	p->o_arg.id = sp->so_owner_id.id; | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 777 | 	p->o_arg.name = &p->path.dentry->d_name; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 778 | 	p->o_arg.server = server; | 
 | 779 | 	p->o_arg.bitmask = server->attr_bitmask; | 
 | 780 | 	p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; | 
| Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 781 | 	if (flags & O_CREAT) { | 
 | 782 | 		u32 *s; | 
 | 783 |  | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 784 | 		p->o_arg.u.attrs = &p->attrs; | 
 | 785 | 		memcpy(&p->attrs, attrs, sizeof(p->attrs)); | 
| Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 786 | 		s = (u32 *) p->o_arg.u.verifier.data; | 
 | 787 | 		s[0] = jiffies; | 
 | 788 | 		s[1] = current->pid; | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 789 | 	} | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 790 | 	p->c_arg.fh = &p->o_res.fh; | 
 | 791 | 	p->c_arg.stateid = &p->o_res.stateid; | 
 | 792 | 	p->c_arg.seqid = p->o_arg.seqid; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 793 | 	nfs4_init_opendata_res(p); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 794 | 	kref_init(&p->kref); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 795 | 	return p; | 
 | 796 | err_free: | 
 | 797 | 	kfree(p); | 
 | 798 | err: | 
 | 799 | 	dput(parent); | 
 | 800 | 	return NULL; | 
 | 801 | } | 
 | 802 |  | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 803 | static void nfs4_opendata_free(struct kref *kref) | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 804 | { | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 805 | 	struct nfs4_opendata *p = container_of(kref, | 
 | 806 | 			struct nfs4_opendata, kref); | 
 | 807 |  | 
 | 808 | 	nfs_free_seqid(p->o_arg.seqid); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 809 | 	if (p->state != NULL) | 
 | 810 | 		nfs4_put_open_state(p->state); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 811 | 	nfs4_put_state_owner(p->owner); | 
 | 812 | 	dput(p->dir); | 
| Jan Blunck | 31f31db | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 813 | 	path_put(&p->path); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 814 | 	kfree(p); | 
 | 815 | } | 
 | 816 |  | 
 | 817 | static void nfs4_opendata_put(struct nfs4_opendata *p) | 
 | 818 | { | 
 | 819 | 	if (p != NULL) | 
 | 820 | 		kref_put(&p->kref, nfs4_opendata_free); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 821 | } | 
 | 822 |  | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 823 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) | 
 | 824 | { | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 825 | 	int ret; | 
 | 826 |  | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 827 | 	ret = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 828 | 	return ret; | 
 | 829 | } | 
 | 830 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 831 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode) | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 832 | { | 
 | 833 | 	int ret = 0; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 834 |  | 
 | 835 | 	if (open_mode & O_EXCL) | 
 | 836 | 		goto out; | 
 | 837 | 	switch (mode & (FMODE_READ|FMODE_WRITE)) { | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 838 | 		case FMODE_READ: | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 839 | 			ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 | 
 | 840 | 				&& state->n_rdonly != 0; | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 841 | 			break; | 
 | 842 | 		case FMODE_WRITE: | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 843 | 			ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 | 
 | 844 | 				&& state->n_wronly != 0; | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 845 | 			break; | 
 | 846 | 		case FMODE_READ|FMODE_WRITE: | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 847 | 			ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 | 
 | 848 | 				&& state->n_rdwr != 0; | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 849 | 	} | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 850 | out: | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 851 | 	return ret; | 
 | 852 | } | 
 | 853 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 854 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 855 | { | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 856 | 	if ((delegation->type & fmode) != fmode) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 857 | 		return 0; | 
| Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 858 | 	if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 859 | 		return 0; | 
| Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 860 | 	nfs_mark_delegation_referenced(delegation); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 861 | 	return 1; | 
 | 862 | } | 
 | 863 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 864 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 865 | { | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 866 | 	switch (fmode) { | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 867 | 		case FMODE_WRITE: | 
 | 868 | 			state->n_wronly++; | 
 | 869 | 			break; | 
 | 870 | 		case FMODE_READ: | 
 | 871 | 			state->n_rdonly++; | 
 | 872 | 			break; | 
 | 873 | 		case FMODE_READ|FMODE_WRITE: | 
 | 874 | 			state->n_rdwr++; | 
 | 875 | 	} | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 876 | 	nfs4_state_set_mode_locked(state, state->state | fmode); | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 877 | } | 
 | 878 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 879 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 880 | { | 
 | 881 | 	if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) | 
 | 882 | 		memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); | 
 | 883 | 	memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 884 | 	switch (fmode) { | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 885 | 		case FMODE_READ: | 
 | 886 | 			set_bit(NFS_O_RDONLY_STATE, &state->flags); | 
 | 887 | 			break; | 
 | 888 | 		case FMODE_WRITE: | 
 | 889 | 			set_bit(NFS_O_WRONLY_STATE, &state->flags); | 
 | 890 | 			break; | 
 | 891 | 		case FMODE_READ|FMODE_WRITE: | 
 | 892 | 			set_bit(NFS_O_RDWR_STATE, &state->flags); | 
 | 893 | 	} | 
 | 894 | } | 
 | 895 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 896 | static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 897 | { | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 898 | 	write_seqlock(&state->seqlock); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 899 | 	nfs_set_open_stateid_locked(state, stateid, fmode); | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 900 | 	write_sequnlock(&state->seqlock); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 901 | } | 
 | 902 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 903 | static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | { | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 905 | 	/* | 
 | 906 | 	 * Protect the call to nfs4_state_set_mode_locked and | 
 | 907 | 	 * serialise the stateid update | 
 | 908 | 	 */ | 
 | 909 | 	write_seqlock(&state->seqlock); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 910 | 	if (deleg_stateid != NULL) { | 
 | 911 | 		memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); | 
 | 912 | 		set_bit(NFS_DELEGATED_STATE, &state->flags); | 
 | 913 | 	} | 
 | 914 | 	if (open_stateid != NULL) | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 915 | 		nfs_set_open_stateid_locked(state, open_stateid, fmode); | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 916 | 	write_sequnlock(&state->seqlock); | 
 | 917 | 	spin_lock(&state->owner->so_lock); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 918 | 	update_open_stateflags(state, fmode); | 
| Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 919 | 	spin_unlock(&state->owner->so_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } | 
 | 921 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 922 | static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode) | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 923 | { | 
 | 924 | 	struct nfs_inode *nfsi = NFS_I(state->inode); | 
 | 925 | 	struct nfs_delegation *deleg_cur; | 
 | 926 | 	int ret = 0; | 
 | 927 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 928 | 	fmode &= (FMODE_READ|FMODE_WRITE); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 929 |  | 
 | 930 | 	rcu_read_lock(); | 
 | 931 | 	deleg_cur = rcu_dereference(nfsi->delegation); | 
 | 932 | 	if (deleg_cur == NULL) | 
 | 933 | 		goto no_delegation; | 
 | 934 |  | 
 | 935 | 	spin_lock(&deleg_cur->lock); | 
 | 936 | 	if (nfsi->delegation != deleg_cur || | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 937 | 	    (deleg_cur->type & fmode) != fmode) | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 938 | 		goto no_delegation_unlock; | 
 | 939 |  | 
 | 940 | 	if (delegation == NULL) | 
 | 941 | 		delegation = &deleg_cur->stateid; | 
 | 942 | 	else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) | 
 | 943 | 		goto no_delegation_unlock; | 
 | 944 |  | 
| Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 945 | 	nfs_mark_delegation_referenced(deleg_cur); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 946 | 	__update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 947 | 	ret = 1; | 
 | 948 | no_delegation_unlock: | 
 | 949 | 	spin_unlock(&deleg_cur->lock); | 
 | 950 | no_delegation: | 
 | 951 | 	rcu_read_unlock(); | 
 | 952 |  | 
 | 953 | 	if (!ret && open_stateid != NULL) { | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 954 | 		__update_open_stateid(state, open_stateid, NULL, fmode); | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 955 | 		ret = 1; | 
 | 956 | 	} | 
 | 957 |  | 
 | 958 | 	return ret; | 
 | 959 | } | 
 | 960 |  | 
 | 961 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 962 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 963 | { | 
 | 964 | 	struct nfs_delegation *delegation; | 
 | 965 |  | 
 | 966 | 	rcu_read_lock(); | 
 | 967 | 	delegation = rcu_dereference(NFS_I(inode)->delegation); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 968 | 	if (delegation == NULL || (delegation->type & fmode) == fmode) { | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 969 | 		rcu_read_unlock(); | 
 | 970 | 		return; | 
 | 971 | 	} | 
 | 972 | 	rcu_read_unlock(); | 
 | 973 | 	nfs_inode_return_delegation(inode); | 
 | 974 | } | 
 | 975 |  | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 976 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 977 | { | 
 | 978 | 	struct nfs4_state *state = opendata->state; | 
 | 979 | 	struct nfs_inode *nfsi = NFS_I(state->inode); | 
 | 980 | 	struct nfs_delegation *delegation; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 981 | 	int open_mode = opendata->o_arg.open_flags & O_EXCL; | 
 | 982 | 	fmode_t fmode = opendata->o_arg.fmode; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 983 | 	nfs4_stateid stateid; | 
 | 984 | 	int ret = -EAGAIN; | 
 | 985 |  | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 986 | 	for (;;) { | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 987 | 		if (can_open_cached(state, fmode, open_mode)) { | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 988 | 			spin_lock(&state->owner->so_lock); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 989 | 			if (can_open_cached(state, fmode, open_mode)) { | 
 | 990 | 				update_open_stateflags(state, fmode); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 991 | 				spin_unlock(&state->owner->so_lock); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 992 | 				goto out_return_state; | 
 | 993 | 			} | 
 | 994 | 			spin_unlock(&state->owner->so_lock); | 
 | 995 | 		} | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 996 | 		rcu_read_lock(); | 
 | 997 | 		delegation = rcu_dereference(nfsi->delegation); | 
 | 998 | 		if (delegation == NULL || | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 999 | 		    !can_open_delegated(delegation, fmode)) { | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1000 | 			rcu_read_unlock(); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1001 | 			break; | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1002 | 		} | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1003 | 		/* Save the delegation */ | 
 | 1004 | 		memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); | 
 | 1005 | 		rcu_read_unlock(); | 
| Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1006 | 		ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1007 | 		if (ret != 0) | 
 | 1008 | 			goto out; | 
 | 1009 | 		ret = -EAGAIN; | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1010 |  | 
 | 1011 | 		/* Try to update the stateid using the delegation */ | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1012 | 		if (update_open_stateid(state, NULL, &stateid, fmode)) | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1013 | 			goto out_return_state; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1014 | 	} | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1015 | out: | 
 | 1016 | 	return ERR_PTR(ret); | 
 | 1017 | out_return_state: | 
 | 1018 | 	atomic_inc(&state->count); | 
 | 1019 | 	return state; | 
 | 1020 | } | 
 | 1021 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1022 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) | 
 | 1023 | { | 
 | 1024 | 	struct inode *inode; | 
 | 1025 | 	struct nfs4_state *state = NULL; | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1026 | 	struct nfs_delegation *delegation; | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1027 | 	int ret; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1028 |  | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1029 | 	if (!data->rpc_done) { | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1030 | 		state = nfs4_try_open_cached(data); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1031 | 		goto out; | 
 | 1032 | 	} | 
 | 1033 |  | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1034 | 	ret = -EAGAIN; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1035 | 	if (!(data->f_attr.valid & NFS_ATTR_FATTR)) | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1036 | 		goto err; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1037 | 	inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1038 | 	ret = PTR_ERR(inode); | 
| Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1039 | 	if (IS_ERR(inode)) | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1040 | 		goto err; | 
 | 1041 | 	ret = -ENOMEM; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1042 | 	state = nfs4_get_open_state(inode, data->owner); | 
 | 1043 | 	if (state == NULL) | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1044 | 		goto err_put_inode; | 
| Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1045 | 	if (data->o_res.delegation_type != 0) { | 
| Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1046 | 		int delegation_flags = 0; | 
 | 1047 |  | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1048 | 		rcu_read_lock(); | 
 | 1049 | 		delegation = rcu_dereference(NFS_I(inode)->delegation); | 
 | 1050 | 		if (delegation) | 
 | 1051 | 			delegation_flags = delegation->flags; | 
 | 1052 | 		rcu_read_unlock(); | 
| Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1053 | 		if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) | 
| Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1054 | 			nfs_inode_set_delegation(state->inode, | 
 | 1055 | 					data->owner->so_cred, | 
 | 1056 | 					&data->o_res); | 
 | 1057 | 		else | 
 | 1058 | 			nfs_inode_reclaim_delegation(state->inode, | 
 | 1059 | 					data->owner->so_cred, | 
 | 1060 | 					&data->o_res); | 
 | 1061 | 	} | 
| Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1062 |  | 
 | 1063 | 	update_open_stateid(state, &data->o_res.stateid, NULL, | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1064 | 			data->o_arg.fmode); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1065 | 	iput(inode); | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1066 | out: | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1067 | 	return state; | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1068 | err_put_inode: | 
 | 1069 | 	iput(inode); | 
 | 1070 | err: | 
 | 1071 | 	return ERR_PTR(ret); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1072 | } | 
 | 1073 |  | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1074 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) | 
 | 1075 | { | 
 | 1076 | 	struct nfs_inode *nfsi = NFS_I(state->inode); | 
 | 1077 | 	struct nfs_open_context *ctx; | 
 | 1078 |  | 
 | 1079 | 	spin_lock(&state->inode->i_lock); | 
 | 1080 | 	list_for_each_entry(ctx, &nfsi->open_files, list) { | 
 | 1081 | 		if (ctx->state != state) | 
 | 1082 | 			continue; | 
 | 1083 | 		get_nfs_open_context(ctx); | 
 | 1084 | 		spin_unlock(&state->inode->i_lock); | 
 | 1085 | 		return ctx; | 
 | 1086 | 	} | 
 | 1087 | 	spin_unlock(&state->inode->i_lock); | 
 | 1088 | 	return ERR_PTR(-ENOENT); | 
 | 1089 | } | 
 | 1090 |  | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1091 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) | 
 | 1092 | { | 
 | 1093 | 	struct nfs4_opendata *opendata; | 
 | 1094 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1095 | 	opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL, GFP_NOFS); | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1096 | 	if (opendata == NULL) | 
 | 1097 | 		return ERR_PTR(-ENOMEM); | 
 | 1098 | 	opendata->state = state; | 
 | 1099 | 	atomic_inc(&state->count); | 
 | 1100 | 	return opendata; | 
 | 1101 | } | 
 | 1102 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1103 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res) | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1104 | { | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1105 | 	struct nfs4_state *newstate; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1106 | 	int ret; | 
 | 1107 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1108 | 	opendata->o_arg.open_flags = 0; | 
 | 1109 | 	opendata->o_arg.fmode = fmode; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1110 | 	memset(&opendata->o_res, 0, sizeof(opendata->o_res)); | 
 | 1111 | 	memset(&opendata->c_res, 0, sizeof(opendata->c_res)); | 
 | 1112 | 	nfs4_init_opendata_res(opendata); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1113 | 	ret = _nfs4_recover_proc_open(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1114 | 	if (ret != 0) | 
 | 1115 | 		return ret;  | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1116 | 	newstate = nfs4_opendata_to_nfs4_state(opendata); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1117 | 	if (IS_ERR(newstate)) | 
 | 1118 | 		return PTR_ERR(newstate); | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1119 | 	nfs4_close_state(&opendata->path, newstate, fmode); | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1120 | 	*res = newstate; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1121 | 	return 0; | 
 | 1122 | } | 
 | 1123 |  | 
 | 1124 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) | 
 | 1125 | { | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1126 | 	struct nfs4_state *newstate; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1127 | 	int ret; | 
 | 1128 |  | 
 | 1129 | 	/* memory barrier prior to reading state->n_* */ | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1130 | 	clear_bit(NFS_DELEGATED_STATE, &state->flags); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1131 | 	smp_rmb(); | 
 | 1132 | 	if (state->n_rdwr != 0) { | 
| Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1133 | 		clear_bit(NFS_O_RDWR_STATE, &state->flags); | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1134 | 		ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1135 | 		if (ret != 0) | 
 | 1136 | 			return ret; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1137 | 		if (newstate != state) | 
 | 1138 | 			return -ESTALE; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1139 | 	} | 
 | 1140 | 	if (state->n_wronly != 0) { | 
| Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1141 | 		clear_bit(NFS_O_WRONLY_STATE, &state->flags); | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1142 | 		ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1143 | 		if (ret != 0) | 
 | 1144 | 			return ret; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1145 | 		if (newstate != state) | 
 | 1146 | 			return -ESTALE; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1147 | 	} | 
 | 1148 | 	if (state->n_rdonly != 0) { | 
| Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1149 | 		clear_bit(NFS_O_RDONLY_STATE, &state->flags); | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1150 | 		ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1151 | 		if (ret != 0) | 
 | 1152 | 			return ret; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1153 | 		if (newstate != state) | 
 | 1154 | 			return -ESTALE; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1155 | 	} | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1156 | 	/* | 
 | 1157 | 	 * We may have performed cached opens for all three recoveries. | 
 | 1158 | 	 * Check if we need to update the current stateid. | 
 | 1159 | 	 */ | 
 | 1160 | 	if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && | 
 | 1161 | 	    memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) { | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1162 | 		write_seqlock(&state->seqlock); | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1163 | 		if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) | 
 | 1164 | 			memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); | 
| Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1165 | 		write_sequnlock(&state->seqlock); | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1166 | 	} | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1167 | 	return 0; | 
 | 1168 | } | 
 | 1169 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | /* | 
 | 1171 |  * OPEN_RECLAIM: | 
 | 1172 |  * 	reclaim state on the server after a reboot. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 |  */ | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1174 | static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | { | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1176 | 	struct nfs_delegation *delegation; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1177 | 	struct nfs4_opendata *opendata; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1178 | 	fmode_t delegation_type = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | 	int status; | 
 | 1180 |  | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1181 | 	opendata = nfs4_open_recoverdata_alloc(ctx, state); | 
 | 1182 | 	if (IS_ERR(opendata)) | 
 | 1183 | 		return PTR_ERR(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1184 | 	opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; | 
 | 1185 | 	opendata->o_arg.fh = NFS_FH(state->inode); | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1186 | 	rcu_read_lock(); | 
 | 1187 | 	delegation = rcu_dereference(NFS_I(state->inode)->delegation); | 
| Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1188 | 	if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) | 
| Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1189 | 		delegation_type = delegation->type; | 
| Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1190 | 	rcu_read_unlock(); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1191 | 	opendata->o_arg.u.delegation_type = delegation_type; | 
 | 1192 | 	status = nfs4_open_recover(opendata, state); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1193 | 	nfs4_opendata_put(opendata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | 	return status; | 
 | 1195 | } | 
 | 1196 |  | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1197 | static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | { | 
 | 1199 | 	struct nfs_server *server = NFS_SERVER(state->inode); | 
 | 1200 | 	struct nfs4_exception exception = { }; | 
 | 1201 | 	int err; | 
 | 1202 | 	do { | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1203 | 		err = _nfs4_do_open_reclaim(ctx, state); | 
| Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1204 | 		if (err != -NFS4ERR_DELAY) | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1205 | 			break; | 
 | 1206 | 		nfs4_handle_exception(server, err, &exception); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | 	} while (exception.retry); | 
 | 1208 | 	return err; | 
 | 1209 | } | 
 | 1210 |  | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1211 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) | 
 | 1212 | { | 
 | 1213 | 	struct nfs_open_context *ctx; | 
 | 1214 | 	int ret; | 
 | 1215 |  | 
 | 1216 | 	ctx = nfs4_state_find_open_context(state); | 
 | 1217 | 	if (IS_ERR(ctx)) | 
 | 1218 | 		return PTR_ERR(ctx); | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1219 | 	ret = nfs4_do_open_reclaim(ctx, state); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1220 | 	put_nfs_open_context(ctx); | 
 | 1221 | 	return ret; | 
 | 1222 | } | 
 | 1223 |  | 
| Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1224 | static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | { | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1226 | 	struct nfs4_opendata *opendata; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1227 | 	int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 |  | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1229 | 	opendata = nfs4_open_recoverdata_alloc(ctx, state); | 
 | 1230 | 	if (IS_ERR(opendata)) | 
 | 1231 | 		return PTR_ERR(opendata); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1232 | 	opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; | 
| Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1233 | 	memcpy(opendata->o_arg.u.delegation.data, stateid->data, | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1234 | 			sizeof(opendata->o_arg.u.delegation.data)); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1235 | 	ret = nfs4_open_recover(opendata, state); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1236 | 	nfs4_opendata_put(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1237 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | } | 
 | 1239 |  | 
| Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1240 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | { | 
 | 1242 | 	struct nfs4_exception exception = { }; | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1243 | 	struct nfs_server *server = NFS_SERVER(state->inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | 	int err; | 
 | 1245 | 	do { | 
| Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1246 | 		err = _nfs4_open_delegation_recall(ctx, state, stateid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | 		switch (err) { | 
 | 1248 | 			case 0: | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1249 | 			case -ENOENT: | 
 | 1250 | 			case -ESTALE: | 
 | 1251 | 				goto out; | 
| Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1252 | 			case -NFS4ERR_BADSESSION: | 
 | 1253 | 			case -NFS4ERR_BADSLOT: | 
 | 1254 | 			case -NFS4ERR_BAD_HIGH_SLOT: | 
 | 1255 | 			case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
 | 1256 | 			case -NFS4ERR_DEADSESSION: | 
 | 1257 | 				nfs4_schedule_state_recovery( | 
 | 1258 | 					server->nfs_client); | 
 | 1259 | 				goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | 			case -NFS4ERR_STALE_CLIENTID: | 
 | 1261 | 			case -NFS4ERR_STALE_STATEID: | 
 | 1262 | 			case -NFS4ERR_EXPIRED: | 
 | 1263 | 				/* Don't recall a delegation if it was lost */ | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1264 | 				nfs4_schedule_state_recovery(server->nfs_client); | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1265 | 				goto out; | 
 | 1266 | 			case -ERESTARTSYS: | 
 | 1267 | 				/* | 
 | 1268 | 				 * The show must go on: exit, but mark the | 
 | 1269 | 				 * stateid as needing recovery. | 
 | 1270 | 				 */ | 
 | 1271 | 			case -NFS4ERR_ADMIN_REVOKED: | 
 | 1272 | 			case -NFS4ERR_BAD_STATEID: | 
 | 1273 | 				nfs4_state_mark_reclaim_nograce(server->nfs_client, state); | 
| Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1274 | 			case -EKEYEXPIRED: | 
 | 1275 | 				/* | 
 | 1276 | 				 * User RPCSEC_GSS context has expired. | 
 | 1277 | 				 * We cannot recover this stateid now, so | 
 | 1278 | 				 * skip it and allow recovery thread to | 
 | 1279 | 				 * proceed. | 
 | 1280 | 				 */ | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1281 | 			case -ENOMEM: | 
 | 1282 | 				err = 0; | 
 | 1283 | 				goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | 		} | 
 | 1285 | 		err = nfs4_handle_exception(server, err, &exception); | 
 | 1286 | 	} while (exception.retry); | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1287 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | 	return err; | 
 | 1289 | } | 
 | 1290 |  | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1291 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) | 
 | 1292 | { | 
 | 1293 | 	struct nfs4_opendata *data = calldata; | 
 | 1294 |  | 
 | 1295 | 	data->rpc_status = task->tk_status; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1296 | 	if (data->rpc_status == 0) { | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1297 | 		memcpy(data->o_res.stateid.data, data->c_res.stateid.data, | 
 | 1298 | 				sizeof(data->o_res.stateid.data)); | 
| Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1299 | 		nfs_confirm_seqid(&data->owner->so_seqid, 0); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1300 | 		renew_lease(data->o_res.server, data->timestamp); | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1301 | 		data->rpc_done = 1; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1302 | 	} | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1303 | } | 
 | 1304 |  | 
 | 1305 | static void nfs4_open_confirm_release(void *calldata) | 
 | 1306 | { | 
 | 1307 | 	struct nfs4_opendata *data = calldata; | 
 | 1308 | 	struct nfs4_state *state = NULL; | 
 | 1309 |  | 
 | 1310 | 	/* If this request hasn't been cancelled, do nothing */ | 
 | 1311 | 	if (data->cancelled == 0) | 
 | 1312 | 		goto out_free; | 
 | 1313 | 	/* In case of error, no cleanup! */ | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1314 | 	if (!data->rpc_done) | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1315 | 		goto out_free; | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1316 | 	state = nfs4_opendata_to_nfs4_state(data); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1317 | 	if (!IS_ERR(state)) | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1318 | 		nfs4_close_state(&data->path, state, data->o_arg.fmode); | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1319 | out_free: | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1320 | 	nfs4_opendata_put(data); | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1321 | } | 
 | 1322 |  | 
 | 1323 | static const struct rpc_call_ops nfs4_open_confirm_ops = { | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1324 | 	.rpc_call_done = nfs4_open_confirm_done, | 
 | 1325 | 	.rpc_release = nfs4_open_confirm_release, | 
 | 1326 | }; | 
 | 1327 |  | 
 | 1328 | /* | 
 | 1329 |  * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata | 
 | 1330 |  */ | 
 | 1331 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) | 
 | 1332 | { | 
 | 1333 | 	struct nfs_server *server = NFS_SERVER(data->dir->d_inode); | 
 | 1334 | 	struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1335 | 	struct  rpc_message msg = { | 
 | 1336 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], | 
 | 1337 | 		.rpc_argp = &data->c_arg, | 
 | 1338 | 		.rpc_resp = &data->c_res, | 
 | 1339 | 		.rpc_cred = data->owner->so_cred, | 
 | 1340 | 	}; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1341 | 	struct rpc_task_setup task_setup_data = { | 
 | 1342 | 		.rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1343 | 		.rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1344 | 		.callback_ops = &nfs4_open_confirm_ops, | 
 | 1345 | 		.callback_data = data, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1346 | 		.workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1347 | 		.flags = RPC_TASK_ASYNC, | 
 | 1348 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | 	int status; | 
 | 1350 |  | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1351 | 	kref_get(&data->kref); | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1352 | 	data->rpc_done = 0; | 
 | 1353 | 	data->rpc_status = 0; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1354 | 	data->timestamp = jiffies; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1355 | 	task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1356 | 	if (IS_ERR(task)) | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1357 | 		return PTR_ERR(task); | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1358 | 	status = nfs4_wait_for_completion_rpc_task(task); | 
 | 1359 | 	if (status != 0) { | 
 | 1360 | 		data->cancelled = 1; | 
 | 1361 | 		smp_wmb(); | 
 | 1362 | 	} else | 
 | 1363 | 		status = data->rpc_status; | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1364 | 	rpc_put_task(task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | 	return status; | 
 | 1366 | } | 
 | 1367 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1368 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | { | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1370 | 	struct nfs4_opendata *data = calldata; | 
 | 1371 | 	struct nfs4_state_owner *sp = data->owner; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1372 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1373 | 	if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) | 
 | 1374 | 		return; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1375 | 	/* | 
 | 1376 | 	 * Check if we still need to send an OPEN call, or if we can use | 
 | 1377 | 	 * a delegation instead. | 
 | 1378 | 	 */ | 
 | 1379 | 	if (data->state != NULL) { | 
 | 1380 | 		struct nfs_delegation *delegation; | 
 | 1381 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1382 | 		if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags)) | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1383 | 			goto out_no_action; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1384 | 		rcu_read_lock(); | 
 | 1385 | 		delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); | 
 | 1386 | 		if (delegation != NULL && | 
| Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1387 | 		    test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1388 | 			rcu_read_unlock(); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1389 | 			goto out_no_action; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1390 | 		} | 
 | 1391 | 		rcu_read_unlock(); | 
 | 1392 | 	} | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1393 | 	/* Update sequence id. */ | 
| Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1394 | 	data->o_arg.id = sp->so_owner_id.id; | 
| Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1395 | 	data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1396 | 	if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1397 | 		task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1398 | 		nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); | 
 | 1399 | 	} | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1400 | 	data->timestamp = jiffies; | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1401 | 	if (nfs4_setup_sequence(data->o_arg.server, | 
| Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1402 | 				&data->o_arg.seq_args, | 
 | 1403 | 				&data->o_res.seq_res, 1, task)) | 
 | 1404 | 		return; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1405 | 	rpc_call_start(task); | 
| Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1406 | 	return; | 
 | 1407 | out_no_action: | 
 | 1408 | 	task->tk_action = NULL; | 
 | 1409 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1410 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1412 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) | 
 | 1413 | { | 
 | 1414 | 	rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); | 
 | 1415 | 	nfs4_open_prepare(task, calldata); | 
 | 1416 | } | 
 | 1417 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1418 | static void nfs4_open_done(struct rpc_task *task, void *calldata) | 
 | 1419 | { | 
 | 1420 | 	struct nfs4_opendata *data = calldata; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1422 | 	data->rpc_status = task->tk_status; | 
| Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1423 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1424 | 	if (!nfs4_sequence_done(task, &data->o_res.seq_res)) | 
 | 1425 | 		return; | 
| Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1426 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1427 | 	if (task->tk_status == 0) { | 
 | 1428 | 		switch (data->o_res.f_attr->mode & S_IFMT) { | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1429 | 			case S_IFREG: | 
 | 1430 | 				break; | 
 | 1431 | 			case S_IFLNK: | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1432 | 				data->rpc_status = -ELOOP; | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1433 | 				break; | 
 | 1434 | 			case S_IFDIR: | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1435 | 				data->rpc_status = -EISDIR; | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1436 | 				break; | 
 | 1437 | 			default: | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1438 | 				data->rpc_status = -ENOTDIR; | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1439 | 		} | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1440 | 		renew_lease(data->o_res.server, data->timestamp); | 
| Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1441 | 		if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) | 
 | 1442 | 			nfs_confirm_seqid(&data->owner->so_seqid, 0); | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1443 | 	} | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1444 | 	data->rpc_done = 1; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1445 | } | 
| Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1446 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1447 | static void nfs4_open_release(void *calldata) | 
 | 1448 | { | 
 | 1449 | 	struct nfs4_opendata *data = calldata; | 
 | 1450 | 	struct nfs4_state *state = NULL; | 
 | 1451 |  | 
 | 1452 | 	/* If this request hasn't been cancelled, do nothing */ | 
 | 1453 | 	if (data->cancelled == 0) | 
 | 1454 | 		goto out_free; | 
 | 1455 | 	/* In case of error, no cleanup! */ | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1456 | 	if (data->rpc_status != 0 || !data->rpc_done) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1457 | 		goto out_free; | 
 | 1458 | 	/* In case we need an open_confirm, no cleanup! */ | 
 | 1459 | 	if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) | 
 | 1460 | 		goto out_free; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1461 | 	state = nfs4_opendata_to_nfs4_state(data); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1462 | 	if (!IS_ERR(state)) | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1463 | 		nfs4_close_state(&data->path, state, data->o_arg.fmode); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1464 | out_free: | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1465 | 	nfs4_opendata_put(data); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1466 | } | 
 | 1467 |  | 
 | 1468 | static const struct rpc_call_ops nfs4_open_ops = { | 
 | 1469 | 	.rpc_call_prepare = nfs4_open_prepare, | 
 | 1470 | 	.rpc_call_done = nfs4_open_done, | 
 | 1471 | 	.rpc_release = nfs4_open_release, | 
 | 1472 | }; | 
 | 1473 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1474 | static const struct rpc_call_ops nfs4_recover_open_ops = { | 
 | 1475 | 	.rpc_call_prepare = nfs4_recover_open_prepare, | 
 | 1476 | 	.rpc_call_done = nfs4_open_done, | 
 | 1477 | 	.rpc_release = nfs4_open_release, | 
 | 1478 | }; | 
 | 1479 |  | 
 | 1480 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1481 | { | 
 | 1482 | 	struct inode *dir = data->dir->d_inode; | 
 | 1483 | 	struct nfs_server *server = NFS_SERVER(dir); | 
 | 1484 | 	struct nfs_openargs *o_arg = &data->o_arg; | 
 | 1485 | 	struct nfs_openres *o_res = &data->o_res; | 
 | 1486 | 	struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1487 | 	struct rpc_message msg = { | 
 | 1488 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], | 
 | 1489 | 		.rpc_argp = o_arg, | 
 | 1490 | 		.rpc_resp = o_res, | 
 | 1491 | 		.rpc_cred = data->owner->so_cred, | 
 | 1492 | 	}; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1493 | 	struct rpc_task_setup task_setup_data = { | 
 | 1494 | 		.rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1495 | 		.rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1496 | 		.callback_ops = &nfs4_open_ops, | 
 | 1497 | 		.callback_data = data, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1498 | 		.workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1499 | 		.flags = RPC_TASK_ASYNC, | 
 | 1500 | 	}; | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1501 | 	int status; | 
 | 1502 |  | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1503 | 	kref_get(&data->kref); | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1504 | 	data->rpc_done = 0; | 
 | 1505 | 	data->rpc_status = 0; | 
| Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1506 | 	data->cancelled = 0; | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1507 | 	if (isrecover) | 
 | 1508 | 		task_setup_data.callback_ops = &nfs4_recover_open_ops; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1509 | 	task = rpc_run_task(&task_setup_data); | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1510 |         if (IS_ERR(task)) | 
 | 1511 |                 return PTR_ERR(task); | 
 | 1512 |         status = nfs4_wait_for_completion_rpc_task(task); | 
 | 1513 |         if (status != 0) { | 
 | 1514 |                 data->cancelled = 1; | 
 | 1515 |                 smp_wmb(); | 
 | 1516 |         } else | 
 | 1517 |                 status = data->rpc_status; | 
 | 1518 |         rpc_put_task(task); | 
 | 1519 |  | 
 | 1520 | 	return status; | 
 | 1521 | } | 
 | 1522 |  | 
 | 1523 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) | 
 | 1524 | { | 
 | 1525 | 	struct inode *dir = data->dir->d_inode; | 
 | 1526 | 	struct nfs_openres *o_res = &data->o_res; | 
 | 1527 |         int status; | 
 | 1528 |  | 
 | 1529 | 	status = nfs4_run_open_task(data, 1); | 
 | 1530 | 	if (status != 0 || !data->rpc_done) | 
 | 1531 | 		return status; | 
 | 1532 |  | 
 | 1533 | 	nfs_refresh_inode(dir, o_res->dir_attr); | 
 | 1534 |  | 
 | 1535 | 	if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { | 
 | 1536 | 		status = _nfs4_proc_open_confirm(data); | 
 | 1537 | 		if (status != 0) | 
 | 1538 | 			return status; | 
 | 1539 | 	} | 
 | 1540 |  | 
 | 1541 | 	return status; | 
 | 1542 | } | 
 | 1543 |  | 
 | 1544 | /* | 
 | 1545 |  * Note: On error, nfs4_proc_open will free the struct nfs4_opendata | 
 | 1546 |  */ | 
 | 1547 | static int _nfs4_proc_open(struct nfs4_opendata *data) | 
 | 1548 | { | 
 | 1549 | 	struct inode *dir = data->dir->d_inode; | 
 | 1550 | 	struct nfs_server *server = NFS_SERVER(dir); | 
 | 1551 | 	struct nfs_openargs *o_arg = &data->o_arg; | 
 | 1552 | 	struct nfs_openres *o_res = &data->o_res; | 
 | 1553 | 	int status; | 
 | 1554 |  | 
 | 1555 | 	status = nfs4_run_open_task(data, 0); | 
| Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1556 | 	if (status != 0 || !data->rpc_done) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1557 | 		return status; | 
 | 1558 |  | 
| Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1559 | 	if (o_arg->open_flags & O_CREAT) { | 
 | 1560 | 		update_changeattr(dir, &o_res->cinfo); | 
 | 1561 | 		nfs_post_op_update_inode(dir, o_res->dir_attr); | 
 | 1562 | 	} else | 
 | 1563 | 		nfs_refresh_inode(dir, o_res->dir_attr); | 
| Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1564 | 	if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) | 
 | 1565 | 		server->caps &= ~NFS_CAP_POSIX_LOCK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | 	if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { | 
| Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1567 | 		status = _nfs4_proc_open_confirm(data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | 		if (status != 0) | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1569 | 			return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | 	} | 
 | 1571 | 	if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) | 
| Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1572 | 		_nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1573 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | } | 
 | 1575 |  | 
| Trond Myklebust | 10afec9 | 2007-05-14 17:16:04 -0400 | [diff] [blame] | 1576 | static int nfs4_recover_expired_lease(struct nfs_server *server) | 
| Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1577 | { | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1578 | 	struct nfs_client *clp = server->nfs_client; | 
| Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1579 | 	unsigned int loop; | 
| Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1580 | 	int ret; | 
| Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1581 |  | 
| Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1582 | 	for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { | 
| Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1583 | 		ret = nfs4_wait_clnt_recover(clp); | 
| Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1584 | 		if (ret != 0) | 
| Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1585 | 			break; | 
| Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1586 | 		if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && | 
 | 1587 | 		    !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) | 
| Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1588 | 			break; | 
| Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1589 | 		nfs4_schedule_state_recovery(clp); | 
| Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1590 | 		ret = -EIO; | 
| Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1591 | 	} | 
| Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1592 | 	return ret; | 
| Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1593 | } | 
 | 1594 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | /* | 
 | 1596 |  * OPEN_EXPIRED: | 
 | 1597 |  * 	reclaim state on the server after a network partition. | 
 | 1598 |  * 	Assumes caller holds the appropriate lock | 
 | 1599 |  */ | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1600 | static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | { | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1602 | 	struct nfs4_opendata *opendata; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1603 | 	int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 |  | 
| Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1605 | 	opendata = nfs4_open_recoverdata_alloc(ctx, state); | 
 | 1606 | 	if (IS_ERR(opendata)) | 
 | 1607 | 		return PTR_ERR(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1608 | 	ret = nfs4_open_recover(opendata, state); | 
| Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1609 | 	if (ret == -ESTALE) | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1610 | 		d_drop(ctx->path.dentry); | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1611 | 	nfs4_opendata_put(opendata); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1612 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | } | 
 | 1614 |  | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1615 | static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state) | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1616 | { | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1617 | 	struct nfs_server *server = NFS_SERVER(state->inode); | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1618 | 	struct nfs4_exception exception = { }; | 
 | 1619 | 	int err; | 
 | 1620 |  | 
 | 1621 | 	do { | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1622 | 		err = _nfs4_open_expired(ctx, state); | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1623 | 		switch (err) { | 
 | 1624 | 		default: | 
 | 1625 | 			goto out; | 
 | 1626 | 		case -NFS4ERR_GRACE: | 
 | 1627 | 		case -NFS4ERR_DELAY: | 
 | 1628 | 			nfs4_handle_exception(server, err, &exception); | 
 | 1629 | 			err = 0; | 
 | 1630 | 		} | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1631 | 	} while (exception.retry); | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1632 | out: | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1633 | 	return err; | 
 | 1634 | } | 
 | 1635 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) | 
 | 1637 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | 	struct nfs_open_context *ctx; | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1639 | 	int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 |  | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1641 | 	ctx = nfs4_state_find_open_context(state); | 
 | 1642 | 	if (IS_ERR(ctx)) | 
 | 1643 | 		return PTR_ERR(ctx); | 
| Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1644 | 	ret = nfs4_do_open_expired(ctx, state); | 
| Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1645 | 	put_nfs_open_context(ctx); | 
 | 1646 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | } | 
 | 1648 |  | 
 | 1649 | /* | 
| Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1650 |  * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* | 
 | 1651 |  * fields corresponding to attributes that were used to store the verifier. | 
 | 1652 |  * Make sure we clobber those fields in the later setattr call | 
 | 1653 |  */ | 
 | 1654 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) | 
 | 1655 | { | 
 | 1656 | 	if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && | 
 | 1657 | 	    !(sattr->ia_valid & ATTR_ATIME_SET)) | 
 | 1658 | 		sattr->ia_valid |= ATTR_ATIME; | 
 | 1659 |  | 
 | 1660 | 	if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && | 
 | 1661 | 	    !(sattr->ia_valid & ATTR_MTIME_SET)) | 
 | 1662 | 		sattr->ia_valid |= ATTR_MTIME; | 
 | 1663 | } | 
 | 1664 |  | 
 | 1665 | /* | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1666 |  * Returns a referenced nfs4_state | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 |  */ | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1668 | static int _nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | { | 
 | 1670 | 	struct nfs4_state_owner  *sp; | 
 | 1671 | 	struct nfs4_state     *state = NULL; | 
 | 1672 | 	struct nfs_server       *server = NFS_SERVER(dir); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1673 | 	struct nfs4_opendata *opendata; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1674 | 	int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 |  | 
 | 1676 | 	/* Protect against reboot recovery conflicts */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | 	status = -ENOMEM; | 
 | 1678 | 	if (!(sp = nfs4_get_state_owner(server, cred))) { | 
 | 1679 | 		dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); | 
 | 1680 | 		goto out_err; | 
 | 1681 | 	} | 
| Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1682 | 	status = nfs4_recover_expired_lease(server); | 
 | 1683 | 	if (status != 0) | 
| Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1684 | 		goto err_put_state_owner; | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1685 | 	if (path->dentry->d_inode != NULL) | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1686 | 		nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); | 
| Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1687 | 	status = -ENOMEM; | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1688 | 	opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1689 | 	if (opendata == NULL) | 
| Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1690 | 		goto err_put_state_owner; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 |  | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1692 | 	if (path->dentry->d_inode != NULL) | 
 | 1693 | 		opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); | 
 | 1694 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1695 | 	status = _nfs4_proc_open(opendata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | 	if (status != 0) | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1697 | 		goto err_opendata_put; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 |  | 
| Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1699 | 	state = nfs4_opendata_to_nfs4_state(opendata); | 
| Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1700 | 	status = PTR_ERR(state); | 
 | 1701 | 	if (IS_ERR(state)) | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1702 | 		goto err_opendata_put; | 
| Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1703 | 	if (server->caps & NFS_CAP_POSIX_LOCK) | 
| Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1704 | 		set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); | 
| Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1705 |  | 
 | 1706 | 	if (opendata->o_arg.open_flags & O_EXCL) { | 
 | 1707 | 		nfs4_exclusive_attrset(opendata, sattr); | 
 | 1708 |  | 
 | 1709 | 		nfs_fattr_init(opendata->o_res.f_attr); | 
 | 1710 | 		status = nfs4_do_setattr(state->inode, cred, | 
 | 1711 | 				opendata->o_res.f_attr, sattr, | 
 | 1712 | 				state); | 
 | 1713 | 		if (status == 0) | 
 | 1714 | 			nfs_setattr_update_inode(state->inode, sattr); | 
 | 1715 | 		nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); | 
 | 1716 | 	} | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1717 | 	nfs4_opendata_put(opendata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | 	nfs4_put_state_owner(sp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | 	*res = state; | 
 | 1720 | 	return 0; | 
| Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1721 | err_opendata_put: | 
 | 1722 | 	nfs4_opendata_put(opendata); | 
| Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1723 | err_put_state_owner: | 
 | 1724 | 	nfs4_put_state_owner(sp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | out_err: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | 	*res = NULL; | 
 | 1727 | 	return status; | 
 | 1728 | } | 
 | 1729 |  | 
 | 1730 |  | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1731 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | { | 
 | 1733 | 	struct nfs4_exception exception = { }; | 
 | 1734 | 	struct nfs4_state *res; | 
 | 1735 | 	int status; | 
 | 1736 |  | 
 | 1737 | 	do { | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1738 | 		status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | 		if (status == 0) | 
 | 1740 | 			break; | 
 | 1741 | 		/* NOTE: BAD_SEQID means the server and client disagree about the | 
 | 1742 | 		 * book-keeping w.r.t. state-changing operations | 
 | 1743 | 		 * (OPEN/CLOSE/LOCK/LOCKU...) | 
 | 1744 | 		 * It is actually a sign of a bug on the client or on the server. | 
 | 1745 | 		 * | 
 | 1746 | 		 * If we receive a BAD_SEQID error in the particular case of | 
| Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1747 | 		 * doing an OPEN, we assume that nfs_increment_open_seqid() will | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | 		 * have unhashed the old state_owner for us, and that we can | 
 | 1749 | 		 * therefore safely retry using a new one. We should still warn | 
 | 1750 | 		 * the user though... | 
 | 1751 | 		 */ | 
 | 1752 | 		if (status == -NFS4ERR_BAD_SEQID) { | 
| Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1753 | 			printk(KERN_WARNING "NFS: v4 server %s " | 
 | 1754 | 					" returned a bad sequence-id error!\n", | 
 | 1755 | 					NFS_SERVER(dir)->nfs_client->cl_hostname); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | 			exception.retry = 1; | 
 | 1757 | 			continue; | 
 | 1758 | 		} | 
| Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1759 | 		/* | 
 | 1760 | 		 * BAD_STATEID on OPEN means that the server cancelled our | 
 | 1761 | 		 * state before it received the OPEN_CONFIRM. | 
 | 1762 | 		 * Recover by retrying the request as per the discussion | 
 | 1763 | 		 * on Page 181 of RFC3530. | 
 | 1764 | 		 */ | 
 | 1765 | 		if (status == -NFS4ERR_BAD_STATEID) { | 
 | 1766 | 			exception.retry = 1; | 
 | 1767 | 			continue; | 
 | 1768 | 		} | 
| Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1769 | 		if (status == -EAGAIN) { | 
 | 1770 | 			/* We must have found a delegation */ | 
 | 1771 | 			exception.retry = 1; | 
 | 1772 | 			continue; | 
 | 1773 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | 		res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), | 
 | 1775 | 					status, &exception)); | 
 | 1776 | 	} while (exception.retry); | 
 | 1777 | 	return res; | 
 | 1778 | } | 
 | 1779 |  | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1780 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, | 
 | 1781 | 			    struct nfs_fattr *fattr, struct iattr *sattr, | 
 | 1782 | 			    struct nfs4_state *state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | { | 
| Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1784 | 	struct nfs_server *server = NFS_SERVER(inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 |         struct nfs_setattrargs  arg = { | 
| Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1786 |                 .fh             = NFS_FH(inode), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 |                 .iap            = sattr, | 
 | 1788 | 		.server		= server, | 
 | 1789 | 		.bitmask = server->attr_bitmask, | 
 | 1790 |         }; | 
 | 1791 |         struct nfs_setattrres  res = { | 
 | 1792 | 		.fattr		= fattr, | 
 | 1793 | 		.server		= server, | 
 | 1794 |         }; | 
 | 1795 |         struct rpc_message msg = { | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1796 | 		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_SETATTR], | 
 | 1797 | 		.rpc_argp	= &arg, | 
 | 1798 | 		.rpc_resp	= &res, | 
 | 1799 | 		.rpc_cred	= cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 |         }; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1801 | 	unsigned long timestamp = jiffies; | 
| Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1802 | 	int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1804 | 	nfs_fattr_init(fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 |  | 
| Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1806 | 	if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { | 
 | 1807 | 		/* Use that stateid */ | 
 | 1808 | 	} else if (state != NULL) { | 
| Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1809 | 		nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); | 
| Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1810 | 	} else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | 		memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); | 
 | 1812 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1813 | 	status = nfs4_call_sync(server, &msg, &arg, &res, 1); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1814 | 	if (status == 0 && state != NULL) | 
 | 1815 | 		renew_lease(server, timestamp); | 
| Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1816 | 	return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | } | 
 | 1818 |  | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1819 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, | 
 | 1820 | 			   struct nfs_fattr *fattr, struct iattr *sattr, | 
 | 1821 | 			   struct nfs4_state *state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | { | 
| Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1823 | 	struct nfs_server *server = NFS_SERVER(inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | 	struct nfs4_exception exception = { }; | 
 | 1825 | 	int err; | 
 | 1826 | 	do { | 
 | 1827 | 		err = nfs4_handle_exception(server, | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1828 | 				_nfs4_do_setattr(inode, cred, fattr, sattr, state), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | 				&exception); | 
 | 1830 | 	} while (exception.retry); | 
 | 1831 | 	return err; | 
 | 1832 | } | 
 | 1833 |  | 
 | 1834 | struct nfs4_closedata { | 
| Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1835 | 	struct path path; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | 	struct inode *inode; | 
 | 1837 | 	struct nfs4_state *state; | 
 | 1838 | 	struct nfs_closeargs arg; | 
 | 1839 | 	struct nfs_closeres res; | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1840 | 	struct nfs_fattr fattr; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1841 | 	unsigned long timestamp; | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1842 | 	bool roc; | 
 | 1843 | 	u32 roc_barrier; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | }; | 
 | 1845 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1846 | static void nfs4_free_closedata(void *data) | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1847 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1848 | 	struct nfs4_closedata *calldata = data; | 
 | 1849 | 	struct nfs4_state_owner *sp = calldata->state->owner; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1850 |  | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1851 | 	if (calldata->roc) | 
 | 1852 | 		pnfs_roc_release(calldata->state->inode); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1853 | 	nfs4_put_open_state(calldata->state); | 
 | 1854 | 	nfs_free_seqid(calldata->arg.seqid); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1855 | 	nfs4_put_state_owner(sp); | 
| Jan Blunck | 31f31db | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1856 | 	path_put(&calldata->path); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1857 | 	kfree(calldata); | 
 | 1858 | } | 
 | 1859 |  | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1860 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, | 
 | 1861 | 		fmode_t fmode) | 
 | 1862 | { | 
 | 1863 | 	spin_lock(&state->owner->so_lock); | 
 | 1864 | 	if (!(fmode & FMODE_READ)) | 
 | 1865 | 		clear_bit(NFS_O_RDONLY_STATE, &state->flags); | 
 | 1866 | 	if (!(fmode & FMODE_WRITE)) | 
 | 1867 | 		clear_bit(NFS_O_WRONLY_STATE, &state->flags); | 
 | 1868 | 	clear_bit(NFS_O_RDWR_STATE, &state->flags); | 
 | 1869 | 	spin_unlock(&state->owner->so_lock); | 
 | 1870 | } | 
 | 1871 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1872 | static void nfs4_close_done(struct rpc_task *task, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1874 | 	struct nfs4_closedata *calldata = data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | 	struct nfs4_state *state = calldata->state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | 	struct nfs_server *server = NFS_SERVER(calldata->inode); | 
 | 1877 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1878 | 	if (!nfs4_sequence_done(task, &calldata->res.seq_res)) | 
 | 1879 | 		return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 |         /* hmm. we are done with the inode, and in the process of freeing | 
 | 1881 | 	 * the state_owner. we keep this around to process errors | 
 | 1882 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | 	switch (task->tk_status) { | 
 | 1884 | 		case 0: | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1885 | 			if (calldata->roc) | 
 | 1886 | 				pnfs_roc_set_barrier(state->inode, | 
 | 1887 | 						     calldata->roc_barrier); | 
| Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1888 | 			nfs_set_open_stateid(state, &calldata->res.stateid, 0); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1889 | 			renew_lease(server, calldata->timestamp); | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1890 | 			nfs4_close_clear_stateid_flags(state, | 
 | 1891 | 					calldata->arg.fmode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | 			break; | 
 | 1893 | 		case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1894 | 		case -NFS4ERR_OLD_STATEID: | 
 | 1895 | 		case -NFS4ERR_BAD_STATEID: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | 		case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1897 | 			if (calldata->arg.fmode == 0) | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1898 | 				break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | 		default: | 
| Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1900 | 			if (nfs4_async_handle_error(task, server, state) == -EAGAIN) | 
 | 1901 | 				rpc_restart_call_prepare(task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | 	} | 
| Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1903 | 	nfs_release_seqid(calldata->arg.seqid); | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1904 | 	nfs_refresh_inode(calldata->inode, calldata->res.fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | } | 
 | 1906 |  | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1907 | static void nfs4_close_prepare(struct rpc_task *task, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1909 | 	struct nfs4_closedata *calldata = data; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1910 | 	struct nfs4_state *state = calldata->state; | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1911 | 	int call_close = 0; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1912 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1913 | 	if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1914 | 		return; | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1915 |  | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1916 | 	task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; | 
 | 1917 | 	calldata->arg.fmode = FMODE_READ|FMODE_WRITE; | 
| Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1918 | 	spin_lock(&state->owner->so_lock); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1919 | 	/* Calculate the change in open mode */ | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1920 | 	if (state->n_rdwr == 0) { | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1921 | 		if (state->n_rdonly == 0) { | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1922 | 			call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); | 
 | 1923 | 			call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); | 
 | 1924 | 			calldata->arg.fmode &= ~FMODE_READ; | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1925 | 		} | 
 | 1926 | 		if (state->n_wronly == 0) { | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1927 | 			call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); | 
 | 1928 | 			call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); | 
 | 1929 | 			calldata->arg.fmode &= ~FMODE_WRITE; | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1930 | 		} | 
| Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1931 | 	} | 
| Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1932 | 	spin_unlock(&state->owner->so_lock); | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1933 |  | 
 | 1934 | 	if (!call_close) { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1935 | 		/* Note: exit _without_ calling nfs4_close_done */ | 
 | 1936 | 		task->tk_action = NULL; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1937 | 		return; | 
 | 1938 | 	} | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1939 |  | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1940 | 	if (calldata->arg.fmode == 0) { | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1941 | 		task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1942 | 		if (calldata->roc && | 
 | 1943 | 		    pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { | 
 | 1944 | 			rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, | 
 | 1945 | 				     task, NULL); | 
 | 1946 | 			return; | 
 | 1947 | 		} | 
 | 1948 | 	} | 
| Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1949 |  | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1950 | 	nfs_fattr_init(calldata->res.fattr); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1951 | 	calldata->timestamp = jiffies; | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1952 | 	if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), | 
| Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1953 | 				&calldata->arg.seq_args, &calldata->res.seq_res, | 
 | 1954 | 				1, task)) | 
 | 1955 | 		return; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1956 | 	rpc_call_start(task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | } | 
 | 1958 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1959 | static const struct rpc_call_ops nfs4_close_ops = { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1960 | 	.rpc_call_prepare = nfs4_close_prepare, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1961 | 	.rpc_call_done = nfs4_close_done, | 
 | 1962 | 	.rpc_release = nfs4_free_closedata, | 
 | 1963 | }; | 
 | 1964 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | /*  | 
 | 1966 |  * It is possible for data to be read/written from a mem-mapped file  | 
 | 1967 |  * after the sys_close call (which hits the vfs layer as a flush). | 
 | 1968 |  * This means that we can't safely call nfsv4 close on a file until  | 
 | 1969 |  * the inode is cleared. This in turn means that we are not good | 
 | 1970 |  * NFSv4 citizens - we do not indicate to the server to update the file's  | 
 | 1971 |  * share state even when we are done with one of the three share  | 
 | 1972 |  * stateid's in the inode. | 
 | 1973 |  * | 
 | 1974 |  * NOTE: Caller must be holding the sp->so_owner semaphore! | 
 | 1975 |  */ | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1976 | int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | { | 
| Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1978 | 	struct nfs_server *server = NFS_SERVER(state->inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | 	struct nfs4_closedata *calldata; | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1980 | 	struct nfs4_state_owner *sp = state->owner; | 
 | 1981 | 	struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1982 | 	struct rpc_message msg = { | 
 | 1983 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], | 
 | 1984 | 		.rpc_cred = state->owner->so_cred, | 
 | 1985 | 	}; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1986 | 	struct rpc_task_setup task_setup_data = { | 
 | 1987 | 		.rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1988 | 		.rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1989 | 		.callback_ops = &nfs4_close_ops, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1990 | 		.workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1991 | 		.flags = RPC_TASK_ASYNC, | 
 | 1992 | 	}; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1993 | 	int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1995 | 	calldata = kzalloc(sizeof(*calldata), gfp_mask); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | 	if (calldata == NULL) | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1997 | 		goto out; | 
| Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1998 | 	calldata->inode = state->inode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | 	calldata->state = state; | 
| Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2000 | 	calldata->arg.fh = NFS_FH(state->inode); | 
| Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2001 | 	calldata->arg.stateid = &state->open_stateid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | 	/* Serialization for the sequence id */ | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2003 | 	calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2004 | 	if (calldata->arg.seqid == NULL) | 
 | 2005 | 		goto out_free_calldata; | 
| Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2006 | 	calldata->arg.fmode = 0; | 
| Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2007 | 	calldata->arg.bitmask = server->cache_consistency_bitmask; | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2008 | 	calldata->res.fattr = &calldata->fattr; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2009 | 	calldata->res.seqid = calldata->arg.seqid; | 
| Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2010 | 	calldata->res.server = server; | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2011 | 	calldata->roc = roc; | 
| Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2012 | 	path_get(path); | 
 | 2013 | 	calldata->path = *path; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2014 |  | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2015 | 	msg.rpc_argp = &calldata->arg; | 
 | 2016 | 	msg.rpc_resp = &calldata->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2017 | 	task_setup_data.callback_data = calldata; | 
 | 2018 | 	task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2019 | 	if (IS_ERR(task)) | 
 | 2020 | 		return PTR_ERR(task); | 
| Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2021 | 	status = 0; | 
 | 2022 | 	if (wait) | 
 | 2023 | 		status = rpc_wait_for_completion_task(task); | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2024 | 	rpc_put_task(task); | 
| Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2025 | 	return status; | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2026 | out_free_calldata: | 
 | 2027 | 	kfree(calldata); | 
 | 2028 | out: | 
| Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2029 | 	if (roc) | 
 | 2030 | 		pnfs_roc_release(state->inode); | 
| Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2031 | 	nfs4_put_open_state(state); | 
 | 2032 | 	nfs4_put_state_owner(sp); | 
| Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2033 | 	return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | } | 
 | 2035 |  | 
| Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2036 | static struct inode * | 
| Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2037 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | 	struct nfs4_state *state; | 
 | 2040 |  | 
| Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2041 | 	/* Protect against concurrent sillydeletes */ | 
| Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2042 | 	state = nfs4_do_open(dir, &ctx->path, ctx->mode, open_flags, attr, ctx->cred); | 
| Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2043 | 	if (IS_ERR(state)) | 
 | 2044 | 		return ERR_CAST(state); | 
| Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2045 | 	ctx->state = state; | 
| Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2046 | 	return igrab(state->inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | } | 
 | 2048 |  | 
| Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2049 | static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync) | 
| Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2050 | { | 
 | 2051 | 	if (ctx->state == NULL) | 
 | 2052 | 		return; | 
 | 2053 | 	if (is_sync) | 
 | 2054 | 		nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); | 
 | 2055 | 	else | 
 | 2056 | 		nfs4_close_state(&ctx->path, ctx->state, ctx->mode); | 
 | 2057 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 |  | 
 | 2059 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) | 
 | 2060 | { | 
| Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2061 | 	struct nfs4_server_caps_arg args = { | 
 | 2062 | 		.fhandle = fhandle, | 
 | 2063 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | 	struct nfs4_server_caps_res res = {}; | 
 | 2065 | 	struct rpc_message msg = { | 
 | 2066 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], | 
| Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2067 | 		.rpc_argp = &args, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | 		.rpc_resp = &res, | 
 | 2069 | 	}; | 
 | 2070 | 	int status; | 
 | 2071 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2072 | 	status = nfs4_call_sync(server, &msg, &args, &res, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | 	if (status == 0) { | 
 | 2074 | 		memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); | 
| Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2075 | 		server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| | 
 | 2076 | 				NFS_CAP_SYMLINKS|NFS_CAP_FILEID| | 
 | 2077 | 				NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| | 
 | 2078 | 				NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| | 
 | 2079 | 				NFS_CAP_CTIME|NFS_CAP_MTIME); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | 		if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) | 
 | 2081 | 			server->caps |= NFS_CAP_ACLS; | 
 | 2082 | 		if (res.has_links != 0) | 
 | 2083 | 			server->caps |= NFS_CAP_HARDLINKS; | 
 | 2084 | 		if (res.has_symlinks != 0) | 
 | 2085 | 			server->caps |= NFS_CAP_SYMLINKS; | 
| Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2086 | 		if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) | 
 | 2087 | 			server->caps |= NFS_CAP_FILEID; | 
 | 2088 | 		if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) | 
 | 2089 | 			server->caps |= NFS_CAP_MODE; | 
 | 2090 | 		if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) | 
 | 2091 | 			server->caps |= NFS_CAP_NLINK; | 
 | 2092 | 		if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) | 
 | 2093 | 			server->caps |= NFS_CAP_OWNER; | 
 | 2094 | 		if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) | 
 | 2095 | 			server->caps |= NFS_CAP_OWNER_GROUP; | 
 | 2096 | 		if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) | 
 | 2097 | 			server->caps |= NFS_CAP_ATIME; | 
 | 2098 | 		if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) | 
 | 2099 | 			server->caps |= NFS_CAP_CTIME; | 
 | 2100 | 		if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) | 
 | 2101 | 			server->caps |= NFS_CAP_MTIME; | 
 | 2102 |  | 
| Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2103 | 		memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); | 
 | 2104 | 		server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; | 
 | 2105 | 		server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | 		server->acl_bitmask = res.acl_bitmask; | 
 | 2107 | 	} | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2108 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | 	return status; | 
 | 2110 | } | 
 | 2111 |  | 
| Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2112 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | { | 
 | 2114 | 	struct nfs4_exception exception = { }; | 
 | 2115 | 	int err; | 
 | 2116 | 	do { | 
 | 2117 | 		err = nfs4_handle_exception(server, | 
 | 2118 | 				_nfs4_server_capabilities(server, fhandle), | 
 | 2119 | 				&exception); | 
 | 2120 | 	} while (exception.retry); | 
 | 2121 | 	return err; | 
 | 2122 | } | 
 | 2123 |  | 
 | 2124 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, | 
 | 2125 | 		struct nfs_fsinfo *info) | 
 | 2126 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | 	struct nfs4_lookup_root_arg args = { | 
 | 2128 | 		.bitmask = nfs4_fattr_bitmap, | 
 | 2129 | 	}; | 
 | 2130 | 	struct nfs4_lookup_res res = { | 
 | 2131 | 		.server = server, | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2132 | 		.fattr = info->fattr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | 		.fh = fhandle, | 
 | 2134 | 	}; | 
 | 2135 | 	struct rpc_message msg = { | 
 | 2136 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], | 
 | 2137 | 		.rpc_argp = &args, | 
 | 2138 | 		.rpc_resp = &res, | 
 | 2139 | 	}; | 
| Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2140 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2141 | 	nfs_fattr_init(info->fattr); | 
| Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 2142 | 	return nfs4_call_sync(server, &msg, &args, &res, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | } | 
 | 2144 |  | 
 | 2145 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, | 
 | 2146 | 		struct nfs_fsinfo *info) | 
 | 2147 | { | 
 | 2148 | 	struct nfs4_exception exception = { }; | 
 | 2149 | 	int err; | 
 | 2150 | 	do { | 
 | 2151 | 		err = nfs4_handle_exception(server, | 
 | 2152 | 				_nfs4_lookup_root(server, fhandle, info), | 
 | 2153 | 				&exception); | 
 | 2154 | 	} while (exception.retry); | 
 | 2155 | 	return err; | 
 | 2156 | } | 
 | 2157 |  | 
| David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2158 | /* | 
 | 2159 |  * get the file handle for the "/" directory on the server | 
 | 2160 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, | 
| David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2162 | 			      struct nfs_fsinfo *info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | 	int status; | 
 | 2165 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | 	status = nfs4_lookup_root(server, fhandle, info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | 	if (status == 0) | 
 | 2168 | 		status = nfs4_server_capabilities(server, fhandle); | 
 | 2169 | 	if (status == 0) | 
 | 2170 | 		status = nfs4_do_fsinfo(server, fhandle, info); | 
| Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2171 | 	return nfs4_map_errors(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | } | 
 | 2173 |  | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2174 | /* | 
 | 2175 |  * Get locations and (maybe) other attributes of a referral. | 
 | 2176 |  * Note that we'll actually follow the referral later when | 
 | 2177 |  * we detect fsid mismatch in inode revalidation | 
 | 2178 |  */ | 
| Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2179 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle) | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2180 | { | 
 | 2181 | 	int status = -ENOMEM; | 
 | 2182 | 	struct page *page = NULL; | 
 | 2183 | 	struct nfs4_fs_locations *locations = NULL; | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2184 |  | 
 | 2185 | 	page = alloc_page(GFP_KERNEL); | 
 | 2186 | 	if (page == NULL) | 
 | 2187 | 		goto out; | 
 | 2188 | 	locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); | 
 | 2189 | 	if (locations == NULL) | 
 | 2190 | 		goto out; | 
 | 2191 |  | 
| Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2192 | 	status = nfs4_proc_fs_locations(dir, name, locations, page); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2193 | 	if (status != 0) | 
 | 2194 | 		goto out; | 
 | 2195 | 	/* Make sure server returned a different fsid for the referral */ | 
 | 2196 | 	if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2197 | 		dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2198 | 		status = -EIO; | 
 | 2199 | 		goto out; | 
 | 2200 | 	} | 
 | 2201 |  | 
 | 2202 | 	memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); | 
 | 2203 | 	fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; | 
 | 2204 | 	if (!fattr->mode) | 
 | 2205 | 		fattr->mode = S_IFDIR; | 
 | 2206 | 	memset(fhandle, 0, sizeof(struct nfs_fh)); | 
 | 2207 | out: | 
 | 2208 | 	if (page) | 
 | 2209 | 		__free_page(page); | 
| Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2210 | 	kfree(locations); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2211 | 	return status; | 
 | 2212 | } | 
 | 2213 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 
 | 2215 | { | 
 | 2216 | 	struct nfs4_getattr_arg args = { | 
 | 2217 | 		.fh = fhandle, | 
 | 2218 | 		.bitmask = server->attr_bitmask, | 
 | 2219 | 	}; | 
 | 2220 | 	struct nfs4_getattr_res res = { | 
 | 2221 | 		.fattr = fattr, | 
 | 2222 | 		.server = server, | 
 | 2223 | 	}; | 
 | 2224 | 	struct rpc_message msg = { | 
 | 2225 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], | 
 | 2226 | 		.rpc_argp = &args, | 
 | 2227 | 		.rpc_resp = &res, | 
 | 2228 | 	}; | 
 | 2229 | 	 | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2230 | 	nfs_fattr_init(fattr); | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2231 | 	return nfs4_call_sync(server, &msg, &args, &res, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | } | 
 | 2233 |  | 
 | 2234 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 
 | 2235 | { | 
 | 2236 | 	struct nfs4_exception exception = { }; | 
 | 2237 | 	int err; | 
 | 2238 | 	do { | 
 | 2239 | 		err = nfs4_handle_exception(server, | 
 | 2240 | 				_nfs4_proc_getattr(server, fhandle, fattr), | 
 | 2241 | 				&exception); | 
 | 2242 | 	} while (exception.retry); | 
 | 2243 | 	return err; | 
 | 2244 | } | 
 | 2245 |  | 
 | 2246 | /*  | 
 | 2247 |  * The file is not closed if it is opened due to the a request to change | 
 | 2248 |  * the size of the file. The open call will not be needed once the | 
 | 2249 |  * VFS layer lookup-intents are implemented. | 
 | 2250 |  * | 
 | 2251 |  * Close is called when the inode is destroyed. | 
 | 2252 |  * If we haven't opened the file for O_WRONLY, we | 
 | 2253 |  * need to in the size_change case to obtain a stateid. | 
 | 2254 |  * | 
 | 2255 |  * Got race? | 
 | 2256 |  * Because OPEN is always done by name in nfsv4, it is | 
 | 2257 |  * possible that we opened a different file by the same | 
 | 2258 |  * name.  We can recognize this race condition, but we | 
 | 2259 |  * can't do anything about it besides returning an error. | 
 | 2260 |  * | 
 | 2261 |  * This will be fixed with VFS changes (lookup-intent). | 
 | 2262 |  */ | 
 | 2263 | static int | 
 | 2264 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, | 
 | 2265 | 		  struct iattr *sattr) | 
 | 2266 | { | 
| Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2267 | 	struct inode *inode = dentry->d_inode; | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2268 | 	struct rpc_cred *cred = NULL; | 
| Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2269 | 	struct nfs4_state *state = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | 	int status; | 
 | 2271 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2272 | 	nfs_fattr_init(fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | 	 | 
| Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2274 | 	/* Search for an existing open(O_WRITE) file */ | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2275 | 	if (sattr->ia_valid & ATTR_FILE) { | 
 | 2276 | 		struct nfs_open_context *ctx; | 
| Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2277 |  | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2278 | 		ctx = nfs_file_open_context(sattr->ia_file); | 
| Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2279 | 		if (ctx) { | 
 | 2280 | 			cred = ctx->cred; | 
 | 2281 | 			state = ctx->state; | 
 | 2282 | 		} | 
| Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2283 | 	} | 
 | 2284 |  | 
 | 2285 | 	status = nfs4_do_setattr(inode, cred, fattr, sattr, state); | 
| Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2286 | 	if (status == 0) | 
 | 2287 | 		nfs_setattr_update_inode(inode, sattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | 	return status; | 
 | 2289 | } | 
 | 2290 |  | 
| Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2291 | static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh, | 
 | 2292 | 		const struct qstr *name, struct nfs_fh *fhandle, | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2293 | 		struct nfs_fattr *fattr) | 
 | 2294 | { | 
 | 2295 | 	int		       status; | 
 | 2296 | 	struct nfs4_lookup_arg args = { | 
 | 2297 | 		.bitmask = server->attr_bitmask, | 
 | 2298 | 		.dir_fh = dirfh, | 
 | 2299 | 		.name = name, | 
 | 2300 | 	}; | 
 | 2301 | 	struct nfs4_lookup_res res = { | 
 | 2302 | 		.server = server, | 
 | 2303 | 		.fattr = fattr, | 
 | 2304 | 		.fh = fhandle, | 
 | 2305 | 	}; | 
 | 2306 | 	struct rpc_message msg = { | 
 | 2307 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], | 
 | 2308 | 		.rpc_argp = &args, | 
 | 2309 | 		.rpc_resp = &res, | 
 | 2310 | 	}; | 
 | 2311 |  | 
 | 2312 | 	nfs_fattr_init(fattr); | 
 | 2313 |  | 
 | 2314 | 	dprintk("NFS call  lookupfh %s\n", name->name); | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2315 | 	status = nfs4_call_sync(server, &msg, &args, &res, 0); | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2316 | 	dprintk("NFS reply lookupfh: %d\n", status); | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2317 | 	return status; | 
 | 2318 | } | 
 | 2319 |  | 
 | 2320 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, | 
 | 2321 | 			      struct qstr *name, struct nfs_fh *fhandle, | 
 | 2322 | 			      struct nfs_fattr *fattr) | 
 | 2323 | { | 
 | 2324 | 	struct nfs4_exception exception = { }; | 
 | 2325 | 	int err; | 
 | 2326 | 	do { | 
| Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2327 | 		err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); | 
 | 2328 | 		/* FIXME: !!!! */ | 
 | 2329 | 		if (err == -NFS4ERR_MOVED) { | 
 | 2330 | 			err = -EREMOTE; | 
 | 2331 | 			break; | 
 | 2332 | 		} | 
 | 2333 | 		err = nfs4_handle_exception(server, err, &exception); | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2334 | 	} while (exception.retry); | 
 | 2335 | 	return err; | 
 | 2336 | } | 
 | 2337 |  | 
| Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2338 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | 		struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 
 | 2340 | { | 
| Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2341 | 	int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | 	 | 
 | 2343 | 	dprintk("NFS call  lookup %s\n", name->name); | 
| Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2344 | 	status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr); | 
| Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2345 | 	if (status == -NFS4ERR_MOVED) | 
 | 2346 | 		status = nfs4_get_referral(dir, name, fattr, fhandle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | 	dprintk("NFS reply lookup: %d\n", status); | 
 | 2348 | 	return status; | 
 | 2349 | } | 
 | 2350 |  | 
 | 2351 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 
 | 2352 | { | 
 | 2353 | 	struct nfs4_exception exception = { }; | 
 | 2354 | 	int err; | 
 | 2355 | 	do { | 
 | 2356 | 		err = nfs4_handle_exception(NFS_SERVER(dir), | 
 | 2357 | 				_nfs4_proc_lookup(dir, name, fhandle, fattr), | 
 | 2358 | 				&exception); | 
 | 2359 | 	} while (exception.retry); | 
 | 2360 | 	return err; | 
 | 2361 | } | 
 | 2362 |  | 
 | 2363 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) | 
 | 2364 | { | 
| Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2365 | 	struct nfs_server *server = NFS_SERVER(inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | 	struct nfs4_accessargs args = { | 
 | 2367 | 		.fh = NFS_FH(inode), | 
| Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2368 | 		.bitmask = server->attr_bitmask, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | 	}; | 
| Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2370 | 	struct nfs4_accessres res = { | 
 | 2371 | 		.server = server, | 
| Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2372 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | 	struct rpc_message msg = { | 
 | 2374 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], | 
 | 2375 | 		.rpc_argp = &args, | 
 | 2376 | 		.rpc_resp = &res, | 
 | 2377 | 		.rpc_cred = entry->cred, | 
 | 2378 | 	}; | 
 | 2379 | 	int mode = entry->mask; | 
 | 2380 | 	int status; | 
 | 2381 |  | 
 | 2382 | 	/* | 
 | 2383 | 	 * Determine which access bits we want to ask for... | 
 | 2384 | 	 */ | 
 | 2385 | 	if (mode & MAY_READ) | 
 | 2386 | 		args.access |= NFS4_ACCESS_READ; | 
 | 2387 | 	if (S_ISDIR(inode->i_mode)) { | 
 | 2388 | 		if (mode & MAY_WRITE) | 
 | 2389 | 			args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; | 
 | 2390 | 		if (mode & MAY_EXEC) | 
 | 2391 | 			args.access |= NFS4_ACCESS_LOOKUP; | 
 | 2392 | 	} else { | 
 | 2393 | 		if (mode & MAY_WRITE) | 
 | 2394 | 			args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; | 
 | 2395 | 		if (mode & MAY_EXEC) | 
 | 2396 | 			args.access |= NFS4_ACCESS_EXECUTE; | 
 | 2397 | 	} | 
| Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2398 |  | 
 | 2399 | 	res.fattr = nfs_alloc_fattr(); | 
 | 2400 | 	if (res.fattr == NULL) | 
 | 2401 | 		return -ENOMEM; | 
 | 2402 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2403 | 	status = nfs4_call_sync(server, &msg, &args, &res, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | 	if (!status) { | 
 | 2405 | 		entry->mask = 0; | 
 | 2406 | 		if (res.access & NFS4_ACCESS_READ) | 
 | 2407 | 			entry->mask |= MAY_READ; | 
 | 2408 | 		if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) | 
 | 2409 | 			entry->mask |= MAY_WRITE; | 
 | 2410 | 		if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) | 
 | 2411 | 			entry->mask |= MAY_EXEC; | 
| Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2412 | 		nfs_refresh_inode(inode, res.fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | 	} | 
| Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2414 | 	nfs_free_fattr(res.fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | 	return status; | 
 | 2416 | } | 
 | 2417 |  | 
 | 2418 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) | 
 | 2419 | { | 
 | 2420 | 	struct nfs4_exception exception = { }; | 
 | 2421 | 	int err; | 
 | 2422 | 	do { | 
 | 2423 | 		err = nfs4_handle_exception(NFS_SERVER(inode), | 
 | 2424 | 				_nfs4_proc_access(inode, entry), | 
 | 2425 | 				&exception); | 
 | 2426 | 	} while (exception.retry); | 
 | 2427 | 	return err; | 
 | 2428 | } | 
 | 2429 |  | 
 | 2430 | /* | 
 | 2431 |  * TODO: For the time being, we don't try to get any attributes | 
 | 2432 |  * along with any of the zero-copy operations READ, READDIR, | 
 | 2433 |  * READLINK, WRITE. | 
 | 2434 |  * | 
 | 2435 |  * In the case of the first three, we want to put the GETATTR | 
 | 2436 |  * after the read-type operation -- this is because it is hard | 
 | 2437 |  * to predict the length of a GETATTR response in v4, and thus | 
 | 2438 |  * align the READ data correctly.  This means that the GETATTR | 
 | 2439 |  * may end up partially falling into the page cache, and we should | 
 | 2440 |  * shift it into the 'tail' of the xdr_buf before processing. | 
 | 2441 |  * To do this efficiently, we need to know the total length | 
 | 2442 |  * of data received, which doesn't seem to be available outside | 
 | 2443 |  * of the RPC layer. | 
 | 2444 |  * | 
 | 2445 |  * In the case of WRITE, we also want to put the GETATTR after | 
 | 2446 |  * the operation -- in this case because we want to make sure | 
 | 2447 |  * we get the post-operation mtime and size.  This means that | 
 | 2448 |  * we can't use xdr_encode_pages() as written: we need a variant | 
 | 2449 |  * of it which would leave room in the 'tail' iovec. | 
 | 2450 |  * | 
 | 2451 |  * Both of these changes to the XDR layer would in fact be quite | 
 | 2452 |  * minor, but I decided to leave them for a subsequent patch. | 
 | 2453 |  */ | 
 | 2454 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, | 
 | 2455 | 		unsigned int pgbase, unsigned int pglen) | 
 | 2456 | { | 
 | 2457 | 	struct nfs4_readlink args = { | 
 | 2458 | 		.fh       = NFS_FH(inode), | 
 | 2459 | 		.pgbase	  = pgbase, | 
 | 2460 | 		.pglen    = pglen, | 
 | 2461 | 		.pages    = &page, | 
 | 2462 | 	}; | 
| Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2463 | 	struct nfs4_readlink_res res; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | 	struct rpc_message msg = { | 
 | 2465 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], | 
 | 2466 | 		.rpc_argp = &args, | 
| Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2467 | 		.rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | 	}; | 
 | 2469 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2470 | 	return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | } | 
 | 2472 |  | 
 | 2473 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, | 
 | 2474 | 		unsigned int pgbase, unsigned int pglen) | 
 | 2475 | { | 
 | 2476 | 	struct nfs4_exception exception = { }; | 
 | 2477 | 	int err; | 
 | 2478 | 	do { | 
 | 2479 | 		err = nfs4_handle_exception(NFS_SERVER(inode), | 
 | 2480 | 				_nfs4_proc_readlink(inode, page, pgbase, pglen), | 
 | 2481 | 				&exception); | 
 | 2482 | 	} while (exception.retry); | 
 | 2483 | 	return err; | 
 | 2484 | } | 
 | 2485 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | /* | 
 | 2487 |  * Got race? | 
 | 2488 |  * We will need to arrange for the VFS layer to provide an atomic open. | 
 | 2489 |  * Until then, this create/open method is prone to inefficiency and race | 
 | 2490 |  * conditions due to the lookup, create, and open VFS calls from sys_open() | 
 | 2491 |  * placed on the wire. | 
 | 2492 |  * | 
 | 2493 |  * Given the above sorry state of affairs, I'm simply sending an OPEN. | 
 | 2494 |  * The file will be opened again in the subsequent VFS open call | 
 | 2495 |  * (nfs4_proc_file_open). | 
 | 2496 |  * | 
 | 2497 |  * The open for read will just hang around to be used by any process that | 
 | 2498 |  * opens the file O_RDONLY. This will all be resolved with the VFS changes. | 
 | 2499 |  */ | 
 | 2500 |  | 
 | 2501 | static int | 
 | 2502 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2503 |                  int flags, struct nfs_open_context *ctx) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 | { | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2505 | 	struct path my_path = { | 
| Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2506 | 		.dentry = dentry, | 
 | 2507 | 	}; | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2508 | 	struct path *path = &my_path; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | 	struct nfs4_state *state; | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2510 | 	struct rpc_cred *cred = NULL; | 
 | 2511 | 	fmode_t fmode = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | 	int status = 0; | 
 | 2513 |  | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2514 | 	if (ctx != NULL) { | 
 | 2515 | 		cred = ctx->cred; | 
 | 2516 | 		path = &ctx->path; | 
 | 2517 | 		fmode = ctx->mode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | 	} | 
| Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2519 | 	sattr->ia_mode &= ~current_umask(); | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2520 | 	state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); | 
| Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2521 | 	d_drop(dentry); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | 	if (IS_ERR(state)) { | 
 | 2523 | 		status = PTR_ERR(state); | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2524 | 		goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2525 | 	} | 
| Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2526 | 	d_add(dentry, igrab(state->inode)); | 
| Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2527 | 	nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2528 | 	if (ctx != NULL) | 
 | 2529 | 		ctx->state = state; | 
| Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2530 | 	else | 
| Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2531 | 		nfs4_close_sync(path, state, fmode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | out: | 
 | 2533 | 	return status; | 
 | 2534 | } | 
 | 2535 |  | 
 | 2536 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) | 
 | 2537 | { | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2538 | 	struct nfs_server *server = NFS_SERVER(dir); | 
| Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2539 | 	struct nfs_removeargs args = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | 		.fh = NFS_FH(dir), | 
| Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2541 | 		.name.len = name->len, | 
 | 2542 | 		.name.name = name->name, | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2543 | 		.bitmask = server->attr_bitmask, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | 	}; | 
| Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2545 | 	struct nfs_removeres res = { | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2546 | 		.server = server, | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2547 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | 	struct rpc_message msg = { | 
| Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2549 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], | 
 | 2550 | 		.rpc_argp = &args, | 
 | 2551 | 		.rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | 	}; | 
| Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2553 | 	int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 |  | 
| Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2555 | 	res.dir_attr = nfs_alloc_fattr(); | 
 | 2556 | 	if (res.dir_attr == NULL) | 
 | 2557 | 		goto out; | 
 | 2558 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2559 | 	status = nfs4_call_sync(server, &msg, &args, &res, 1); | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2560 | 	if (status == 0) { | 
 | 2561 | 		update_changeattr(dir, &res.cinfo); | 
| Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2562 | 		nfs_post_op_update_inode(dir, res.dir_attr); | 
| Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2563 | 	} | 
| Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2564 | 	nfs_free_fattr(res.dir_attr); | 
 | 2565 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | 	return status; | 
 | 2567 | } | 
 | 2568 |  | 
 | 2569 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) | 
 | 2570 | { | 
 | 2571 | 	struct nfs4_exception exception = { }; | 
 | 2572 | 	int err; | 
 | 2573 | 	do { | 
 | 2574 | 		err = nfs4_handle_exception(NFS_SERVER(dir), | 
 | 2575 | 				_nfs4_proc_remove(dir, name), | 
 | 2576 | 				&exception); | 
 | 2577 | 	} while (exception.retry); | 
 | 2578 | 	return err; | 
 | 2579 | } | 
 | 2580 |  | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2581 | static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | { | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2583 | 	struct nfs_server *server = NFS_SERVER(dir); | 
 | 2584 | 	struct nfs_removeargs *args = msg->rpc_argp; | 
 | 2585 | 	struct nfs_removeres *res = msg->rpc_resp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 |  | 
| Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2587 | 	args->bitmask = server->cache_consistency_bitmask; | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2588 | 	res->server = server; | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2589 | 	res->seq_res.sr_slot = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | 	msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | } | 
 | 2592 |  | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2593 | static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | { | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2595 | 	struct nfs_removeres *res = task->tk_msg.rpc_resp; | 
 | 2596 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2597 | 	if (!nfs4_sequence_done(task, &res->seq_res)) | 
 | 2598 | 		return 0; | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2599 | 	if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2600 | 		return 0; | 
 | 2601 | 	update_changeattr(dir, &res->cinfo); | 
| Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2602 | 	nfs_post_op_update_inode(dir, res->dir_attr); | 
| Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2603 | 	return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | } | 
 | 2605 |  | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2606 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) | 
 | 2607 | { | 
 | 2608 | 	struct nfs_server *server = NFS_SERVER(dir); | 
 | 2609 | 	struct nfs_renameargs *arg = msg->rpc_argp; | 
 | 2610 | 	struct nfs_renameres *res = msg->rpc_resp; | 
 | 2611 |  | 
 | 2612 | 	msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; | 
 | 2613 | 	arg->bitmask = server->attr_bitmask; | 
 | 2614 | 	res->server = server; | 
 | 2615 | } | 
 | 2616 |  | 
 | 2617 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, | 
 | 2618 | 				 struct inode *new_dir) | 
 | 2619 | { | 
 | 2620 | 	struct nfs_renameres *res = task->tk_msg.rpc_resp; | 
 | 2621 |  | 
 | 2622 | 	if (!nfs4_sequence_done(task, &res->seq_res)) | 
 | 2623 | 		return 0; | 
 | 2624 | 	if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) | 
 | 2625 | 		return 0; | 
 | 2626 |  | 
 | 2627 | 	update_changeattr(old_dir, &res->old_cinfo); | 
 | 2628 | 	nfs_post_op_update_inode(old_dir, res->old_fattr); | 
 | 2629 | 	update_changeattr(new_dir, &res->new_cinfo); | 
 | 2630 | 	nfs_post_op_update_inode(new_dir, res->new_fattr); | 
 | 2631 | 	return 1; | 
 | 2632 | } | 
 | 2633 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, | 
 | 2635 | 		struct inode *new_dir, struct qstr *new_name) | 
 | 2636 | { | 
| Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2637 | 	struct nfs_server *server = NFS_SERVER(old_dir); | 
| Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2638 | 	struct nfs_renameargs arg = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | 		.old_dir = NFS_FH(old_dir), | 
 | 2640 | 		.new_dir = NFS_FH(new_dir), | 
 | 2641 | 		.old_name = old_name, | 
 | 2642 | 		.new_name = new_name, | 
| Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2643 | 		.bitmask = server->attr_bitmask, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | 	}; | 
| Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2645 | 	struct nfs_renameres res = { | 
| Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2646 | 		.server = server, | 
| Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2647 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | 	struct rpc_message msg = { | 
 | 2649 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], | 
 | 2650 | 		.rpc_argp = &arg, | 
 | 2651 | 		.rpc_resp = &res, | 
 | 2652 | 	}; | 
| Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2653 | 	int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | 	 | 
| Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2655 | 	res.old_fattr = nfs_alloc_fattr(); | 
 | 2656 | 	res.new_fattr = nfs_alloc_fattr(); | 
 | 2657 | 	if (res.old_fattr == NULL || res.new_fattr == NULL) | 
 | 2658 | 		goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 |  | 
| Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2660 | 	status = nfs4_call_sync(server, &msg, &arg, &res, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | 	if (!status) { | 
 | 2662 | 		update_changeattr(old_dir, &res.old_cinfo); | 
| Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2663 | 		nfs_post_op_update_inode(old_dir, res.old_fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | 		update_changeattr(new_dir, &res.new_cinfo); | 
| Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2665 | 		nfs_post_op_update_inode(new_dir, res.new_fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | 	} | 
| Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2667 | out: | 
 | 2668 | 	nfs_free_fattr(res.new_fattr); | 
 | 2669 | 	nfs_free_fattr(res.old_fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | 	return status; | 
 | 2671 | } | 
 | 2672 |  | 
 | 2673 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, | 
 | 2674 | 		struct inode *new_dir, struct qstr *new_name) | 
 | 2675 | { | 
 | 2676 | 	struct nfs4_exception exception = { }; | 
 | 2677 | 	int err; | 
 | 2678 | 	do { | 
 | 2679 | 		err = nfs4_handle_exception(NFS_SERVER(old_dir), | 
 | 2680 | 				_nfs4_proc_rename(old_dir, old_name, | 
 | 2681 | 					new_dir, new_name), | 
 | 2682 | 				&exception); | 
 | 2683 | 	} while (exception.retry); | 
 | 2684 | 	return err; | 
 | 2685 | } | 
 | 2686 |  | 
 | 2687 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) | 
 | 2688 | { | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2689 | 	struct nfs_server *server = NFS_SERVER(inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | 	struct nfs4_link_arg arg = { | 
 | 2691 | 		.fh     = NFS_FH(inode), | 
 | 2692 | 		.dir_fh = NFS_FH(dir), | 
 | 2693 | 		.name   = name, | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2694 | 		.bitmask = server->attr_bitmask, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | 	}; | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2696 | 	struct nfs4_link_res res = { | 
 | 2697 | 		.server = server, | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2698 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | 	struct rpc_message msg = { | 
 | 2700 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], | 
 | 2701 | 		.rpc_argp = &arg, | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2702 | 		.rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | 	}; | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2704 | 	int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 |  | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2706 | 	res.fattr = nfs_alloc_fattr(); | 
 | 2707 | 	res.dir_attr = nfs_alloc_fattr(); | 
 | 2708 | 	if (res.fattr == NULL || res.dir_attr == NULL) | 
 | 2709 | 		goto out; | 
 | 2710 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2711 | 	status = nfs4_call_sync(server, &msg, &arg, &res, 1); | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2712 | 	if (!status) { | 
 | 2713 | 		update_changeattr(dir, &res.cinfo); | 
 | 2714 | 		nfs_post_op_update_inode(dir, res.dir_attr); | 
| Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2715 | 		nfs_post_op_update_inode(inode, res.fattr); | 
| Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2716 | 	} | 
| Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2717 | out: | 
 | 2718 | 	nfs_free_fattr(res.dir_attr); | 
 | 2719 | 	nfs_free_fattr(res.fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | 	return status; | 
 | 2721 | } | 
 | 2722 |  | 
 | 2723 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) | 
 | 2724 | { | 
 | 2725 | 	struct nfs4_exception exception = { }; | 
 | 2726 | 	int err; | 
 | 2727 | 	do { | 
 | 2728 | 		err = nfs4_handle_exception(NFS_SERVER(inode), | 
 | 2729 | 				_nfs4_proc_link(inode, dir, name), | 
 | 2730 | 				&exception); | 
 | 2731 | 	} while (exception.retry); | 
 | 2732 | 	return err; | 
 | 2733 | } | 
 | 2734 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2735 | struct nfs4_createdata { | 
 | 2736 | 	struct rpc_message msg; | 
 | 2737 | 	struct nfs4_create_arg arg; | 
 | 2738 | 	struct nfs4_create_res res; | 
 | 2739 | 	struct nfs_fh fh; | 
 | 2740 | 	struct nfs_fattr fattr; | 
 | 2741 | 	struct nfs_fattr dir_fattr; | 
 | 2742 | }; | 
 | 2743 |  | 
 | 2744 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, | 
 | 2745 | 		struct qstr *name, struct iattr *sattr, u32 ftype) | 
 | 2746 | { | 
 | 2747 | 	struct nfs4_createdata *data; | 
 | 2748 |  | 
 | 2749 | 	data = kzalloc(sizeof(*data), GFP_KERNEL); | 
 | 2750 | 	if (data != NULL) { | 
 | 2751 | 		struct nfs_server *server = NFS_SERVER(dir); | 
 | 2752 |  | 
 | 2753 | 		data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; | 
 | 2754 | 		data->msg.rpc_argp = &data->arg; | 
 | 2755 | 		data->msg.rpc_resp = &data->res; | 
 | 2756 | 		data->arg.dir_fh = NFS_FH(dir); | 
 | 2757 | 		data->arg.server = server; | 
 | 2758 | 		data->arg.name = name; | 
 | 2759 | 		data->arg.attrs = sattr; | 
 | 2760 | 		data->arg.ftype = ftype; | 
 | 2761 | 		data->arg.bitmask = server->attr_bitmask; | 
 | 2762 | 		data->res.server = server; | 
 | 2763 | 		data->res.fh = &data->fh; | 
 | 2764 | 		data->res.fattr = &data->fattr; | 
 | 2765 | 		data->res.dir_fattr = &data->dir_fattr; | 
 | 2766 | 		nfs_fattr_init(data->res.fattr); | 
 | 2767 | 		nfs_fattr_init(data->res.dir_fattr); | 
 | 2768 | 	} | 
 | 2769 | 	return data; | 
 | 2770 | } | 
 | 2771 |  | 
 | 2772 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) | 
 | 2773 | { | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2774 | 	int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg, | 
 | 2775 | 				    &data->arg, &data->res, 1); | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2776 | 	if (status == 0) { | 
 | 2777 | 		update_changeattr(dir, &data->res.dir_cinfo); | 
 | 2778 | 		nfs_post_op_update_inode(dir, data->res.dir_fattr); | 
 | 2779 | 		status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); | 
 | 2780 | 	} | 
 | 2781 | 	return status; | 
 | 2782 | } | 
 | 2783 |  | 
 | 2784 | static void nfs4_free_createdata(struct nfs4_createdata *data) | 
 | 2785 | { | 
 | 2786 | 	kfree(data); | 
 | 2787 | } | 
 | 2788 |  | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2789 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2790 | 		struct page *page, unsigned int len, struct iattr *sattr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2792 | 	struct nfs4_createdata *data; | 
 | 2793 | 	int status = -ENAMETOOLONG; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 |  | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2795 | 	if (len > NFS4_MAXPATHLEN) | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2796 | 		goto out; | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2797 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2798 | 	status = -ENOMEM; | 
 | 2799 | 	data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); | 
 | 2800 | 	if (data == NULL) | 
 | 2801 | 		goto out; | 
 | 2802 |  | 
 | 2803 | 	data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; | 
 | 2804 | 	data->arg.u.symlink.pages = &page; | 
 | 2805 | 	data->arg.u.symlink.len = len; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | 	 | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2807 | 	status = nfs4_do_create(dir, dentry, data); | 
 | 2808 |  | 
 | 2809 | 	nfs4_free_createdata(data); | 
 | 2810 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | 	return status; | 
 | 2812 | } | 
 | 2813 |  | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2814 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2815 | 		struct page *page, unsigned int len, struct iattr *sattr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | { | 
 | 2817 | 	struct nfs4_exception exception = { }; | 
 | 2818 | 	int err; | 
 | 2819 | 	do { | 
 | 2820 | 		err = nfs4_handle_exception(NFS_SERVER(dir), | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2821 | 				_nfs4_proc_symlink(dir, dentry, page, | 
 | 2822 | 							len, sattr), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | 				&exception); | 
 | 2824 | 	} while (exception.retry); | 
 | 2825 | 	return err; | 
 | 2826 | } | 
 | 2827 |  | 
 | 2828 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, | 
 | 2829 | 		struct iattr *sattr) | 
 | 2830 | { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2831 | 	struct nfs4_createdata *data; | 
 | 2832 | 	int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 |  | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2834 | 	data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); | 
 | 2835 | 	if (data == NULL) | 
 | 2836 | 		goto out; | 
 | 2837 |  | 
 | 2838 | 	status = nfs4_do_create(dir, dentry, data); | 
 | 2839 |  | 
 | 2840 | 	nfs4_free_createdata(data); | 
 | 2841 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | 	return status; | 
 | 2843 | } | 
 | 2844 |  | 
 | 2845 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, | 
 | 2846 | 		struct iattr *sattr) | 
 | 2847 | { | 
 | 2848 | 	struct nfs4_exception exception = { }; | 
 | 2849 | 	int err; | 
| Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2850 |  | 
 | 2851 | 	sattr->ia_mode &= ~current_umask(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | 	do { | 
 | 2853 | 		err = nfs4_handle_exception(NFS_SERVER(dir), | 
 | 2854 | 				_nfs4_proc_mkdir(dir, dentry, sattr), | 
 | 2855 | 				&exception); | 
 | 2856 | 	} while (exception.retry); | 
 | 2857 | 	return err; | 
 | 2858 | } | 
 | 2859 |  | 
 | 2860 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | 
| Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2861 | 		u64 cookie, struct page **pages, unsigned int count, int plus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | { | 
 | 2863 | 	struct inode		*dir = dentry->d_inode; | 
 | 2864 | 	struct nfs4_readdir_arg args = { | 
 | 2865 | 		.fh = NFS_FH(dir), | 
| Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2866 | 		.pages = pages, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | 		.pgbase = 0, | 
 | 2868 | 		.count = count, | 
| Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2869 | 		.bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, | 
| Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2870 | 		.plus = plus, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | 	}; | 
 | 2872 | 	struct nfs4_readdir_res res; | 
 | 2873 | 	struct rpc_message msg = { | 
 | 2874 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], | 
 | 2875 | 		.rpc_argp = &args, | 
 | 2876 | 		.rpc_resp = &res, | 
 | 2877 | 		.rpc_cred = cred, | 
 | 2878 | 	}; | 
 | 2879 | 	int			status; | 
 | 2880 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2881 | 	dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, | 
| Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2882 | 			dentry->d_parent->d_name.name, | 
 | 2883 | 			dentry->d_name.name, | 
 | 2884 | 			(unsigned long long)cookie); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | 	nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); | 
 | 2886 | 	res.pgbase = args.pgbase; | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2887 | 	status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); | 
| Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2888 | 	if (status >= 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | 		memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); | 
| Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2890 | 		status += args.pgbase; | 
 | 2891 | 	} | 
| Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2892 |  | 
 | 2893 | 	nfs_invalidate_atime(dir); | 
 | 2894 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2895 | 	dprintk("%s: returns %d\n", __func__, status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | 	return status; | 
 | 2897 | } | 
 | 2898 |  | 
 | 2899 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | 
| Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2900 | 		u64 cookie, struct page **pages, unsigned int count, int plus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | { | 
 | 2902 | 	struct nfs4_exception exception = { }; | 
 | 2903 | 	int err; | 
 | 2904 | 	do { | 
 | 2905 | 		err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), | 
 | 2906 | 				_nfs4_proc_readdir(dentry, cred, cookie, | 
| Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2907 | 					pages, count, plus), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | 				&exception); | 
 | 2909 | 	} while (exception.retry); | 
 | 2910 | 	return err; | 
 | 2911 | } | 
 | 2912 |  | 
 | 2913 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, | 
 | 2914 | 		struct iattr *sattr, dev_t rdev) | 
 | 2915 | { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2916 | 	struct nfs4_createdata *data; | 
 | 2917 | 	int mode = sattr->ia_mode; | 
 | 2918 | 	int status = -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 |  | 
 | 2920 | 	BUG_ON(!(sattr->ia_valid & ATTR_MODE)); | 
 | 2921 | 	BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode)); | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2922 |  | 
 | 2923 | 	data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); | 
 | 2924 | 	if (data == NULL) | 
 | 2925 | 		goto out; | 
 | 2926 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | 	if (S_ISFIFO(mode)) | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2928 | 		data->arg.ftype = NF4FIFO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | 	else if (S_ISBLK(mode)) { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2930 | 		data->arg.ftype = NF4BLK; | 
 | 2931 | 		data->arg.u.device.specdata1 = MAJOR(rdev); | 
 | 2932 | 		data->arg.u.device.specdata2 = MINOR(rdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | 	} | 
 | 2934 | 	else if (S_ISCHR(mode)) { | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2935 | 		data->arg.ftype = NF4CHR; | 
 | 2936 | 		data->arg.u.device.specdata1 = MAJOR(rdev); | 
 | 2937 | 		data->arg.u.device.specdata2 = MINOR(rdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | 	 | 
| Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2940 | 	status = nfs4_do_create(dir, dentry, data); | 
 | 2941 |  | 
 | 2942 | 	nfs4_free_createdata(data); | 
 | 2943 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | 	return status; | 
 | 2945 | } | 
 | 2946 |  | 
 | 2947 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, | 
 | 2948 | 		struct iattr *sattr, dev_t rdev) | 
 | 2949 | { | 
 | 2950 | 	struct nfs4_exception exception = { }; | 
 | 2951 | 	int err; | 
| Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2952 |  | 
 | 2953 | 	sattr->ia_mode &= ~current_umask(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | 	do { | 
 | 2955 | 		err = nfs4_handle_exception(NFS_SERVER(dir), | 
 | 2956 | 				_nfs4_proc_mknod(dir, dentry, sattr, rdev), | 
 | 2957 | 				&exception); | 
 | 2958 | 	} while (exception.retry); | 
 | 2959 | 	return err; | 
 | 2960 | } | 
 | 2961 |  | 
 | 2962 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, | 
 | 2963 | 		 struct nfs_fsstat *fsstat) | 
 | 2964 | { | 
 | 2965 | 	struct nfs4_statfs_arg args = { | 
 | 2966 | 		.fh = fhandle, | 
 | 2967 | 		.bitmask = server->attr_bitmask, | 
 | 2968 | 	}; | 
| Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2969 | 	struct nfs4_statfs_res res = { | 
 | 2970 | 		.fsstat = fsstat, | 
 | 2971 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | 	struct rpc_message msg = { | 
 | 2973 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], | 
 | 2974 | 		.rpc_argp = &args, | 
| Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2975 | 		.rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | 	}; | 
 | 2977 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2978 | 	nfs_fattr_init(fsstat->fattr); | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2979 | 	return  nfs4_call_sync(server, &msg, &args, &res, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | } | 
 | 2981 |  | 
 | 2982 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) | 
 | 2983 | { | 
 | 2984 | 	struct nfs4_exception exception = { }; | 
 | 2985 | 	int err; | 
 | 2986 | 	do { | 
 | 2987 | 		err = nfs4_handle_exception(server, | 
 | 2988 | 				_nfs4_proc_statfs(server, fhandle, fsstat), | 
 | 2989 | 				&exception); | 
 | 2990 | 	} while (exception.retry); | 
 | 2991 | 	return err; | 
 | 2992 | } | 
 | 2993 |  | 
 | 2994 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, | 
 | 2995 | 		struct nfs_fsinfo *fsinfo) | 
 | 2996 | { | 
 | 2997 | 	struct nfs4_fsinfo_arg args = { | 
 | 2998 | 		.fh = fhandle, | 
 | 2999 | 		.bitmask = server->attr_bitmask, | 
 | 3000 | 	}; | 
| Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3001 | 	struct nfs4_fsinfo_res res = { | 
 | 3002 | 		.fsinfo = fsinfo, | 
 | 3003 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | 	struct rpc_message msg = { | 
 | 3005 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], | 
 | 3006 | 		.rpc_argp = &args, | 
| Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3007 | 		.rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | 	}; | 
 | 3009 |  | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3010 | 	return nfs4_call_sync(server, &msg, &args, &res, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | } | 
 | 3012 |  | 
 | 3013 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) | 
 | 3014 | { | 
 | 3015 | 	struct nfs4_exception exception = { }; | 
 | 3016 | 	int err; | 
 | 3017 |  | 
 | 3018 | 	do { | 
 | 3019 | 		err = nfs4_handle_exception(server, | 
 | 3020 | 				_nfs4_do_fsinfo(server, fhandle, fsinfo), | 
 | 3021 | 				&exception); | 
 | 3022 | 	} while (exception.retry); | 
 | 3023 | 	return err; | 
 | 3024 | } | 
 | 3025 |  | 
 | 3026 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) | 
 | 3027 | { | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3028 | 	nfs_fattr_init(fsinfo->fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | 	return nfs4_do_fsinfo(server, fhandle, fsinfo); | 
 | 3030 | } | 
 | 3031 |  | 
 | 3032 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | 
 | 3033 | 		struct nfs_pathconf *pathconf) | 
 | 3034 | { | 
 | 3035 | 	struct nfs4_pathconf_arg args = { | 
 | 3036 | 		.fh = fhandle, | 
 | 3037 | 		.bitmask = server->attr_bitmask, | 
 | 3038 | 	}; | 
| Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3039 | 	struct nfs4_pathconf_res res = { | 
 | 3040 | 		.pathconf = pathconf, | 
 | 3041 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | 	struct rpc_message msg = { | 
 | 3043 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], | 
 | 3044 | 		.rpc_argp = &args, | 
| Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3045 | 		.rpc_resp = &res, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | 	}; | 
 | 3047 |  | 
 | 3048 | 	/* None of the pathconf attributes are mandatory to implement */ | 
 | 3049 | 	if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { | 
 | 3050 | 		memset(pathconf, 0, sizeof(*pathconf)); | 
 | 3051 | 		return 0; | 
 | 3052 | 	} | 
 | 3053 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3054 | 	nfs_fattr_init(pathconf->fattr); | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3055 | 	return nfs4_call_sync(server, &msg, &args, &res, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | } | 
 | 3057 |  | 
 | 3058 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | 
 | 3059 | 		struct nfs_pathconf *pathconf) | 
 | 3060 | { | 
 | 3061 | 	struct nfs4_exception exception = { }; | 
 | 3062 | 	int err; | 
 | 3063 |  | 
 | 3064 | 	do { | 
 | 3065 | 		err = nfs4_handle_exception(server, | 
 | 3066 | 				_nfs4_proc_pathconf(server, fhandle, pathconf), | 
 | 3067 | 				&exception); | 
 | 3068 | 	} while (exception.retry); | 
 | 3069 | 	return err; | 
 | 3070 | } | 
 | 3071 |  | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3072 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | { | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3074 | 	struct nfs_server *server = NFS_SERVER(data->inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 |  | 
| Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3076 | 	dprintk("--> %s\n", __func__); | 
 | 3077 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3078 | 	if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
 | 3079 | 		return -EAGAIN; | 
| Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3080 |  | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3081 | 	if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { | 
| Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3082 | 		nfs_restart_rpc(task, server->nfs_client); | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3083 | 		return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | 	} | 
| Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3085 |  | 
 | 3086 | 	nfs_invalidate_atime(data->inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | 	if (task->tk_status > 0) | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3088 | 		renew_lease(server, data->timestamp); | 
 | 3089 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | } | 
 | 3091 |  | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3092 | static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | 	data->timestamp   = jiffies; | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3095 | 	msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | } | 
 | 3097 |  | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3098 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | 	struct inode *inode = data->inode; | 
 | 3101 | 	 | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3102 | 	if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
 | 3103 | 		return -EAGAIN; | 
| Andy Adamson | def6ed7 | 2009-04-01 09:22:26 -0400 | [diff] [blame] | 3104 |  | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3105 | 	if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { | 
| Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3106 | 		nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3107 | 		return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | 	} | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3109 | 	if (task->tk_status >= 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | 		renew_lease(NFS_SERVER(inode), data->timestamp); | 
| Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3111 | 		nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3112 | 	} | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3113 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | } | 
 | 3115 |  | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3116 | static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3117 | { | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3118 | 	struct nfs_server *server = NFS_SERVER(data->inode); | 
 | 3119 |  | 
| Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3120 | 	data->args.bitmask = server->cache_consistency_bitmask; | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3121 | 	data->res.server = server; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | 	data->timestamp   = jiffies; | 
 | 3123 |  | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3124 | 	msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | } | 
 | 3126 |  | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3127 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3128 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | 	struct inode *inode = data->inode; | 
 | 3130 | 	 | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3131 | 	if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
 | 3132 | 		return -EAGAIN; | 
 | 3133 |  | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3134 | 	if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { | 
| Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3135 | 		nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3136 | 		return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | 	} | 
| Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3138 | 	nfs_refresh_inode(inode, data->res.fattr); | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3139 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | } | 
 | 3141 |  | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3142 | static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3143 | { | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3144 | 	struct nfs_server *server = NFS_SERVER(data->inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | 	 | 
| Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3146 | 	data->args.bitmask = server->cache_consistency_bitmask; | 
| Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3147 | 	data->res.server = server; | 
| Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3148 | 	msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | } | 
 | 3150 |  | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3151 | struct nfs4_renewdata { | 
 | 3152 | 	struct nfs_client	*client; | 
 | 3153 | 	unsigned long		timestamp; | 
 | 3154 | }; | 
 | 3155 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | /* | 
 | 3157 |  * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special | 
 | 3158 |  * standalone procedure for queueing an asynchronous RENEW. | 
 | 3159 |  */ | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3160 | static void nfs4_renew_release(void *calldata) | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3161 | { | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3162 | 	struct nfs4_renewdata *data = calldata; | 
 | 3163 | 	struct nfs_client *clp = data->client; | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3164 |  | 
| Alexandros Batsakis | 0851de0 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3165 | 	if (atomic_read(&clp->cl_count) > 1) | 
 | 3166 | 		nfs4_schedule_state_renewal(clp); | 
 | 3167 | 	nfs_put_client(clp); | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3168 | 	kfree(data); | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3169 | } | 
 | 3170 |  | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3171 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | { | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3173 | 	struct nfs4_renewdata *data = calldata; | 
 | 3174 | 	struct nfs_client *clp = data->client; | 
 | 3175 | 	unsigned long timestamp = data->timestamp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 |  | 
 | 3177 | 	if (task->tk_status < 0) { | 
| Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3178 | 		/* Unless we're shutting down, schedule state recovery! */ | 
 | 3179 | 		if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) | 
 | 3180 | 			nfs4_schedule_state_recovery(clp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | 		return; | 
 | 3182 | 	} | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3183 | 	do_renew_lease(clp, timestamp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | } | 
 | 3185 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3186 | static const struct rpc_call_ops nfs4_renew_ops = { | 
 | 3187 | 	.rpc_call_done = nfs4_renew_done, | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3188 | 	.rpc_release = nfs4_renew_release, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3189 | }; | 
 | 3190 |  | 
| David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3191 | int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | { | 
 | 3193 | 	struct rpc_message msg = { | 
 | 3194 | 		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_RENEW], | 
 | 3195 | 		.rpc_argp	= clp, | 
| Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3196 | 		.rpc_cred	= cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | 	}; | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3198 | 	struct nfs4_renewdata *data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 |  | 
| Alexandros Batsakis | 0851de0 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3200 | 	if (!atomic_inc_not_zero(&clp->cl_count)) | 
 | 3201 | 		return -EIO; | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3202 | 	data = kmalloc(sizeof(*data), GFP_KERNEL); | 
 | 3203 | 	if (data == NULL) | 
 | 3204 | 		return -ENOMEM; | 
 | 3205 | 	data->client = clp; | 
 | 3206 | 	data->timestamp = jiffies; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | 	return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, | 
| Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3208 | 			&nfs4_renew_ops, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | } | 
 | 3210 |  | 
| David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3211 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | { | 
 | 3213 | 	struct rpc_message msg = { | 
 | 3214 | 		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_RENEW], | 
 | 3215 | 		.rpc_argp	= clp, | 
| Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3216 | 		.rpc_cred	= cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | 	}; | 
 | 3218 | 	unsigned long now = jiffies; | 
 | 3219 | 	int status; | 
 | 3220 |  | 
 | 3221 | 	status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); | 
 | 3222 | 	if (status < 0) | 
 | 3223 | 		return status; | 
| Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3224 | 	do_renew_lease(clp, now); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | 	return 0; | 
 | 3226 | } | 
 | 3227 |  | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3228 | static inline int nfs4_server_supports_acls(struct nfs_server *server) | 
 | 3229 | { | 
 | 3230 | 	return (server->caps & NFS_CAP_ACLS) | 
 | 3231 | 		&& (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) | 
 | 3232 | 		&& (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); | 
 | 3233 | } | 
 | 3234 |  | 
 | 3235 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that | 
 | 3236 |  * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on | 
 | 3237 |  * the stack. | 
 | 3238 |  */ | 
 | 3239 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) | 
 | 3240 |  | 
 | 3241 | static void buf_to_pages(const void *buf, size_t buflen, | 
 | 3242 | 		struct page **pages, unsigned int *pgbase) | 
 | 3243 | { | 
 | 3244 | 	const void *p = buf; | 
 | 3245 |  | 
 | 3246 | 	*pgbase = offset_in_page(buf); | 
 | 3247 | 	p -= *pgbase; | 
 | 3248 | 	while (p < buf + buflen) { | 
 | 3249 | 		*(pages++) = virt_to_page(p); | 
 | 3250 | 		p += PAGE_CACHE_SIZE; | 
 | 3251 | 	} | 
 | 3252 | } | 
 | 3253 |  | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3254 | struct nfs4_cached_acl { | 
 | 3255 | 	int cached; | 
 | 3256 | 	size_t len; | 
| Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3257 | 	char data[0]; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3258 | }; | 
 | 3259 |  | 
 | 3260 | static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl) | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3261 | { | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3262 | 	struct nfs_inode *nfsi = NFS_I(inode); | 
 | 3263 |  | 
 | 3264 | 	spin_lock(&inode->i_lock); | 
 | 3265 | 	kfree(nfsi->nfs4_acl); | 
 | 3266 | 	nfsi->nfs4_acl = acl; | 
 | 3267 | 	spin_unlock(&inode->i_lock); | 
 | 3268 | } | 
 | 3269 |  | 
 | 3270 | static void nfs4_zap_acl_attr(struct inode *inode) | 
 | 3271 | { | 
 | 3272 | 	nfs4_set_cached_acl(inode, NULL); | 
 | 3273 | } | 
 | 3274 |  | 
 | 3275 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) | 
 | 3276 | { | 
 | 3277 | 	struct nfs_inode *nfsi = NFS_I(inode); | 
 | 3278 | 	struct nfs4_cached_acl *acl; | 
 | 3279 | 	int ret = -ENOENT; | 
 | 3280 |  | 
 | 3281 | 	spin_lock(&inode->i_lock); | 
 | 3282 | 	acl = nfsi->nfs4_acl; | 
 | 3283 | 	if (acl == NULL) | 
 | 3284 | 		goto out; | 
 | 3285 | 	if (buf == NULL) /* user is just asking for length */ | 
 | 3286 | 		goto out_len; | 
 | 3287 | 	if (acl->cached == 0) | 
 | 3288 | 		goto out; | 
 | 3289 | 	ret = -ERANGE; /* see getxattr(2) man page */ | 
 | 3290 | 	if (acl->len > buflen) | 
 | 3291 | 		goto out; | 
 | 3292 | 	memcpy(buf, acl->data, acl->len); | 
 | 3293 | out_len: | 
 | 3294 | 	ret = acl->len; | 
 | 3295 | out: | 
 | 3296 | 	spin_unlock(&inode->i_lock); | 
 | 3297 | 	return ret; | 
 | 3298 | } | 
 | 3299 |  | 
 | 3300 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) | 
 | 3301 | { | 
 | 3302 | 	struct nfs4_cached_acl *acl; | 
 | 3303 |  | 
 | 3304 | 	if (buf && acl_len <= PAGE_SIZE) { | 
 | 3305 | 		acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); | 
 | 3306 | 		if (acl == NULL) | 
 | 3307 | 			goto out; | 
 | 3308 | 		acl->cached = 1; | 
 | 3309 | 		memcpy(acl->data, buf, acl_len); | 
 | 3310 | 	} else { | 
 | 3311 | 		acl = kmalloc(sizeof(*acl), GFP_KERNEL); | 
 | 3312 | 		if (acl == NULL) | 
 | 3313 | 			goto out; | 
 | 3314 | 		acl->cached = 0; | 
 | 3315 | 	} | 
 | 3316 | 	acl->len = acl_len; | 
 | 3317 | out: | 
 | 3318 | 	nfs4_set_cached_acl(inode, acl); | 
 | 3319 | } | 
 | 3320 |  | 
| Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3321 | static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3322 | { | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3323 | 	struct page *pages[NFS4ACL_MAXPAGES]; | 
 | 3324 | 	struct nfs_getaclargs args = { | 
 | 3325 | 		.fh = NFS_FH(inode), | 
 | 3326 | 		.acl_pages = pages, | 
 | 3327 | 		.acl_len = buflen, | 
 | 3328 | 	}; | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3329 | 	struct nfs_getaclres res = { | 
 | 3330 | 		.acl_len = buflen, | 
 | 3331 | 	}; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3332 | 	void *resp_buf; | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3333 | 	struct rpc_message msg = { | 
 | 3334 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], | 
 | 3335 | 		.rpc_argp = &args, | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3336 | 		.rpc_resp = &res, | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3337 | 	}; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3338 | 	struct page *localpage = NULL; | 
 | 3339 | 	int ret; | 
 | 3340 |  | 
 | 3341 | 	if (buflen < PAGE_SIZE) { | 
 | 3342 | 		/* As long as we're doing a round trip to the server anyway, | 
 | 3343 | 		 * let's be prepared for a page of acl data. */ | 
 | 3344 | 		localpage = alloc_page(GFP_KERNEL); | 
 | 3345 | 		resp_buf = page_address(localpage); | 
 | 3346 | 		if (localpage == NULL) | 
 | 3347 | 			return -ENOMEM; | 
 | 3348 | 		args.acl_pages[0] = localpage; | 
 | 3349 | 		args.acl_pgbase = 0; | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3350 | 		args.acl_len = PAGE_SIZE; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3351 | 	} else { | 
 | 3352 | 		resp_buf = buf; | 
 | 3353 | 		buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); | 
 | 3354 | 	} | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3355 | 	ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3356 | 	if (ret) | 
 | 3357 | 		goto out_free; | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3358 | 	if (res.acl_len > args.acl_len) | 
 | 3359 | 		nfs4_write_cached_acl(inode, NULL, res.acl_len); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3360 | 	else | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3361 | 		nfs4_write_cached_acl(inode, resp_buf, res.acl_len); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3362 | 	if (buf) { | 
 | 3363 | 		ret = -ERANGE; | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3364 | 		if (res.acl_len > buflen) | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3365 | 			goto out_free; | 
 | 3366 | 		if (localpage) | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3367 | 			memcpy(buf, resp_buf, res.acl_len); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3368 | 	} | 
| Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3369 | 	ret = res.acl_len; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3370 | out_free: | 
 | 3371 | 	if (localpage) | 
 | 3372 | 		__free_page(localpage); | 
 | 3373 | 	return ret; | 
 | 3374 | } | 
 | 3375 |  | 
| Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3376 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) | 
 | 3377 | { | 
 | 3378 | 	struct nfs4_exception exception = { }; | 
 | 3379 | 	ssize_t ret; | 
 | 3380 | 	do { | 
 | 3381 | 		ret = __nfs4_get_acl_uncached(inode, buf, buflen); | 
 | 3382 | 		if (ret >= 0) | 
 | 3383 | 			break; | 
 | 3384 | 		ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); | 
 | 3385 | 	} while (exception.retry); | 
 | 3386 | 	return ret; | 
 | 3387 | } | 
 | 3388 |  | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3389 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) | 
 | 3390 | { | 
 | 3391 | 	struct nfs_server *server = NFS_SERVER(inode); | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3392 | 	int ret; | 
 | 3393 |  | 
 | 3394 | 	if (!nfs4_server_supports_acls(server)) | 
 | 3395 | 		return -EOPNOTSUPP; | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3396 | 	ret = nfs_revalidate_inode(server, inode); | 
 | 3397 | 	if (ret < 0) | 
 | 3398 | 		return ret; | 
| Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3399 | 	if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) | 
 | 3400 | 		nfs_zap_acl_cache(inode); | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3401 | 	ret = nfs4_read_cached_acl(inode, buf, buflen); | 
 | 3402 | 	if (ret != -ENOENT) | 
 | 3403 | 		return ret; | 
 | 3404 | 	return nfs4_get_acl_uncached(inode, buf, buflen); | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3405 | } | 
 | 3406 |  | 
| Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3407 | static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3408 | { | 
 | 3409 | 	struct nfs_server *server = NFS_SERVER(inode); | 
 | 3410 | 	struct page *pages[NFS4ACL_MAXPAGES]; | 
 | 3411 | 	struct nfs_setaclargs arg = { | 
 | 3412 | 		.fh		= NFS_FH(inode), | 
 | 3413 | 		.acl_pages	= pages, | 
 | 3414 | 		.acl_len	= buflen, | 
 | 3415 | 	}; | 
| Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3416 | 	struct nfs_setaclres res; | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3417 | 	struct rpc_message msg = { | 
 | 3418 | 		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_SETACL], | 
 | 3419 | 		.rpc_argp	= &arg, | 
| Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3420 | 		.rpc_resp	= &res, | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3421 | 	}; | 
 | 3422 | 	int ret; | 
 | 3423 |  | 
 | 3424 | 	if (!nfs4_server_supports_acls(server)) | 
 | 3425 | 		return -EOPNOTSUPP; | 
| Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3426 | 	nfs_inode_return_delegation(inode); | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3427 | 	buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3428 | 	ret = nfs4_call_sync(server, &msg, &arg, &res, 1); | 
| Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3429 | 	/* | 
 | 3430 | 	 * Acl update can result in inode attribute update. | 
 | 3431 | 	 * so mark the attribute cache invalid. | 
 | 3432 | 	 */ | 
 | 3433 | 	spin_lock(&inode->i_lock); | 
 | 3434 | 	NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; | 
 | 3435 | 	spin_unlock(&inode->i_lock); | 
| Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3436 | 	nfs_access_zap_cache(inode); | 
 | 3437 | 	nfs_zap_acl_cache(inode); | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3438 | 	return ret; | 
 | 3439 | } | 
 | 3440 |  | 
| Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3441 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) | 
 | 3442 | { | 
 | 3443 | 	struct nfs4_exception exception = { }; | 
 | 3444 | 	int err; | 
 | 3445 | 	do { | 
 | 3446 | 		err = nfs4_handle_exception(NFS_SERVER(inode), | 
 | 3447 | 				__nfs4_proc_set_acl(inode, buf, buflen), | 
 | 3448 | 				&exception); | 
 | 3449 | 	} while (exception.retry); | 
 | 3450 | 	return err; | 
 | 3451 | } | 
 | 3452 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | static int | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3454 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3455 | { | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3456 | 	struct nfs_client *clp = server->nfs_client; | 
 | 3457 |  | 
 | 3458 | 	if (task->tk_status >= 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | 		return 0; | 
 | 3460 | 	switch(task->tk_status) { | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3461 | 		case -NFS4ERR_ADMIN_REVOKED: | 
 | 3462 | 		case -NFS4ERR_BAD_STATEID: | 
 | 3463 | 		case -NFS4ERR_OPENMODE: | 
 | 3464 | 			if (state == NULL) | 
 | 3465 | 				break; | 
 | 3466 | 			nfs4_state_mark_reclaim_nograce(clp, state); | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3467 | 			goto do_state_recovery; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | 		case -NFS4ERR_STALE_STATEID: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3469 | 		case -NFS4ERR_STALE_CLIENTID: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | 		case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3471 | 			goto do_state_recovery; | 
| Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3472 | #if defined(CONFIG_NFS_V4_1) | 
 | 3473 | 		case -NFS4ERR_BADSESSION: | 
 | 3474 | 		case -NFS4ERR_BADSLOT: | 
 | 3475 | 		case -NFS4ERR_BAD_HIGH_SLOT: | 
 | 3476 | 		case -NFS4ERR_DEADSESSION: | 
 | 3477 | 		case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
 | 3478 | 		case -NFS4ERR_SEQ_FALSE_RETRY: | 
 | 3479 | 		case -NFS4ERR_SEQ_MISORDERED: | 
 | 3480 | 			dprintk("%s ERROR %d, Reset session\n", __func__, | 
 | 3481 | 				task->tk_status); | 
| Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 3482 | 			nfs4_schedule_state_recovery(clp); | 
| Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3483 | 			task->tk_status = 0; | 
 | 3484 | 			return -EAGAIN; | 
 | 3485 | #endif /* CONFIG_NFS_V4_1 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | 		case -NFS4ERR_DELAY: | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3487 | 			nfs_inc_server_stats(server, NFSIOS_DELAY); | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3488 | 		case -NFS4ERR_GRACE: | 
| Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3489 | 		case -EKEYEXPIRED: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | 			rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
 | 3491 | 			task->tk_status = 0; | 
 | 3492 | 			return -EAGAIN; | 
 | 3493 | 		case -NFS4ERR_OLD_STATEID: | 
 | 3494 | 			task->tk_status = 0; | 
 | 3495 | 			return -EAGAIN; | 
 | 3496 | 	} | 
 | 3497 | 	task->tk_status = nfs4_map_errors(task->tk_status); | 
 | 3498 | 	return 0; | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3499 | do_state_recovery: | 
 | 3500 | 	rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); | 
 | 3501 | 	nfs4_schedule_state_recovery(clp); | 
 | 3502 | 	if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) | 
 | 3503 | 		rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); | 
 | 3504 | 	task->tk_status = 0; | 
 | 3505 | 	return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | } | 
 | 3507 |  | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3508 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, | 
 | 3509 | 		unsigned short port, struct rpc_cred *cred, | 
 | 3510 | 		struct nfs4_setclientid_res *res) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | { | 
 | 3512 | 	nfs4_verifier sc_verifier; | 
 | 3513 | 	struct nfs4_setclientid setclientid = { | 
 | 3514 | 		.sc_verifier = &sc_verifier, | 
 | 3515 | 		.sc_prog = program, | 
| Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3516 | 		.sc_cb_ident = clp->cl_cb_ident, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | 	}; | 
 | 3518 | 	struct rpc_message msg = { | 
 | 3519 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], | 
 | 3520 | 		.rpc_argp = &setclientid, | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3521 | 		.rpc_resp = res, | 
| Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3522 | 		.rpc_cred = cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | 	}; | 
| Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3524 | 	__be32 *p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | 	int loop = 0; | 
 | 3526 | 	int status; | 
 | 3527 |  | 
| Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3528 | 	p = (__be32*)sc_verifier.data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | 	*p++ = htonl((u32)clp->cl_boot_time.tv_sec); | 
 | 3530 | 	*p = htonl((u32)clp->cl_boot_time.tv_nsec); | 
 | 3531 |  | 
 | 3532 | 	for(;;) { | 
 | 3533 | 		setclientid.sc_name_len = scnprintf(setclientid.sc_name, | 
| Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3534 | 				sizeof(setclientid.sc_name), "%s/%s %s %s %u", | 
| Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3535 | 				clp->cl_ipaddr, | 
 | 3536 | 				rpc_peeraddr2str(clp->cl_rpcclient, | 
 | 3537 | 							RPC_DISPLAY_ADDR), | 
| Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3538 | 				rpc_peeraddr2str(clp->cl_rpcclient, | 
 | 3539 | 							RPC_DISPLAY_PROTO), | 
| Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3540 | 				clp->cl_rpcclient->cl_auth->au_ops->au_name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | 				clp->cl_id_uniquifier); | 
 | 3542 | 		setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, | 
| Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3543 | 				sizeof(setclientid.sc_netid), | 
 | 3544 | 				rpc_peeraddr2str(clp->cl_rpcclient, | 
 | 3545 | 							RPC_DISPLAY_NETID)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | 		setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, | 
| Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3547 | 				sizeof(setclientid.sc_uaddr), "%s.%u.%u", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | 				clp->cl_ipaddr, port >> 8, port & 255); | 
 | 3549 |  | 
 | 3550 | 		status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); | 
 | 3551 | 		if (status != -NFS4ERR_CLID_INUSE) | 
 | 3552 | 			break; | 
 | 3553 | 		if (signalled()) | 
 | 3554 | 			break; | 
 | 3555 | 		if (loop++ & 1) | 
| J. Bruce Fields | 611c96c | 2010-12-13 19:05:46 -0500 | [diff] [blame] | 3556 | 			ssleep(clp->cl_lease_time / HZ + 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | 		else | 
 | 3558 | 			if (++clp->cl_id_uniquifier == 0) | 
 | 3559 | 				break; | 
 | 3560 | 	} | 
 | 3561 | 	return status; | 
 | 3562 | } | 
 | 3563 |  | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3564 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, | 
 | 3565 | 		struct nfs4_setclientid_res *arg, | 
 | 3566 | 		struct rpc_cred *cred) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | { | 
 | 3568 | 	struct nfs_fsinfo fsinfo; | 
 | 3569 | 	struct rpc_message msg = { | 
 | 3570 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3571 | 		.rpc_argp = arg, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | 		.rpc_resp = &fsinfo, | 
| Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3573 | 		.rpc_cred = cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | 	}; | 
 | 3575 | 	unsigned long now; | 
 | 3576 | 	int status; | 
 | 3577 |  | 
 | 3578 | 	now = jiffies; | 
 | 3579 | 	status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); | 
 | 3580 | 	if (status == 0) { | 
 | 3581 | 		spin_lock(&clp->cl_lock); | 
 | 3582 | 		clp->cl_lease_time = fsinfo.lease_time * HZ; | 
 | 3583 | 		clp->cl_last_renewal = now; | 
 | 3584 | 		spin_unlock(&clp->cl_lock); | 
 | 3585 | 	} | 
 | 3586 | 	return status; | 
 | 3587 | } | 
 | 3588 |  | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3589 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, | 
 | 3590 | 		struct nfs4_setclientid_res *arg, | 
 | 3591 | 		struct rpc_cred *cred) | 
| Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3592 | { | 
| Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3593 | 	long timeout = 0; | 
| Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3594 | 	int err; | 
 | 3595 | 	do { | 
| Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3596 | 		err = _nfs4_proc_setclientid_confirm(clp, arg, cred); | 
| Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3597 | 		switch (err) { | 
 | 3598 | 			case 0: | 
 | 3599 | 				return err; | 
 | 3600 | 			case -NFS4ERR_RESOURCE: | 
 | 3601 | 				/* The IBM lawyers misread another document! */ | 
 | 3602 | 			case -NFS4ERR_DELAY: | 
 | 3603 | 				err = nfs4_delay(clp->cl_rpcclient, &timeout); | 
 | 3604 | 		} | 
 | 3605 | 	} while (err == 0); | 
 | 3606 | 	return err; | 
 | 3607 | } | 
 | 3608 |  | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3609 | struct nfs4_delegreturndata { | 
 | 3610 | 	struct nfs4_delegreturnargs args; | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3611 | 	struct nfs4_delegreturnres res; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3612 | 	struct nfs_fh fh; | 
 | 3613 | 	nfs4_stateid stateid; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3614 | 	unsigned long timestamp; | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3615 | 	struct nfs_fattr fattr; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3616 | 	int rpc_status; | 
 | 3617 | }; | 
 | 3618 |  | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3619 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) | 
 | 3620 | { | 
 | 3621 | 	struct nfs4_delegreturndata *data = calldata; | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3622 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3623 | 	if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
 | 3624 | 		return; | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3625 |  | 
| Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3626 | 	switch (task->tk_status) { | 
 | 3627 | 	case -NFS4ERR_STALE_STATEID: | 
 | 3628 | 	case -NFS4ERR_EXPIRED: | 
 | 3629 | 	case 0: | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3630 | 		renew_lease(data->res.server, data->timestamp); | 
| Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3631 | 		break; | 
 | 3632 | 	default: | 
 | 3633 | 		if (nfs4_async_handle_error(task, data->res.server, NULL) == | 
 | 3634 | 				-EAGAIN) { | 
 | 3635 | 			nfs_restart_rpc(task, data->res.server->nfs_client); | 
 | 3636 | 			return; | 
 | 3637 | 		} | 
 | 3638 | 	} | 
 | 3639 | 	data->rpc_status = task->tk_status; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3640 | } | 
 | 3641 |  | 
 | 3642 | static void nfs4_delegreturn_release(void *calldata) | 
 | 3643 | { | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3644 | 	kfree(calldata); | 
 | 3645 | } | 
 | 3646 |  | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3647 | #if defined(CONFIG_NFS_V4_1) | 
 | 3648 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) | 
 | 3649 | { | 
 | 3650 | 	struct nfs4_delegreturndata *d_data; | 
 | 3651 |  | 
 | 3652 | 	d_data = (struct nfs4_delegreturndata *)data; | 
 | 3653 |  | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3654 | 	if (nfs4_setup_sequence(d_data->res.server, | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3655 | 				&d_data->args.seq_args, | 
 | 3656 | 				&d_data->res.seq_res, 1, task)) | 
 | 3657 | 		return; | 
 | 3658 | 	rpc_call_start(task); | 
 | 3659 | } | 
 | 3660 | #endif /* CONFIG_NFS_V4_1 */ | 
 | 3661 |  | 
| Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3662 | static const struct rpc_call_ops nfs4_delegreturn_ops = { | 
| Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3663 | #if defined(CONFIG_NFS_V4_1) | 
 | 3664 | 	.rpc_call_prepare = nfs4_delegreturn_prepare, | 
 | 3665 | #endif /* CONFIG_NFS_V4_1 */ | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3666 | 	.rpc_call_done = nfs4_delegreturn_done, | 
 | 3667 | 	.rpc_release = nfs4_delegreturn_release, | 
 | 3668 | }; | 
 | 3669 |  | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3670 | static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3671 | { | 
 | 3672 | 	struct nfs4_delegreturndata *data; | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3673 | 	struct nfs_server *server = NFS_SERVER(inode); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3674 | 	struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3675 | 	struct rpc_message msg = { | 
 | 3676 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], | 
 | 3677 | 		.rpc_cred = cred, | 
 | 3678 | 	}; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3679 | 	struct rpc_task_setup task_setup_data = { | 
 | 3680 | 		.rpc_client = server->client, | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3681 | 		.rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3682 | 		.callback_ops = &nfs4_delegreturn_ops, | 
 | 3683 | 		.flags = RPC_TASK_ASYNC, | 
 | 3684 | 	}; | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3685 | 	int status = 0; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3686 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3687 | 	data = kzalloc(sizeof(*data), GFP_NOFS); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3688 | 	if (data == NULL) | 
 | 3689 | 		return -ENOMEM; | 
 | 3690 | 	data->args.fhandle = &data->fh; | 
 | 3691 | 	data->args.stateid = &data->stateid; | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3692 | 	data->args.bitmask = server->attr_bitmask; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3693 | 	nfs_copy_fh(&data->fh, NFS_FH(inode)); | 
 | 3694 | 	memcpy(&data->stateid, stateid, sizeof(data->stateid)); | 
| Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3695 | 	data->res.fattr = &data->fattr; | 
 | 3696 | 	data->res.server = server; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3697 | 	nfs_fattr_init(data->res.fattr); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3698 | 	data->timestamp = jiffies; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3699 | 	data->rpc_status = 0; | 
 | 3700 |  | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3701 | 	task_setup_data.callback_data = data; | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3702 | 	msg.rpc_argp = &data->args; | 
 | 3703 | 	msg.rpc_resp = &data->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3704 | 	task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3705 | 	if (IS_ERR(task)) | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3706 | 		return PTR_ERR(task); | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3707 | 	if (!issync) | 
 | 3708 | 		goto out; | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3709 | 	status = nfs4_wait_for_completion_rpc_task(task); | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3710 | 	if (status != 0) | 
 | 3711 | 		goto out; | 
 | 3712 | 	status = data->rpc_status; | 
 | 3713 | 	if (status != 0) | 
 | 3714 | 		goto out; | 
 | 3715 | 	nfs_refresh_inode(inode, &data->fattr); | 
 | 3716 | out: | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3717 | 	rpc_put_task(task); | 
| Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3718 | 	return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3719 | } | 
 | 3720 |  | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3721 | int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | { | 
 | 3723 | 	struct nfs_server *server = NFS_SERVER(inode); | 
 | 3724 | 	struct nfs4_exception exception = { }; | 
 | 3725 | 	int err; | 
 | 3726 | 	do { | 
| Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3727 | 		err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | 		switch (err) { | 
 | 3729 | 			case -NFS4ERR_STALE_STATEID: | 
 | 3730 | 			case -NFS4ERR_EXPIRED: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | 			case 0: | 
 | 3732 | 				return 0; | 
 | 3733 | 		} | 
 | 3734 | 		err = nfs4_handle_exception(server, err, &exception); | 
 | 3735 | 	} while (exception.retry); | 
 | 3736 | 	return err; | 
 | 3737 | } | 
 | 3738 |  | 
 | 3739 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) | 
 | 3740 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) | 
 | 3741 |  | 
 | 3742 | /*  | 
 | 3743 |  * sleep, with exponential backoff, and retry the LOCK operation.  | 
 | 3744 |  */ | 
 | 3745 | static unsigned long | 
 | 3746 | nfs4_set_lock_task_retry(unsigned long timeout) | 
 | 3747 | { | 
| Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3748 | 	schedule_timeout_killable(timeout); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | 	timeout <<= 1; | 
 | 3750 | 	if (timeout > NFS4_LOCK_MAXTIMEOUT) | 
 | 3751 | 		return NFS4_LOCK_MAXTIMEOUT; | 
 | 3752 | 	return timeout; | 
 | 3753 | } | 
 | 3754 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
 | 3756 | { | 
 | 3757 | 	struct inode *inode = state->inode; | 
 | 3758 | 	struct nfs_server *server = NFS_SERVER(inode); | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3759 | 	struct nfs_client *clp = server->nfs_client; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3760 | 	struct nfs_lockt_args arg = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | 		.fh = NFS_FH(inode), | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3762 | 		.fl = request, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | 	}; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3764 | 	struct nfs_lockt_res res = { | 
 | 3765 | 		.denied = request, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | 	}; | 
 | 3767 | 	struct rpc_message msg = { | 
 | 3768 | 		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_LOCKT], | 
 | 3769 | 		.rpc_argp       = &arg, | 
 | 3770 | 		.rpc_resp       = &res, | 
 | 3771 | 		.rpc_cred	= state->owner->so_cred, | 
 | 3772 | 	}; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | 	struct nfs4_lock_state *lsp; | 
 | 3774 | 	int status; | 
 | 3775 |  | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3776 | 	arg.lock_owner.clientid = clp->cl_clientid; | 
| Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3777 | 	status = nfs4_set_lock_state(state, request); | 
 | 3778 | 	if (status != 0) | 
 | 3779 | 		goto out; | 
 | 3780 | 	lsp = request->fl_u.nfs4_fl.owner; | 
| Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3781 | 	arg.lock_owner.id = lsp->ls_id.id; | 
| Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3782 | 	arg.lock_owner.s_dev = server->s_dev; | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3783 | 	status = nfs4_call_sync(server, &msg, &arg, &res, 1); | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3784 | 	switch (status) { | 
 | 3785 | 		case 0: | 
 | 3786 | 			request->fl_type = F_UNLCK; | 
 | 3787 | 			break; | 
 | 3788 | 		case -NFS4ERR_DENIED: | 
 | 3789 | 			status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | 	} | 
| J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3791 | 	request->fl_ops->fl_release_private(request); | 
| Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3792 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3793 | 	return status; | 
 | 3794 | } | 
 | 3795 |  | 
 | 3796 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
 | 3797 | { | 
 | 3798 | 	struct nfs4_exception exception = { }; | 
 | 3799 | 	int err; | 
 | 3800 |  | 
 | 3801 | 	do { | 
 | 3802 | 		err = nfs4_handle_exception(NFS_SERVER(state->inode), | 
 | 3803 | 				_nfs4_proc_getlk(state, cmd, request), | 
 | 3804 | 				&exception); | 
 | 3805 | 	} while (exception.retry); | 
 | 3806 | 	return err; | 
 | 3807 | } | 
 | 3808 |  | 
 | 3809 | static int do_vfs_lock(struct file *file, struct file_lock *fl) | 
 | 3810 | { | 
 | 3811 | 	int res = 0; | 
 | 3812 | 	switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { | 
 | 3813 | 		case FL_POSIX: | 
 | 3814 | 			res = posix_lock_file_wait(file, fl); | 
 | 3815 | 			break; | 
 | 3816 | 		case FL_FLOCK: | 
 | 3817 | 			res = flock_lock_file_wait(file, fl); | 
 | 3818 | 			break; | 
 | 3819 | 		default: | 
 | 3820 | 			BUG(); | 
 | 3821 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | 	return res; | 
 | 3823 | } | 
 | 3824 |  | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3825 | struct nfs4_unlockdata { | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3826 | 	struct nfs_locku_args arg; | 
 | 3827 | 	struct nfs_locku_res res; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3828 | 	struct nfs4_lock_state *lsp; | 
 | 3829 | 	struct nfs_open_context *ctx; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3830 | 	struct file_lock fl; | 
 | 3831 | 	const struct nfs_server *server; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3832 | 	unsigned long timestamp; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3833 | }; | 
 | 3834 |  | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3835 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, | 
 | 3836 | 		struct nfs_open_context *ctx, | 
 | 3837 | 		struct nfs4_lock_state *lsp, | 
 | 3838 | 		struct nfs_seqid *seqid) | 
 | 3839 | { | 
 | 3840 | 	struct nfs4_unlockdata *p; | 
 | 3841 | 	struct inode *inode = lsp->ls_state->inode; | 
 | 3842 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3843 | 	p = kzalloc(sizeof(*p), GFP_NOFS); | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3844 | 	if (p == NULL) | 
 | 3845 | 		return NULL; | 
 | 3846 | 	p->arg.fh = NFS_FH(inode); | 
 | 3847 | 	p->arg.fl = &p->fl; | 
 | 3848 | 	p->arg.seqid = seqid; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3849 | 	p->res.seqid = seqid; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3850 | 	p->arg.stateid = &lsp->ls_stateid; | 
 | 3851 | 	p->lsp = lsp; | 
 | 3852 | 	atomic_inc(&lsp->ls_count); | 
 | 3853 | 	/* Ensure we don't close file until we're done freeing locks! */ | 
 | 3854 | 	p->ctx = get_nfs_open_context(ctx); | 
 | 3855 | 	memcpy(&p->fl, fl, sizeof(p->fl)); | 
 | 3856 | 	p->server = NFS_SERVER(inode); | 
 | 3857 | 	return p; | 
 | 3858 | } | 
 | 3859 |  | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3860 | static void nfs4_locku_release_calldata(void *data) | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3861 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3862 | 	struct nfs4_unlockdata *calldata = data; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3863 | 	nfs_free_seqid(calldata->arg.seqid); | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3864 | 	nfs4_put_lock_state(calldata->lsp); | 
 | 3865 | 	put_nfs_open_context(calldata->ctx); | 
 | 3866 | 	kfree(calldata); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3867 | } | 
 | 3868 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3869 | static void nfs4_locku_done(struct rpc_task *task, void *data) | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3870 | { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3871 | 	struct nfs4_unlockdata *calldata = data; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3872 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3873 | 	if (!nfs4_sequence_done(task, &calldata->res.seq_res)) | 
 | 3874 | 		return; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3875 | 	switch (task->tk_status) { | 
 | 3876 | 		case 0: | 
 | 3877 | 			memcpy(calldata->lsp->ls_stateid.data, | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3878 | 					calldata->res.stateid.data, | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3879 | 					sizeof(calldata->lsp->ls_stateid.data)); | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3880 | 			renew_lease(calldata->server, calldata->timestamp); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3881 | 			break; | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3882 | 		case -NFS4ERR_BAD_STATEID: | 
 | 3883 | 		case -NFS4ERR_OLD_STATEID: | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3884 | 		case -NFS4ERR_STALE_STATEID: | 
 | 3885 | 		case -NFS4ERR_EXPIRED: | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3886 | 			break; | 
 | 3887 | 		default: | 
| Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3888 | 			if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) | 
| Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3889 | 				nfs_restart_rpc(task, | 
| Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 3890 | 						 calldata->server->nfs_client); | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3891 | 	} | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3892 | } | 
 | 3893 |  | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3894 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3895 | { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3896 | 	struct nfs4_unlockdata *calldata = data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 |  | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3898 | 	if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3899 | 		return; | 
 | 3900 | 	if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3901 | 		/* Note: exit _without_ running nfs4_locku_done */ | 
 | 3902 | 		task->tk_action = NULL; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3903 | 		return; | 
 | 3904 | 	} | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3905 | 	calldata->timestamp = jiffies; | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3906 | 	if (nfs4_setup_sequence(calldata->server, | 
| Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3907 | 				&calldata->arg.seq_args, | 
 | 3908 | 				&calldata->res.seq_res, 1, task)) | 
 | 3909 | 		return; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3910 | 	rpc_call_start(task); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3911 | } | 
 | 3912 |  | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3913 | static const struct rpc_call_ops nfs4_locku_ops = { | 
| Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3914 | 	.rpc_call_prepare = nfs4_locku_prepare, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3915 | 	.rpc_call_done = nfs4_locku_done, | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3916 | 	.rpc_release = nfs4_locku_release_calldata, | 
| Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3917 | }; | 
 | 3918 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3919 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, | 
 | 3920 | 		struct nfs_open_context *ctx, | 
 | 3921 | 		struct nfs4_lock_state *lsp, | 
 | 3922 | 		struct nfs_seqid *seqid) | 
 | 3923 | { | 
 | 3924 | 	struct nfs4_unlockdata *data; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3925 | 	struct rpc_message msg = { | 
 | 3926 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], | 
 | 3927 | 		.rpc_cred = ctx->cred, | 
 | 3928 | 	}; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3929 | 	struct rpc_task_setup task_setup_data = { | 
 | 3930 | 		.rpc_client = NFS_CLIENT(lsp->ls_state->inode), | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3931 | 		.rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3932 | 		.callback_ops = &nfs4_locku_ops, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3933 | 		.workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3934 | 		.flags = RPC_TASK_ASYNC, | 
 | 3935 | 	}; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3936 |  | 
| Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 3937 | 	/* Ensure this is an unlock - when canceling a lock, the | 
 | 3938 | 	 * canceled lock is passed in, and it won't be an unlock. | 
 | 3939 | 	 */ | 
 | 3940 | 	fl->fl_type = F_UNLCK; | 
 | 3941 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3942 | 	data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); | 
 | 3943 | 	if (data == NULL) { | 
 | 3944 | 		nfs_free_seqid(seqid); | 
 | 3945 | 		return ERR_PTR(-ENOMEM); | 
 | 3946 | 	} | 
 | 3947 |  | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3948 | 	msg.rpc_argp = &data->arg; | 
 | 3949 | 	msg.rpc_resp = &data->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3950 | 	task_setup_data.callback_data = data; | 
 | 3951 | 	return rpc_run_task(&task_setup_data); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3952 | } | 
 | 3953 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) | 
 | 3955 | { | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3956 | 	struct nfs_inode *nfsi = NFS_I(state->inode); | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3957 | 	struct nfs_seqid *seqid; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3958 | 	struct nfs4_lock_state *lsp; | 
| Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3959 | 	struct rpc_task *task; | 
 | 3960 | 	int status = 0; | 
| Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3961 | 	unsigned char fl_flags = request->fl_flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 |  | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3963 | 	status = nfs4_set_lock_state(state, request); | 
 | 3964 | 	/* Unlock _before_ we do the RPC call */ | 
 | 3965 | 	request->fl_flags |= FL_EXISTS; | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3966 | 	down_read(&nfsi->rwsem); | 
 | 3967 | 	if (do_vfs_lock(request->fl_file, request) == -ENOENT) { | 
 | 3968 | 		up_read(&nfsi->rwsem); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3969 | 		goto out; | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3970 | 	} | 
 | 3971 | 	up_read(&nfsi->rwsem); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3972 | 	if (status != 0) | 
 | 3973 | 		goto out; | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3974 | 	/* Is this a delegated lock? */ | 
 | 3975 | 	if (test_bit(NFS_DELEGATED_STATE, &state->flags)) | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3976 | 		goto out; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3977 | 	lsp = request->fl_u.nfs4_fl.owner; | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3978 | 	seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3979 | 	status = -ENOMEM; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3980 | 	if (seqid == NULL) | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3981 | 		goto out; | 
| Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 3982 | 	task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3983 | 	status = PTR_ERR(task); | 
 | 3984 | 	if (IS_ERR(task)) | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3985 | 		goto out; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3986 | 	status = nfs4_wait_for_completion_rpc_task(task); | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3987 | 	rpc_put_task(task); | 
| Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3988 | out: | 
| Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3989 | 	request->fl_flags = fl_flags; | 
| Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3990 | 	return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | } | 
 | 3992 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3993 | struct nfs4_lockdata { | 
 | 3994 | 	struct nfs_lock_args arg; | 
| Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3995 | 	struct nfs_lock_res res; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3996 | 	struct nfs4_lock_state *lsp; | 
 | 3997 | 	struct nfs_open_context *ctx; | 
 | 3998 | 	struct file_lock fl; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3999 | 	unsigned long timestamp; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4000 | 	int rpc_status; | 
 | 4001 | 	int cancelled; | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4002 | 	struct nfs_server *server; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4003 | }; | 
 | 4004 |  | 
 | 4005 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4006 | 		struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, | 
 | 4007 | 		gfp_t gfp_mask) | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4008 | { | 
 | 4009 | 	struct nfs4_lockdata *p; | 
 | 4010 | 	struct inode *inode = lsp->ls_state->inode; | 
 | 4011 | 	struct nfs_server *server = NFS_SERVER(inode); | 
 | 4012 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4013 | 	p = kzalloc(sizeof(*p), gfp_mask); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4014 | 	if (p == NULL) | 
 | 4015 | 		return NULL; | 
 | 4016 |  | 
 | 4017 | 	p->arg.fh = NFS_FH(inode); | 
 | 4018 | 	p->arg.fl = &p->fl; | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4019 | 	p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask); | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4020 | 	if (p->arg.open_seqid == NULL) | 
 | 4021 | 		goto out_free; | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4022 | 	p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4023 | 	if (p->arg.lock_seqid == NULL) | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4024 | 		goto out_free_seqid; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4025 | 	p->arg.lock_stateid = &lsp->ls_stateid; | 
| David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4026 | 	p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; | 
| Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4027 | 	p->arg.lock_owner.id = lsp->ls_id.id; | 
| Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4028 | 	p->arg.lock_owner.s_dev = server->s_dev; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4029 | 	p->res.lock_seqid = p->arg.lock_seqid; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4030 | 	p->lsp = lsp; | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4031 | 	p->server = server; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4032 | 	atomic_inc(&lsp->ls_count); | 
 | 4033 | 	p->ctx = get_nfs_open_context(ctx); | 
 | 4034 | 	memcpy(&p->fl, fl, sizeof(p->fl)); | 
 | 4035 | 	return p; | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4036 | out_free_seqid: | 
 | 4037 | 	nfs_free_seqid(p->arg.open_seqid); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4038 | out_free: | 
 | 4039 | 	kfree(p); | 
 | 4040 | 	return NULL; | 
 | 4041 | } | 
 | 4042 |  | 
 | 4043 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) | 
 | 4044 | { | 
 | 4045 | 	struct nfs4_lockdata *data = calldata; | 
 | 4046 | 	struct nfs4_state *state = data->lsp->ls_state; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4048 | 	dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4049 | 	if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) | 
 | 4050 | 		return; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4051 | 	/* Do we need to do an open_to_lock_owner? */ | 
 | 4052 | 	if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { | 
| Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4053 | 		if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) | 
 | 4054 | 			return; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4055 | 		data->arg.open_stateid = &state->stateid; | 
 | 4056 | 		data->arg.new_lock_owner = 1; | 
| Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4057 | 		data->res.open_seqid = data->arg.open_seqid; | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4058 | 	} else | 
 | 4059 | 		data->arg.new_lock_owner = 0; | 
| Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4060 | 	data->timestamp = jiffies; | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4061 | 	if (nfs4_setup_sequence(data->server, | 
 | 4062 | 				&data->arg.seq_args, | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4063 | 				&data->res.seq_res, 1, task)) | 
 | 4064 | 		return; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4065 | 	rpc_call_start(task); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4066 | 	dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4067 | } | 
 | 4068 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4069 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) | 
 | 4070 | { | 
 | 4071 | 	rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); | 
 | 4072 | 	nfs4_lock_prepare(task, calldata); | 
 | 4073 | } | 
 | 4074 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4075 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) | 
 | 4076 | { | 
 | 4077 | 	struct nfs4_lockdata *data = calldata; | 
 | 4078 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4079 | 	dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4080 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4081 | 	if (!nfs4_sequence_done(task, &data->res.seq_res)) | 
 | 4082 | 		return; | 
| Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4083 |  | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4084 | 	data->rpc_status = task->tk_status; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4085 | 	if (data->arg.new_lock_owner != 0) { | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4086 | 		if (data->rpc_status == 0) | 
 | 4087 | 			nfs_confirm_seqid(&data->lsp->ls_seqid, 0); | 
 | 4088 | 		else | 
 | 4089 | 			goto out; | 
 | 4090 | 	} | 
 | 4091 | 	if (data->rpc_status == 0) { | 
 | 4092 | 		memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, | 
 | 4093 | 					sizeof(data->lsp->ls_stateid.data)); | 
 | 4094 | 		data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; | 
| Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4095 | 		renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4096 | 	} | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4097 | out: | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4098 | 	dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4099 | } | 
 | 4100 |  | 
 | 4101 | static void nfs4_lock_release(void *calldata) | 
 | 4102 | { | 
 | 4103 | 	struct nfs4_lockdata *data = calldata; | 
 | 4104 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4105 | 	dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4106 | 	nfs_free_seqid(data->arg.open_seqid); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4107 | 	if (data->cancelled != 0) { | 
 | 4108 | 		struct rpc_task *task; | 
 | 4109 | 		task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, | 
 | 4110 | 				data->arg.lock_seqid); | 
 | 4111 | 		if (!IS_ERR(task)) | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4112 | 			rpc_put_task(task); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4113 | 		dprintk("%s: cancelling lock!\n", __func__); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4114 | 	} else | 
 | 4115 | 		nfs_free_seqid(data->arg.lock_seqid); | 
 | 4116 | 	nfs4_put_lock_state(data->lsp); | 
 | 4117 | 	put_nfs_open_context(data->ctx); | 
 | 4118 | 	kfree(data); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4119 | 	dprintk("%s: done!\n", __func__); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4120 | } | 
 | 4121 |  | 
 | 4122 | static const struct rpc_call_ops nfs4_lock_ops = { | 
 | 4123 | 	.rpc_call_prepare = nfs4_lock_prepare, | 
 | 4124 | 	.rpc_call_done = nfs4_lock_done, | 
 | 4125 | 	.rpc_release = nfs4_lock_release, | 
 | 4126 | }; | 
 | 4127 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4128 | static const struct rpc_call_ops nfs4_recover_lock_ops = { | 
 | 4129 | 	.rpc_call_prepare = nfs4_recover_lock_prepare, | 
 | 4130 | 	.rpc_call_done = nfs4_lock_done, | 
 | 4131 | 	.rpc_release = nfs4_lock_release, | 
 | 4132 | }; | 
 | 4133 |  | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4134 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) | 
 | 4135 | { | 
 | 4136 | 	struct nfs_client *clp = server->nfs_client; | 
 | 4137 | 	struct nfs4_state *state = lsp->ls_state; | 
 | 4138 |  | 
 | 4139 | 	switch (error) { | 
 | 4140 | 	case -NFS4ERR_ADMIN_REVOKED: | 
 | 4141 | 	case -NFS4ERR_BAD_STATEID: | 
 | 4142 | 	case -NFS4ERR_EXPIRED: | 
 | 4143 | 		if (new_lock_owner != 0 || | 
 | 4144 | 		   (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) | 
 | 4145 | 			nfs4_state_mark_reclaim_nograce(clp, state); | 
 | 4146 | 		lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; | 
| Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4147 | 		break; | 
 | 4148 | 	case -NFS4ERR_STALE_STATEID: | 
 | 4149 | 		if (new_lock_owner != 0 || | 
 | 4150 | 		    (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) | 
 | 4151 | 			nfs4_state_mark_reclaim_reboot(clp, state); | 
 | 4152 | 		lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4153 | 	}; | 
 | 4154 | } | 
 | 4155 |  | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4156 | static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type) | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4157 | { | 
 | 4158 | 	struct nfs4_lockdata *data; | 
 | 4159 | 	struct rpc_task *task; | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4160 | 	struct rpc_message msg = { | 
 | 4161 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], | 
 | 4162 | 		.rpc_cred = state->owner->so_cred, | 
 | 4163 | 	}; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4164 | 	struct rpc_task_setup task_setup_data = { | 
 | 4165 | 		.rpc_client = NFS_CLIENT(state->inode), | 
| Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4166 | 		.rpc_message = &msg, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4167 | 		.callback_ops = &nfs4_lock_ops, | 
| Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4168 | 		.workqueue = nfsiod_workqueue, | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4169 | 		.flags = RPC_TASK_ASYNC, | 
 | 4170 | 	}; | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4171 | 	int ret; | 
 | 4172 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4173 | 	dprintk("%s: begin!\n", __func__); | 
| Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4174 | 	data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4175 | 			fl->fl_u.nfs4_fl.owner, | 
 | 4176 | 			recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4177 | 	if (data == NULL) | 
 | 4178 | 		return -ENOMEM; | 
 | 4179 | 	if (IS_SETLKW(cmd)) | 
 | 4180 | 		data->arg.block = 1; | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4181 | 	if (recovery_type > NFS_LOCK_NEW) { | 
 | 4182 | 		if (recovery_type == NFS_LOCK_RECLAIM) | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4183 | 			data->arg.reclaim = NFS_LOCK_RECLAIM; | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4184 | 		task_setup_data.callback_ops = &nfs4_recover_lock_ops; | 
 | 4185 | 	} | 
| Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4186 | 	msg.rpc_argp = &data->arg; | 
 | 4187 | 	msg.rpc_resp = &data->res; | 
| Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4188 | 	task_setup_data.callback_data = data; | 
 | 4189 | 	task = rpc_run_task(&task_setup_data); | 
| Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4190 | 	if (IS_ERR(task)) | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4191 | 		return PTR_ERR(task); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4192 | 	ret = nfs4_wait_for_completion_rpc_task(task); | 
 | 4193 | 	if (ret == 0) { | 
 | 4194 | 		ret = data->rpc_status; | 
| Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4195 | 		if (ret) | 
 | 4196 | 			nfs4_handle_setlk_error(data->server, data->lsp, | 
 | 4197 | 					data->arg.new_lock_owner, ret); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4198 | 	} else | 
 | 4199 | 		data->cancelled = 1; | 
| Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4200 | 	rpc_put_task(task); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4201 | 	dprintk("%s: done, ret = %d!\n", __func__, ret); | 
| Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4202 | 	return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | } | 
 | 4204 |  | 
 | 4205 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) | 
 | 4206 | { | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4207 | 	struct nfs_server *server = NFS_SERVER(state->inode); | 
 | 4208 | 	struct nfs4_exception exception = { }; | 
 | 4209 | 	int err; | 
 | 4210 |  | 
 | 4211 | 	do { | 
| Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4212 | 		/* Cache the lock if possible... */ | 
 | 4213 | 		if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) | 
 | 4214 | 			return 0; | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4215 | 		err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); | 
| Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4216 | 		if (err != -NFS4ERR_DELAY) | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4217 | 			break; | 
 | 4218 | 		nfs4_handle_exception(server, err, &exception); | 
 | 4219 | 	} while (exception.retry); | 
 | 4220 | 	return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | } | 
 | 4222 |  | 
 | 4223 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) | 
 | 4224 | { | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4225 | 	struct nfs_server *server = NFS_SERVER(state->inode); | 
 | 4226 | 	struct nfs4_exception exception = { }; | 
 | 4227 | 	int err; | 
 | 4228 |  | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4229 | 	err = nfs4_set_lock_state(state, request); | 
 | 4230 | 	if (err != 0) | 
 | 4231 | 		return err; | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4232 | 	do { | 
| Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4233 | 		if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) | 
 | 4234 | 			return 0; | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4235 | 		err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4236 | 		switch (err) { | 
 | 4237 | 		default: | 
 | 4238 | 			goto out; | 
 | 4239 | 		case -NFS4ERR_GRACE: | 
 | 4240 | 		case -NFS4ERR_DELAY: | 
 | 4241 | 			nfs4_handle_exception(server, err, &exception); | 
 | 4242 | 			err = 0; | 
 | 4243 | 		} | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4244 | 	} while (exception.retry); | 
| Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4245 | out: | 
| Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4246 | 	return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | } | 
 | 4248 |  | 
 | 4249 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
 | 4250 | { | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4251 | 	struct nfs_inode *nfsi = NFS_I(state->inode); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4252 | 	unsigned char fl_flags = request->fl_flags; | 
| Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4253 | 	int status = -ENOLCK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 |  | 
| Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4255 | 	if ((fl_flags & FL_POSIX) && | 
 | 4256 | 			!test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) | 
 | 4257 | 		goto out; | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4258 | 	/* Is this a delegated open? */ | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4259 | 	status = nfs4_set_lock_state(state, request); | 
 | 4260 | 	if (status != 0) | 
 | 4261 | 		goto out; | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4262 | 	request->fl_flags |= FL_ACCESS; | 
 | 4263 | 	status = do_vfs_lock(request->fl_file, request); | 
 | 4264 | 	if (status < 0) | 
 | 4265 | 		goto out; | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4266 | 	down_read(&nfsi->rwsem); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4267 | 	if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4268 | 		/* Yes: cache locks! */ | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4269 | 		/* ...but avoid races with delegation recall... */ | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4270 | 		request->fl_flags = fl_flags & ~FL_SLEEP; | 
 | 4271 | 		status = do_vfs_lock(request->fl_file, request); | 
 | 4272 | 		goto out_unlock; | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4273 | 	} | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4274 | 	status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4275 | 	if (status != 0) | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4276 | 		goto out_unlock; | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4277 | 	/* Note: we always want to sleep here! */ | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4278 | 	request->fl_flags = fl_flags | FL_SLEEP; | 
| Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4279 | 	if (do_vfs_lock(request->fl_file, request) < 0) | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4280 | 		printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4281 | out_unlock: | 
| Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4282 | 	up_read(&nfsi->rwsem); | 
| Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4283 | out: | 
 | 4284 | 	request->fl_flags = fl_flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | 	return status; | 
 | 4286 | } | 
 | 4287 |  | 
 | 4288 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) | 
 | 4289 | { | 
 | 4290 | 	struct nfs4_exception exception = { }; | 
 | 4291 | 	int err; | 
 | 4292 |  | 
 | 4293 | 	do { | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4294 | 		err = _nfs4_proc_setlk(state, cmd, request); | 
 | 4295 | 		if (err == -NFS4ERR_DENIED) | 
 | 4296 | 			err = -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | 		err = nfs4_handle_exception(NFS_SERVER(state->inode), | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4298 | 				err, &exception); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | 	} while (exception.retry); | 
 | 4300 | 	return err; | 
 | 4301 | } | 
 | 4302 |  | 
 | 4303 | static int | 
 | 4304 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) | 
 | 4305 | { | 
 | 4306 | 	struct nfs_open_context *ctx; | 
 | 4307 | 	struct nfs4_state *state; | 
 | 4308 | 	unsigned long timeout = NFS4_LOCK_MINTIMEOUT; | 
 | 4309 | 	int status; | 
 | 4310 |  | 
 | 4311 | 	/* verify open state */ | 
| Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4312 | 	ctx = nfs_file_open_context(filp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4313 | 	state = ctx->state; | 
 | 4314 |  | 
 | 4315 | 	if (request->fl_start < 0 || request->fl_end < 0) | 
 | 4316 | 		return -EINVAL; | 
 | 4317 |  | 
| Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4318 | 	if (IS_GETLK(cmd)) { | 
 | 4319 | 		if (state != NULL) | 
 | 4320 | 			return nfs4_proc_getlk(state, F_GETLK, request); | 
 | 4321 | 		return 0; | 
 | 4322 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 |  | 
 | 4324 | 	if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) | 
 | 4325 | 		return -EINVAL; | 
 | 4326 |  | 
| Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4327 | 	if (request->fl_type == F_UNLCK) { | 
 | 4328 | 		if (state != NULL) | 
 | 4329 | 			return nfs4_proc_unlck(state, cmd, request); | 
 | 4330 | 		return 0; | 
 | 4331 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 |  | 
| Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4333 | 	if (state == NULL) | 
 | 4334 | 		return -ENOLCK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | 	do { | 
 | 4336 | 		status = nfs4_proc_setlk(state, cmd, request); | 
 | 4337 | 		if ((status != -EAGAIN) || IS_SETLK(cmd)) | 
 | 4338 | 			break; | 
 | 4339 | 		timeout = nfs4_set_lock_task_retry(timeout); | 
 | 4340 | 		status = -ERESTARTSYS; | 
 | 4341 | 		if (signalled()) | 
 | 4342 | 			break; | 
 | 4343 | 	} while(status < 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4344 | 	return status; | 
 | 4345 | } | 
 | 4346 |  | 
| Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4347 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) | 
 | 4348 | { | 
 | 4349 | 	struct nfs_server *server = NFS_SERVER(state->inode); | 
 | 4350 | 	struct nfs4_exception exception = { }; | 
 | 4351 | 	int err; | 
 | 4352 |  | 
 | 4353 | 	err = nfs4_set_lock_state(state, fl); | 
 | 4354 | 	if (err != 0) | 
 | 4355 | 		goto out; | 
 | 4356 | 	do { | 
| Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4357 | 		err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); | 
| Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4358 | 		switch (err) { | 
 | 4359 | 			default: | 
 | 4360 | 				printk(KERN_ERR "%s: unhandled error %d.\n", | 
 | 4361 | 						__func__, err); | 
 | 4362 | 			case 0: | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4363 | 			case -ESTALE: | 
| Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4364 | 				goto out; | 
 | 4365 | 			case -NFS4ERR_EXPIRED: | 
 | 4366 | 			case -NFS4ERR_STALE_CLIENTID: | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4367 | 			case -NFS4ERR_STALE_STATEID: | 
| Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4368 | 			case -NFS4ERR_BADSESSION: | 
 | 4369 | 			case -NFS4ERR_BADSLOT: | 
 | 4370 | 			case -NFS4ERR_BAD_HIGH_SLOT: | 
 | 4371 | 			case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: | 
 | 4372 | 			case -NFS4ERR_DEADSESSION: | 
| Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4373 | 				nfs4_schedule_state_recovery(server->nfs_client); | 
 | 4374 | 				goto out; | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4375 | 			case -ERESTARTSYS: | 
 | 4376 | 				/* | 
 | 4377 | 				 * The show must go on: exit, but mark the | 
 | 4378 | 				 * stateid as needing recovery. | 
 | 4379 | 				 */ | 
 | 4380 | 			case -NFS4ERR_ADMIN_REVOKED: | 
 | 4381 | 			case -NFS4ERR_BAD_STATEID: | 
 | 4382 | 			case -NFS4ERR_OPENMODE: | 
 | 4383 | 				nfs4_state_mark_reclaim_nograce(server->nfs_client, state); | 
 | 4384 | 				err = 0; | 
 | 4385 | 				goto out; | 
| Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4386 | 			case -EKEYEXPIRED: | 
 | 4387 | 				/* | 
 | 4388 | 				 * User RPCSEC_GSS context has expired. | 
 | 4389 | 				 * We cannot recover this stateid now, so | 
 | 4390 | 				 * skip it and allow recovery thread to | 
 | 4391 | 				 * proceed. | 
 | 4392 | 				 */ | 
 | 4393 | 				err = 0; | 
 | 4394 | 				goto out; | 
| Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4395 | 			case -ENOMEM: | 
 | 4396 | 			case -NFS4ERR_DENIED: | 
 | 4397 | 				/* kill_proc(fl->fl_pid, SIGLOST, 1); */ | 
 | 4398 | 				err = 0; | 
 | 4399 | 				goto out; | 
| Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4400 | 			case -NFS4ERR_DELAY: | 
 | 4401 | 				break; | 
 | 4402 | 		} | 
| Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4403 | 		err = nfs4_handle_exception(server, err, &exception); | 
 | 4404 | 	} while (exception.retry); | 
 | 4405 | out: | 
 | 4406 | 	return err; | 
 | 4407 | } | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4408 |  | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4409 | static void nfs4_release_lockowner_release(void *calldata) | 
 | 4410 | { | 
 | 4411 | 	kfree(calldata); | 
 | 4412 | } | 
 | 4413 |  | 
 | 4414 | const struct rpc_call_ops nfs4_release_lockowner_ops = { | 
 | 4415 | 	.rpc_release = nfs4_release_lockowner_release, | 
 | 4416 | }; | 
 | 4417 |  | 
 | 4418 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) | 
 | 4419 | { | 
 | 4420 | 	struct nfs_server *server = lsp->ls_state->owner->so_server; | 
 | 4421 | 	struct nfs_release_lockowner_args *args; | 
 | 4422 | 	struct rpc_message msg = { | 
 | 4423 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], | 
 | 4424 | 	}; | 
 | 4425 |  | 
 | 4426 | 	if (server->nfs_client->cl_mvops->minor_version != 0) | 
 | 4427 | 		return; | 
 | 4428 | 	args = kmalloc(sizeof(*args), GFP_NOFS); | 
 | 4429 | 	if (!args) | 
 | 4430 | 		return; | 
 | 4431 | 	args->lock_owner.clientid = server->nfs_client->cl_clientid; | 
 | 4432 | 	args->lock_owner.id = lsp->ls_id.id; | 
| Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4433 | 	args->lock_owner.s_dev = server->s_dev; | 
| Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4434 | 	msg.rpc_argp = args; | 
 | 4435 | 	rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); | 
 | 4436 | } | 
 | 4437 |  | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4438 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" | 
 | 4439 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4440 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, | 
 | 4441 | 				   const void *buf, size_t buflen, | 
 | 4442 | 				   int flags, int type) | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4443 | { | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4444 | 	if (strcmp(key, "") != 0) | 
 | 4445 | 		return -EINVAL; | 
| J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4446 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4447 | 	return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4448 | } | 
 | 4449 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4450 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, | 
 | 4451 | 				   void *buf, size_t buflen, int type) | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4452 | { | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4453 | 	if (strcmp(key, "") != 0) | 
 | 4454 | 		return -EINVAL; | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4455 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4456 | 	return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4457 | } | 
 | 4458 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4459 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, | 
 | 4460 | 				       size_t list_len, const char *name, | 
 | 4461 | 				       size_t name_len, int type) | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4462 | { | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4463 | 	size_t len = sizeof(XATTR_NAME_NFSV4_ACL); | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4464 |  | 
| J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4465 | 	if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) | 
 | 4466 | 		return 0; | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4467 |  | 
 | 4468 | 	if (list && len <= list_len) | 
 | 4469 | 		memcpy(list, XATTR_NAME_NFSV4_ACL, len); | 
| J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4470 | 	return len; | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4471 | } | 
 | 4472 |  | 
| Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4473 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) | 
 | 4474 | { | 
 | 4475 | 	if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && | 
 | 4476 | 		(fattr->valid & NFS_ATTR_FATTR_FSID) && | 
 | 4477 | 		(fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) | 
 | 4478 | 		return; | 
 | 4479 |  | 
 | 4480 | 	fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | | 
 | 4481 | 		NFS_ATTR_FATTR_NLINK; | 
 | 4482 | 	fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; | 
 | 4483 | 	fattr->nlink = 2; | 
 | 4484 | } | 
 | 4485 |  | 
| Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4486 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, | 
| Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4487 | 		struct nfs4_fs_locations *fs_locations, struct page *page) | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4488 | { | 
 | 4489 | 	struct nfs_server *server = NFS_SERVER(dir); | 
 | 4490 | 	u32 bitmask[2] = { | 
| Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4491 | 		[0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, | 
 | 4492 | 		[1] = FATTR4_WORD1_MOUNTED_ON_FILEID, | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4493 | 	}; | 
 | 4494 | 	struct nfs4_fs_locations_arg args = { | 
 | 4495 | 		.dir_fh = NFS_FH(dir), | 
| Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4496 | 		.name = name, | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4497 | 		.page = page, | 
 | 4498 | 		.bitmask = bitmask, | 
 | 4499 | 	}; | 
| Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4500 | 	struct nfs4_fs_locations_res res = { | 
 | 4501 | 		.fs_locations = fs_locations, | 
 | 4502 | 	}; | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4503 | 	struct rpc_message msg = { | 
 | 4504 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], | 
 | 4505 | 		.rpc_argp = &args, | 
| Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4506 | 		.rpc_resp = &res, | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4507 | 	}; | 
 | 4508 | 	int status; | 
 | 4509 |  | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4510 | 	dprintk("%s: start\n", __func__); | 
| Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4511 | 	nfs_fattr_init(&fs_locations->fattr); | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4512 | 	fs_locations->server = server; | 
| Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4513 | 	fs_locations->nlocations = 0; | 
| Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 4514 | 	status = nfs4_call_sync(server, &msg, &args, &res, 0); | 
| Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4515 | 	nfs_fixup_referral_attributes(&fs_locations->fattr); | 
| Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4516 | 	dprintk("%s: returned status = %d\n", __func__, status); | 
| Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4517 | 	return status; | 
 | 4518 | } | 
 | 4519 |  | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4520 | #ifdef CONFIG_NFS_V4_1 | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4521 | /* | 
| Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4522 |  * Check the exchange flags returned by the server for invalid flags, having | 
 | 4523 |  * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or | 
 | 4524 |  * DS flags set. | 
 | 4525 |  */ | 
 | 4526 | static int nfs4_check_cl_exchange_flags(u32 flags) | 
 | 4527 | { | 
 | 4528 | 	if (flags & ~EXCHGID4_FLAG_MASK_R) | 
 | 4529 | 		goto out_inval; | 
 | 4530 | 	if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && | 
 | 4531 | 	    (flags & EXCHGID4_FLAG_USE_NON_PNFS)) | 
 | 4532 | 		goto out_inval; | 
 | 4533 | 	if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) | 
 | 4534 | 		goto out_inval; | 
 | 4535 | 	return NFS_OK; | 
 | 4536 | out_inval: | 
 | 4537 | 	return -NFS4ERR_INVAL; | 
 | 4538 | } | 
 | 4539 |  | 
 | 4540 | /* | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4541 |  * nfs4_proc_exchange_id() | 
 | 4542 |  * | 
 | 4543 |  * Since the clientid has expired, all compounds using sessions | 
 | 4544 |  * associated with the stale clientid will be returning | 
 | 4545 |  * NFS4ERR_BADSESSION in the sequence operation, and will therefore | 
 | 4546 |  * be in some phase of session reset. | 
 | 4547 |  */ | 
| Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4548 | int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4549 | { | 
 | 4550 | 	nfs4_verifier verifier; | 
 | 4551 | 	struct nfs41_exchange_id_args args = { | 
 | 4552 | 		.client = clp, | 
| Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4553 | 		.flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4554 | 	}; | 
 | 4555 | 	struct nfs41_exchange_id_res res = { | 
 | 4556 | 		.client = clp, | 
 | 4557 | 	}; | 
 | 4558 | 	int status; | 
 | 4559 | 	struct rpc_message msg = { | 
 | 4560 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], | 
 | 4561 | 		.rpc_argp = &args, | 
 | 4562 | 		.rpc_resp = &res, | 
 | 4563 | 		.rpc_cred = cred, | 
 | 4564 | 	}; | 
 | 4565 | 	__be32 *p; | 
 | 4566 |  | 
 | 4567 | 	dprintk("--> %s\n", __func__); | 
 | 4568 | 	BUG_ON(clp == NULL); | 
| Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4569 |  | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4570 | 	p = (u32 *)verifier.data; | 
 | 4571 | 	*p++ = htonl((u32)clp->cl_boot_time.tv_sec); | 
 | 4572 | 	*p = htonl((u32)clp->cl_boot_time.tv_nsec); | 
 | 4573 | 	args.verifier = &verifier; | 
 | 4574 |  | 
 | 4575 | 	while (1) { | 
 | 4576 | 		args.id_len = scnprintf(args.id, sizeof(args.id), | 
 | 4577 | 					"%s/%s %u", | 
 | 4578 | 					clp->cl_ipaddr, | 
 | 4579 | 					rpc_peeraddr2str(clp->cl_rpcclient, | 
 | 4580 | 							 RPC_DISPLAY_ADDR), | 
 | 4581 | 					clp->cl_id_uniquifier); | 
 | 4582 |  | 
 | 4583 | 		status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); | 
 | 4584 |  | 
| Andy Adamson | 180b62a | 2010-03-02 13:19:36 -0500 | [diff] [blame] | 4585 | 		if (status != -NFS4ERR_CLID_INUSE) | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4586 | 			break; | 
 | 4587 |  | 
 | 4588 | 		if (signalled()) | 
 | 4589 | 			break; | 
 | 4590 |  | 
 | 4591 | 		if (++clp->cl_id_uniquifier == 0) | 
 | 4592 | 			break; | 
 | 4593 | 	} | 
 | 4594 |  | 
| Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4595 | 	status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); | 
| Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4596 | 	dprintk("<-- %s status= %d\n", __func__, status); | 
 | 4597 | 	return status; | 
 | 4598 | } | 
 | 4599 |  | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4600 | struct nfs4_get_lease_time_data { | 
 | 4601 | 	struct nfs4_get_lease_time_args *args; | 
 | 4602 | 	struct nfs4_get_lease_time_res *res; | 
 | 4603 | 	struct nfs_client *clp; | 
 | 4604 | }; | 
 | 4605 |  | 
 | 4606 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, | 
 | 4607 | 					void *calldata) | 
 | 4608 | { | 
 | 4609 | 	int ret; | 
 | 4610 | 	struct nfs4_get_lease_time_data *data = | 
 | 4611 | 			(struct nfs4_get_lease_time_data *)calldata; | 
 | 4612 |  | 
 | 4613 | 	dprintk("--> %s\n", __func__); | 
| Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4614 | 	rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4615 | 	/* just setup sequence, do not trigger session recovery | 
 | 4616 | 	   since we're invoked within one */ | 
 | 4617 | 	ret = nfs41_setup_sequence(data->clp->cl_session, | 
| Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4618 | 				   &data->args->la_seq_args, | 
 | 4619 | 				   &data->res->lr_seq_res, 0, task); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4620 |  | 
 | 4621 | 	BUG_ON(ret == -EAGAIN); | 
 | 4622 | 	rpc_call_start(task); | 
 | 4623 | 	dprintk("<-- %s\n", __func__); | 
 | 4624 | } | 
 | 4625 |  | 
 | 4626 | /* | 
 | 4627 |  * Called from nfs4_state_manager thread for session setup, so don't recover | 
 | 4628 |  * from sequence operation or clientid errors. | 
 | 4629 |  */ | 
 | 4630 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) | 
 | 4631 | { | 
 | 4632 | 	struct nfs4_get_lease_time_data *data = | 
 | 4633 | 			(struct nfs4_get_lease_time_data *)calldata; | 
 | 4634 |  | 
 | 4635 | 	dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4636 | 	if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) | 
 | 4637 | 		return; | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4638 | 	switch (task->tk_status) { | 
 | 4639 | 	case -NFS4ERR_DELAY: | 
 | 4640 | 	case -NFS4ERR_GRACE: | 
 | 4641 | 		dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); | 
 | 4642 | 		rpc_delay(task, NFS4_POLL_RETRY_MIN); | 
 | 4643 | 		task->tk_status = 0; | 
| Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4644 | 		nfs_restart_rpc(task, data->clp); | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4645 | 		return; | 
 | 4646 | 	} | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4647 | 	dprintk("<-- %s\n", __func__); | 
 | 4648 | } | 
 | 4649 |  | 
 | 4650 | struct rpc_call_ops nfs4_get_lease_time_ops = { | 
 | 4651 | 	.rpc_call_prepare = nfs4_get_lease_time_prepare, | 
 | 4652 | 	.rpc_call_done = nfs4_get_lease_time_done, | 
 | 4653 | }; | 
 | 4654 |  | 
 | 4655 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) | 
 | 4656 | { | 
 | 4657 | 	struct rpc_task *task; | 
 | 4658 | 	struct nfs4_get_lease_time_args args; | 
 | 4659 | 	struct nfs4_get_lease_time_res res = { | 
 | 4660 | 		.lr_fsinfo = fsinfo, | 
 | 4661 | 	}; | 
 | 4662 | 	struct nfs4_get_lease_time_data data = { | 
 | 4663 | 		.args = &args, | 
 | 4664 | 		.res = &res, | 
 | 4665 | 		.clp = clp, | 
 | 4666 | 	}; | 
 | 4667 | 	struct rpc_message msg = { | 
 | 4668 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], | 
 | 4669 | 		.rpc_argp = &args, | 
 | 4670 | 		.rpc_resp = &res, | 
 | 4671 | 	}; | 
 | 4672 | 	struct rpc_task_setup task_setup = { | 
 | 4673 | 		.rpc_client = clp->cl_rpcclient, | 
 | 4674 | 		.rpc_message = &msg, | 
 | 4675 | 		.callback_ops = &nfs4_get_lease_time_ops, | 
 | 4676 | 		.callback_data = &data | 
 | 4677 | 	}; | 
 | 4678 | 	int status; | 
 | 4679 |  | 
| Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4680 | 	dprintk("--> %s\n", __func__); | 
 | 4681 | 	task = rpc_run_task(&task_setup); | 
 | 4682 |  | 
 | 4683 | 	if (IS_ERR(task)) | 
 | 4684 | 		status = PTR_ERR(task); | 
 | 4685 | 	else { | 
 | 4686 | 		status = task->tk_status; | 
 | 4687 | 		rpc_put_task(task); | 
 | 4688 | 	} | 
 | 4689 | 	dprintk("<-- %s return %d\n", __func__, status); | 
 | 4690 |  | 
 | 4691 | 	return status; | 
 | 4692 | } | 
 | 4693 |  | 
| Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4694 | /* | 
 | 4695 |  * Reset a slot table | 
 | 4696 |  */ | 
| Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4697 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, | 
 | 4698 | 				 int ivalue) | 
| Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4699 | { | 
| Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4700 | 	struct nfs4_slot *new = NULL; | 
| Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4701 | 	int i; | 
| Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4702 | 	int ret = 0; | 
 | 4703 |  | 
| Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4704 | 	dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, | 
 | 4705 | 		max_reqs, tbl->max_slots); | 
| Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4706 |  | 
| Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4707 | 	/* Does the newly negotiated max_reqs match the existing slot table? */ | 
 | 4708 | 	if (max_reqs != tbl->max_slots) { | 
 | 4709 | 		ret = -ENOMEM; | 
 | 4710 | 		new = kmalloc(max_reqs * sizeof(struct nfs4_slot), | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4711 | 			      GFP_NOFS); | 
| Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4712 | 		if (!new) | 
 | 4713 | 			goto out; | 
 | 4714 | 		ret = 0; | 
 | 4715 | 		kfree(tbl->slots); | 
| Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4716 | 	} | 
 | 4717 | 	spin_lock(&tbl->slot_tbl_lock); | 
| Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4718 | 	if (new) { | 
 | 4719 | 		tbl->slots = new; | 
 | 4720 | 		tbl->max_slots = max_reqs; | 
 | 4721 | 	} | 
 | 4722 | 	for (i = 0; i < tbl->max_slots; ++i) | 
| Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4723 | 		tbl->slots[i].seq_nr = ivalue; | 
| Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4724 | 	spin_unlock(&tbl->slot_tbl_lock); | 
 | 4725 | 	dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, | 
 | 4726 | 		tbl, tbl->slots, tbl->max_slots); | 
 | 4727 | out: | 
 | 4728 | 	dprintk("<-- %s: return %d\n", __func__, ret); | 
 | 4729 | 	return ret; | 
 | 4730 | } | 
 | 4731 |  | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4732 | /* | 
| Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4733 |  * Reset the forechannel and backchannel slot tables | 
 | 4734 |  */ | 
 | 4735 | static int nfs4_reset_slot_tables(struct nfs4_session *session) | 
 | 4736 | { | 
 | 4737 | 	int status; | 
 | 4738 |  | 
 | 4739 | 	status = nfs4_reset_slot_table(&session->fc_slot_table, | 
| Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4740 | 			session->fc_attrs.max_reqs, 1); | 
| Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4741 | 	if (status) | 
 | 4742 | 		return status; | 
 | 4743 |  | 
 | 4744 | 	status = nfs4_reset_slot_table(&session->bc_slot_table, | 
| Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4745 | 			session->bc_attrs.max_reqs, 0); | 
| Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4746 | 	return status; | 
 | 4747 | } | 
 | 4748 |  | 
| Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4749 | /* Destroy the slot table */ | 
 | 4750 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) | 
 | 4751 | { | 
 | 4752 | 	if (session->fc_slot_table.slots != NULL) { | 
 | 4753 | 		kfree(session->fc_slot_table.slots); | 
 | 4754 | 		session->fc_slot_table.slots = NULL; | 
 | 4755 | 	} | 
 | 4756 | 	if (session->bc_slot_table.slots != NULL) { | 
 | 4757 | 		kfree(session->bc_slot_table.slots); | 
 | 4758 | 		session->bc_slot_table.slots = NULL; | 
 | 4759 | 	} | 
 | 4760 | 	return; | 
 | 4761 | } | 
 | 4762 |  | 
| Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4763 | /* | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4764 |  * Initialize slot table | 
 | 4765 |  */ | 
| Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4766 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, | 
 | 4767 | 		int max_slots, int ivalue) | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4768 | { | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4769 | 	struct nfs4_slot *slot; | 
 | 4770 | 	int ret = -ENOMEM; | 
 | 4771 |  | 
 | 4772 | 	BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); | 
 | 4773 |  | 
| Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4774 | 	dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4775 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4776 | 	slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4777 | 	if (!slot) | 
 | 4778 | 		goto out; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4779 | 	ret = 0; | 
 | 4780 |  | 
 | 4781 | 	spin_lock(&tbl->slot_tbl_lock); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4782 | 	tbl->max_slots = max_slots; | 
 | 4783 | 	tbl->slots = slot; | 
 | 4784 | 	tbl->highest_used_slotid = -1;  /* no slot is currently used */ | 
 | 4785 | 	spin_unlock(&tbl->slot_tbl_lock); | 
 | 4786 | 	dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, | 
 | 4787 | 		tbl, tbl->slots, tbl->max_slots); | 
 | 4788 | out: | 
 | 4789 | 	dprintk("<-- %s: return %d\n", __func__, ret); | 
 | 4790 | 	return ret; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4791 | } | 
 | 4792 |  | 
| Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4793 | /* | 
 | 4794 |  * Initialize the forechannel and backchannel tables | 
 | 4795 |  */ | 
 | 4796 | static int nfs4_init_slot_tables(struct nfs4_session *session) | 
 | 4797 | { | 
| Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4798 | 	struct nfs4_slot_table *tbl; | 
 | 4799 | 	int status = 0; | 
| Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4800 |  | 
| Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4801 | 	tbl = &session->fc_slot_table; | 
 | 4802 | 	if (tbl->slots == NULL) { | 
 | 4803 | 		status = nfs4_init_slot_table(tbl, | 
 | 4804 | 				session->fc_attrs.max_reqs, 1); | 
 | 4805 | 		if (status) | 
 | 4806 | 			return status; | 
 | 4807 | 	} | 
| Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4808 |  | 
| Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4809 | 	tbl = &session->bc_slot_table; | 
 | 4810 | 	if (tbl->slots == NULL) { | 
 | 4811 | 		status = nfs4_init_slot_table(tbl, | 
 | 4812 | 				session->bc_attrs.max_reqs, 0); | 
 | 4813 | 		if (status) | 
 | 4814 | 			nfs4_destroy_slot_tables(session); | 
 | 4815 | 	} | 
| Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4816 |  | 
 | 4817 | 	return status; | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4818 | } | 
 | 4819 |  | 
 | 4820 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) | 
 | 4821 | { | 
 | 4822 | 	struct nfs4_session *session; | 
 | 4823 | 	struct nfs4_slot_table *tbl; | 
 | 4824 |  | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4825 | 	session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4826 | 	if (!session) | 
 | 4827 | 		return NULL; | 
| Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4828 |  | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4829 | 	tbl = &session->fc_slot_table; | 
| Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4830 | 	tbl->highest_used_slotid = -1; | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4831 | 	spin_lock_init(&tbl->slot_tbl_lock); | 
| Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4832 | 	rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); | 
| Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4833 | 	init_completion(&tbl->complete); | 
| Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4834 |  | 
 | 4835 | 	tbl = &session->bc_slot_table; | 
| Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4836 | 	tbl->highest_used_slotid = -1; | 
| Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4837 | 	spin_lock_init(&tbl->slot_tbl_lock); | 
 | 4838 | 	rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); | 
| Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4839 | 	init_completion(&tbl->complete); | 
| Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4840 |  | 
| Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 4841 | 	session->session_state = 1<<NFS4_SESSION_INITING; | 
 | 4842 |  | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4843 | 	session->clp = clp; | 
 | 4844 | 	return session; | 
 | 4845 | } | 
 | 4846 |  | 
 | 4847 | void nfs4_destroy_session(struct nfs4_session *session) | 
 | 4848 | { | 
| Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 4849 | 	nfs4_proc_destroy_session(session); | 
 | 4850 | 	dprintk("%s Destroy backchannel for xprt %p\n", | 
 | 4851 | 		__func__, session->clp->cl_rpcclient->cl_xprt); | 
 | 4852 | 	xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, | 
 | 4853 | 				NFS41_BC_MIN_CALLBACKS); | 
| Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4854 | 	nfs4_destroy_slot_tables(session); | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4855 | 	kfree(session); | 
 | 4856 | } | 
 | 4857 |  | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4858 | /* | 
 | 4859 |  * Initialize the values to be used by the client in CREATE_SESSION | 
 | 4860 |  * If nfs4_init_session set the fore channel request and response sizes, | 
 | 4861 |  * use them. | 
 | 4862 |  * | 
 | 4863 |  * Set the back channel max_resp_sz_cached to zero to force the client to | 
 | 4864 |  * always set csa_cachethis to FALSE because the current implementation | 
 | 4865 |  * of the back channel DRC only supports caching the CB_SEQUENCE operation. | 
 | 4866 |  */ | 
 | 4867 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) | 
 | 4868 | { | 
 | 4869 | 	struct nfs4_session *session = args->client->cl_session; | 
 | 4870 | 	unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, | 
 | 4871 | 		     mxresp_sz = session->fc_attrs.max_resp_sz; | 
 | 4872 |  | 
 | 4873 | 	if (mxrqst_sz == 0) | 
 | 4874 | 		mxrqst_sz = NFS_MAX_FILE_IO_SIZE; | 
 | 4875 | 	if (mxresp_sz == 0) | 
 | 4876 | 		mxresp_sz = NFS_MAX_FILE_IO_SIZE; | 
 | 4877 | 	/* Fore channel attributes */ | 
 | 4878 | 	args->fc_attrs.headerpadsz = 0; | 
 | 4879 | 	args->fc_attrs.max_rqst_sz = mxrqst_sz; | 
 | 4880 | 	args->fc_attrs.max_resp_sz = mxresp_sz; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4881 | 	args->fc_attrs.max_ops = NFS4_MAX_OPS; | 
 | 4882 | 	args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; | 
 | 4883 |  | 
 | 4884 | 	dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " | 
| Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4885 | 		"max_ops=%u max_reqs=%u\n", | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4886 | 		__func__, | 
 | 4887 | 		args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, | 
| Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4888 | 		args->fc_attrs.max_ops, args->fc_attrs.max_reqs); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4889 |  | 
 | 4890 | 	/* Back channel attributes */ | 
 | 4891 | 	args->bc_attrs.headerpadsz = 0; | 
 | 4892 | 	args->bc_attrs.max_rqst_sz = PAGE_SIZE; | 
 | 4893 | 	args->bc_attrs.max_resp_sz = PAGE_SIZE; | 
 | 4894 | 	args->bc_attrs.max_resp_sz_cached = 0; | 
 | 4895 | 	args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; | 
 | 4896 | 	args->bc_attrs.max_reqs = 1; | 
 | 4897 |  | 
 | 4898 | 	dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " | 
 | 4899 | 		"max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", | 
 | 4900 | 		__func__, | 
 | 4901 | 		args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, | 
 | 4902 | 		args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, | 
 | 4903 | 		args->bc_attrs.max_reqs); | 
 | 4904 | } | 
 | 4905 |  | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4906 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4907 | { | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4908 | 	struct nfs4_channel_attrs *sent = &args->fc_attrs; | 
 | 4909 | 	struct nfs4_channel_attrs *rcvd = &session->fc_attrs; | 
 | 4910 |  | 
 | 4911 | 	if (rcvd->headerpadsz > sent->headerpadsz) | 
 | 4912 | 		return -EINVAL; | 
 | 4913 | 	if (rcvd->max_resp_sz > sent->max_resp_sz) | 
 | 4914 | 		return -EINVAL; | 
 | 4915 | 	/* | 
 | 4916 | 	 * Our requested max_ops is the minimum we need; we're not | 
 | 4917 | 	 * prepared to break up compounds into smaller pieces than that. | 
 | 4918 | 	 * So, no point even trying to continue if the server won't | 
 | 4919 | 	 * cooperate: | 
 | 4920 | 	 */ | 
 | 4921 | 	if (rcvd->max_ops < sent->max_ops) | 
 | 4922 | 		return -EINVAL; | 
 | 4923 | 	if (rcvd->max_reqs == 0) | 
 | 4924 | 		return -EINVAL; | 
 | 4925 | 	return 0; | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4926 | } | 
 | 4927 |  | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4928 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) | 
 | 4929 | { | 
 | 4930 | 	struct nfs4_channel_attrs *sent = &args->bc_attrs; | 
 | 4931 | 	struct nfs4_channel_attrs *rcvd = &session->bc_attrs; | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4932 |  | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4933 | 	if (rcvd->max_rqst_sz > sent->max_rqst_sz) | 
 | 4934 | 		return -EINVAL; | 
 | 4935 | 	if (rcvd->max_resp_sz < sent->max_resp_sz) | 
 | 4936 | 		return -EINVAL; | 
 | 4937 | 	if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) | 
 | 4938 | 		return -EINVAL; | 
 | 4939 | 	/* These would render the backchannel useless: */ | 
 | 4940 | 	if (rcvd->max_ops  == 0) | 
 | 4941 | 		return -EINVAL; | 
 | 4942 | 	if (rcvd->max_reqs == 0) | 
 | 4943 | 		return -EINVAL; | 
 | 4944 | 	return 0; | 
 | 4945 | } | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4946 |  | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4947 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, | 
 | 4948 | 				     struct nfs4_session *session) | 
 | 4949 | { | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4950 | 	int ret; | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4951 |  | 
| J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4952 | 	ret = nfs4_verify_fore_channel_attrs(args, session); | 
 | 4953 | 	if (ret) | 
 | 4954 | 		return ret; | 
 | 4955 | 	return nfs4_verify_back_channel_attrs(args, session); | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4956 | } | 
 | 4957 |  | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4958 | static int _nfs4_proc_create_session(struct nfs_client *clp) | 
 | 4959 | { | 
 | 4960 | 	struct nfs4_session *session = clp->cl_session; | 
 | 4961 | 	struct nfs41_create_session_args args = { | 
 | 4962 | 		.client = clp, | 
 | 4963 | 		.cb_program = NFS4_CALLBACK, | 
 | 4964 | 	}; | 
 | 4965 | 	struct nfs41_create_session_res res = { | 
 | 4966 | 		.client = clp, | 
 | 4967 | 	}; | 
 | 4968 | 	struct rpc_message msg = { | 
 | 4969 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], | 
 | 4970 | 		.rpc_argp = &args, | 
 | 4971 | 		.rpc_resp = &res, | 
 | 4972 | 	}; | 
 | 4973 | 	int status; | 
 | 4974 |  | 
 | 4975 | 	nfs4_init_channel_attrs(&args); | 
| Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 4976 | 	args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4977 |  | 
 | 4978 | 	status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); | 
 | 4979 |  | 
| Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4980 | 	if (!status) | 
 | 4981 | 		/* Verify the session's negotiated channel_attrs values */ | 
 | 4982 | 		status = nfs4_verify_channel_attrs(&args, session); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4983 | 	if (!status) { | 
 | 4984 | 		/* Increment the clientid slot sequence id */ | 
 | 4985 | 		clp->cl_seqid++; | 
 | 4986 | 	} | 
 | 4987 |  | 
 | 4988 | 	return status; | 
 | 4989 | } | 
 | 4990 |  | 
 | 4991 | /* | 
 | 4992 |  * Issues a CREATE_SESSION operation to the server. | 
 | 4993 |  * It is the responsibility of the caller to verify the session is | 
 | 4994 |  * expired before calling this routine. | 
 | 4995 |  */ | 
| Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4996 | int nfs4_proc_create_session(struct nfs_client *clp) | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4997 | { | 
 | 4998 | 	int status; | 
 | 4999 | 	unsigned *ptr; | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5000 | 	struct nfs4_session *session = clp->cl_session; | 
 | 5001 |  | 
 | 5002 | 	dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); | 
 | 5003 |  | 
 | 5004 | 	status = _nfs4_proc_create_session(clp); | 
 | 5005 | 	if (status) | 
 | 5006 | 		goto out; | 
 | 5007 |  | 
| Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5008 | 	/* Init and reset the fore channel */ | 
 | 5009 | 	status = nfs4_init_slot_tables(session); | 
 | 5010 | 	dprintk("slot table initialization returned %d\n", status); | 
 | 5011 | 	if (status) | 
 | 5012 | 		goto out; | 
 | 5013 | 	status = nfs4_reset_slot_tables(session); | 
 | 5014 | 	dprintk("slot table reset returned %d\n", status); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5015 | 	if (status) | 
 | 5016 | 		goto out; | 
 | 5017 |  | 
 | 5018 | 	ptr = (unsigned *)&session->sess_id.data[0]; | 
 | 5019 | 	dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, | 
 | 5020 | 		clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); | 
| Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5021 | out: | 
 | 5022 | 	dprintk("<-- %s\n", __func__); | 
 | 5023 | 	return status; | 
 | 5024 | } | 
 | 5025 |  | 
| Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5026 | /* | 
 | 5027 |  * Issue the over-the-wire RPC DESTROY_SESSION. | 
 | 5028 |  * The caller must serialize access to this routine. | 
 | 5029 |  */ | 
 | 5030 | int nfs4_proc_destroy_session(struct nfs4_session *session) | 
 | 5031 | { | 
 | 5032 | 	int status = 0; | 
 | 5033 | 	struct rpc_message msg; | 
 | 5034 |  | 
 | 5035 | 	dprintk("--> nfs4_proc_destroy_session\n"); | 
 | 5036 |  | 
 | 5037 | 	/* session is still being setup */ | 
 | 5038 | 	if (session->clp->cl_cons_state != NFS_CS_READY) | 
 | 5039 | 		return status; | 
 | 5040 |  | 
 | 5041 | 	msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; | 
 | 5042 | 	msg.rpc_argp = session; | 
 | 5043 | 	msg.rpc_resp = NULL; | 
 | 5044 | 	msg.rpc_cred = NULL; | 
 | 5045 | 	status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); | 
 | 5046 |  | 
 | 5047 | 	if (status) | 
 | 5048 | 		printk(KERN_WARNING | 
 | 5049 | 			"Got error %d from the server on DESTROY_SESSION. " | 
 | 5050 | 			"Session has been destroyed regardless...\n", status); | 
 | 5051 |  | 
 | 5052 | 	dprintk("<-- nfs4_proc_destroy_session\n"); | 
 | 5053 | 	return status; | 
 | 5054 | } | 
 | 5055 |  | 
| Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5056 | int nfs4_init_session(struct nfs_server *server) | 
 | 5057 | { | 
 | 5058 | 	struct nfs_client *clp = server->nfs_client; | 
| Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5059 | 	struct nfs4_session *session; | 
| Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5060 | 	unsigned int rsize, wsize; | 
| Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5061 | 	int ret; | 
 | 5062 |  | 
 | 5063 | 	if (!nfs4_has_session(clp)) | 
 | 5064 | 		return 0; | 
 | 5065 |  | 
| Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5066 | 	session = clp->cl_session; | 
 | 5067 | 	if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) | 
 | 5068 | 		return 0; | 
 | 5069 |  | 
| Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5070 | 	rsize = server->rsize; | 
 | 5071 | 	if (rsize == 0) | 
 | 5072 | 		rsize = NFS_MAX_FILE_IO_SIZE; | 
 | 5073 | 	wsize = server->wsize; | 
 | 5074 | 	if (wsize == 0) | 
 | 5075 | 		wsize = NFS_MAX_FILE_IO_SIZE; | 
 | 5076 |  | 
| Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5077 | 	session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; | 
 | 5078 | 	session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; | 
| Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5079 |  | 
| Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5080 | 	ret = nfs4_recover_expired_lease(server); | 
 | 5081 | 	if (!ret) | 
 | 5082 | 		ret = nfs4_check_client_ready(clp); | 
 | 5083 | 	return ret; | 
 | 5084 | } | 
 | 5085 |  | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5086 | /* | 
 | 5087 |  * Renew the cl_session lease. | 
 | 5088 |  */ | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5089 | struct nfs4_sequence_data { | 
 | 5090 | 	struct nfs_client *clp; | 
 | 5091 | 	struct nfs4_sequence_args args; | 
 | 5092 | 	struct nfs4_sequence_res res; | 
 | 5093 | }; | 
 | 5094 |  | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5095 | static void nfs41_sequence_release(void *data) | 
 | 5096 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5097 | 	struct nfs4_sequence_data *calldata = data; | 
 | 5098 | 	struct nfs_client *clp = calldata->clp; | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5099 |  | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5100 | 	if (atomic_read(&clp->cl_count) > 1) | 
 | 5101 | 		nfs4_schedule_state_renewal(clp); | 
 | 5102 | 	nfs_put_client(clp); | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5103 | 	kfree(calldata); | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5104 | } | 
 | 5105 |  | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5106 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) | 
 | 5107 | { | 
 | 5108 | 	switch(task->tk_status) { | 
 | 5109 | 	case -NFS4ERR_DELAY: | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5110 | 		rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
 | 5111 | 		return -EAGAIN; | 
 | 5112 | 	default: | 
 | 5113 | 		nfs4_schedule_state_recovery(clp); | 
 | 5114 | 	} | 
 | 5115 | 	return 0; | 
 | 5116 | } | 
 | 5117 |  | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5118 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5119 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5120 | 	struct nfs4_sequence_data *calldata = data; | 
 | 5121 | 	struct nfs_client *clp = calldata->clp; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5122 |  | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5123 | 	if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) | 
 | 5124 | 		return; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5125 |  | 
 | 5126 | 	if (task->tk_status < 0) { | 
 | 5127 | 		dprintk("%s ERROR %d\n", __func__, task->tk_status); | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5128 | 		if (atomic_read(&clp->cl_count) == 1) | 
 | 5129 | 			goto out; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5130 |  | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5131 | 		if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { | 
 | 5132 | 			rpc_restart_call_prepare(task); | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5133 | 			return; | 
 | 5134 | 		} | 
 | 5135 | 	} | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5136 | 	dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5137 | out: | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5138 | 	dprintk("<-- %s\n", __func__); | 
 | 5139 | } | 
 | 5140 |  | 
 | 5141 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) | 
 | 5142 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5143 | 	struct nfs4_sequence_data *calldata = data; | 
 | 5144 | 	struct nfs_client *clp = calldata->clp; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5145 | 	struct nfs4_sequence_args *args; | 
 | 5146 | 	struct nfs4_sequence_res *res; | 
 | 5147 |  | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5148 | 	args = task->tk_msg.rpc_argp; | 
 | 5149 | 	res = task->tk_msg.rpc_resp; | 
 | 5150 |  | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5151 | 	if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5152 | 		return; | 
 | 5153 | 	rpc_call_start(task); | 
 | 5154 | } | 
 | 5155 |  | 
 | 5156 | static const struct rpc_call_ops nfs41_sequence_ops = { | 
 | 5157 | 	.rpc_call_done = nfs41_sequence_call_done, | 
 | 5158 | 	.rpc_call_prepare = nfs41_sequence_prepare, | 
| Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5159 | 	.rpc_release = nfs41_sequence_release, | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5160 | }; | 
 | 5161 |  | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5162 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5163 | { | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5164 | 	struct nfs4_sequence_data *calldata; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5165 | 	struct rpc_message msg = { | 
 | 5166 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], | 
 | 5167 | 		.rpc_cred = cred, | 
 | 5168 | 	}; | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5169 | 	struct rpc_task_setup task_setup_data = { | 
 | 5170 | 		.rpc_client = clp->cl_rpcclient, | 
 | 5171 | 		.rpc_message = &msg, | 
 | 5172 | 		.callback_ops = &nfs41_sequence_ops, | 
 | 5173 | 		.flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, | 
 | 5174 | 	}; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5175 |  | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5176 | 	if (!atomic_inc_not_zero(&clp->cl_count)) | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5177 | 		return ERR_PTR(-EIO); | 
| Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5178 | 	calldata = kzalloc(sizeof(*calldata), GFP_NOFS); | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5179 | 	if (calldata == NULL) { | 
| Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5180 | 		nfs_put_client(clp); | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5181 | 		return ERR_PTR(-ENOMEM); | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5182 | 	} | 
| Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5183 | 	msg.rpc_argp = &calldata->args; | 
 | 5184 | 	msg.rpc_resp = &calldata->res; | 
 | 5185 | 	calldata->clp = clp; | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5186 | 	task_setup_data.callback_data = calldata; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5187 |  | 
| Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5188 | 	return rpc_run_task(&task_setup_data); | 
 | 5189 | } | 
 | 5190 |  | 
 | 5191 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) | 
 | 5192 | { | 
 | 5193 | 	struct rpc_task *task; | 
 | 5194 | 	int ret = 0; | 
 | 5195 |  | 
 | 5196 | 	task = _nfs41_proc_sequence(clp, cred); | 
 | 5197 | 	if (IS_ERR(task)) | 
 | 5198 | 		ret = PTR_ERR(task); | 
 | 5199 | 	else | 
 | 5200 | 		rpc_put_task(task); | 
 | 5201 | 	dprintk("<-- %s status=%d\n", __func__, ret); | 
 | 5202 | 	return ret; | 
 | 5203 | } | 
 | 5204 |  | 
 | 5205 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) | 
 | 5206 | { | 
 | 5207 | 	struct rpc_task *task; | 
 | 5208 | 	int ret; | 
 | 5209 |  | 
 | 5210 | 	task = _nfs41_proc_sequence(clp, cred); | 
 | 5211 | 	if (IS_ERR(task)) { | 
 | 5212 | 		ret = PTR_ERR(task); | 
 | 5213 | 		goto out; | 
 | 5214 | 	} | 
 | 5215 | 	ret = rpc_wait_for_completion_task(task); | 
 | 5216 | 	if (!ret) | 
 | 5217 | 		ret = task->tk_status; | 
 | 5218 | 	rpc_put_task(task); | 
 | 5219 | out: | 
 | 5220 | 	dprintk("<-- %s status=%d\n", __func__, ret); | 
 | 5221 | 	return ret; | 
| Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5222 | } | 
 | 5223 |  | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5224 | struct nfs4_reclaim_complete_data { | 
 | 5225 | 	struct nfs_client *clp; | 
 | 5226 | 	struct nfs41_reclaim_complete_args arg; | 
 | 5227 | 	struct nfs41_reclaim_complete_res res; | 
 | 5228 | }; | 
 | 5229 |  | 
 | 5230 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) | 
 | 5231 | { | 
 | 5232 | 	struct nfs4_reclaim_complete_data *calldata = data; | 
 | 5233 |  | 
| Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5234 | 	rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); | 
| Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5235 | 	if (nfs41_setup_sequence(calldata->clp->cl_session, | 
 | 5236 | 				&calldata->arg.seq_args, | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5237 | 				&calldata->res.seq_res, 0, task)) | 
 | 5238 | 		return; | 
 | 5239 |  | 
 | 5240 | 	rpc_call_start(task); | 
 | 5241 | } | 
 | 5242 |  | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5243 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) | 
 | 5244 | { | 
 | 5245 | 	switch(task->tk_status) { | 
 | 5246 | 	case 0: | 
 | 5247 | 	case -NFS4ERR_COMPLETE_ALREADY: | 
 | 5248 | 	case -NFS4ERR_WRONG_CRED: /* What to do here? */ | 
 | 5249 | 		break; | 
 | 5250 | 	case -NFS4ERR_DELAY: | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5251 | 		rpc_delay(task, NFS4_POLL_RETRY_MAX); | 
 | 5252 | 		return -EAGAIN; | 
 | 5253 | 	default: | 
 | 5254 | 		nfs4_schedule_state_recovery(clp); | 
 | 5255 | 	} | 
 | 5256 | 	return 0; | 
 | 5257 | } | 
 | 5258 |  | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5259 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) | 
 | 5260 | { | 
 | 5261 | 	struct nfs4_reclaim_complete_data *calldata = data; | 
 | 5262 | 	struct nfs_client *clp = calldata->clp; | 
 | 5263 | 	struct nfs4_sequence_res *res = &calldata->res.seq_res; | 
 | 5264 |  | 
 | 5265 | 	dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5266 | 	if (!nfs41_sequence_done(task, res)) | 
 | 5267 | 		return; | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5268 |  | 
| Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5269 | 	if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { | 
 | 5270 | 		rpc_restart_call_prepare(task); | 
 | 5271 | 		return; | 
 | 5272 | 	} | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5273 | 	dprintk("<-- %s\n", __func__); | 
 | 5274 | } | 
 | 5275 |  | 
 | 5276 | static void nfs4_free_reclaim_complete_data(void *data) | 
 | 5277 | { | 
 | 5278 | 	struct nfs4_reclaim_complete_data *calldata = data; | 
 | 5279 |  | 
 | 5280 | 	kfree(calldata); | 
 | 5281 | } | 
 | 5282 |  | 
 | 5283 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { | 
 | 5284 | 	.rpc_call_prepare = nfs4_reclaim_complete_prepare, | 
 | 5285 | 	.rpc_call_done = nfs4_reclaim_complete_done, | 
 | 5286 | 	.rpc_release = nfs4_free_reclaim_complete_data, | 
 | 5287 | }; | 
 | 5288 |  | 
 | 5289 | /* | 
 | 5290 |  * Issue a global reclaim complete. | 
 | 5291 |  */ | 
 | 5292 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) | 
 | 5293 | { | 
 | 5294 | 	struct nfs4_reclaim_complete_data *calldata; | 
 | 5295 | 	struct rpc_task *task; | 
 | 5296 | 	struct rpc_message msg = { | 
 | 5297 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], | 
 | 5298 | 	}; | 
 | 5299 | 	struct rpc_task_setup task_setup_data = { | 
 | 5300 | 		.rpc_client = clp->cl_rpcclient, | 
 | 5301 | 		.rpc_message = &msg, | 
 | 5302 | 		.callback_ops = &nfs4_reclaim_complete_call_ops, | 
 | 5303 | 		.flags = RPC_TASK_ASYNC, | 
 | 5304 | 	}; | 
 | 5305 | 	int status = -ENOMEM; | 
 | 5306 |  | 
 | 5307 | 	dprintk("--> %s\n", __func__); | 
| Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5308 | 	calldata = kzalloc(sizeof(*calldata), GFP_NOFS); | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5309 | 	if (calldata == NULL) | 
 | 5310 | 		goto out; | 
 | 5311 | 	calldata->clp = clp; | 
 | 5312 | 	calldata->arg.one_fs = 0; | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5313 |  | 
 | 5314 | 	msg.rpc_argp = &calldata->arg; | 
 | 5315 | 	msg.rpc_resp = &calldata->res; | 
 | 5316 | 	task_setup_data.callback_data = calldata; | 
 | 5317 | 	task = rpc_run_task(&task_setup_data); | 
| Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5318 | 	if (IS_ERR(task)) { | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5319 | 		status = PTR_ERR(task); | 
| Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5320 | 		goto out; | 
 | 5321 | 	} | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5322 | 	rpc_put_task(task); | 
| Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5323 | 	return 0; | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5324 | out: | 
 | 5325 | 	dprintk("<-- %s status=%d\n", __func__, status); | 
 | 5326 | 	return status; | 
 | 5327 | } | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5328 |  | 
 | 5329 | static void | 
 | 5330 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) | 
 | 5331 | { | 
 | 5332 | 	struct nfs4_layoutget *lgp = calldata; | 
| Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5333 | 	struct nfs_server *server = NFS_SERVER(lgp->args.inode); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5334 |  | 
 | 5335 | 	dprintk("--> %s\n", __func__); | 
| Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5336 | 	/* Note the is a race here, where a CB_LAYOUTRECALL can come in | 
 | 5337 | 	 * right now covering the LAYOUTGET we are about to send. | 
 | 5338 | 	 * However, that is not so catastrophic, and there seems | 
 | 5339 | 	 * to be no way to prevent it completely. | 
 | 5340 | 	 */ | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5341 | 	if (nfs4_setup_sequence(server, &lgp->args.seq_args, | 
 | 5342 | 				&lgp->res.seq_res, 0, task)) | 
 | 5343 | 		return; | 
| Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5344 | 	if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, | 
 | 5345 | 					  NFS_I(lgp->args.inode)->layout, | 
 | 5346 | 					  lgp->args.ctx->state)) { | 
 | 5347 | 		rpc_exit(task, NFS4_OK); | 
 | 5348 | 		return; | 
 | 5349 | 	} | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5350 | 	rpc_call_start(task); | 
 | 5351 | } | 
 | 5352 |  | 
 | 5353 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) | 
 | 5354 | { | 
 | 5355 | 	struct nfs4_layoutget *lgp = calldata; | 
 | 5356 | 	struct nfs_server *server = NFS_SERVER(lgp->args.inode); | 
 | 5357 |  | 
 | 5358 | 	dprintk("--> %s\n", __func__); | 
 | 5359 |  | 
 | 5360 | 	if (!nfs4_sequence_done(task, &lgp->res.seq_res)) | 
 | 5361 | 		return; | 
 | 5362 |  | 
 | 5363 | 	switch (task->tk_status) { | 
 | 5364 | 	case 0: | 
 | 5365 | 		break; | 
 | 5366 | 	case -NFS4ERR_LAYOUTTRYLATER: | 
 | 5367 | 	case -NFS4ERR_RECALLCONFLICT: | 
 | 5368 | 		task->tk_status = -NFS4ERR_DELAY; | 
 | 5369 | 		/* Fall through */ | 
 | 5370 | 	default: | 
 | 5371 | 		if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { | 
 | 5372 | 			rpc_restart_call_prepare(task); | 
 | 5373 | 			return; | 
 | 5374 | 		} | 
 | 5375 | 	} | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5376 | 	dprintk("<-- %s\n", __func__); | 
 | 5377 | } | 
 | 5378 |  | 
 | 5379 | static void nfs4_layoutget_release(void *calldata) | 
 | 5380 | { | 
 | 5381 | 	struct nfs4_layoutget *lgp = calldata; | 
 | 5382 |  | 
 | 5383 | 	dprintk("--> %s\n", __func__); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5384 | 	if (lgp->res.layout.buf != NULL) | 
 | 5385 | 		free_page((unsigned long) lgp->res.layout.buf); | 
 | 5386 | 	put_nfs_open_context(lgp->args.ctx); | 
 | 5387 | 	kfree(calldata); | 
 | 5388 | 	dprintk("<-- %s\n", __func__); | 
 | 5389 | } | 
 | 5390 |  | 
 | 5391 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { | 
 | 5392 | 	.rpc_call_prepare = nfs4_layoutget_prepare, | 
 | 5393 | 	.rpc_call_done = nfs4_layoutget_done, | 
 | 5394 | 	.rpc_release = nfs4_layoutget_release, | 
 | 5395 | }; | 
 | 5396 |  | 
 | 5397 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) | 
 | 5398 | { | 
 | 5399 | 	struct nfs_server *server = NFS_SERVER(lgp->args.inode); | 
 | 5400 | 	struct rpc_task *task; | 
 | 5401 | 	struct rpc_message msg = { | 
 | 5402 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], | 
 | 5403 | 		.rpc_argp = &lgp->args, | 
 | 5404 | 		.rpc_resp = &lgp->res, | 
 | 5405 | 	}; | 
 | 5406 | 	struct rpc_task_setup task_setup_data = { | 
 | 5407 | 		.rpc_client = server->client, | 
 | 5408 | 		.rpc_message = &msg, | 
 | 5409 | 		.callback_ops = &nfs4_layoutget_call_ops, | 
 | 5410 | 		.callback_data = lgp, | 
 | 5411 | 		.flags = RPC_TASK_ASYNC, | 
 | 5412 | 	}; | 
 | 5413 | 	int status = 0; | 
 | 5414 |  | 
 | 5415 | 	dprintk("--> %s\n", __func__); | 
 | 5416 |  | 
 | 5417 | 	lgp->res.layout.buf = (void *)__get_free_page(GFP_NOFS); | 
 | 5418 | 	if (lgp->res.layout.buf == NULL) { | 
 | 5419 | 		nfs4_layoutget_release(lgp); | 
 | 5420 | 		return -ENOMEM; | 
 | 5421 | 	} | 
 | 5422 |  | 
 | 5423 | 	lgp->res.seq_res.sr_slot = NULL; | 
 | 5424 | 	task = rpc_run_task(&task_setup_data); | 
 | 5425 | 	if (IS_ERR(task)) | 
 | 5426 | 		return PTR_ERR(task); | 
 | 5427 | 	status = nfs4_wait_for_completion_rpc_task(task); | 
| Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5428 | 	if (status == 0) | 
 | 5429 | 		status = task->tk_status; | 
 | 5430 | 	if (status == 0) | 
 | 5431 | 		status = pnfs_layout_process(lgp); | 
| Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5432 | 	rpc_put_task(task); | 
 | 5433 | 	dprintk("<-- %s status=%d\n", __func__, status); | 
 | 5434 | 	return status; | 
 | 5435 | } | 
 | 5436 |  | 
 | 5437 | static int | 
 | 5438 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) | 
 | 5439 | { | 
 | 5440 | 	struct nfs4_getdeviceinfo_args args = { | 
 | 5441 | 		.pdev = pdev, | 
 | 5442 | 	}; | 
 | 5443 | 	struct nfs4_getdeviceinfo_res res = { | 
 | 5444 | 		.pdev = pdev, | 
 | 5445 | 	}; | 
 | 5446 | 	struct rpc_message msg = { | 
 | 5447 | 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], | 
 | 5448 | 		.rpc_argp = &args, | 
 | 5449 | 		.rpc_resp = &res, | 
 | 5450 | 	}; | 
 | 5451 | 	int status; | 
 | 5452 |  | 
 | 5453 | 	dprintk("--> %s\n", __func__); | 
 | 5454 | 	status = nfs4_call_sync(server, &msg, &args, &res, 0); | 
 | 5455 | 	dprintk("<-- %s status=%d\n", __func__, status); | 
 | 5456 |  | 
 | 5457 | 	return status; | 
 | 5458 | } | 
 | 5459 |  | 
 | 5460 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) | 
 | 5461 | { | 
 | 5462 | 	struct nfs4_exception exception = { }; | 
 | 5463 | 	int err; | 
 | 5464 |  | 
 | 5465 | 	do { | 
 | 5466 | 		err = nfs4_handle_exception(server, | 
 | 5467 | 					_nfs4_proc_getdeviceinfo(server, pdev), | 
 | 5468 | 					&exception); | 
 | 5469 | 	} while (exception.retry); | 
 | 5470 | 	return err; | 
 | 5471 | } | 
 | 5472 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); | 
 | 5473 |  | 
| Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5474 | #endif /* CONFIG_NFS_V4_1 */ | 
 | 5475 |  | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5476 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { | 
| Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5477 | 	.owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, | 
| Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5478 | 	.state_flag_bit	= NFS_STATE_RECLAIM_REBOOT, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | 	.recover_open	= nfs4_open_reclaim, | 
 | 5480 | 	.recover_lock	= nfs4_lock_reclaim, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5481 | 	.establish_clid = nfs4_init_clientid, | 
| Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5482 | 	.get_clid_cred	= nfs4_get_setclientid_cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5483 | }; | 
 | 5484 |  | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5485 | #if defined(CONFIG_NFS_V4_1) | 
 | 5486 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { | 
 | 5487 | 	.owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, | 
 | 5488 | 	.state_flag_bit	= NFS_STATE_RECLAIM_REBOOT, | 
 | 5489 | 	.recover_open	= nfs4_open_reclaim, | 
 | 5490 | 	.recover_lock	= nfs4_lock_reclaim, | 
| Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5491 | 	.establish_clid = nfs41_init_clientid, | 
| Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5492 | 	.get_clid_cred	= nfs4_get_exchange_id_cred, | 
| Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5493 | 	.reclaim_complete = nfs41_proc_reclaim_complete, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5494 | }; | 
 | 5495 | #endif /* CONFIG_NFS_V4_1 */ | 
 | 5496 |  | 
 | 5497 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { | 
| Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5498 | 	.owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, | 
| Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5499 | 	.state_flag_bit	= NFS_STATE_RECLAIM_NOGRACE, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | 	.recover_open	= nfs4_open_expired, | 
 | 5501 | 	.recover_lock	= nfs4_lock_expired, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5502 | 	.establish_clid = nfs4_init_clientid, | 
| Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5503 | 	.get_clid_cred	= nfs4_get_setclientid_cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5504 | }; | 
 | 5505 |  | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5506 | #if defined(CONFIG_NFS_V4_1) | 
 | 5507 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { | 
 | 5508 | 	.owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, | 
 | 5509 | 	.state_flag_bit	= NFS_STATE_RECLAIM_NOGRACE, | 
 | 5510 | 	.recover_open	= nfs4_open_expired, | 
 | 5511 | 	.recover_lock	= nfs4_lock_expired, | 
| Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5512 | 	.establish_clid = nfs41_init_clientid, | 
| Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5513 | 	.get_clid_cred	= nfs4_get_exchange_id_cred, | 
| Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5514 | }; | 
 | 5515 | #endif /* CONFIG_NFS_V4_1 */ | 
 | 5516 |  | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5517 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { | 
 | 5518 | 	.sched_state_renewal = nfs4_proc_async_renew, | 
| Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5519 | 	.get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, | 
| Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5520 | 	.renew_lease = nfs4_proc_renew, | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5521 | }; | 
 | 5522 |  | 
 | 5523 | #if defined(CONFIG_NFS_V4_1) | 
 | 5524 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { | 
 | 5525 | 	.sched_state_renewal = nfs41_proc_async_sequence, | 
| Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5526 | 	.get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, | 
| Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5527 | 	.renew_lease = nfs4_proc_sequence, | 
| Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5528 | }; | 
 | 5529 | #endif | 
 | 5530 |  | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5531 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { | 
 | 5532 | 	.minor_version = 0, | 
 | 5533 | 	.call_sync = _nfs4_call_sync, | 
| Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5534 | 	.validate_stateid = nfs4_validate_delegation_stateid, | 
| Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5535 | 	.reboot_recovery_ops = &nfs40_reboot_recovery_ops, | 
 | 5536 | 	.nograce_recovery_ops = &nfs40_nograce_recovery_ops, | 
 | 5537 | 	.state_renewal_ops = &nfs40_state_renewal_ops, | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5538 | }; | 
 | 5539 |  | 
 | 5540 | #if defined(CONFIG_NFS_V4_1) | 
 | 5541 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { | 
 | 5542 | 	.minor_version = 1, | 
 | 5543 | 	.call_sync = _nfs4_call_sync_session, | 
| Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5544 | 	.validate_stateid = nfs41_validate_delegation_stateid, | 
| Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5545 | 	.reboot_recovery_ops = &nfs41_reboot_recovery_ops, | 
 | 5546 | 	.nograce_recovery_ops = &nfs41_nograce_recovery_ops, | 
 | 5547 | 	.state_renewal_ops = &nfs41_state_renewal_ops, | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5548 | }; | 
 | 5549 | #endif | 
 | 5550 |  | 
| Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5551 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { | 
 | 5552 | 	[0] = &nfs_v4_0_minor_ops, | 
 | 5553 | #if defined(CONFIG_NFS_V4_1) | 
 | 5554 | 	[1] = &nfs_v4_1_minor_ops, | 
 | 5555 | #endif | 
 | 5556 | }; | 
 | 5557 |  | 
| Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5558 | static const struct inode_operations nfs4_file_inode_operations = { | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5559 | 	.permission	= nfs_permission, | 
 | 5560 | 	.getattr	= nfs_getattr, | 
 | 5561 | 	.setattr	= nfs_setattr, | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5562 | 	.getxattr	= generic_getxattr, | 
 | 5563 | 	.setxattr	= generic_setxattr, | 
 | 5564 | 	.listxattr	= generic_listxattr, | 
 | 5565 | 	.removexattr	= generic_removexattr, | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5566 | }; | 
 | 5567 |  | 
| David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5568 | const struct nfs_rpc_ops nfs_v4_clientops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5569 | 	.version	= 4,			/* protocol version */ | 
 | 5570 | 	.dentry_ops	= &nfs4_dentry_operations, | 
 | 5571 | 	.dir_inode_ops	= &nfs4_dir_inode_operations, | 
| J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5572 | 	.file_inode_ops	= &nfs4_file_inode_operations, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | 	.getroot	= nfs4_proc_get_root, | 
 | 5574 | 	.getattr	= nfs4_proc_getattr, | 
 | 5575 | 	.setattr	= nfs4_proc_setattr, | 
| David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5576 | 	.lookupfh	= nfs4_proc_lookupfh, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5577 | 	.lookup		= nfs4_proc_lookup, | 
 | 5578 | 	.access		= nfs4_proc_access, | 
 | 5579 | 	.readlink	= nfs4_proc_readlink, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 | 	.create		= nfs4_proc_create, | 
 | 5581 | 	.remove		= nfs4_proc_remove, | 
 | 5582 | 	.unlink_setup	= nfs4_proc_unlink_setup, | 
 | 5583 | 	.unlink_done	= nfs4_proc_unlink_done, | 
 | 5584 | 	.rename		= nfs4_proc_rename, | 
| Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 5585 | 	.rename_setup	= nfs4_proc_rename_setup, | 
 | 5586 | 	.rename_done	= nfs4_proc_rename_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | 	.link		= nfs4_proc_link, | 
 | 5588 | 	.symlink	= nfs4_proc_symlink, | 
 | 5589 | 	.mkdir		= nfs4_proc_mkdir, | 
 | 5590 | 	.rmdir		= nfs4_proc_remove, | 
 | 5591 | 	.readdir	= nfs4_proc_readdir, | 
 | 5592 | 	.mknod		= nfs4_proc_mknod, | 
 | 5593 | 	.statfs		= nfs4_proc_statfs, | 
 | 5594 | 	.fsinfo		= nfs4_proc_fsinfo, | 
 | 5595 | 	.pathconf	= nfs4_proc_pathconf, | 
| David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5596 | 	.set_capabilities = nfs4_server_capabilities, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5597 | 	.decode_dirent	= nfs4_decode_dirent, | 
 | 5598 | 	.read_setup	= nfs4_proc_read_setup, | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5599 | 	.read_done	= nfs4_read_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5600 | 	.write_setup	= nfs4_proc_write_setup, | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5601 | 	.write_done	= nfs4_write_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5602 | 	.commit_setup	= nfs4_proc_commit_setup, | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5603 | 	.commit_done	= nfs4_commit_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5604 | 	.lock		= nfs4_proc_lock, | 
| J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5605 | 	.clear_acl_cache = nfs4_zap_acl_attr, | 
| Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5606 | 	.close_context  = nfs4_close_context, | 
| Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 5607 | 	.open_context	= nfs4_atomic_open, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5608 | }; | 
 | 5609 |  | 
| Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5610 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { | 
 | 5611 | 	.prefix	= XATTR_NAME_NFSV4_ACL, | 
 | 5612 | 	.list	= nfs4_xattr_list_nfs4_acl, | 
 | 5613 | 	.get	= nfs4_xattr_get_nfs4_acl, | 
 | 5614 | 	.set	= nfs4_xattr_set_nfs4_acl, | 
 | 5615 | }; | 
 | 5616 |  | 
 | 5617 | const struct xattr_handler *nfs4_xattr_handlers[] = { | 
 | 5618 | 	&nfs4_xattr_nfs4_acl_handler, | 
 | 5619 | 	NULL | 
 | 5620 | }; | 
 | 5621 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5622 | /* | 
 | 5623 |  * Local variables: | 
 | 5624 |  *  c-basic-offset: 8 | 
 | 5625 |  * End: | 
 | 5626 |  */ |