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> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 53 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 55 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 57 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 58 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 59 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 60 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 63 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 64 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 66 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 67 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 68 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 69 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 70 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 71 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | 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] | 73 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 74 | static int _nfs4_proc_lookup(struct rpc_clnt *client, struct inode *dir, |
| 75 | const struct qstr *name, struct nfs_fh *fhandle, |
| 76 | struct nfs_fattr *fattr); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 77 | 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] | 78 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 79 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 80 | struct nfs4_state *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 83 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 85 | if (err >= -1000) |
| 86 | return err; |
| 87 | switch (err) { |
| 88 | case -NFS4ERR_RESOURCE: |
| 89 | return -EREMOTEIO; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 90 | case -NFS4ERR_BADOWNER: |
| 91 | case -NFS4ERR_BADNAME: |
| 92 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 93 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 95 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 96 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 98 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* |
| 102 | * This is our standard bitmap for GETATTR requests. |
| 103 | */ |
| 104 | const u32 nfs4_fattr_bitmap[2] = { |
| 105 | FATTR4_WORD0_TYPE |
| 106 | | FATTR4_WORD0_CHANGE |
| 107 | | FATTR4_WORD0_SIZE |
| 108 | | FATTR4_WORD0_FSID |
| 109 | | FATTR4_WORD0_FILEID, |
| 110 | FATTR4_WORD1_MODE |
| 111 | | FATTR4_WORD1_NUMLINKS |
| 112 | | FATTR4_WORD1_OWNER |
| 113 | | FATTR4_WORD1_OWNER_GROUP |
| 114 | | FATTR4_WORD1_RAWDEV |
| 115 | | FATTR4_WORD1_SPACE_USED |
| 116 | | FATTR4_WORD1_TIME_ACCESS |
| 117 | | FATTR4_WORD1_TIME_METADATA |
| 118 | | FATTR4_WORD1_TIME_MODIFY |
| 119 | }; |
| 120 | |
| 121 | const u32 nfs4_statfs_bitmap[2] = { |
| 122 | FATTR4_WORD0_FILES_AVAIL |
| 123 | | FATTR4_WORD0_FILES_FREE |
| 124 | | FATTR4_WORD0_FILES_TOTAL, |
| 125 | FATTR4_WORD1_SPACE_AVAIL |
| 126 | | FATTR4_WORD1_SPACE_FREE |
| 127 | | FATTR4_WORD1_SPACE_TOTAL |
| 128 | }; |
| 129 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 130 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | FATTR4_WORD0_MAXLINK |
| 132 | | FATTR4_WORD0_MAXNAME, |
| 133 | 0 |
| 134 | }; |
| 135 | |
| 136 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 137 | | FATTR4_WORD0_MAXREAD |
| 138 | | FATTR4_WORD0_MAXWRITE |
| 139 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 140 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 141 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 144 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 145 | FATTR4_WORD0_TYPE |
| 146 | | FATTR4_WORD0_CHANGE |
| 147 | | FATTR4_WORD0_SIZE |
| 148 | | FATTR4_WORD0_FSID |
| 149 | | FATTR4_WORD0_FILEID |
| 150 | | FATTR4_WORD0_FS_LOCATIONS, |
| 151 | FATTR4_WORD1_MODE |
| 152 | | FATTR4_WORD1_NUMLINKS |
| 153 | | FATTR4_WORD1_OWNER |
| 154 | | FATTR4_WORD1_OWNER_GROUP |
| 155 | | FATTR4_WORD1_RAWDEV |
| 156 | | FATTR4_WORD1_SPACE_USED |
| 157 | | FATTR4_WORD1_TIME_ACCESS |
| 158 | | FATTR4_WORD1_TIME_METADATA |
| 159 | | FATTR4_WORD1_TIME_MODIFY |
| 160 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 161 | }; |
| 162 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 163 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | struct nfs4_readdir_arg *readdir) |
| 165 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 166 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | BUG_ON(readdir->count < 80); |
| 169 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 170 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | readdir->cookie = 0; |
| 176 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 177 | if (cookie == 2) |
| 178 | return; |
| 179 | |
| 180 | /* |
| 181 | * NFSv4 servers do not return entries for '.' and '..' |
| 182 | * Therefore, we fake these entries here. We let '.' |
| 183 | * have cookie 0 and '..' have cookie 1. Note that |
| 184 | * when talking to the server, we always send cookie 0 |
| 185 | * instead of 1 or 2. |
| 186 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 187 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | if (cookie == 0) { |
| 190 | *p++ = xdr_one; /* next */ |
| 191 | *p++ = xdr_zero; /* cookie, first word */ |
| 192 | *p++ = xdr_one; /* cookie, second word */ |
| 193 | *p++ = xdr_one; /* entry len */ |
| 194 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 195 | p++; |
| 196 | *p++ = xdr_one; /* bitmap length */ |
| 197 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 198 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 199 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | *p++ = xdr_one; /* next */ |
| 203 | *p++ = xdr_zero; /* cookie, first word */ |
| 204 | *p++ = xdr_two; /* cookie, second word */ |
| 205 | *p++ = xdr_two; /* entry len */ |
| 206 | memcpy(p, "..\0\0", 4); /* entry */ |
| 207 | p++; |
| 208 | *p++ = xdr_one; /* bitmap length */ |
| 209 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 210 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 211 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
| 213 | readdir->pgbase = (char *)p - (char *)start; |
| 214 | readdir->count -= readdir->pgbase; |
| 215 | kunmap_atomic(start, KM_USER0); |
| 216 | } |
| 217 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 218 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 219 | { |
| 220 | int res; |
| 221 | |
| 222 | might_sleep(); |
| 223 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 224 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 225 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 226 | return res; |
| 227 | } |
| 228 | |
| 229 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 230 | { |
| 231 | int res = 0; |
| 232 | |
| 233 | might_sleep(); |
| 234 | |
| 235 | if (*timeout <= 0) |
| 236 | *timeout = NFS4_POLL_RETRY_MIN; |
| 237 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 238 | *timeout = NFS4_POLL_RETRY_MAX; |
| 239 | schedule_timeout_killable(*timeout); |
| 240 | if (fatal_signal_pending(current)) |
| 241 | res = -ERESTARTSYS; |
| 242 | *timeout <<= 1; |
| 243 | return res; |
| 244 | } |
| 245 | |
| 246 | /* This is the error handling routine for processes that are allowed |
| 247 | * to sleep. |
| 248 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 249 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 250 | { |
| 251 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 252 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 253 | int ret = errorcode; |
| 254 | |
| 255 | exception->retry = 0; |
| 256 | switch(errorcode) { |
| 257 | case 0: |
| 258 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 259 | case -NFS4ERR_ADMIN_REVOKED: |
| 260 | case -NFS4ERR_BAD_STATEID: |
| 261 | case -NFS4ERR_OPENMODE: |
| 262 | if (state == NULL) |
| 263 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 264 | nfs4_schedule_stateid_recovery(server, state); |
| 265 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 266 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 267 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 268 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 269 | nfs4_schedule_lease_recovery(clp); |
| 270 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 271 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 272 | case -NFS4ERR_BADSESSION: |
| 273 | case -NFS4ERR_BADSLOT: |
| 274 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 275 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 276 | case -NFS4ERR_DEADSESSION: |
| 277 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 278 | case -NFS4ERR_SEQ_MISORDERED: |
| 279 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 280 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 281 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 282 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 283 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 284 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 285 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 286 | if (exception->timeout > HZ) { |
| 287 | /* We have retried a decent amount, time to |
| 288 | * fail |
| 289 | */ |
| 290 | ret = -EBUSY; |
| 291 | break; |
| 292 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 293 | case -NFS4ERR_GRACE: |
| 294 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 295 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 296 | ret = nfs4_delay(server->client, &exception->timeout); |
| 297 | if (ret != 0) |
| 298 | break; |
| 299 | case -NFS4ERR_OLD_STATEID: |
| 300 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 301 | break; |
| 302 | case -NFS4ERR_BADOWNER: |
| 303 | /* The following works around a Linux server bug! */ |
| 304 | case -NFS4ERR_BADNAME: |
| 305 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 306 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 307 | exception->retry = 1; |
| 308 | printk(KERN_WARNING "NFS: v4 server %s " |
| 309 | "does not accept raw " |
| 310 | "uid/gids. " |
| 311 | "Reenabling the idmapper.\n", |
| 312 | server->nfs_client->cl_hostname); |
| 313 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 314 | } |
| 315 | /* We failed to handle the error */ |
| 316 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 317 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 318 | ret = nfs4_wait_clnt_recover(clp); |
| 319 | if (ret == 0) |
| 320 | exception->retry = 1; |
| 321 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 325 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | spin_lock(&clp->cl_lock); |
| 328 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 329 | clp->cl_last_renewal = timestamp; |
| 330 | spin_unlock(&clp->cl_lock); |
| 331 | } |
| 332 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 333 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 334 | { |
| 335 | do_renew_lease(server->nfs_client, timestamp); |
| 336 | } |
| 337 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 338 | #if defined(CONFIG_NFS_V4_1) |
| 339 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 340 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 341 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 342 | * |
| 343 | * freeing a slot is trivially done by clearing its respective bit |
| 344 | * in the bitmap. |
| 345 | * If the freed slotid equals highest_used_slotid we want to update it |
| 346 | * so that the server would be able to size down the slot table if needed, |
| 347 | * otherwise we know that the highest_used_slotid is still in use. |
| 348 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 349 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 350 | * highest slotid in use. |
| 351 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 352 | * |
| 353 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 354 | */ |
| 355 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 356 | 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] | 357 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 358 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 359 | int slotid = free_slotid; |
| 360 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 361 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 362 | /* clear used bit in bitmap */ |
| 363 | __clear_bit(slotid, tbl->used_slots); |
| 364 | |
| 365 | /* update highest_used_slotid when it is freed */ |
| 366 | if (slotid == tbl->highest_used_slotid) { |
| 367 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 368 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 369 | tbl->highest_used_slotid = slotid; |
| 370 | else |
| 371 | tbl->highest_used_slotid = -1; |
| 372 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 373 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 374 | free_slotid, tbl->highest_used_slotid); |
| 375 | } |
| 376 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 377 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 378 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 379 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 380 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 381 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 382 | struct rpc_task *task; |
| 383 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 384 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 385 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 386 | if (task) |
| 387 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 388 | return; |
| 389 | } |
| 390 | |
| 391 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 392 | return; |
| 393 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 394 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 395 | complete(&ses->fc_slot_table.complete); |
| 396 | } |
| 397 | |
| 398 | /* |
| 399 | * Signal state manager thread if session back channel is drained |
| 400 | */ |
| 401 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 402 | { |
| 403 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 404 | ses->bc_slot_table.highest_used_slotid != -1) |
| 405 | return; |
| 406 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 407 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 410 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 411 | { |
| 412 | struct nfs4_slot_table *tbl; |
| 413 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 414 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 415 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 416 | /* just wake up the next guy waiting since |
| 417 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 418 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 419 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 420 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 421 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 422 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 423 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 424 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 425 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 426 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 427 | } |
| 428 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 429 | 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] | 430 | { |
| 431 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 432 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 433 | |
| 434 | /* |
| 435 | * sr_status remains 1 if an RPC level error occurred. The server |
| 436 | * may or may not have processed the sequence operation.. |
| 437 | * Proceed as if the server received and processed the sequence |
| 438 | * operation. |
| 439 | */ |
| 440 | if (res->sr_status == 1) |
| 441 | res->sr_status = NFS_OK; |
| 442 | |
| 443 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 444 | if (!res->sr_slot) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 445 | goto out; |
| 446 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 447 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 448 | switch (res->sr_status) { |
| 449 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 450 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 451 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 452 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 453 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 454 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 455 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 456 | if (res->sr_status_flags != 0) |
| 457 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 458 | break; |
| 459 | case -NFS4ERR_DELAY: |
| 460 | /* The server detected a resend of the RPC call and |
| 461 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 462 | * of RFC5661. |
| 463 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 464 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 465 | __func__, |
| 466 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 467 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 468 | goto out_retry; |
| 469 | default: |
| 470 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 471 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 472 | } |
| 473 | out: |
| 474 | /* The session may be reset by one of the error handlers. */ |
| 475 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 476 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 477 | return 1; |
| 478 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 479 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 480 | goto out; |
| 481 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 482 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 483 | } |
| 484 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 485 | static int nfs4_sequence_done(struct rpc_task *task, |
| 486 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 487 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 488 | if (res->sr_session == NULL) |
| 489 | return 1; |
| 490 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 491 | } |
| 492 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 493 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 494 | * nfs4_find_slot - efficiently look for a free slot |
| 495 | * |
| 496 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 497 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 498 | * and respectively set up the sequence operation args. |
| 499 | * 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] | 500 | * |
| 501 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 502 | */ |
| 503 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 504 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 505 | { |
| 506 | int slotid; |
| 507 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 508 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 509 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 510 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 511 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 512 | tbl->max_slots); |
| 513 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 514 | if (slotid >= tbl->max_slots) |
| 515 | goto out; |
| 516 | __set_bit(slotid, tbl->used_slots); |
| 517 | if (slotid > tbl->highest_used_slotid) |
| 518 | tbl->highest_used_slotid = slotid; |
| 519 | ret_id = slotid; |
| 520 | out: |
| 521 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 522 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 523 | return ret_id; |
| 524 | } |
| 525 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 526 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 527 | struct nfs4_sequence_args *args, |
| 528 | struct nfs4_sequence_res *res, |
| 529 | int cache_reply, |
| 530 | struct rpc_task *task) |
| 531 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 532 | struct nfs4_slot *slot; |
| 533 | struct nfs4_slot_table *tbl; |
| 534 | u8 slotid; |
| 535 | |
| 536 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 537 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 538 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 539 | return 0; |
| 540 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 541 | tbl = &session->fc_slot_table; |
| 542 | |
| 543 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 544 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 545 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 546 | /* |
| 547 | * The state manager will wait until the slot table is empty. |
| 548 | * Schedule the reset thread |
| 549 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 550 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 551 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 552 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 553 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 554 | } |
| 555 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 556 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 557 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 558 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 559 | spin_unlock(&tbl->slot_tbl_lock); |
| 560 | dprintk("%s enforce FIFO order\n", __func__); |
| 561 | return -EAGAIN; |
| 562 | } |
| 563 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 564 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 565 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 566 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 567 | spin_unlock(&tbl->slot_tbl_lock); |
| 568 | dprintk("<-- %s: no free slots\n", __func__); |
| 569 | return -EAGAIN; |
| 570 | } |
| 571 | spin_unlock(&tbl->slot_tbl_lock); |
| 572 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 573 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 574 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 575 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 576 | args->sa_slotid = slotid; |
| 577 | args->sa_cache_this = cache_reply; |
| 578 | |
| 579 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 580 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 581 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 582 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 583 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 584 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 585 | /* |
| 586 | * sr_status is only set in decode_sequence, and so will remain |
| 587 | * set to 1 if an rpc level failure occurs. |
| 588 | */ |
| 589 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 590 | return 0; |
| 591 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 592 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 593 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 594 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 595 | struct nfs4_sequence_args *args, |
| 596 | struct nfs4_sequence_res *res, |
| 597 | int cache_reply, |
| 598 | struct rpc_task *task) |
| 599 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 600 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 601 | int ret = 0; |
| 602 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 603 | if (session == NULL) { |
| 604 | args->sa_session = NULL; |
| 605 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 606 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 607 | } |
| 608 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 609 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 610 | __func__, session->clp, session, res->sr_slot ? |
| 611 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 612 | |
| 613 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 614 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 615 | out: |
| 616 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 617 | return ret; |
| 618 | } |
| 619 | |
| 620 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 621 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 622 | struct nfs4_sequence_args *seq_args; |
| 623 | struct nfs4_sequence_res *seq_res; |
| 624 | int cache_reply; |
| 625 | }; |
| 626 | |
| 627 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 628 | { |
| 629 | struct nfs41_call_sync_data *data = calldata; |
| 630 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 631 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 632 | |
| 633 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 634 | data->seq_res, data->cache_reply, task)) |
| 635 | return; |
| 636 | rpc_call_start(task); |
| 637 | } |
| 638 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 639 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 640 | { |
| 641 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 642 | nfs41_call_sync_prepare(task, calldata); |
| 643 | } |
| 644 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 645 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 646 | { |
| 647 | struct nfs41_call_sync_data *data = calldata; |
| 648 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 649 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 650 | } |
| 651 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 652 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 653 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 654 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 655 | }; |
| 656 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 657 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 658 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 659 | .rpc_call_done = nfs41_call_sync_done, |
| 660 | }; |
| 661 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 662 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 663 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 664 | struct rpc_message *msg, |
| 665 | struct nfs4_sequence_args *args, |
| 666 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 667 | int cache_reply, |
| 668 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 669 | { |
| 670 | int ret; |
| 671 | struct rpc_task *task; |
| 672 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 673 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 674 | .seq_args = args, |
| 675 | .seq_res = res, |
| 676 | .cache_reply = cache_reply, |
| 677 | }; |
| 678 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 679 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 680 | .rpc_message = msg, |
| 681 | .callback_ops = &nfs41_call_sync_ops, |
| 682 | .callback_data = &data |
| 683 | }; |
| 684 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 685 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 686 | if (privileged) |
| 687 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 688 | task = rpc_run_task(&task_setup); |
| 689 | if (IS_ERR(task)) |
| 690 | ret = PTR_ERR(task); |
| 691 | else { |
| 692 | ret = task->tk_status; |
| 693 | rpc_put_task(task); |
| 694 | } |
| 695 | return ret; |
| 696 | } |
| 697 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 698 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 699 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 700 | struct rpc_message *msg, |
| 701 | struct nfs4_sequence_args *args, |
| 702 | struct nfs4_sequence_res *res, |
| 703 | int cache_reply) |
| 704 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 705 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 706 | } |
| 707 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 708 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 709 | static int nfs4_sequence_done(struct rpc_task *task, |
| 710 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 711 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 712 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 713 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 714 | #endif /* CONFIG_NFS_V4_1 */ |
| 715 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 716 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 717 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 718 | struct rpc_message *msg, |
| 719 | struct nfs4_sequence_args *args, |
| 720 | struct nfs4_sequence_res *res, |
| 721 | int cache_reply) |
| 722 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 723 | args->sa_session = res->sr_session = NULL; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 724 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 725 | } |
| 726 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 727 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 728 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 729 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 730 | struct rpc_message *msg, |
| 731 | struct nfs4_sequence_args *args, |
| 732 | struct nfs4_sequence_res *res, |
| 733 | int cache_reply) |
| 734 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 735 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 736 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 737 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 738 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 739 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 741 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 743 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 744 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 745 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 746 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 747 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 748 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 751 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 752 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 753 | struct nfs_openargs o_arg; |
| 754 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 755 | struct nfs_open_confirmargs c_arg; |
| 756 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 757 | struct nfs_fattr f_attr; |
| 758 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 759 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 760 | struct dentry *dir; |
| 761 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 762 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 763 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 764 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 765 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 766 | int rpc_status; |
| 767 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 768 | }; |
| 769 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 770 | |
| 771 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 772 | { |
| 773 | p->o_res.f_attr = &p->f_attr; |
| 774 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 775 | p->o_res.seqid = p->o_arg.seqid; |
| 776 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 777 | p->o_res.server = p->o_arg.server; |
| 778 | nfs_fattr_init(&p->f_attr); |
| 779 | nfs_fattr_init(&p->dir_attr); |
| 780 | } |
| 781 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 782 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 783 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 784 | const struct iattr *attrs, |
| 785 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 786 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 787 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 788 | struct inode *dir = parent->d_inode; |
| 789 | struct nfs_server *server = NFS_SERVER(dir); |
| 790 | struct nfs4_opendata *p; |
| 791 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 792 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 793 | if (p == NULL) |
| 794 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 795 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 796 | if (p->o_arg.seqid == NULL) |
| 797 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 798 | path_get(path); |
| 799 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 800 | p->dir = parent; |
| 801 | p->owner = sp; |
| 802 | atomic_inc(&sp->so_count); |
| 803 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 804 | p->o_arg.open_flags = flags; |
| 805 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 806 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 807 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 808 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 809 | p->o_arg.server = server; |
| 810 | p->o_arg.bitmask = server->attr_bitmask; |
| 811 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 812 | if (flags & O_CREAT) { |
| 813 | u32 *s; |
| 814 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 815 | p->o_arg.u.attrs = &p->attrs; |
| 816 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 817 | s = (u32 *) p->o_arg.u.verifier.data; |
| 818 | s[0] = jiffies; |
| 819 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 820 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 821 | p->c_arg.fh = &p->o_res.fh; |
| 822 | p->c_arg.stateid = &p->o_res.stateid; |
| 823 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 824 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 825 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 826 | return p; |
| 827 | err_free: |
| 828 | kfree(p); |
| 829 | err: |
| 830 | dput(parent); |
| 831 | return NULL; |
| 832 | } |
| 833 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 834 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 835 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 836 | struct nfs4_opendata *p = container_of(kref, |
| 837 | struct nfs4_opendata, kref); |
| 838 | |
| 839 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 840 | if (p->state != NULL) |
| 841 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 842 | nfs4_put_state_owner(p->owner); |
| 843 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 844 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 845 | kfree(p); |
| 846 | } |
| 847 | |
| 848 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 849 | { |
| 850 | if (p != NULL) |
| 851 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 852 | } |
| 853 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 854 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 855 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 856 | int ret; |
| 857 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 858 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 859 | return ret; |
| 860 | } |
| 861 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 862 | 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] | 863 | { |
| 864 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 865 | |
| 866 | if (open_mode & O_EXCL) |
| 867 | goto out; |
| 868 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 869 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 870 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 871 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 872 | break; |
| 873 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 874 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 875 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 876 | break; |
| 877 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 878 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 879 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 880 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 881 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 882 | return ret; |
| 883 | } |
| 884 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 885 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 886 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 887 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 888 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 889 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 890 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 891 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 892 | return 1; |
| 893 | } |
| 894 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 895 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 896 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 897 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 898 | case FMODE_WRITE: |
| 899 | state->n_wronly++; |
| 900 | break; |
| 901 | case FMODE_READ: |
| 902 | state->n_rdonly++; |
| 903 | break; |
| 904 | case FMODE_READ|FMODE_WRITE: |
| 905 | state->n_rdwr++; |
| 906 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 907 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 908 | } |
| 909 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 910 | 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] | 911 | { |
| 912 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 913 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 914 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 915 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 916 | case FMODE_READ: |
| 917 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 918 | break; |
| 919 | case FMODE_WRITE: |
| 920 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 921 | break; |
| 922 | case FMODE_READ|FMODE_WRITE: |
| 923 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 924 | } |
| 925 | } |
| 926 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 927 | 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] | 928 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 929 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 930 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 931 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 932 | } |
| 933 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 934 | 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] | 935 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 936 | /* |
| 937 | * Protect the call to nfs4_state_set_mode_locked and |
| 938 | * serialise the stateid update |
| 939 | */ |
| 940 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 941 | if (deleg_stateid != NULL) { |
| 942 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 943 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 944 | } |
| 945 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 946 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 947 | write_sequnlock(&state->seqlock); |
| 948 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 949 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 950 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | } |
| 952 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 953 | 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] | 954 | { |
| 955 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 956 | struct nfs_delegation *deleg_cur; |
| 957 | int ret = 0; |
| 958 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 959 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 960 | |
| 961 | rcu_read_lock(); |
| 962 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 963 | if (deleg_cur == NULL) |
| 964 | goto no_delegation; |
| 965 | |
| 966 | spin_lock(&deleg_cur->lock); |
| 967 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 968 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 969 | goto no_delegation_unlock; |
| 970 | |
| 971 | if (delegation == NULL) |
| 972 | delegation = &deleg_cur->stateid; |
| 973 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 974 | goto no_delegation_unlock; |
| 975 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 976 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 977 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 978 | ret = 1; |
| 979 | no_delegation_unlock: |
| 980 | spin_unlock(&deleg_cur->lock); |
| 981 | no_delegation: |
| 982 | rcu_read_unlock(); |
| 983 | |
| 984 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 985 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 986 | ret = 1; |
| 987 | } |
| 988 | |
| 989 | return ret; |
| 990 | } |
| 991 | |
| 992 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 993 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 994 | { |
| 995 | struct nfs_delegation *delegation; |
| 996 | |
| 997 | rcu_read_lock(); |
| 998 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 999 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1000 | rcu_read_unlock(); |
| 1001 | return; |
| 1002 | } |
| 1003 | rcu_read_unlock(); |
| 1004 | nfs_inode_return_delegation(inode); |
| 1005 | } |
| 1006 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1007 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1008 | { |
| 1009 | struct nfs4_state *state = opendata->state; |
| 1010 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1011 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1012 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 1013 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1014 | nfs4_stateid stateid; |
| 1015 | int ret = -EAGAIN; |
| 1016 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1017 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1018 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1019 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1020 | if (can_open_cached(state, fmode, open_mode)) { |
| 1021 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1022 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1023 | goto out_return_state; |
| 1024 | } |
| 1025 | spin_unlock(&state->owner->so_lock); |
| 1026 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1027 | rcu_read_lock(); |
| 1028 | delegation = rcu_dereference(nfsi->delegation); |
| 1029 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1030 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1031 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1032 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1033 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1034 | /* Save the delegation */ |
| 1035 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1036 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1037 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1038 | if (ret != 0) |
| 1039 | goto out; |
| 1040 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1041 | |
| 1042 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1043 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1044 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1045 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1046 | out: |
| 1047 | return ERR_PTR(ret); |
| 1048 | out_return_state: |
| 1049 | atomic_inc(&state->count); |
| 1050 | return state; |
| 1051 | } |
| 1052 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1053 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1054 | { |
| 1055 | struct inode *inode; |
| 1056 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1057 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1058 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1059 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1060 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1061 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1062 | goto out; |
| 1063 | } |
| 1064 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1065 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1066 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1067 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1068 | 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] | 1069 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1070 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1071 | goto err; |
| 1072 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1073 | state = nfs4_get_open_state(inode, data->owner); |
| 1074 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1075 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1076 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1077 | int delegation_flags = 0; |
| 1078 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1079 | rcu_read_lock(); |
| 1080 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1081 | if (delegation) |
| 1082 | delegation_flags = delegation->flags; |
| 1083 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1084 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1085 | nfs_inode_set_delegation(state->inode, |
| 1086 | data->owner->so_cred, |
| 1087 | &data->o_res); |
| 1088 | else |
| 1089 | nfs_inode_reclaim_delegation(state->inode, |
| 1090 | data->owner->so_cred, |
| 1091 | &data->o_res); |
| 1092 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1093 | |
| 1094 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1095 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1096 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1097 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1098 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1099 | err_put_inode: |
| 1100 | iput(inode); |
| 1101 | err: |
| 1102 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1103 | } |
| 1104 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1105 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1106 | { |
| 1107 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1108 | struct nfs_open_context *ctx; |
| 1109 | |
| 1110 | spin_lock(&state->inode->i_lock); |
| 1111 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1112 | if (ctx->state != state) |
| 1113 | continue; |
| 1114 | get_nfs_open_context(ctx); |
| 1115 | spin_unlock(&state->inode->i_lock); |
| 1116 | return ctx; |
| 1117 | } |
| 1118 | spin_unlock(&state->inode->i_lock); |
| 1119 | return ERR_PTR(-ENOENT); |
| 1120 | } |
| 1121 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1122 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1123 | { |
| 1124 | struct nfs4_opendata *opendata; |
| 1125 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1126 | 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] | 1127 | if (opendata == NULL) |
| 1128 | return ERR_PTR(-ENOMEM); |
| 1129 | opendata->state = state; |
| 1130 | atomic_inc(&state->count); |
| 1131 | return opendata; |
| 1132 | } |
| 1133 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1134 | 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] | 1135 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1136 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1137 | int ret; |
| 1138 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1139 | opendata->o_arg.open_flags = 0; |
| 1140 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1141 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1142 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1143 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1144 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1145 | if (ret != 0) |
| 1146 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1147 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1148 | if (IS_ERR(newstate)) |
| 1149 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1150 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1151 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1152 | return 0; |
| 1153 | } |
| 1154 | |
| 1155 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1156 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1157 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1158 | int ret; |
| 1159 | |
| 1160 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1161 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1162 | smp_rmb(); |
| 1163 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1164 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1165 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1166 | if (ret != 0) |
| 1167 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1168 | if (newstate != state) |
| 1169 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1170 | } |
| 1171 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1172 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1173 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1174 | if (ret != 0) |
| 1175 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1176 | if (newstate != state) |
| 1177 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1178 | } |
| 1179 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1180 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1181 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1182 | if (ret != 0) |
| 1183 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1184 | if (newstate != state) |
| 1185 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1186 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1187 | /* |
| 1188 | * We may have performed cached opens for all three recoveries. |
| 1189 | * Check if we need to update the current stateid. |
| 1190 | */ |
| 1191 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1192 | 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] | 1193 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1194 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1195 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1196 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1197 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1198 | return 0; |
| 1199 | } |
| 1200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | /* |
| 1202 | * OPEN_RECLAIM: |
| 1203 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1205 | 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] | 1206 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1207 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1208 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1209 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | int status; |
| 1211 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1212 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1213 | if (IS_ERR(opendata)) |
| 1214 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1215 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1216 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1217 | rcu_read_lock(); |
| 1218 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1219 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1220 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1221 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1222 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1223 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1224 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | return status; |
| 1226 | } |
| 1227 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1228 | 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] | 1229 | { |
| 1230 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1231 | struct nfs4_exception exception = { }; |
| 1232 | int err; |
| 1233 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1234 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1235 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1236 | break; |
| 1237 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | } while (exception.retry); |
| 1239 | return err; |
| 1240 | } |
| 1241 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1242 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1243 | { |
| 1244 | struct nfs_open_context *ctx; |
| 1245 | int ret; |
| 1246 | |
| 1247 | ctx = nfs4_state_find_open_context(state); |
| 1248 | if (IS_ERR(ctx)) |
| 1249 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1250 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1251 | put_nfs_open_context(ctx); |
| 1252 | return ret; |
| 1253 | } |
| 1254 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1255 | 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] | 1256 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1257 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1258 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1260 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1261 | if (IS_ERR(opendata)) |
| 1262 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1263 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1264 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1265 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1266 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1267 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1268 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1271 | 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] | 1272 | { |
| 1273 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1274 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | int err; |
| 1276 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1277 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | switch (err) { |
| 1279 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1280 | case -ENOENT: |
| 1281 | case -ESTALE: |
| 1282 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1283 | case -NFS4ERR_BADSESSION: |
| 1284 | case -NFS4ERR_BADSLOT: |
| 1285 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1286 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1287 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1288 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1289 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | case -NFS4ERR_STALE_CLIENTID: |
| 1291 | case -NFS4ERR_STALE_STATEID: |
| 1292 | case -NFS4ERR_EXPIRED: |
| 1293 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1294 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1295 | goto out; |
| 1296 | case -ERESTARTSYS: |
| 1297 | /* |
| 1298 | * The show must go on: exit, but mark the |
| 1299 | * stateid as needing recovery. |
| 1300 | */ |
| 1301 | case -NFS4ERR_ADMIN_REVOKED: |
| 1302 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1303 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1304 | case -EKEYEXPIRED: |
| 1305 | /* |
| 1306 | * User RPCSEC_GSS context has expired. |
| 1307 | * We cannot recover this stateid now, so |
| 1308 | * skip it and allow recovery thread to |
| 1309 | * proceed. |
| 1310 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1311 | case -ENOMEM: |
| 1312 | err = 0; |
| 1313 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | } |
| 1315 | err = nfs4_handle_exception(server, err, &exception); |
| 1316 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1317 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | return err; |
| 1319 | } |
| 1320 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1321 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1322 | { |
| 1323 | struct nfs4_opendata *data = calldata; |
| 1324 | |
| 1325 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1326 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1327 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1328 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1329 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1330 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1331 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1332 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | static void nfs4_open_confirm_release(void *calldata) |
| 1336 | { |
| 1337 | struct nfs4_opendata *data = calldata; |
| 1338 | struct nfs4_state *state = NULL; |
| 1339 | |
| 1340 | /* If this request hasn't been cancelled, do nothing */ |
| 1341 | if (data->cancelled == 0) |
| 1342 | goto out_free; |
| 1343 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1344 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1345 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1346 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1347 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1348 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1349 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1350 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1354 | .rpc_call_done = nfs4_open_confirm_done, |
| 1355 | .rpc_release = nfs4_open_confirm_release, |
| 1356 | }; |
| 1357 | |
| 1358 | /* |
| 1359 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1360 | */ |
| 1361 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1362 | { |
| 1363 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1364 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1365 | struct rpc_message msg = { |
| 1366 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1367 | .rpc_argp = &data->c_arg, |
| 1368 | .rpc_resp = &data->c_res, |
| 1369 | .rpc_cred = data->owner->so_cred, |
| 1370 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1371 | struct rpc_task_setup task_setup_data = { |
| 1372 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1373 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1374 | .callback_ops = &nfs4_open_confirm_ops, |
| 1375 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1376 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1377 | .flags = RPC_TASK_ASYNC, |
| 1378 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | int status; |
| 1380 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1381 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1382 | data->rpc_done = 0; |
| 1383 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1384 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1385 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1386 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1387 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1388 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1389 | if (status != 0) { |
| 1390 | data->cancelled = 1; |
| 1391 | smp_wmb(); |
| 1392 | } else |
| 1393 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1394 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | return status; |
| 1396 | } |
| 1397 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1398 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1400 | struct nfs4_opendata *data = calldata; |
| 1401 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1402 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1403 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1404 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1405 | /* |
| 1406 | * Check if we still need to send an OPEN call, or if we can use |
| 1407 | * a delegation instead. |
| 1408 | */ |
| 1409 | if (data->state != NULL) { |
| 1410 | struct nfs_delegation *delegation; |
| 1411 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1412 | 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] | 1413 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1414 | rcu_read_lock(); |
| 1415 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1416 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1417 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1418 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1419 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1420 | } |
| 1421 | rcu_read_unlock(); |
| 1422 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1423 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1424 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1425 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1426 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1427 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1428 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1429 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1430 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1431 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1432 | &data->o_arg.seq_args, |
| 1433 | &data->o_res.seq_res, 1, task)) |
| 1434 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1435 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1436 | return; |
| 1437 | out_no_action: |
| 1438 | task->tk_action = NULL; |
| 1439 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1440 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1442 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1443 | { |
| 1444 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1445 | nfs4_open_prepare(task, calldata); |
| 1446 | } |
| 1447 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1448 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1449 | { |
| 1450 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1452 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1453 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1454 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1455 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1456 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1457 | if (task->tk_status == 0) { |
| 1458 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1459 | case S_IFREG: |
| 1460 | break; |
| 1461 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1462 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1463 | break; |
| 1464 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1465 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1466 | break; |
| 1467 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1468 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1469 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1470 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1471 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1472 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1473 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1474 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1475 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1476 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1477 | static void nfs4_open_release(void *calldata) |
| 1478 | { |
| 1479 | struct nfs4_opendata *data = calldata; |
| 1480 | struct nfs4_state *state = NULL; |
| 1481 | |
| 1482 | /* If this request hasn't been cancelled, do nothing */ |
| 1483 | if (data->cancelled == 0) |
| 1484 | goto out_free; |
| 1485 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1486 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1487 | goto out_free; |
| 1488 | /* In case we need an open_confirm, no cleanup! */ |
| 1489 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1490 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1491 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1492 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1493 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1494 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1495 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1499 | .rpc_call_prepare = nfs4_open_prepare, |
| 1500 | .rpc_call_done = nfs4_open_done, |
| 1501 | .rpc_release = nfs4_open_release, |
| 1502 | }; |
| 1503 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1504 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1505 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1506 | .rpc_call_done = nfs4_open_done, |
| 1507 | .rpc_release = nfs4_open_release, |
| 1508 | }; |
| 1509 | |
| 1510 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1511 | { |
| 1512 | struct inode *dir = data->dir->d_inode; |
| 1513 | struct nfs_server *server = NFS_SERVER(dir); |
| 1514 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1515 | struct nfs_openres *o_res = &data->o_res; |
| 1516 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1517 | struct rpc_message msg = { |
| 1518 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1519 | .rpc_argp = o_arg, |
| 1520 | .rpc_resp = o_res, |
| 1521 | .rpc_cred = data->owner->so_cred, |
| 1522 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1523 | struct rpc_task_setup task_setup_data = { |
| 1524 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1525 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1526 | .callback_ops = &nfs4_open_ops, |
| 1527 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1528 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1529 | .flags = RPC_TASK_ASYNC, |
| 1530 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1531 | int status; |
| 1532 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1533 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1534 | data->rpc_done = 0; |
| 1535 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1536 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1537 | if (isrecover) |
| 1538 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1539 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1540 | if (IS_ERR(task)) |
| 1541 | return PTR_ERR(task); |
| 1542 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1543 | if (status != 0) { |
| 1544 | data->cancelled = 1; |
| 1545 | smp_wmb(); |
| 1546 | } else |
| 1547 | status = data->rpc_status; |
| 1548 | rpc_put_task(task); |
| 1549 | |
| 1550 | return status; |
| 1551 | } |
| 1552 | |
| 1553 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1554 | { |
| 1555 | struct inode *dir = data->dir->d_inode; |
| 1556 | struct nfs_openres *o_res = &data->o_res; |
| 1557 | int status; |
| 1558 | |
| 1559 | status = nfs4_run_open_task(data, 1); |
| 1560 | if (status != 0 || !data->rpc_done) |
| 1561 | return status; |
| 1562 | |
| 1563 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1564 | |
| 1565 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1566 | status = _nfs4_proc_open_confirm(data); |
| 1567 | if (status != 0) |
| 1568 | return status; |
| 1569 | } |
| 1570 | |
| 1571 | return status; |
| 1572 | } |
| 1573 | |
| 1574 | /* |
| 1575 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1576 | */ |
| 1577 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1578 | { |
| 1579 | struct inode *dir = data->dir->d_inode; |
| 1580 | struct nfs_server *server = NFS_SERVER(dir); |
| 1581 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1582 | struct nfs_openres *o_res = &data->o_res; |
| 1583 | int status; |
| 1584 | |
| 1585 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1586 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1587 | return status; |
| 1588 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1589 | if (o_arg->open_flags & O_CREAT) { |
| 1590 | update_changeattr(dir, &o_res->cinfo); |
| 1591 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1592 | } else |
| 1593 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1594 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1595 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1597 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1599 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | } |
| 1601 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1602 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1603 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1606 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1607 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1608 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1609 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1610 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1611 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1612 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1613 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1614 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1615 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1616 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1617 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1618 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1619 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1620 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1621 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1622 | } |
| 1623 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1624 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1625 | { |
| 1626 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1627 | } |
| 1628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | /* |
| 1630 | * OPEN_EXPIRED: |
| 1631 | * reclaim state on the server after a network partition. |
| 1632 | * Assumes caller holds the appropriate lock |
| 1633 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1634 | 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] | 1635 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1636 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1637 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1639 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1640 | if (IS_ERR(opendata)) |
| 1641 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1642 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1643 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1644 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1645 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1646 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1649 | 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] | 1650 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1651 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1652 | struct nfs4_exception exception = { }; |
| 1653 | int err; |
| 1654 | |
| 1655 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1656 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1657 | switch (err) { |
| 1658 | default: |
| 1659 | goto out; |
| 1660 | case -NFS4ERR_GRACE: |
| 1661 | case -NFS4ERR_DELAY: |
| 1662 | nfs4_handle_exception(server, err, &exception); |
| 1663 | err = 0; |
| 1664 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1665 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1666 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1667 | return err; |
| 1668 | } |
| 1669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1671 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1673 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1675 | ctx = nfs4_state_find_open_context(state); |
| 1676 | if (IS_ERR(ctx)) |
| 1677 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1678 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1679 | put_nfs_open_context(ctx); |
| 1680 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1684 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1685 | * fields corresponding to attributes that were used to store the verifier. |
| 1686 | * Make sure we clobber those fields in the later setattr call |
| 1687 | */ |
| 1688 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1689 | { |
| 1690 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1691 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1692 | sattr->ia_valid |= ATTR_ATIME; |
| 1693 | |
| 1694 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1695 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1696 | sattr->ia_valid |= ATTR_MTIME; |
| 1697 | } |
| 1698 | |
| 1699 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1700 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1702 | 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] | 1703 | { |
| 1704 | struct nfs4_state_owner *sp; |
| 1705 | struct nfs4_state *state = NULL; |
| 1706 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1707 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1708 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | |
| 1710 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | status = -ENOMEM; |
| 1712 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1713 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1714 | goto out_err; |
| 1715 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1716 | status = nfs4_recover_expired_lease(server); |
| 1717 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1718 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1719 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1720 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1721 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1722 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1723 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1724 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1726 | if (path->dentry->d_inode != NULL) |
| 1727 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1728 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1729 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1731 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1733 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1734 | status = PTR_ERR(state); |
| 1735 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1736 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1737 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1738 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1739 | |
| 1740 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1741 | nfs4_exclusive_attrset(opendata, sattr); |
| 1742 | |
| 1743 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1744 | status = nfs4_do_setattr(state->inode, cred, |
| 1745 | opendata->o_res.f_attr, sattr, |
| 1746 | state); |
| 1747 | if (status == 0) |
| 1748 | nfs_setattr_update_inode(state->inode, sattr); |
| 1749 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1750 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1751 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | *res = state; |
| 1754 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1755 | err_opendata_put: |
| 1756 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1757 | err_put_state_owner: |
| 1758 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | *res = NULL; |
| 1761 | return status; |
| 1762 | } |
| 1763 | |
| 1764 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1765 | 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] | 1766 | { |
| 1767 | struct nfs4_exception exception = { }; |
| 1768 | struct nfs4_state *res; |
| 1769 | int status; |
| 1770 | |
| 1771 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1772 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | if (status == 0) |
| 1774 | break; |
| 1775 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1776 | * book-keeping w.r.t. state-changing operations |
| 1777 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1778 | * It is actually a sign of a bug on the client or on the server. |
| 1779 | * |
| 1780 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1781 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | * have unhashed the old state_owner for us, and that we can |
| 1783 | * therefore safely retry using a new one. We should still warn |
| 1784 | * the user though... |
| 1785 | */ |
| 1786 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1787 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1788 | " returned a bad sequence-id error!\n", |
| 1789 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | exception.retry = 1; |
| 1791 | continue; |
| 1792 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1793 | /* |
| 1794 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1795 | * state before it received the OPEN_CONFIRM. |
| 1796 | * Recover by retrying the request as per the discussion |
| 1797 | * on Page 181 of RFC3530. |
| 1798 | */ |
| 1799 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1800 | exception.retry = 1; |
| 1801 | continue; |
| 1802 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1803 | if (status == -EAGAIN) { |
| 1804 | /* We must have found a delegation */ |
| 1805 | exception.retry = 1; |
| 1806 | continue; |
| 1807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1809 | status, &exception)); |
| 1810 | } while (exception.retry); |
| 1811 | return res; |
| 1812 | } |
| 1813 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1814 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1815 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1816 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1818 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1820 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | .iap = sattr, |
| 1822 | .server = server, |
| 1823 | .bitmask = server->attr_bitmask, |
| 1824 | }; |
| 1825 | struct nfs_setattrres res = { |
| 1826 | .fattr = fattr, |
| 1827 | .server = server, |
| 1828 | }; |
| 1829 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1830 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1831 | .rpc_argp = &arg, |
| 1832 | .rpc_resp = &res, |
| 1833 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1835 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1836 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1838 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1840 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1841 | /* Use that stateid */ |
| 1842 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1843 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1844 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1846 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1847 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1848 | if (status == 0 && state != NULL) |
| 1849 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1850 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1853 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1854 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1855 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1857 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | struct nfs4_exception exception = { }; |
| 1859 | int err; |
| 1860 | do { |
| 1861 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1862 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | &exception); |
| 1864 | } while (exception.retry); |
| 1865 | return err; |
| 1866 | } |
| 1867 | |
| 1868 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1869 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | struct inode *inode; |
| 1871 | struct nfs4_state *state; |
| 1872 | struct nfs_closeargs arg; |
| 1873 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1874 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1875 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1876 | bool roc; |
| 1877 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | }; |
| 1879 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1880 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1881 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1882 | struct nfs4_closedata *calldata = data; |
| 1883 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1884 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1885 | if (calldata->roc) |
| 1886 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1887 | nfs4_put_open_state(calldata->state); |
| 1888 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1889 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1890 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1891 | kfree(calldata); |
| 1892 | } |
| 1893 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1894 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1895 | fmode_t fmode) |
| 1896 | { |
| 1897 | spin_lock(&state->owner->so_lock); |
| 1898 | if (!(fmode & FMODE_READ)) |
| 1899 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1900 | if (!(fmode & FMODE_WRITE)) |
| 1901 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1902 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1903 | spin_unlock(&state->owner->so_lock); |
| 1904 | } |
| 1905 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1906 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1908 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1911 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1912 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1913 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | /* hmm. we are done with the inode, and in the process of freeing |
| 1915 | * the state_owner. we keep this around to process errors |
| 1916 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | switch (task->tk_status) { |
| 1918 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1919 | if (calldata->roc) |
| 1920 | pnfs_roc_set_barrier(state->inode, |
| 1921 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1922 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1923 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1924 | nfs4_close_clear_stateid_flags(state, |
| 1925 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | break; |
| 1927 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1928 | case -NFS4ERR_OLD_STATEID: |
| 1929 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1931 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1932 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1934 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1935 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1937 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1938 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1941 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1943 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1944 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1945 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1946 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1947 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1948 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1949 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1950 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1951 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1952 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1953 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1954 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1955 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1956 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1957 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1958 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1959 | } |
| 1960 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1961 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1962 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1963 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1964 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1965 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1966 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1967 | |
| 1968 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1969 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1970 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1971 | return; |
| 1972 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1973 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1974 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1975 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1976 | if (calldata->roc && |
| 1977 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 1978 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 1979 | task, NULL); |
| 1980 | return; |
| 1981 | } |
| 1982 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1983 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1984 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1985 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1986 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1987 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1988 | 1, task)) |
| 1989 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1990 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1993 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1994 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1995 | .rpc_call_done = nfs4_close_done, |
| 1996 | .rpc_release = nfs4_free_closedata, |
| 1997 | }; |
| 1998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | /* |
| 2000 | * It is possible for data to be read/written from a mem-mapped file |
| 2001 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2002 | * This means that we can't safely call nfsv4 close on a file until |
| 2003 | * the inode is cleared. This in turn means that we are not good |
| 2004 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2005 | * share state even when we are done with one of the three share |
| 2006 | * stateid's in the inode. |
| 2007 | * |
| 2008 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2009 | */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2010 | 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] | 2011 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2012 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2014 | struct nfs4_state_owner *sp = state->owner; |
| 2015 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2016 | struct rpc_message msg = { |
| 2017 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2018 | .rpc_cred = state->owner->so_cred, |
| 2019 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2020 | struct rpc_task_setup task_setup_data = { |
| 2021 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2022 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2023 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2024 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2025 | .flags = RPC_TASK_ASYNC, |
| 2026 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2027 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2029 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2031 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2032 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2034 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2035 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2037 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2038 | if (calldata->arg.seqid == NULL) |
| 2039 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2040 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2041 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2042 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2043 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2044 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2045 | calldata->roc = roc; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2046 | path_get(path); |
| 2047 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2048 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2049 | msg.rpc_argp = &calldata->arg; |
| 2050 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2051 | task_setup_data.callback_data = calldata; |
| 2052 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2053 | if (IS_ERR(task)) |
| 2054 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2055 | status = 0; |
| 2056 | if (wait) |
| 2057 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2058 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2059 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2060 | out_free_calldata: |
| 2061 | kfree(calldata); |
| 2062 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2063 | if (roc) |
| 2064 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2065 | nfs4_put_open_state(state); |
| 2066 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2067 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2070 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2071 | 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] | 2072 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | struct nfs4_state *state; |
| 2074 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2075 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2076 | 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] | 2077 | if (IS_ERR(state)) |
| 2078 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2079 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2080 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2083 | 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] | 2084 | { |
| 2085 | if (ctx->state == NULL) |
| 2086 | return; |
| 2087 | if (is_sync) |
| 2088 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2089 | else |
| 2090 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2091 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | |
| 2093 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2094 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2095 | struct nfs4_server_caps_arg args = { |
| 2096 | .fhandle = fhandle, |
| 2097 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | struct nfs4_server_caps_res res = {}; |
| 2099 | struct rpc_message msg = { |
| 2100 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2101 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | .rpc_resp = &res, |
| 2103 | }; |
| 2104 | int status; |
| 2105 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2106 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | if (status == 0) { |
| 2108 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2109 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2110 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2111 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2112 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2113 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2115 | server->caps |= NFS_CAP_ACLS; |
| 2116 | if (res.has_links != 0) |
| 2117 | server->caps |= NFS_CAP_HARDLINKS; |
| 2118 | if (res.has_symlinks != 0) |
| 2119 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2120 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2121 | server->caps |= NFS_CAP_FILEID; |
| 2122 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2123 | server->caps |= NFS_CAP_MODE; |
| 2124 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2125 | server->caps |= NFS_CAP_NLINK; |
| 2126 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2127 | server->caps |= NFS_CAP_OWNER; |
| 2128 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2129 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2130 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2131 | server->caps |= NFS_CAP_ATIME; |
| 2132 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2133 | server->caps |= NFS_CAP_CTIME; |
| 2134 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2135 | server->caps |= NFS_CAP_MTIME; |
| 2136 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2137 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2138 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2139 | 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] | 2140 | server->acl_bitmask = res.acl_bitmask; |
| 2141 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | return status; |
| 2144 | } |
| 2145 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2146 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | { |
| 2148 | struct nfs4_exception exception = { }; |
| 2149 | int err; |
| 2150 | do { |
| 2151 | err = nfs4_handle_exception(server, |
| 2152 | _nfs4_server_capabilities(server, fhandle), |
| 2153 | &exception); |
| 2154 | } while (exception.retry); |
| 2155 | return err; |
| 2156 | } |
| 2157 | |
| 2158 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2159 | struct nfs_fsinfo *info) |
| 2160 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | struct nfs4_lookup_root_arg args = { |
| 2162 | .bitmask = nfs4_fattr_bitmap, |
| 2163 | }; |
| 2164 | struct nfs4_lookup_res res = { |
| 2165 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2166 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | .fh = fhandle, |
| 2168 | }; |
| 2169 | struct rpc_message msg = { |
| 2170 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2171 | .rpc_argp = &args, |
| 2172 | .rpc_resp = &res, |
| 2173 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2174 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2175 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2176 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2180 | struct nfs_fsinfo *info) |
| 2181 | { |
| 2182 | struct nfs4_exception exception = { }; |
| 2183 | int err; |
| 2184 | do { |
| 2185 | err = nfs4_handle_exception(server, |
| 2186 | _nfs4_lookup_root(server, fhandle, info), |
| 2187 | &exception); |
| 2188 | } while (exception.retry); |
| 2189 | return err; |
| 2190 | } |
| 2191 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2192 | /* |
| 2193 | * get the file handle for the "/" directory on the server |
| 2194 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | 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] | 2196 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | int status; |
| 2199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | if (status == 0) |
| 2202 | status = nfs4_server_capabilities(server, fhandle); |
| 2203 | if (status == 0) |
| 2204 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2205 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2208 | /* |
| 2209 | * Get locations and (maybe) other attributes of a referral. |
| 2210 | * Note that we'll actually follow the referral later when |
| 2211 | * we detect fsid mismatch in inode revalidation |
| 2212 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2213 | 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] | 2214 | { |
| 2215 | int status = -ENOMEM; |
| 2216 | struct page *page = NULL; |
| 2217 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2218 | |
| 2219 | page = alloc_page(GFP_KERNEL); |
| 2220 | if (page == NULL) |
| 2221 | goto out; |
| 2222 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2223 | if (locations == NULL) |
| 2224 | goto out; |
| 2225 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2226 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2227 | if (status != 0) |
| 2228 | goto out; |
| 2229 | /* Make sure server returned a different fsid for the referral */ |
| 2230 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2231 | 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] | 2232 | status = -EIO; |
| 2233 | goto out; |
| 2234 | } |
| 2235 | |
| 2236 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2237 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2238 | if (!fattr->mode) |
| 2239 | fattr->mode = S_IFDIR; |
| 2240 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2241 | out: |
| 2242 | if (page) |
| 2243 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2244 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2245 | return status; |
| 2246 | } |
| 2247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2249 | { |
| 2250 | struct nfs4_getattr_arg args = { |
| 2251 | .fh = fhandle, |
| 2252 | .bitmask = server->attr_bitmask, |
| 2253 | }; |
| 2254 | struct nfs4_getattr_res res = { |
| 2255 | .fattr = fattr, |
| 2256 | .server = server, |
| 2257 | }; |
| 2258 | struct rpc_message msg = { |
| 2259 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2260 | .rpc_argp = &args, |
| 2261 | .rpc_resp = &res, |
| 2262 | }; |
| 2263 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2264 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2265 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2269 | { |
| 2270 | struct nfs4_exception exception = { }; |
| 2271 | int err; |
| 2272 | do { |
| 2273 | err = nfs4_handle_exception(server, |
| 2274 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2275 | &exception); |
| 2276 | } while (exception.retry); |
| 2277 | return err; |
| 2278 | } |
| 2279 | |
| 2280 | /* |
| 2281 | * The file is not closed if it is opened due to the a request to change |
| 2282 | * the size of the file. The open call will not be needed once the |
| 2283 | * VFS layer lookup-intents are implemented. |
| 2284 | * |
| 2285 | * Close is called when the inode is destroyed. |
| 2286 | * If we haven't opened the file for O_WRONLY, we |
| 2287 | * need to in the size_change case to obtain a stateid. |
| 2288 | * |
| 2289 | * Got race? |
| 2290 | * Because OPEN is always done by name in nfsv4, it is |
| 2291 | * possible that we opened a different file by the same |
| 2292 | * name. We can recognize this race condition, but we |
| 2293 | * can't do anything about it besides returning an error. |
| 2294 | * |
| 2295 | * This will be fixed with VFS changes (lookup-intent). |
| 2296 | */ |
| 2297 | static int |
| 2298 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2299 | struct iattr *sattr) |
| 2300 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2301 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2302 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2303 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | int status; |
| 2305 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2306 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2308 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2309 | if (sattr->ia_valid & ATTR_FILE) { |
| 2310 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2311 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2312 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2313 | if (ctx) { |
| 2314 | cred = ctx->cred; |
| 2315 | state = ctx->state; |
| 2316 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2320 | if (status == 0) |
| 2321 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | return status; |
| 2323 | } |
| 2324 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2325 | static int _nfs4_proc_lookupfh(struct rpc_clnt *clnt, struct nfs_server *server, |
| 2326 | const struct nfs_fh *dirfh, const struct qstr *name, |
| 2327 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2328 | { |
| 2329 | int status; |
| 2330 | struct nfs4_lookup_arg args = { |
| 2331 | .bitmask = server->attr_bitmask, |
| 2332 | .dir_fh = dirfh, |
| 2333 | .name = name, |
| 2334 | }; |
| 2335 | struct nfs4_lookup_res res = { |
| 2336 | .server = server, |
| 2337 | .fattr = fattr, |
| 2338 | .fh = fhandle, |
| 2339 | }; |
| 2340 | struct rpc_message msg = { |
| 2341 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2342 | .rpc_argp = &args, |
| 2343 | .rpc_resp = &res, |
| 2344 | }; |
| 2345 | |
| 2346 | nfs_fattr_init(fattr); |
| 2347 | |
| 2348 | dprintk("NFS call lookupfh %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2349 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2350 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2351 | return status; |
| 2352 | } |
| 2353 | |
| 2354 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2355 | struct qstr *name, struct nfs_fh *fhandle, |
| 2356 | struct nfs_fattr *fattr) |
| 2357 | { |
| 2358 | struct nfs4_exception exception = { }; |
| 2359 | int err; |
| 2360 | do { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2361 | err = _nfs4_proc_lookupfh(server->client, server, dirfh, name, fhandle, fattr); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2362 | /* FIXME: !!!! */ |
| 2363 | if (err == -NFS4ERR_MOVED) { |
| 2364 | err = -EREMOTE; |
| 2365 | break; |
| 2366 | } |
| 2367 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2368 | } while (exception.retry); |
| 2369 | return err; |
| 2370 | } |
| 2371 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2372 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2373 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2374 | struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2376 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | |
| 2378 | dprintk("NFS call lookup %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2379 | status = _nfs4_proc_lookupfh(clnt, NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2380 | if (status == -NFS4ERR_MOVED) |
| 2381 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | dprintk("NFS reply lookup: %d\n", status); |
| 2383 | return status; |
| 2384 | } |
| 2385 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2386 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2387 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | { |
| 2389 | struct nfs4_exception exception = { }; |
| 2390 | int err; |
| 2391 | do { |
| 2392 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2393 | _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | &exception); |
| 2395 | } while (exception.retry); |
| 2396 | return err; |
| 2397 | } |
| 2398 | |
| 2399 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2400 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2401 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | struct nfs4_accessargs args = { |
| 2403 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2404 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2406 | struct nfs4_accessres res = { |
| 2407 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2408 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | struct rpc_message msg = { |
| 2410 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2411 | .rpc_argp = &args, |
| 2412 | .rpc_resp = &res, |
| 2413 | .rpc_cred = entry->cred, |
| 2414 | }; |
| 2415 | int mode = entry->mask; |
| 2416 | int status; |
| 2417 | |
| 2418 | /* |
| 2419 | * Determine which access bits we want to ask for... |
| 2420 | */ |
| 2421 | if (mode & MAY_READ) |
| 2422 | args.access |= NFS4_ACCESS_READ; |
| 2423 | if (S_ISDIR(inode->i_mode)) { |
| 2424 | if (mode & MAY_WRITE) |
| 2425 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2426 | if (mode & MAY_EXEC) |
| 2427 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2428 | } else { |
| 2429 | if (mode & MAY_WRITE) |
| 2430 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2431 | if (mode & MAY_EXEC) |
| 2432 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2433 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2434 | |
| 2435 | res.fattr = nfs_alloc_fattr(); |
| 2436 | if (res.fattr == NULL) |
| 2437 | return -ENOMEM; |
| 2438 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2439 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | if (!status) { |
| 2441 | entry->mask = 0; |
| 2442 | if (res.access & NFS4_ACCESS_READ) |
| 2443 | entry->mask |= MAY_READ; |
| 2444 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2445 | entry->mask |= MAY_WRITE; |
| 2446 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2447 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2448 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2450 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | return status; |
| 2452 | } |
| 2453 | |
| 2454 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2455 | { |
| 2456 | struct nfs4_exception exception = { }; |
| 2457 | int err; |
| 2458 | do { |
| 2459 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2460 | _nfs4_proc_access(inode, entry), |
| 2461 | &exception); |
| 2462 | } while (exception.retry); |
| 2463 | return err; |
| 2464 | } |
| 2465 | |
| 2466 | /* |
| 2467 | * TODO: For the time being, we don't try to get any attributes |
| 2468 | * along with any of the zero-copy operations READ, READDIR, |
| 2469 | * READLINK, WRITE. |
| 2470 | * |
| 2471 | * In the case of the first three, we want to put the GETATTR |
| 2472 | * after the read-type operation -- this is because it is hard |
| 2473 | * to predict the length of a GETATTR response in v4, and thus |
| 2474 | * align the READ data correctly. This means that the GETATTR |
| 2475 | * may end up partially falling into the page cache, and we should |
| 2476 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2477 | * To do this efficiently, we need to know the total length |
| 2478 | * of data received, which doesn't seem to be available outside |
| 2479 | * of the RPC layer. |
| 2480 | * |
| 2481 | * In the case of WRITE, we also want to put the GETATTR after |
| 2482 | * the operation -- in this case because we want to make sure |
| 2483 | * we get the post-operation mtime and size. This means that |
| 2484 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2485 | * of it which would leave room in the 'tail' iovec. |
| 2486 | * |
| 2487 | * Both of these changes to the XDR layer would in fact be quite |
| 2488 | * minor, but I decided to leave them for a subsequent patch. |
| 2489 | */ |
| 2490 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2491 | unsigned int pgbase, unsigned int pglen) |
| 2492 | { |
| 2493 | struct nfs4_readlink args = { |
| 2494 | .fh = NFS_FH(inode), |
| 2495 | .pgbase = pgbase, |
| 2496 | .pglen = pglen, |
| 2497 | .pages = &page, |
| 2498 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2499 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | struct rpc_message msg = { |
| 2501 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2502 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2503 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 | }; |
| 2505 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2506 | return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2510 | unsigned int pgbase, unsigned int pglen) |
| 2511 | { |
| 2512 | struct nfs4_exception exception = { }; |
| 2513 | int err; |
| 2514 | do { |
| 2515 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2516 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2517 | &exception); |
| 2518 | } while (exception.retry); |
| 2519 | return err; |
| 2520 | } |
| 2521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | /* |
| 2523 | * Got race? |
| 2524 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2525 | * Until then, this create/open method is prone to inefficiency and race |
| 2526 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2527 | * placed on the wire. |
| 2528 | * |
| 2529 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2530 | * The file will be opened again in the subsequent VFS open call |
| 2531 | * (nfs4_proc_file_open). |
| 2532 | * |
| 2533 | * The open for read will just hang around to be used by any process that |
| 2534 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2535 | */ |
| 2536 | |
| 2537 | static int |
| 2538 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2539 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2541 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2542 | .dentry = dentry, |
| 2543 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2544 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2546 | struct rpc_cred *cred = NULL; |
| 2547 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2548 | int status = 0; |
| 2549 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2550 | if (ctx != NULL) { |
| 2551 | cred = ctx->cred; |
| 2552 | path = &ctx->path; |
| 2553 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2555 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2556 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2557 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | if (IS_ERR(state)) { |
| 2559 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2560 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2562 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2563 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2564 | if (ctx != NULL) |
| 2565 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2566 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2567 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | out: |
| 2569 | return status; |
| 2570 | } |
| 2571 | |
| 2572 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2573 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2574 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2575 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2577 | .name.len = name->len, |
| 2578 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2579 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2580 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2581 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2582 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2583 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2585 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2586 | .rpc_argp = &args, |
| 2587 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2589 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2591 | res.dir_attr = nfs_alloc_fattr(); |
| 2592 | if (res.dir_attr == NULL) |
| 2593 | goto out; |
| 2594 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2595 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2596 | if (status == 0) { |
| 2597 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2598 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2599 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2600 | nfs_free_fattr(res.dir_attr); |
| 2601 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | return status; |
| 2603 | } |
| 2604 | |
| 2605 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2606 | { |
| 2607 | struct nfs4_exception exception = { }; |
| 2608 | int err; |
| 2609 | do { |
| 2610 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2611 | _nfs4_proc_remove(dir, name), |
| 2612 | &exception); |
| 2613 | } while (exception.retry); |
| 2614 | return err; |
| 2615 | } |
| 2616 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2617 | 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] | 2618 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2619 | struct nfs_server *server = NFS_SERVER(dir); |
| 2620 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2621 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2623 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2624 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2625 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2629 | 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] | 2630 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2631 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2632 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2633 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2634 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2635 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2636 | return 0; |
| 2637 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2638 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2639 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | } |
| 2641 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2642 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2643 | { |
| 2644 | struct nfs_server *server = NFS_SERVER(dir); |
| 2645 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2646 | struct nfs_renameres *res = msg->rpc_resp; |
| 2647 | |
| 2648 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2649 | arg->bitmask = server->attr_bitmask; |
| 2650 | res->server = server; |
| 2651 | } |
| 2652 | |
| 2653 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2654 | struct inode *new_dir) |
| 2655 | { |
| 2656 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2657 | |
| 2658 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2659 | return 0; |
| 2660 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2661 | return 0; |
| 2662 | |
| 2663 | update_changeattr(old_dir, &res->old_cinfo); |
| 2664 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2665 | update_changeattr(new_dir, &res->new_cinfo); |
| 2666 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2667 | return 1; |
| 2668 | } |
| 2669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2671 | struct inode *new_dir, struct qstr *new_name) |
| 2672 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2673 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2674 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | .old_dir = NFS_FH(old_dir), |
| 2676 | .new_dir = NFS_FH(new_dir), |
| 2677 | .old_name = old_name, |
| 2678 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2679 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2681 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2682 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2683 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | struct rpc_message msg = { |
| 2685 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2686 | .rpc_argp = &arg, |
| 2687 | .rpc_resp = &res, |
| 2688 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2689 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2691 | res.old_fattr = nfs_alloc_fattr(); |
| 2692 | res.new_fattr = nfs_alloc_fattr(); |
| 2693 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2694 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2696 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | if (!status) { |
| 2698 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2699 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2701 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2703 | out: |
| 2704 | nfs_free_fattr(res.new_fattr); |
| 2705 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | return status; |
| 2707 | } |
| 2708 | |
| 2709 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2710 | struct inode *new_dir, struct qstr *new_name) |
| 2711 | { |
| 2712 | struct nfs4_exception exception = { }; |
| 2713 | int err; |
| 2714 | do { |
| 2715 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2716 | _nfs4_proc_rename(old_dir, old_name, |
| 2717 | new_dir, new_name), |
| 2718 | &exception); |
| 2719 | } while (exception.retry); |
| 2720 | return err; |
| 2721 | } |
| 2722 | |
| 2723 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2724 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2725 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | struct nfs4_link_arg arg = { |
| 2727 | .fh = NFS_FH(inode), |
| 2728 | .dir_fh = NFS_FH(dir), |
| 2729 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2730 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2732 | struct nfs4_link_res res = { |
| 2733 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2734 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | struct rpc_message msg = { |
| 2736 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2737 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2738 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2740 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2742 | res.fattr = nfs_alloc_fattr(); |
| 2743 | res.dir_attr = nfs_alloc_fattr(); |
| 2744 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2745 | goto out; |
| 2746 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2747 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2748 | if (!status) { |
| 2749 | update_changeattr(dir, &res.cinfo); |
| 2750 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2751 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2752 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2753 | out: |
| 2754 | nfs_free_fattr(res.dir_attr); |
| 2755 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | return status; |
| 2757 | } |
| 2758 | |
| 2759 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2760 | { |
| 2761 | struct nfs4_exception exception = { }; |
| 2762 | int err; |
| 2763 | do { |
| 2764 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2765 | _nfs4_proc_link(inode, dir, name), |
| 2766 | &exception); |
| 2767 | } while (exception.retry); |
| 2768 | return err; |
| 2769 | } |
| 2770 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2771 | struct nfs4_createdata { |
| 2772 | struct rpc_message msg; |
| 2773 | struct nfs4_create_arg arg; |
| 2774 | struct nfs4_create_res res; |
| 2775 | struct nfs_fh fh; |
| 2776 | struct nfs_fattr fattr; |
| 2777 | struct nfs_fattr dir_fattr; |
| 2778 | }; |
| 2779 | |
| 2780 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2781 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2782 | { |
| 2783 | struct nfs4_createdata *data; |
| 2784 | |
| 2785 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2786 | if (data != NULL) { |
| 2787 | struct nfs_server *server = NFS_SERVER(dir); |
| 2788 | |
| 2789 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2790 | data->msg.rpc_argp = &data->arg; |
| 2791 | data->msg.rpc_resp = &data->res; |
| 2792 | data->arg.dir_fh = NFS_FH(dir); |
| 2793 | data->arg.server = server; |
| 2794 | data->arg.name = name; |
| 2795 | data->arg.attrs = sattr; |
| 2796 | data->arg.ftype = ftype; |
| 2797 | data->arg.bitmask = server->attr_bitmask; |
| 2798 | data->res.server = server; |
| 2799 | data->res.fh = &data->fh; |
| 2800 | data->res.fattr = &data->fattr; |
| 2801 | data->res.dir_fattr = &data->dir_fattr; |
| 2802 | nfs_fattr_init(data->res.fattr); |
| 2803 | nfs_fattr_init(data->res.dir_fattr); |
| 2804 | } |
| 2805 | return data; |
| 2806 | } |
| 2807 | |
| 2808 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2809 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2810 | int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 2811 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2812 | if (status == 0) { |
| 2813 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2814 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2815 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2816 | } |
| 2817 | return status; |
| 2818 | } |
| 2819 | |
| 2820 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2821 | { |
| 2822 | kfree(data); |
| 2823 | } |
| 2824 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2825 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2826 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2828 | struct nfs4_createdata *data; |
| 2829 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2830 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2831 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2832 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2833 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2834 | status = -ENOMEM; |
| 2835 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2836 | if (data == NULL) |
| 2837 | goto out; |
| 2838 | |
| 2839 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2840 | data->arg.u.symlink.pages = &page; |
| 2841 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2843 | status = nfs4_do_create(dir, dentry, data); |
| 2844 | |
| 2845 | nfs4_free_createdata(data); |
| 2846 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | return status; |
| 2848 | } |
| 2849 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2850 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2851 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | { |
| 2853 | struct nfs4_exception exception = { }; |
| 2854 | int err; |
| 2855 | do { |
| 2856 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2857 | _nfs4_proc_symlink(dir, dentry, page, |
| 2858 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | &exception); |
| 2860 | } while (exception.retry); |
| 2861 | return err; |
| 2862 | } |
| 2863 | |
| 2864 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2865 | struct iattr *sattr) |
| 2866 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2867 | struct nfs4_createdata *data; |
| 2868 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2870 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2871 | if (data == NULL) |
| 2872 | goto out; |
| 2873 | |
| 2874 | status = nfs4_do_create(dir, dentry, data); |
| 2875 | |
| 2876 | nfs4_free_createdata(data); |
| 2877 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | return status; |
| 2879 | } |
| 2880 | |
| 2881 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2882 | struct iattr *sattr) |
| 2883 | { |
| 2884 | struct nfs4_exception exception = { }; |
| 2885 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2886 | |
| 2887 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | do { |
| 2889 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2890 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2891 | &exception); |
| 2892 | } while (exception.retry); |
| 2893 | return err; |
| 2894 | } |
| 2895 | |
| 2896 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2897 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | { |
| 2899 | struct inode *dir = dentry->d_inode; |
| 2900 | struct nfs4_readdir_arg args = { |
| 2901 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2902 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | .pgbase = 0, |
| 2904 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2905 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2906 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | }; |
| 2908 | struct nfs4_readdir_res res; |
| 2909 | struct rpc_message msg = { |
| 2910 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2911 | .rpc_argp = &args, |
| 2912 | .rpc_resp = &res, |
| 2913 | .rpc_cred = cred, |
| 2914 | }; |
| 2915 | int status; |
| 2916 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2917 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2918 | dentry->d_parent->d_name.name, |
| 2919 | dentry->d_name.name, |
| 2920 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2922 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2923 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2924 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2926 | status += args.pgbase; |
| 2927 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2928 | |
| 2929 | nfs_invalidate_atime(dir); |
| 2930 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2931 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | return status; |
| 2933 | } |
| 2934 | |
| 2935 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2936 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | { |
| 2938 | struct nfs4_exception exception = { }; |
| 2939 | int err; |
| 2940 | do { |
| 2941 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2942 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2943 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | &exception); |
| 2945 | } while (exception.retry); |
| 2946 | return err; |
| 2947 | } |
| 2948 | |
| 2949 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2950 | struct iattr *sattr, dev_t rdev) |
| 2951 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2952 | struct nfs4_createdata *data; |
| 2953 | int mode = sattr->ia_mode; |
| 2954 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | |
| 2956 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2957 | 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] | 2958 | |
| 2959 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2960 | if (data == NULL) |
| 2961 | goto out; |
| 2962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2964 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2966 | data->arg.ftype = NF4BLK; |
| 2967 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2968 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | } |
| 2970 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2971 | data->arg.ftype = NF4CHR; |
| 2972 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2973 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2976 | status = nfs4_do_create(dir, dentry, data); |
| 2977 | |
| 2978 | nfs4_free_createdata(data); |
| 2979 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | return status; |
| 2981 | } |
| 2982 | |
| 2983 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2984 | struct iattr *sattr, dev_t rdev) |
| 2985 | { |
| 2986 | struct nfs4_exception exception = { }; |
| 2987 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2988 | |
| 2989 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | do { |
| 2991 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2992 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 2993 | &exception); |
| 2994 | } while (exception.retry); |
| 2995 | return err; |
| 2996 | } |
| 2997 | |
| 2998 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2999 | struct nfs_fsstat *fsstat) |
| 3000 | { |
| 3001 | struct nfs4_statfs_arg args = { |
| 3002 | .fh = fhandle, |
| 3003 | .bitmask = server->attr_bitmask, |
| 3004 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3005 | struct nfs4_statfs_res res = { |
| 3006 | .fsstat = fsstat, |
| 3007 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | struct rpc_message msg = { |
| 3009 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3010 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3011 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | }; |
| 3013 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3014 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3015 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3019 | { |
| 3020 | struct nfs4_exception exception = { }; |
| 3021 | int err; |
| 3022 | do { |
| 3023 | err = nfs4_handle_exception(server, |
| 3024 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3025 | &exception); |
| 3026 | } while (exception.retry); |
| 3027 | return err; |
| 3028 | } |
| 3029 | |
| 3030 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3031 | struct nfs_fsinfo *fsinfo) |
| 3032 | { |
| 3033 | struct nfs4_fsinfo_arg args = { |
| 3034 | .fh = fhandle, |
| 3035 | .bitmask = server->attr_bitmask, |
| 3036 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3037 | struct nfs4_fsinfo_res res = { |
| 3038 | .fsinfo = fsinfo, |
| 3039 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | struct rpc_message msg = { |
| 3041 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3042 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3043 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | }; |
| 3045 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3046 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3050 | { |
| 3051 | struct nfs4_exception exception = { }; |
| 3052 | int err; |
| 3053 | |
| 3054 | do { |
| 3055 | err = nfs4_handle_exception(server, |
| 3056 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3057 | &exception); |
| 3058 | } while (exception.retry); |
| 3059 | return err; |
| 3060 | } |
| 3061 | |
| 3062 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3063 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3064 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3066 | } |
| 3067 | |
| 3068 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3069 | struct nfs_pathconf *pathconf) |
| 3070 | { |
| 3071 | struct nfs4_pathconf_arg args = { |
| 3072 | .fh = fhandle, |
| 3073 | .bitmask = server->attr_bitmask, |
| 3074 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3075 | struct nfs4_pathconf_res res = { |
| 3076 | .pathconf = pathconf, |
| 3077 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | struct rpc_message msg = { |
| 3079 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3080 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3081 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | }; |
| 3083 | |
| 3084 | /* None of the pathconf attributes are mandatory to implement */ |
| 3085 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3086 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3087 | return 0; |
| 3088 | } |
| 3089 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3090 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3091 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3095 | struct nfs_pathconf *pathconf) |
| 3096 | { |
| 3097 | struct nfs4_exception exception = { }; |
| 3098 | int err; |
| 3099 | |
| 3100 | do { |
| 3101 | err = nfs4_handle_exception(server, |
| 3102 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3103 | &exception); |
| 3104 | } while (exception.retry); |
| 3105 | return err; |
| 3106 | } |
| 3107 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3108 | static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3110 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3112 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3113 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3114 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3116 | |
| 3117 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3119 | renew_lease(server, data->timestamp); |
| 3120 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3123 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3124 | { |
| 3125 | |
| 3126 | dprintk("--> %s\n", __func__); |
| 3127 | |
| 3128 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3129 | return -EAGAIN; |
| 3130 | |
| 3131 | return data->read_done_cb(task, data); |
| 3132 | } |
| 3133 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3134 | 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] | 3135 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3137 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3138 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | } |
| 3140 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3141 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3142 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3143 | { |
| 3144 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3145 | put_lseg(data->lseg); |
| 3146 | data->lseg = NULL; |
| 3147 | /* offsets will differ in the dense stripe case */ |
| 3148 | data->args.offset = data->mds_offset; |
| 3149 | data->ds_clp = NULL; |
| 3150 | data->args.fh = NFS_FH(data->inode); |
| 3151 | data->read_done_cb = nfs4_read_done_cb; |
| 3152 | task->tk_ops = data->mds_ops; |
| 3153 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3154 | } |
| 3155 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3156 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3157 | static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | struct inode *inode = data->inode; |
| 3160 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3161 | 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] | 3162 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3163 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3165 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3167 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3168 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3169 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | } |
| 3171 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3172 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3173 | { |
| 3174 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3175 | return -EAGAIN; |
| 3176 | return data->write_done_cb(task, data); |
| 3177 | } |
| 3178 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3179 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3180 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3181 | { |
| 3182 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3183 | put_lseg(data->lseg); |
| 3184 | data->lseg = NULL; |
| 3185 | data->ds_clp = NULL; |
| 3186 | data->write_done_cb = nfs4_write_done_cb; |
| 3187 | data->args.fh = NFS_FH(data->inode); |
| 3188 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3189 | data->args.offset = data->mds_offset; |
| 3190 | data->res.fattr = &data->fattr; |
| 3191 | task->tk_ops = data->mds_ops; |
| 3192 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3193 | } |
| 3194 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3195 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3196 | 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] | 3197 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3198 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3199 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3200 | if (data->lseg) { |
| 3201 | data->args.bitmask = NULL; |
| 3202 | data->res.fattr = NULL; |
| 3203 | } else |
| 3204 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3205 | if (!data->write_done_cb) |
| 3206 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3207 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | data->timestamp = jiffies; |
| 3209 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3210 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3213 | 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] | 3214 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | struct inode *inode = data->inode; |
| 3216 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3217 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3218 | return -EAGAIN; |
| 3219 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3220 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3221 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3222 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3224 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3225 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3228 | 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] | 3229 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3230 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3232 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3233 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3234 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3237 | struct nfs4_renewdata { |
| 3238 | struct nfs_client *client; |
| 3239 | unsigned long timestamp; |
| 3240 | }; |
| 3241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | /* |
| 3243 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3244 | * standalone procedure for queueing an asynchronous RENEW. |
| 3245 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3246 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3247 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3248 | struct nfs4_renewdata *data = calldata; |
| 3249 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3250 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3251 | if (atomic_read(&clp->cl_count) > 1) |
| 3252 | nfs4_schedule_state_renewal(clp); |
| 3253 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3254 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3255 | } |
| 3256 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3257 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3259 | struct nfs4_renewdata *data = calldata; |
| 3260 | struct nfs_client *clp = data->client; |
| 3261 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | |
| 3263 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3264 | /* Unless we're shutting down, schedule state recovery! */ |
| 3265 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3266 | nfs4_schedule_lease_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | return; |
| 3268 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3269 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | } |
| 3271 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3272 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3273 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3274 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3275 | }; |
| 3276 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3277 | 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] | 3278 | { |
| 3279 | struct rpc_message msg = { |
| 3280 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3281 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3282 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3284 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3286 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3287 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3288 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3289 | if (data == NULL) |
| 3290 | return -ENOMEM; |
| 3291 | data->client = clp; |
| 3292 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3294 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | } |
| 3296 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3297 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | { |
| 3299 | struct rpc_message msg = { |
| 3300 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3301 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3302 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | }; |
| 3304 | unsigned long now = jiffies; |
| 3305 | int status; |
| 3306 | |
| 3307 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3308 | if (status < 0) |
| 3309 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3310 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | return 0; |
| 3312 | } |
| 3313 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3314 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3315 | { |
| 3316 | return (server->caps & NFS_CAP_ACLS) |
| 3317 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3318 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3319 | } |
| 3320 | |
| 3321 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3322 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3323 | * the stack. |
| 3324 | */ |
| 3325 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3326 | |
| 3327 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3328 | struct page **pages, unsigned int *pgbase) |
| 3329 | { |
| 3330 | const void *p = buf; |
| 3331 | |
| 3332 | *pgbase = offset_in_page(buf); |
| 3333 | p -= *pgbase; |
| 3334 | while (p < buf + buflen) { |
| 3335 | *(pages++) = virt_to_page(p); |
| 3336 | p += PAGE_CACHE_SIZE; |
| 3337 | } |
| 3338 | } |
| 3339 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3340 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3341 | struct page **pages, unsigned int *pgbase) |
| 3342 | { |
| 3343 | struct page *newpage, **spages; |
| 3344 | int rc = 0; |
| 3345 | size_t len; |
| 3346 | spages = pages; |
| 3347 | |
| 3348 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3349 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3350 | newpage = alloc_page(GFP_KERNEL); |
| 3351 | |
| 3352 | if (newpage == NULL) |
| 3353 | goto unwind; |
| 3354 | memcpy(page_address(newpage), buf, len); |
| 3355 | buf += len; |
| 3356 | buflen -= len; |
| 3357 | *pages++ = newpage; |
| 3358 | rc++; |
| 3359 | } while (buflen != 0); |
| 3360 | |
| 3361 | return rc; |
| 3362 | |
| 3363 | unwind: |
| 3364 | for(; rc > 0; rc--) |
| 3365 | __free_page(spages[rc-1]); |
| 3366 | return -ENOMEM; |
| 3367 | } |
| 3368 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3369 | struct nfs4_cached_acl { |
| 3370 | int cached; |
| 3371 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3372 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3373 | }; |
| 3374 | |
| 3375 | 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] | 3376 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3377 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3378 | |
| 3379 | spin_lock(&inode->i_lock); |
| 3380 | kfree(nfsi->nfs4_acl); |
| 3381 | nfsi->nfs4_acl = acl; |
| 3382 | spin_unlock(&inode->i_lock); |
| 3383 | } |
| 3384 | |
| 3385 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3386 | { |
| 3387 | nfs4_set_cached_acl(inode, NULL); |
| 3388 | } |
| 3389 | |
| 3390 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3391 | { |
| 3392 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3393 | struct nfs4_cached_acl *acl; |
| 3394 | int ret = -ENOENT; |
| 3395 | |
| 3396 | spin_lock(&inode->i_lock); |
| 3397 | acl = nfsi->nfs4_acl; |
| 3398 | if (acl == NULL) |
| 3399 | goto out; |
| 3400 | if (buf == NULL) /* user is just asking for length */ |
| 3401 | goto out_len; |
| 3402 | if (acl->cached == 0) |
| 3403 | goto out; |
| 3404 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3405 | if (acl->len > buflen) |
| 3406 | goto out; |
| 3407 | memcpy(buf, acl->data, acl->len); |
| 3408 | out_len: |
| 3409 | ret = acl->len; |
| 3410 | out: |
| 3411 | spin_unlock(&inode->i_lock); |
| 3412 | return ret; |
| 3413 | } |
| 3414 | |
| 3415 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3416 | { |
| 3417 | struct nfs4_cached_acl *acl; |
| 3418 | |
| 3419 | if (buf && acl_len <= PAGE_SIZE) { |
| 3420 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3421 | if (acl == NULL) |
| 3422 | goto out; |
| 3423 | acl->cached = 1; |
| 3424 | memcpy(acl->data, buf, acl_len); |
| 3425 | } else { |
| 3426 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3427 | if (acl == NULL) |
| 3428 | goto out; |
| 3429 | acl->cached = 0; |
| 3430 | } |
| 3431 | acl->len = acl_len; |
| 3432 | out: |
| 3433 | nfs4_set_cached_acl(inode, acl); |
| 3434 | } |
| 3435 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3436 | 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] | 3437 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3438 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3439 | struct nfs_getaclargs args = { |
| 3440 | .fh = NFS_FH(inode), |
| 3441 | .acl_pages = pages, |
| 3442 | .acl_len = buflen, |
| 3443 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3444 | struct nfs_getaclres res = { |
| 3445 | .acl_len = buflen, |
| 3446 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3447 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3448 | struct rpc_message msg = { |
| 3449 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3450 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3451 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3452 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3453 | struct page *localpage = NULL; |
| 3454 | int ret; |
| 3455 | |
| 3456 | if (buflen < PAGE_SIZE) { |
| 3457 | /* As long as we're doing a round trip to the server anyway, |
| 3458 | * let's be prepared for a page of acl data. */ |
| 3459 | localpage = alloc_page(GFP_KERNEL); |
| 3460 | resp_buf = page_address(localpage); |
| 3461 | if (localpage == NULL) |
| 3462 | return -ENOMEM; |
| 3463 | args.acl_pages[0] = localpage; |
| 3464 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3465 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3466 | } else { |
| 3467 | resp_buf = buf; |
| 3468 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3469 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3470 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3471 | if (ret) |
| 3472 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3473 | if (res.acl_len > args.acl_len) |
| 3474 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3475 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3476 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3477 | if (buf) { |
| 3478 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3479 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3480 | goto out_free; |
| 3481 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3482 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3483 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3484 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3485 | out_free: |
| 3486 | if (localpage) |
| 3487 | __free_page(localpage); |
| 3488 | return ret; |
| 3489 | } |
| 3490 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3491 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3492 | { |
| 3493 | struct nfs4_exception exception = { }; |
| 3494 | ssize_t ret; |
| 3495 | do { |
| 3496 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3497 | if (ret >= 0) |
| 3498 | break; |
| 3499 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3500 | } while (exception.retry); |
| 3501 | return ret; |
| 3502 | } |
| 3503 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3504 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3505 | { |
| 3506 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3507 | int ret; |
| 3508 | |
| 3509 | if (!nfs4_server_supports_acls(server)) |
| 3510 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3511 | ret = nfs_revalidate_inode(server, inode); |
| 3512 | if (ret < 0) |
| 3513 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3514 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3515 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3516 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3517 | if (ret != -ENOENT) |
| 3518 | return ret; |
| 3519 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3520 | } |
| 3521 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3522 | 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] | 3523 | { |
| 3524 | struct nfs_server *server = NFS_SERVER(inode); |
| 3525 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3526 | struct nfs_setaclargs arg = { |
| 3527 | .fh = NFS_FH(inode), |
| 3528 | .acl_pages = pages, |
| 3529 | .acl_len = buflen, |
| 3530 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3531 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3532 | struct rpc_message msg = { |
| 3533 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3534 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3535 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3536 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3537 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3538 | |
| 3539 | if (!nfs4_server_supports_acls(server)) |
| 3540 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3541 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3542 | if (i < 0) |
| 3543 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3544 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3545 | ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3546 | |
| 3547 | /* |
| 3548 | * Free each page after tx, so the only ref left is |
| 3549 | * held by the network stack |
| 3550 | */ |
| 3551 | for (; i > 0; i--) |
| 3552 | put_page(pages[i-1]); |
| 3553 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3554 | /* |
| 3555 | * Acl update can result in inode attribute update. |
| 3556 | * so mark the attribute cache invalid. |
| 3557 | */ |
| 3558 | spin_lock(&inode->i_lock); |
| 3559 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3560 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3561 | nfs_access_zap_cache(inode); |
| 3562 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3563 | return ret; |
| 3564 | } |
| 3565 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3566 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3567 | { |
| 3568 | struct nfs4_exception exception = { }; |
| 3569 | int err; |
| 3570 | do { |
| 3571 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3572 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3573 | &exception); |
| 3574 | } while (exception.retry); |
| 3575 | return err; |
| 3576 | } |
| 3577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3578 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3579 | 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] | 3580 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3581 | struct nfs_client *clp = server->nfs_client; |
| 3582 | |
| 3583 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | return 0; |
| 3585 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3586 | case -NFS4ERR_ADMIN_REVOKED: |
| 3587 | case -NFS4ERR_BAD_STATEID: |
| 3588 | case -NFS4ERR_OPENMODE: |
| 3589 | if (state == NULL) |
| 3590 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3591 | nfs4_schedule_stateid_recovery(server, state); |
| 3592 | goto wait_on_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3594 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3596 | nfs4_schedule_lease_recovery(clp); |
| 3597 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3598 | #if defined(CONFIG_NFS_V4_1) |
| 3599 | case -NFS4ERR_BADSESSION: |
| 3600 | case -NFS4ERR_BADSLOT: |
| 3601 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3602 | case -NFS4ERR_DEADSESSION: |
| 3603 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3604 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3605 | case -NFS4ERR_SEQ_MISORDERED: |
| 3606 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3607 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3608 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3609 | task->tk_status = 0; |
| 3610 | return -EAGAIN; |
| 3611 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3613 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3614 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3615 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3617 | task->tk_status = 0; |
| 3618 | return -EAGAIN; |
| 3619 | case -NFS4ERR_OLD_STATEID: |
| 3620 | task->tk_status = 0; |
| 3621 | return -EAGAIN; |
| 3622 | } |
| 3623 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3624 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3625 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3626 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3627 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3628 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3629 | task->tk_status = 0; |
| 3630 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | } |
| 3632 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3633 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3634 | unsigned short port, struct rpc_cred *cred, |
| 3635 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | { |
| 3637 | nfs4_verifier sc_verifier; |
| 3638 | struct nfs4_setclientid setclientid = { |
| 3639 | .sc_verifier = &sc_verifier, |
| 3640 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3641 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | }; |
| 3643 | struct rpc_message msg = { |
| 3644 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3645 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3646 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3647 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3649 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | int loop = 0; |
| 3651 | int status; |
| 3652 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3653 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3655 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3656 | |
| 3657 | for(;;) { |
| 3658 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3659 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3660 | clp->cl_ipaddr, |
| 3661 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3662 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3663 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3664 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3665 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | clp->cl_id_uniquifier); |
| 3667 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3668 | sizeof(setclientid.sc_netid), |
| 3669 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3670 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3672 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3674 | |
| 3675 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3676 | if (status != -NFS4ERR_CLID_INUSE) |
| 3677 | break; |
| 3678 | if (signalled()) |
| 3679 | break; |
| 3680 | if (loop++ & 1) |
J. Bruce Fields | 611c96c | 2010-12-13 19:05:46 -0500 | [diff] [blame] | 3681 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | else |
| 3683 | if (++clp->cl_id_uniquifier == 0) |
| 3684 | break; |
| 3685 | } |
| 3686 | return status; |
| 3687 | } |
| 3688 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3689 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3690 | struct nfs4_setclientid_res *arg, |
| 3691 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | { |
| 3693 | struct nfs_fsinfo fsinfo; |
| 3694 | struct rpc_message msg = { |
| 3695 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3696 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3698 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | }; |
| 3700 | unsigned long now; |
| 3701 | int status; |
| 3702 | |
| 3703 | now = jiffies; |
| 3704 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3705 | if (status == 0) { |
| 3706 | spin_lock(&clp->cl_lock); |
| 3707 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3708 | clp->cl_last_renewal = now; |
| 3709 | spin_unlock(&clp->cl_lock); |
| 3710 | } |
| 3711 | return status; |
| 3712 | } |
| 3713 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3714 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3715 | struct nfs4_setclientid_res *arg, |
| 3716 | struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3717 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3718 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3719 | int err; |
| 3720 | do { |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3721 | err = _nfs4_proc_setclientid_confirm(clp, arg, cred); |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3722 | switch (err) { |
| 3723 | case 0: |
| 3724 | return err; |
| 3725 | case -NFS4ERR_RESOURCE: |
| 3726 | /* The IBM lawyers misread another document! */ |
| 3727 | case -NFS4ERR_DELAY: |
| 3728 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3729 | } |
| 3730 | } while (err == 0); |
| 3731 | return err; |
| 3732 | } |
| 3733 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3734 | struct nfs4_delegreturndata { |
| 3735 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3736 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3737 | struct nfs_fh fh; |
| 3738 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3739 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3740 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3741 | int rpc_status; |
| 3742 | }; |
| 3743 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3744 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3745 | { |
| 3746 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3747 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3748 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3749 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3750 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3751 | switch (task->tk_status) { |
| 3752 | case -NFS4ERR_STALE_STATEID: |
| 3753 | case -NFS4ERR_EXPIRED: |
| 3754 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3755 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3756 | break; |
| 3757 | default: |
| 3758 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3759 | -EAGAIN) { |
| 3760 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3761 | return; |
| 3762 | } |
| 3763 | } |
| 3764 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | static void nfs4_delegreturn_release(void *calldata) |
| 3768 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3769 | kfree(calldata); |
| 3770 | } |
| 3771 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3772 | #if defined(CONFIG_NFS_V4_1) |
| 3773 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3774 | { |
| 3775 | struct nfs4_delegreturndata *d_data; |
| 3776 | |
| 3777 | d_data = (struct nfs4_delegreturndata *)data; |
| 3778 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3779 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3780 | &d_data->args.seq_args, |
| 3781 | &d_data->res.seq_res, 1, task)) |
| 3782 | return; |
| 3783 | rpc_call_start(task); |
| 3784 | } |
| 3785 | #endif /* CONFIG_NFS_V4_1 */ |
| 3786 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3787 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3788 | #if defined(CONFIG_NFS_V4_1) |
| 3789 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3790 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3791 | .rpc_call_done = nfs4_delegreturn_done, |
| 3792 | .rpc_release = nfs4_delegreturn_release, |
| 3793 | }; |
| 3794 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3795 | 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] | 3796 | { |
| 3797 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3798 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3799 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3800 | struct rpc_message msg = { |
| 3801 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3802 | .rpc_cred = cred, |
| 3803 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3804 | struct rpc_task_setup task_setup_data = { |
| 3805 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3806 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3807 | .callback_ops = &nfs4_delegreturn_ops, |
| 3808 | .flags = RPC_TASK_ASYNC, |
| 3809 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3810 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3811 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3812 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3813 | if (data == NULL) |
| 3814 | return -ENOMEM; |
| 3815 | data->args.fhandle = &data->fh; |
| 3816 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3817 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3818 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3819 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3820 | data->res.fattr = &data->fattr; |
| 3821 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3822 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3823 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3824 | data->rpc_status = 0; |
| 3825 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3826 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3827 | msg.rpc_argp = &data->args; |
| 3828 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3829 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3830 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3831 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3832 | if (!issync) |
| 3833 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3834 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3835 | if (status != 0) |
| 3836 | goto out; |
| 3837 | status = data->rpc_status; |
| 3838 | if (status != 0) |
| 3839 | goto out; |
| 3840 | nfs_refresh_inode(inode, &data->fattr); |
| 3841 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3842 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3843 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | } |
| 3845 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3846 | 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] | 3847 | { |
| 3848 | struct nfs_server *server = NFS_SERVER(inode); |
| 3849 | struct nfs4_exception exception = { }; |
| 3850 | int err; |
| 3851 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3852 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3853 | switch (err) { |
| 3854 | case -NFS4ERR_STALE_STATEID: |
| 3855 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | case 0: |
| 3857 | return 0; |
| 3858 | } |
| 3859 | err = nfs4_handle_exception(server, err, &exception); |
| 3860 | } while (exception.retry); |
| 3861 | return err; |
| 3862 | } |
| 3863 | |
| 3864 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3865 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3866 | |
| 3867 | /* |
| 3868 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3869 | */ |
| 3870 | static unsigned long |
| 3871 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3872 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3873 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | timeout <<= 1; |
| 3875 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3876 | return NFS4_LOCK_MAXTIMEOUT; |
| 3877 | return timeout; |
| 3878 | } |
| 3879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3880 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3881 | { |
| 3882 | struct inode *inode = state->inode; |
| 3883 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3884 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3885 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3887 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3889 | struct nfs_lockt_res res = { |
| 3890 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | }; |
| 3892 | struct rpc_message msg = { |
| 3893 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3894 | .rpc_argp = &arg, |
| 3895 | .rpc_resp = &res, |
| 3896 | .rpc_cred = state->owner->so_cred, |
| 3897 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | struct nfs4_lock_state *lsp; |
| 3899 | int status; |
| 3900 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3901 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3902 | status = nfs4_set_lock_state(state, request); |
| 3903 | if (status != 0) |
| 3904 | goto out; |
| 3905 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3906 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3907 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3908 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3909 | switch (status) { |
| 3910 | case 0: |
| 3911 | request->fl_type = F_UNLCK; |
| 3912 | break; |
| 3913 | case -NFS4ERR_DENIED: |
| 3914 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3916 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3917 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | return status; |
| 3919 | } |
| 3920 | |
| 3921 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3922 | { |
| 3923 | struct nfs4_exception exception = { }; |
| 3924 | int err; |
| 3925 | |
| 3926 | do { |
| 3927 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3928 | _nfs4_proc_getlk(state, cmd, request), |
| 3929 | &exception); |
| 3930 | } while (exception.retry); |
| 3931 | return err; |
| 3932 | } |
| 3933 | |
| 3934 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3935 | { |
| 3936 | int res = 0; |
| 3937 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3938 | case FL_POSIX: |
| 3939 | res = posix_lock_file_wait(file, fl); |
| 3940 | break; |
| 3941 | case FL_FLOCK: |
| 3942 | res = flock_lock_file_wait(file, fl); |
| 3943 | break; |
| 3944 | default: |
| 3945 | BUG(); |
| 3946 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3947 | return res; |
| 3948 | } |
| 3949 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3950 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3951 | struct nfs_locku_args arg; |
| 3952 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3953 | struct nfs4_lock_state *lsp; |
| 3954 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3955 | struct file_lock fl; |
| 3956 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3957 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3958 | }; |
| 3959 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3960 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 3961 | struct nfs_open_context *ctx, |
| 3962 | struct nfs4_lock_state *lsp, |
| 3963 | struct nfs_seqid *seqid) |
| 3964 | { |
| 3965 | struct nfs4_unlockdata *p; |
| 3966 | struct inode *inode = lsp->ls_state->inode; |
| 3967 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3968 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3969 | if (p == NULL) |
| 3970 | return NULL; |
| 3971 | p->arg.fh = NFS_FH(inode); |
| 3972 | p->arg.fl = &p->fl; |
| 3973 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3974 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3975 | p->arg.stateid = &lsp->ls_stateid; |
| 3976 | p->lsp = lsp; |
| 3977 | atomic_inc(&lsp->ls_count); |
| 3978 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3979 | p->ctx = get_nfs_open_context(ctx); |
| 3980 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3981 | p->server = NFS_SERVER(inode); |
| 3982 | return p; |
| 3983 | } |
| 3984 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3985 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3986 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3987 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3988 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3989 | nfs4_put_lock_state(calldata->lsp); |
| 3990 | put_nfs_open_context(calldata->ctx); |
| 3991 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3992 | } |
| 3993 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3994 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3995 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3996 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3997 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3998 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3999 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4000 | switch (task->tk_status) { |
| 4001 | case 0: |
| 4002 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4003 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4004 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4005 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4006 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4007 | case -NFS4ERR_BAD_STATEID: |
| 4008 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4009 | case -NFS4ERR_STALE_STATEID: |
| 4010 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4011 | break; |
| 4012 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4013 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4014 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 4015 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4016 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4017 | } |
| 4018 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4019 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4020 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4021 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4023 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4024 | return; |
| 4025 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4026 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4027 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4028 | return; |
| 4029 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4030 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4031 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4032 | &calldata->arg.seq_args, |
| 4033 | &calldata->res.seq_res, 1, task)) |
| 4034 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4035 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | } |
| 4037 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4038 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4039 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4040 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4041 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4042 | }; |
| 4043 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4044 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4045 | struct nfs_open_context *ctx, |
| 4046 | struct nfs4_lock_state *lsp, |
| 4047 | struct nfs_seqid *seqid) |
| 4048 | { |
| 4049 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4050 | struct rpc_message msg = { |
| 4051 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4052 | .rpc_cred = ctx->cred, |
| 4053 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4054 | struct rpc_task_setup task_setup_data = { |
| 4055 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4056 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4057 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4058 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4059 | .flags = RPC_TASK_ASYNC, |
| 4060 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4061 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4062 | /* Ensure this is an unlock - when canceling a lock, the |
| 4063 | * canceled lock is passed in, and it won't be an unlock. |
| 4064 | */ |
| 4065 | fl->fl_type = F_UNLCK; |
| 4066 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4067 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4068 | if (data == NULL) { |
| 4069 | nfs_free_seqid(seqid); |
| 4070 | return ERR_PTR(-ENOMEM); |
| 4071 | } |
| 4072 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4073 | msg.rpc_argp = &data->arg; |
| 4074 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4075 | task_setup_data.callback_data = data; |
| 4076 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4077 | } |
| 4078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4080 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4081 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4082 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4083 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4084 | struct rpc_task *task; |
| 4085 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4086 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4088 | status = nfs4_set_lock_state(state, request); |
| 4089 | /* Unlock _before_ we do the RPC call */ |
| 4090 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4091 | down_read(&nfsi->rwsem); |
| 4092 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4093 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4094 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4095 | } |
| 4096 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4097 | if (status != 0) |
| 4098 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4099 | /* Is this a delegated lock? */ |
| 4100 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4101 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4102 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4103 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4104 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4105 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4106 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4107 | 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] | 4108 | status = PTR_ERR(task); |
| 4109 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4110 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4111 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4112 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4113 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4114 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4115 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | } |
| 4117 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4118 | struct nfs4_lockdata { |
| 4119 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4120 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4121 | struct nfs4_lock_state *lsp; |
| 4122 | struct nfs_open_context *ctx; |
| 4123 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4124 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4125 | int rpc_status; |
| 4126 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4127 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4128 | }; |
| 4129 | |
| 4130 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4131 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4132 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4133 | { |
| 4134 | struct nfs4_lockdata *p; |
| 4135 | struct inode *inode = lsp->ls_state->inode; |
| 4136 | struct nfs_server *server = NFS_SERVER(inode); |
| 4137 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4138 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4139 | if (p == NULL) |
| 4140 | return NULL; |
| 4141 | |
| 4142 | p->arg.fh = NFS_FH(inode); |
| 4143 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4144 | 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] | 4145 | if (p->arg.open_seqid == NULL) |
| 4146 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4147 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4148 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4149 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4150 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4151 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4152 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4153 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4154 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4155 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4156 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4157 | atomic_inc(&lsp->ls_count); |
| 4158 | p->ctx = get_nfs_open_context(ctx); |
| 4159 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4160 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4161 | out_free_seqid: |
| 4162 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4163 | out_free: |
| 4164 | kfree(p); |
| 4165 | return NULL; |
| 4166 | } |
| 4167 | |
| 4168 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4169 | { |
| 4170 | struct nfs4_lockdata *data = calldata; |
| 4171 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4173 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4174 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4175 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4176 | /* Do we need to do an open_to_lock_owner? */ |
| 4177 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4178 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4179 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4180 | data->arg.open_stateid = &state->stateid; |
| 4181 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4182 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4183 | } else |
| 4184 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4185 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4186 | if (nfs4_setup_sequence(data->server, |
| 4187 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4188 | &data->res.seq_res, 1, task)) |
| 4189 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4190 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4191 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4192 | } |
| 4193 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4194 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4195 | { |
| 4196 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4197 | nfs4_lock_prepare(task, calldata); |
| 4198 | } |
| 4199 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4200 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4201 | { |
| 4202 | struct nfs4_lockdata *data = calldata; |
| 4203 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4204 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4205 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4206 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4207 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4208 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4209 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4210 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4211 | if (data->rpc_status == 0) |
| 4212 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4213 | else |
| 4214 | goto out; |
| 4215 | } |
| 4216 | if (data->rpc_status == 0) { |
| 4217 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4218 | sizeof(data->lsp->ls_stateid.data)); |
| 4219 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4220 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4221 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4222 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4223 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4224 | } |
| 4225 | |
| 4226 | static void nfs4_lock_release(void *calldata) |
| 4227 | { |
| 4228 | struct nfs4_lockdata *data = calldata; |
| 4229 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4230 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4231 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4232 | if (data->cancelled != 0) { |
| 4233 | struct rpc_task *task; |
| 4234 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4235 | data->arg.lock_seqid); |
| 4236 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4237 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4238 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4239 | } else |
| 4240 | nfs_free_seqid(data->arg.lock_seqid); |
| 4241 | nfs4_put_lock_state(data->lsp); |
| 4242 | put_nfs_open_context(data->ctx); |
| 4243 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4244 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4245 | } |
| 4246 | |
| 4247 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4248 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4249 | .rpc_call_done = nfs4_lock_done, |
| 4250 | .rpc_release = nfs4_lock_release, |
| 4251 | }; |
| 4252 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4253 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4254 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4255 | .rpc_call_done = nfs4_lock_done, |
| 4256 | .rpc_release = nfs4_lock_release, |
| 4257 | }; |
| 4258 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4259 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4260 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4261 | switch (error) { |
| 4262 | case -NFS4ERR_ADMIN_REVOKED: |
| 4263 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4264 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4265 | if (new_lock_owner != 0 || |
| 4266 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4267 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4268 | break; |
| 4269 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4270 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4271 | case -NFS4ERR_EXPIRED: |
| 4272 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4273 | }; |
| 4274 | } |
| 4275 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4276 | 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] | 4277 | { |
| 4278 | struct nfs4_lockdata *data; |
| 4279 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4280 | struct rpc_message msg = { |
| 4281 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4282 | .rpc_cred = state->owner->so_cred, |
| 4283 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4284 | struct rpc_task_setup task_setup_data = { |
| 4285 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4286 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4287 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4288 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4289 | .flags = RPC_TASK_ASYNC, |
| 4290 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4291 | int ret; |
| 4292 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4293 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4294 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4295 | fl->fl_u.nfs4_fl.owner, |
| 4296 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4297 | if (data == NULL) |
| 4298 | return -ENOMEM; |
| 4299 | if (IS_SETLKW(cmd)) |
| 4300 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4301 | if (recovery_type > NFS_LOCK_NEW) { |
| 4302 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4303 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4304 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4305 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4306 | msg.rpc_argp = &data->arg; |
| 4307 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4308 | task_setup_data.callback_data = data; |
| 4309 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4310 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4311 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4312 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4313 | if (ret == 0) { |
| 4314 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4315 | if (ret) |
| 4316 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4317 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4318 | } else |
| 4319 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4320 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4321 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4322 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4326 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4327 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4328 | struct nfs4_exception exception = { }; |
| 4329 | int err; |
| 4330 | |
| 4331 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4332 | /* Cache the lock if possible... */ |
| 4333 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4334 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4335 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4336 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4337 | break; |
| 4338 | nfs4_handle_exception(server, err, &exception); |
| 4339 | } while (exception.retry); |
| 4340 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4344 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4345 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4346 | struct nfs4_exception exception = { }; |
| 4347 | int err; |
| 4348 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4349 | err = nfs4_set_lock_state(state, request); |
| 4350 | if (err != 0) |
| 4351 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4352 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4353 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4354 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4355 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4356 | switch (err) { |
| 4357 | default: |
| 4358 | goto out; |
| 4359 | case -NFS4ERR_GRACE: |
| 4360 | case -NFS4ERR_DELAY: |
| 4361 | nfs4_handle_exception(server, err, &exception); |
| 4362 | err = 0; |
| 4363 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4364 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4365 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4366 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4370 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4371 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4372 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4373 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4375 | if ((fl_flags & FL_POSIX) && |
| 4376 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4377 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4378 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4379 | status = nfs4_set_lock_state(state, request); |
| 4380 | if (status != 0) |
| 4381 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4382 | request->fl_flags |= FL_ACCESS; |
| 4383 | status = do_vfs_lock(request->fl_file, request); |
| 4384 | if (status < 0) |
| 4385 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4386 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4387 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4388 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4389 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4390 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4391 | status = do_vfs_lock(request->fl_file, request); |
| 4392 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4393 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4394 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4395 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4396 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4397 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4398 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4399 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4400 | 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] | 4401 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4402 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4403 | out: |
| 4404 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | return status; |
| 4406 | } |
| 4407 | |
| 4408 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4409 | { |
| 4410 | struct nfs4_exception exception = { }; |
| 4411 | int err; |
| 4412 | |
| 4413 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4414 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4415 | if (err == -NFS4ERR_DENIED) |
| 4416 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4417 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4418 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | } while (exception.retry); |
| 4420 | return err; |
| 4421 | } |
| 4422 | |
| 4423 | static int |
| 4424 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4425 | { |
| 4426 | struct nfs_open_context *ctx; |
| 4427 | struct nfs4_state *state; |
| 4428 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4429 | int status; |
| 4430 | |
| 4431 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4432 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | state = ctx->state; |
| 4434 | |
| 4435 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4436 | return -EINVAL; |
| 4437 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4438 | if (IS_GETLK(cmd)) { |
| 4439 | if (state != NULL) |
| 4440 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4441 | return 0; |
| 4442 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | |
| 4444 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4445 | return -EINVAL; |
| 4446 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4447 | if (request->fl_type == F_UNLCK) { |
| 4448 | if (state != NULL) |
| 4449 | return nfs4_proc_unlck(state, cmd, request); |
| 4450 | return 0; |
| 4451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4453 | if (state == NULL) |
| 4454 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | do { |
| 4456 | status = nfs4_proc_setlk(state, cmd, request); |
| 4457 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4458 | break; |
| 4459 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4460 | status = -ERESTARTSYS; |
| 4461 | if (signalled()) |
| 4462 | break; |
| 4463 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | return status; |
| 4465 | } |
| 4466 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4467 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4468 | { |
| 4469 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4470 | struct nfs4_exception exception = { }; |
| 4471 | int err; |
| 4472 | |
| 4473 | err = nfs4_set_lock_state(state, fl); |
| 4474 | if (err != 0) |
| 4475 | goto out; |
| 4476 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4477 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4478 | switch (err) { |
| 4479 | default: |
| 4480 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4481 | __func__, err); |
| 4482 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4483 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4484 | goto out; |
| 4485 | case -NFS4ERR_EXPIRED: |
| 4486 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4487 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4488 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4489 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4490 | case -NFS4ERR_BADSESSION: |
| 4491 | case -NFS4ERR_BADSLOT: |
| 4492 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4493 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4494 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4495 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4496 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4497 | case -ERESTARTSYS: |
| 4498 | /* |
| 4499 | * The show must go on: exit, but mark the |
| 4500 | * stateid as needing recovery. |
| 4501 | */ |
| 4502 | case -NFS4ERR_ADMIN_REVOKED: |
| 4503 | case -NFS4ERR_BAD_STATEID: |
| 4504 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4505 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4506 | err = 0; |
| 4507 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4508 | case -EKEYEXPIRED: |
| 4509 | /* |
| 4510 | * User RPCSEC_GSS context has expired. |
| 4511 | * We cannot recover this stateid now, so |
| 4512 | * skip it and allow recovery thread to |
| 4513 | * proceed. |
| 4514 | */ |
| 4515 | err = 0; |
| 4516 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4517 | case -ENOMEM: |
| 4518 | case -NFS4ERR_DENIED: |
| 4519 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4520 | err = 0; |
| 4521 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4522 | case -NFS4ERR_DELAY: |
| 4523 | break; |
| 4524 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4525 | err = nfs4_handle_exception(server, err, &exception); |
| 4526 | } while (exception.retry); |
| 4527 | out: |
| 4528 | return err; |
| 4529 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4530 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4531 | static void nfs4_release_lockowner_release(void *calldata) |
| 4532 | { |
| 4533 | kfree(calldata); |
| 4534 | } |
| 4535 | |
| 4536 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4537 | .rpc_release = nfs4_release_lockowner_release, |
| 4538 | }; |
| 4539 | |
| 4540 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4541 | { |
| 4542 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4543 | struct nfs_release_lockowner_args *args; |
| 4544 | struct rpc_message msg = { |
| 4545 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4546 | }; |
| 4547 | |
| 4548 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4549 | return; |
| 4550 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4551 | if (!args) |
| 4552 | return; |
| 4553 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4554 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4555 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4556 | msg.rpc_argp = args; |
| 4557 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4558 | } |
| 4559 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4560 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4561 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4562 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4563 | const void *buf, size_t buflen, |
| 4564 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4565 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4566 | if (strcmp(key, "") != 0) |
| 4567 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4568 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4569 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4570 | } |
| 4571 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4572 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4573 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4574 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4575 | if (strcmp(key, "") != 0) |
| 4576 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4577 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4578 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4579 | } |
| 4580 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4581 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4582 | size_t list_len, const char *name, |
| 4583 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4584 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4585 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4586 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4587 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4588 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4589 | |
| 4590 | if (list && len <= list_len) |
| 4591 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4592 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4593 | } |
| 4594 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4595 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4596 | { |
| 4597 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4598 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4599 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4600 | return; |
| 4601 | |
| 4602 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4603 | NFS_ATTR_FATTR_NLINK; |
| 4604 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4605 | fattr->nlink = 2; |
| 4606 | } |
| 4607 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4608 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4609 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4610 | { |
| 4611 | struct nfs_server *server = NFS_SERVER(dir); |
| 4612 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4613 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4614 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4615 | }; |
| 4616 | struct nfs4_fs_locations_arg args = { |
| 4617 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4618 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4619 | .page = page, |
| 4620 | .bitmask = bitmask, |
| 4621 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4622 | struct nfs4_fs_locations_res res = { |
| 4623 | .fs_locations = fs_locations, |
| 4624 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4625 | struct rpc_message msg = { |
| 4626 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4627 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4628 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4629 | }; |
| 4630 | int status; |
| 4631 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4632 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4633 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4634 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4635 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4636 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4637 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4638 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4639 | return status; |
| 4640 | } |
| 4641 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame^] | 4642 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4643 | { |
| 4644 | int status; |
| 4645 | struct nfs4_secinfo_arg args = { |
| 4646 | .dir_fh = NFS_FH(dir), |
| 4647 | .name = name, |
| 4648 | }; |
| 4649 | struct nfs4_secinfo_res res = { |
| 4650 | .flavors = flavors, |
| 4651 | }; |
| 4652 | struct rpc_message msg = { |
| 4653 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4654 | .rpc_argp = &args, |
| 4655 | .rpc_resp = &res, |
| 4656 | }; |
| 4657 | |
| 4658 | dprintk("NFS call secinfo %s\n", name->name); |
| 4659 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4660 | dprintk("NFS reply secinfo: %d\n", status); |
| 4661 | return status; |
| 4662 | } |
| 4663 | |
| 4664 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4665 | { |
| 4666 | struct nfs4_exception exception = { }; |
| 4667 | int err; |
| 4668 | do { |
| 4669 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4670 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4671 | &exception); |
| 4672 | } while (exception.retry); |
| 4673 | return err; |
| 4674 | } |
| 4675 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4676 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4677 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4678 | * Check the exchange flags returned by the server for invalid flags, having |
| 4679 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4680 | * DS flags set. |
| 4681 | */ |
| 4682 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4683 | { |
| 4684 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4685 | goto out_inval; |
| 4686 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4687 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4688 | goto out_inval; |
| 4689 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4690 | goto out_inval; |
| 4691 | return NFS_OK; |
| 4692 | out_inval: |
| 4693 | return -NFS4ERR_INVAL; |
| 4694 | } |
| 4695 | |
| 4696 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4697 | * nfs4_proc_exchange_id() |
| 4698 | * |
| 4699 | * Since the clientid has expired, all compounds using sessions |
| 4700 | * associated with the stale clientid will be returning |
| 4701 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4702 | * be in some phase of session reset. |
| 4703 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4704 | 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] | 4705 | { |
| 4706 | nfs4_verifier verifier; |
| 4707 | struct nfs41_exchange_id_args args = { |
| 4708 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4709 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4710 | }; |
| 4711 | struct nfs41_exchange_id_res res = { |
| 4712 | .client = clp, |
| 4713 | }; |
| 4714 | int status; |
| 4715 | struct rpc_message msg = { |
| 4716 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4717 | .rpc_argp = &args, |
| 4718 | .rpc_resp = &res, |
| 4719 | .rpc_cred = cred, |
| 4720 | }; |
| 4721 | __be32 *p; |
| 4722 | |
| 4723 | dprintk("--> %s\n", __func__); |
| 4724 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4725 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4726 | p = (u32 *)verifier.data; |
| 4727 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4728 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4729 | args.verifier = &verifier; |
| 4730 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4731 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4732 | "%s/%s.%s/%u", |
| 4733 | clp->cl_ipaddr, |
| 4734 | init_utsname()->nodename, |
| 4735 | init_utsname()->domainname, |
| 4736 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4737 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4738 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4739 | if (!status) |
| 4740 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4741 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4742 | return status; |
| 4743 | } |
| 4744 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4745 | struct nfs4_get_lease_time_data { |
| 4746 | struct nfs4_get_lease_time_args *args; |
| 4747 | struct nfs4_get_lease_time_res *res; |
| 4748 | struct nfs_client *clp; |
| 4749 | }; |
| 4750 | |
| 4751 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4752 | void *calldata) |
| 4753 | { |
| 4754 | int ret; |
| 4755 | struct nfs4_get_lease_time_data *data = |
| 4756 | (struct nfs4_get_lease_time_data *)calldata; |
| 4757 | |
| 4758 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4759 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4760 | /* just setup sequence, do not trigger session recovery |
| 4761 | since we're invoked within one */ |
| 4762 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4763 | &data->args->la_seq_args, |
| 4764 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4765 | |
| 4766 | BUG_ON(ret == -EAGAIN); |
| 4767 | rpc_call_start(task); |
| 4768 | dprintk("<-- %s\n", __func__); |
| 4769 | } |
| 4770 | |
| 4771 | /* |
| 4772 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4773 | * from sequence operation or clientid errors. |
| 4774 | */ |
| 4775 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4776 | { |
| 4777 | struct nfs4_get_lease_time_data *data = |
| 4778 | (struct nfs4_get_lease_time_data *)calldata; |
| 4779 | |
| 4780 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4781 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4782 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4783 | switch (task->tk_status) { |
| 4784 | case -NFS4ERR_DELAY: |
| 4785 | case -NFS4ERR_GRACE: |
| 4786 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4787 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4788 | task->tk_status = 0; |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4789 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4790 | return; |
| 4791 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4792 | dprintk("<-- %s\n", __func__); |
| 4793 | } |
| 4794 | |
| 4795 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4796 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4797 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4798 | }; |
| 4799 | |
| 4800 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4801 | { |
| 4802 | struct rpc_task *task; |
| 4803 | struct nfs4_get_lease_time_args args; |
| 4804 | struct nfs4_get_lease_time_res res = { |
| 4805 | .lr_fsinfo = fsinfo, |
| 4806 | }; |
| 4807 | struct nfs4_get_lease_time_data data = { |
| 4808 | .args = &args, |
| 4809 | .res = &res, |
| 4810 | .clp = clp, |
| 4811 | }; |
| 4812 | struct rpc_message msg = { |
| 4813 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4814 | .rpc_argp = &args, |
| 4815 | .rpc_resp = &res, |
| 4816 | }; |
| 4817 | struct rpc_task_setup task_setup = { |
| 4818 | .rpc_client = clp->cl_rpcclient, |
| 4819 | .rpc_message = &msg, |
| 4820 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4821 | .callback_data = &data |
| 4822 | }; |
| 4823 | int status; |
| 4824 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4825 | dprintk("--> %s\n", __func__); |
| 4826 | task = rpc_run_task(&task_setup); |
| 4827 | |
| 4828 | if (IS_ERR(task)) |
| 4829 | status = PTR_ERR(task); |
| 4830 | else { |
| 4831 | status = task->tk_status; |
| 4832 | rpc_put_task(task); |
| 4833 | } |
| 4834 | dprintk("<-- %s return %d\n", __func__, status); |
| 4835 | |
| 4836 | return status; |
| 4837 | } |
| 4838 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4839 | /* |
| 4840 | * Reset a slot table |
| 4841 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4842 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4843 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4844 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4845 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4846 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4847 | int ret = 0; |
| 4848 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4849 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4850 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4851 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4852 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4853 | if (max_reqs != tbl->max_slots) { |
| 4854 | ret = -ENOMEM; |
| 4855 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4856 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4857 | if (!new) |
| 4858 | goto out; |
| 4859 | ret = 0; |
| 4860 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4861 | } |
| 4862 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4863 | if (new) { |
| 4864 | tbl->slots = new; |
| 4865 | tbl->max_slots = max_reqs; |
| 4866 | } |
| 4867 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4868 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4869 | spin_unlock(&tbl->slot_tbl_lock); |
| 4870 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4871 | tbl, tbl->slots, tbl->max_slots); |
| 4872 | out: |
| 4873 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4874 | return ret; |
| 4875 | } |
| 4876 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4877 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4878 | * Reset the forechannel and backchannel slot tables |
| 4879 | */ |
| 4880 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4881 | { |
| 4882 | int status; |
| 4883 | |
| 4884 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4885 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4886 | if (status) |
| 4887 | return status; |
| 4888 | |
| 4889 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4890 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4891 | return status; |
| 4892 | } |
| 4893 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4894 | /* Destroy the slot table */ |
| 4895 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4896 | { |
| 4897 | if (session->fc_slot_table.slots != NULL) { |
| 4898 | kfree(session->fc_slot_table.slots); |
| 4899 | session->fc_slot_table.slots = NULL; |
| 4900 | } |
| 4901 | if (session->bc_slot_table.slots != NULL) { |
| 4902 | kfree(session->bc_slot_table.slots); |
| 4903 | session->bc_slot_table.slots = NULL; |
| 4904 | } |
| 4905 | return; |
| 4906 | } |
| 4907 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4908 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4909 | * Initialize slot table |
| 4910 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4911 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4912 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4913 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4914 | struct nfs4_slot *slot; |
| 4915 | int ret = -ENOMEM; |
| 4916 | |
| 4917 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4918 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4919 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4920 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4921 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4922 | if (!slot) |
| 4923 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4924 | ret = 0; |
| 4925 | |
| 4926 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4927 | tbl->max_slots = max_slots; |
| 4928 | tbl->slots = slot; |
| 4929 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4930 | spin_unlock(&tbl->slot_tbl_lock); |
| 4931 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4932 | tbl, tbl->slots, tbl->max_slots); |
| 4933 | out: |
| 4934 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4935 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4936 | } |
| 4937 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4938 | /* |
| 4939 | * Initialize the forechannel and backchannel tables |
| 4940 | */ |
| 4941 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4942 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4943 | struct nfs4_slot_table *tbl; |
| 4944 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4945 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4946 | tbl = &session->fc_slot_table; |
| 4947 | if (tbl->slots == NULL) { |
| 4948 | status = nfs4_init_slot_table(tbl, |
| 4949 | session->fc_attrs.max_reqs, 1); |
| 4950 | if (status) |
| 4951 | return status; |
| 4952 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4953 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4954 | tbl = &session->bc_slot_table; |
| 4955 | if (tbl->slots == NULL) { |
| 4956 | status = nfs4_init_slot_table(tbl, |
| 4957 | session->bc_attrs.max_reqs, 0); |
| 4958 | if (status) |
| 4959 | nfs4_destroy_slot_tables(session); |
| 4960 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4961 | |
| 4962 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4963 | } |
| 4964 | |
| 4965 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 4966 | { |
| 4967 | struct nfs4_session *session; |
| 4968 | struct nfs4_slot_table *tbl; |
| 4969 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4970 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4971 | if (!session) |
| 4972 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4973 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4974 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4975 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4976 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4977 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4978 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4979 | |
| 4980 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4981 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4982 | spin_lock_init(&tbl->slot_tbl_lock); |
| 4983 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4984 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4985 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 4986 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 4987 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4988 | session->clp = clp; |
| 4989 | return session; |
| 4990 | } |
| 4991 | |
| 4992 | void nfs4_destroy_session(struct nfs4_session *session) |
| 4993 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 4994 | nfs4_proc_destroy_session(session); |
| 4995 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 4996 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 4997 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 4998 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4999 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5000 | kfree(session); |
| 5001 | } |
| 5002 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5003 | /* |
| 5004 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5005 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5006 | * use them. |
| 5007 | * |
| 5008 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5009 | * always set csa_cachethis to FALSE because the current implementation |
| 5010 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5011 | */ |
| 5012 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5013 | { |
| 5014 | struct nfs4_session *session = args->client->cl_session; |
| 5015 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5016 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5017 | |
| 5018 | if (mxrqst_sz == 0) |
| 5019 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5020 | if (mxresp_sz == 0) |
| 5021 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5022 | /* Fore channel attributes */ |
| 5023 | args->fc_attrs.headerpadsz = 0; |
| 5024 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5025 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5026 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 5027 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 5028 | |
| 5029 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5030 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5031 | __func__, |
| 5032 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5033 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5034 | |
| 5035 | /* Back channel attributes */ |
| 5036 | args->bc_attrs.headerpadsz = 0; |
| 5037 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5038 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5039 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5040 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5041 | args->bc_attrs.max_reqs = 1; |
| 5042 | |
| 5043 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5044 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5045 | __func__, |
| 5046 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5047 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5048 | args->bc_attrs.max_reqs); |
| 5049 | } |
| 5050 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5051 | 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] | 5052 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5053 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5054 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5055 | |
| 5056 | if (rcvd->headerpadsz > sent->headerpadsz) |
| 5057 | return -EINVAL; |
| 5058 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5059 | return -EINVAL; |
| 5060 | /* |
| 5061 | * Our requested max_ops is the minimum we need; we're not |
| 5062 | * prepared to break up compounds into smaller pieces than that. |
| 5063 | * So, no point even trying to continue if the server won't |
| 5064 | * cooperate: |
| 5065 | */ |
| 5066 | if (rcvd->max_ops < sent->max_ops) |
| 5067 | return -EINVAL; |
| 5068 | if (rcvd->max_reqs == 0) |
| 5069 | return -EINVAL; |
| 5070 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5071 | } |
| 5072 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5073 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5074 | { |
| 5075 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5076 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5077 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5078 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5079 | return -EINVAL; |
| 5080 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5081 | return -EINVAL; |
| 5082 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5083 | return -EINVAL; |
| 5084 | /* These would render the backchannel useless: */ |
| 5085 | if (rcvd->max_ops == 0) |
| 5086 | return -EINVAL; |
| 5087 | if (rcvd->max_reqs == 0) |
| 5088 | return -EINVAL; |
| 5089 | return 0; |
| 5090 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5091 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5092 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5093 | struct nfs4_session *session) |
| 5094 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5095 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5096 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5097 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5098 | if (ret) |
| 5099 | return ret; |
| 5100 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5101 | } |
| 5102 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5103 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5104 | { |
| 5105 | struct nfs4_session *session = clp->cl_session; |
| 5106 | struct nfs41_create_session_args args = { |
| 5107 | .client = clp, |
| 5108 | .cb_program = NFS4_CALLBACK, |
| 5109 | }; |
| 5110 | struct nfs41_create_session_res res = { |
| 5111 | .client = clp, |
| 5112 | }; |
| 5113 | struct rpc_message msg = { |
| 5114 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5115 | .rpc_argp = &args, |
| 5116 | .rpc_resp = &res, |
| 5117 | }; |
| 5118 | int status; |
| 5119 | |
| 5120 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5121 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5122 | |
| 5123 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5124 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5125 | if (!status) |
| 5126 | /* Verify the session's negotiated channel_attrs values */ |
| 5127 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5128 | if (!status) { |
| 5129 | /* Increment the clientid slot sequence id */ |
| 5130 | clp->cl_seqid++; |
| 5131 | } |
| 5132 | |
| 5133 | return status; |
| 5134 | } |
| 5135 | |
| 5136 | /* |
| 5137 | * Issues a CREATE_SESSION operation to the server. |
| 5138 | * It is the responsibility of the caller to verify the session is |
| 5139 | * expired before calling this routine. |
| 5140 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5141 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5142 | { |
| 5143 | int status; |
| 5144 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5145 | struct nfs4_session *session = clp->cl_session; |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5146 | long timeout = 0; |
| 5147 | int err; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5148 | |
| 5149 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5150 | |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5151 | do { |
| 5152 | status = _nfs4_proc_create_session(clp); |
| 5153 | if (status == -NFS4ERR_DELAY) { |
| 5154 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 5155 | if (err) |
| 5156 | status = err; |
| 5157 | } |
| 5158 | } while (status == -NFS4ERR_DELAY); |
| 5159 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5160 | if (status) |
| 5161 | goto out; |
| 5162 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5163 | /* Init and reset the fore channel */ |
| 5164 | status = nfs4_init_slot_tables(session); |
| 5165 | dprintk("slot table initialization returned %d\n", status); |
| 5166 | if (status) |
| 5167 | goto out; |
| 5168 | status = nfs4_reset_slot_tables(session); |
| 5169 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5170 | if (status) |
| 5171 | goto out; |
| 5172 | |
| 5173 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5174 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5175 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5176 | out: |
| 5177 | dprintk("<-- %s\n", __func__); |
| 5178 | return status; |
| 5179 | } |
| 5180 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5181 | /* |
| 5182 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5183 | * The caller must serialize access to this routine. |
| 5184 | */ |
| 5185 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5186 | { |
| 5187 | int status = 0; |
| 5188 | struct rpc_message msg; |
| 5189 | |
| 5190 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5191 | |
| 5192 | /* session is still being setup */ |
| 5193 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5194 | return status; |
| 5195 | |
| 5196 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5197 | msg.rpc_argp = session; |
| 5198 | msg.rpc_resp = NULL; |
| 5199 | msg.rpc_cred = NULL; |
| 5200 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5201 | |
| 5202 | if (status) |
| 5203 | printk(KERN_WARNING |
| 5204 | "Got error %d from the server on DESTROY_SESSION. " |
| 5205 | "Session has been destroyed regardless...\n", status); |
| 5206 | |
| 5207 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5208 | return status; |
| 5209 | } |
| 5210 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5211 | int nfs4_init_session(struct nfs_server *server) |
| 5212 | { |
| 5213 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5214 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5215 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5216 | int ret; |
| 5217 | |
| 5218 | if (!nfs4_has_session(clp)) |
| 5219 | return 0; |
| 5220 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5221 | session = clp->cl_session; |
| 5222 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5223 | return 0; |
| 5224 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5225 | rsize = server->rsize; |
| 5226 | if (rsize == 0) |
| 5227 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5228 | wsize = server->wsize; |
| 5229 | if (wsize == 0) |
| 5230 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5231 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5232 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5233 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5234 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5235 | ret = nfs4_recover_expired_lease(server); |
| 5236 | if (!ret) |
| 5237 | ret = nfs4_check_client_ready(clp); |
| 5238 | return ret; |
| 5239 | } |
| 5240 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5241 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5242 | { |
| 5243 | struct nfs4_session *session = clp->cl_session; |
| 5244 | int ret; |
| 5245 | |
| 5246 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5247 | return 0; |
| 5248 | |
| 5249 | ret = nfs4_client_recover_expired_lease(clp); |
| 5250 | if (!ret) |
| 5251 | /* Test for the DS role */ |
| 5252 | if (!is_ds_client(clp)) |
| 5253 | ret = -ENODEV; |
| 5254 | if (!ret) |
| 5255 | ret = nfs4_check_client_ready(clp); |
| 5256 | return ret; |
| 5257 | |
| 5258 | } |
| 5259 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5260 | |
| 5261 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5262 | /* |
| 5263 | * Renew the cl_session lease. |
| 5264 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5265 | struct nfs4_sequence_data { |
| 5266 | struct nfs_client *clp; |
| 5267 | struct nfs4_sequence_args args; |
| 5268 | struct nfs4_sequence_res res; |
| 5269 | }; |
| 5270 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5271 | static void nfs41_sequence_release(void *data) |
| 5272 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5273 | struct nfs4_sequence_data *calldata = data; |
| 5274 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5275 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5276 | if (atomic_read(&clp->cl_count) > 1) |
| 5277 | nfs4_schedule_state_renewal(clp); |
| 5278 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5279 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5280 | } |
| 5281 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5282 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5283 | { |
| 5284 | switch(task->tk_status) { |
| 5285 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5286 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5287 | return -EAGAIN; |
| 5288 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5289 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5290 | } |
| 5291 | return 0; |
| 5292 | } |
| 5293 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5294 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5295 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5296 | struct nfs4_sequence_data *calldata = data; |
| 5297 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5298 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5299 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5300 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5301 | |
| 5302 | if (task->tk_status < 0) { |
| 5303 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5304 | if (atomic_read(&clp->cl_count) == 1) |
| 5305 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5306 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5307 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5308 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5309 | return; |
| 5310 | } |
| 5311 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5312 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5313 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5314 | dprintk("<-- %s\n", __func__); |
| 5315 | } |
| 5316 | |
| 5317 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5318 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5319 | struct nfs4_sequence_data *calldata = data; |
| 5320 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5321 | struct nfs4_sequence_args *args; |
| 5322 | struct nfs4_sequence_res *res; |
| 5323 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5324 | args = task->tk_msg.rpc_argp; |
| 5325 | res = task->tk_msg.rpc_resp; |
| 5326 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5327 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5328 | return; |
| 5329 | rpc_call_start(task); |
| 5330 | } |
| 5331 | |
| 5332 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5333 | .rpc_call_done = nfs41_sequence_call_done, |
| 5334 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5335 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5336 | }; |
| 5337 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5338 | 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] | 5339 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5340 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5341 | struct rpc_message msg = { |
| 5342 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5343 | .rpc_cred = cred, |
| 5344 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5345 | struct rpc_task_setup task_setup_data = { |
| 5346 | .rpc_client = clp->cl_rpcclient, |
| 5347 | .rpc_message = &msg, |
| 5348 | .callback_ops = &nfs41_sequence_ops, |
| 5349 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5350 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5351 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5352 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5353 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5354 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5355 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5356 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5357 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5358 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5359 | msg.rpc_argp = &calldata->args; |
| 5360 | msg.rpc_resp = &calldata->res; |
| 5361 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5362 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5363 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5364 | return rpc_run_task(&task_setup_data); |
| 5365 | } |
| 5366 | |
| 5367 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5368 | { |
| 5369 | struct rpc_task *task; |
| 5370 | int ret = 0; |
| 5371 | |
| 5372 | task = _nfs41_proc_sequence(clp, cred); |
| 5373 | if (IS_ERR(task)) |
| 5374 | ret = PTR_ERR(task); |
| 5375 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5376 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5377 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5378 | return ret; |
| 5379 | } |
| 5380 | |
| 5381 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5382 | { |
| 5383 | struct rpc_task *task; |
| 5384 | int ret; |
| 5385 | |
| 5386 | task = _nfs41_proc_sequence(clp, cred); |
| 5387 | if (IS_ERR(task)) { |
| 5388 | ret = PTR_ERR(task); |
| 5389 | goto out; |
| 5390 | } |
| 5391 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5392 | if (!ret) { |
| 5393 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5394 | |
| 5395 | if (task->tk_status == 0) |
| 5396 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5397 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5398 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5399 | rpc_put_task(task); |
| 5400 | out: |
| 5401 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5402 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5403 | } |
| 5404 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5405 | struct nfs4_reclaim_complete_data { |
| 5406 | struct nfs_client *clp; |
| 5407 | struct nfs41_reclaim_complete_args arg; |
| 5408 | struct nfs41_reclaim_complete_res res; |
| 5409 | }; |
| 5410 | |
| 5411 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5412 | { |
| 5413 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5414 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5415 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5416 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5417 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5418 | &calldata->res.seq_res, 0, task)) |
| 5419 | return; |
| 5420 | |
| 5421 | rpc_call_start(task); |
| 5422 | } |
| 5423 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5424 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5425 | { |
| 5426 | switch(task->tk_status) { |
| 5427 | case 0: |
| 5428 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5429 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5430 | break; |
| 5431 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5432 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5433 | return -EAGAIN; |
| 5434 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5435 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5436 | } |
| 5437 | return 0; |
| 5438 | } |
| 5439 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5440 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5441 | { |
| 5442 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5443 | struct nfs_client *clp = calldata->clp; |
| 5444 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5445 | |
| 5446 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5447 | if (!nfs41_sequence_done(task, res)) |
| 5448 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5449 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5450 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5451 | rpc_restart_call_prepare(task); |
| 5452 | return; |
| 5453 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5454 | dprintk("<-- %s\n", __func__); |
| 5455 | } |
| 5456 | |
| 5457 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5458 | { |
| 5459 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5460 | |
| 5461 | kfree(calldata); |
| 5462 | } |
| 5463 | |
| 5464 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5465 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5466 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5467 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5468 | }; |
| 5469 | |
| 5470 | /* |
| 5471 | * Issue a global reclaim complete. |
| 5472 | */ |
| 5473 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5474 | { |
| 5475 | struct nfs4_reclaim_complete_data *calldata; |
| 5476 | struct rpc_task *task; |
| 5477 | struct rpc_message msg = { |
| 5478 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5479 | }; |
| 5480 | struct rpc_task_setup task_setup_data = { |
| 5481 | .rpc_client = clp->cl_rpcclient, |
| 5482 | .rpc_message = &msg, |
| 5483 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5484 | .flags = RPC_TASK_ASYNC, |
| 5485 | }; |
| 5486 | int status = -ENOMEM; |
| 5487 | |
| 5488 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5489 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5490 | if (calldata == NULL) |
| 5491 | goto out; |
| 5492 | calldata->clp = clp; |
| 5493 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5494 | |
| 5495 | msg.rpc_argp = &calldata->arg; |
| 5496 | msg.rpc_resp = &calldata->res; |
| 5497 | task_setup_data.callback_data = calldata; |
| 5498 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5499 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5500 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5501 | goto out; |
| 5502 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5503 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5504 | if (status == 0) |
| 5505 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5506 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5507 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5508 | out: |
| 5509 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5510 | return status; |
| 5511 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5512 | |
| 5513 | static void |
| 5514 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5515 | { |
| 5516 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5517 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5518 | |
| 5519 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5520 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5521 | * right now covering the LAYOUTGET we are about to send. |
| 5522 | * However, that is not so catastrophic, and there seems |
| 5523 | * to be no way to prevent it completely. |
| 5524 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5525 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5526 | &lgp->res.seq_res, 0, task)) |
| 5527 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5528 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5529 | NFS_I(lgp->args.inode)->layout, |
| 5530 | lgp->args.ctx->state)) { |
| 5531 | rpc_exit(task, NFS4_OK); |
| 5532 | return; |
| 5533 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5534 | rpc_call_start(task); |
| 5535 | } |
| 5536 | |
| 5537 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5538 | { |
| 5539 | struct nfs4_layoutget *lgp = calldata; |
| 5540 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5541 | |
| 5542 | dprintk("--> %s\n", __func__); |
| 5543 | |
| 5544 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5545 | return; |
| 5546 | |
| 5547 | switch (task->tk_status) { |
| 5548 | case 0: |
| 5549 | break; |
| 5550 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5551 | case -NFS4ERR_RECALLCONFLICT: |
| 5552 | task->tk_status = -NFS4ERR_DELAY; |
| 5553 | /* Fall through */ |
| 5554 | default: |
| 5555 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5556 | rpc_restart_call_prepare(task); |
| 5557 | return; |
| 5558 | } |
| 5559 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5560 | dprintk("<-- %s\n", __func__); |
| 5561 | } |
| 5562 | |
| 5563 | static void nfs4_layoutget_release(void *calldata) |
| 5564 | { |
| 5565 | struct nfs4_layoutget *lgp = calldata; |
| 5566 | |
| 5567 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5568 | if (lgp->res.layout.buf != NULL) |
| 5569 | free_page((unsigned long) lgp->res.layout.buf); |
| 5570 | put_nfs_open_context(lgp->args.ctx); |
| 5571 | kfree(calldata); |
| 5572 | dprintk("<-- %s\n", __func__); |
| 5573 | } |
| 5574 | |
| 5575 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5576 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5577 | .rpc_call_done = nfs4_layoutget_done, |
| 5578 | .rpc_release = nfs4_layoutget_release, |
| 5579 | }; |
| 5580 | |
| 5581 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5582 | { |
| 5583 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5584 | struct rpc_task *task; |
| 5585 | struct rpc_message msg = { |
| 5586 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5587 | .rpc_argp = &lgp->args, |
| 5588 | .rpc_resp = &lgp->res, |
| 5589 | }; |
| 5590 | struct rpc_task_setup task_setup_data = { |
| 5591 | .rpc_client = server->client, |
| 5592 | .rpc_message = &msg, |
| 5593 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5594 | .callback_data = lgp, |
| 5595 | .flags = RPC_TASK_ASYNC, |
| 5596 | }; |
| 5597 | int status = 0; |
| 5598 | |
| 5599 | dprintk("--> %s\n", __func__); |
| 5600 | |
| 5601 | lgp->res.layout.buf = (void *)__get_free_page(GFP_NOFS); |
| 5602 | if (lgp->res.layout.buf == NULL) { |
| 5603 | nfs4_layoutget_release(lgp); |
| 5604 | return -ENOMEM; |
| 5605 | } |
| 5606 | |
| 5607 | lgp->res.seq_res.sr_slot = NULL; |
| 5608 | task = rpc_run_task(&task_setup_data); |
| 5609 | if (IS_ERR(task)) |
| 5610 | return PTR_ERR(task); |
| 5611 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5612 | if (status == 0) |
| 5613 | status = task->tk_status; |
| 5614 | if (status == 0) |
| 5615 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5616 | rpc_put_task(task); |
| 5617 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5618 | return status; |
| 5619 | } |
| 5620 | |
| 5621 | static int |
| 5622 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5623 | { |
| 5624 | struct nfs4_getdeviceinfo_args args = { |
| 5625 | .pdev = pdev, |
| 5626 | }; |
| 5627 | struct nfs4_getdeviceinfo_res res = { |
| 5628 | .pdev = pdev, |
| 5629 | }; |
| 5630 | struct rpc_message msg = { |
| 5631 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5632 | .rpc_argp = &args, |
| 5633 | .rpc_resp = &res, |
| 5634 | }; |
| 5635 | int status; |
| 5636 | |
| 5637 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5638 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5639 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5640 | |
| 5641 | return status; |
| 5642 | } |
| 5643 | |
| 5644 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5645 | { |
| 5646 | struct nfs4_exception exception = { }; |
| 5647 | int err; |
| 5648 | |
| 5649 | do { |
| 5650 | err = nfs4_handle_exception(server, |
| 5651 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5652 | &exception); |
| 5653 | } while (exception.retry); |
| 5654 | return err; |
| 5655 | } |
| 5656 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5657 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5658 | #endif /* CONFIG_NFS_V4_1 */ |
| 5659 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5660 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5661 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5662 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5663 | .recover_open = nfs4_open_reclaim, |
| 5664 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5665 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5666 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | }; |
| 5668 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5669 | #if defined(CONFIG_NFS_V4_1) |
| 5670 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5671 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5672 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5673 | .recover_open = nfs4_open_reclaim, |
| 5674 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5675 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5676 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5677 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5678 | }; |
| 5679 | #endif /* CONFIG_NFS_V4_1 */ |
| 5680 | |
| 5681 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5682 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5683 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 | .recover_open = nfs4_open_expired, |
| 5685 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5686 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5687 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5688 | }; |
| 5689 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5690 | #if defined(CONFIG_NFS_V4_1) |
| 5691 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5692 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5693 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5694 | .recover_open = nfs4_open_expired, |
| 5695 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5696 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5697 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5698 | }; |
| 5699 | #endif /* CONFIG_NFS_V4_1 */ |
| 5700 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5701 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5702 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5703 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5704 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5705 | }; |
| 5706 | |
| 5707 | #if defined(CONFIG_NFS_V4_1) |
| 5708 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5709 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5710 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5711 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5712 | }; |
| 5713 | #endif |
| 5714 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5715 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 5716 | .minor_version = 0, |
| 5717 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5718 | .validate_stateid = nfs4_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5719 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 5720 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 5721 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5722 | }; |
| 5723 | |
| 5724 | #if defined(CONFIG_NFS_V4_1) |
| 5725 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 5726 | .minor_version = 1, |
| 5727 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5728 | .validate_stateid = nfs41_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5729 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 5730 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 5731 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5732 | }; |
| 5733 | #endif |
| 5734 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5735 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 5736 | [0] = &nfs_v4_0_minor_ops, |
| 5737 | #if defined(CONFIG_NFS_V4_1) |
| 5738 | [1] = &nfs_v4_1_minor_ops, |
| 5739 | #endif |
| 5740 | }; |
| 5741 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5742 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5743 | .permission = nfs_permission, |
| 5744 | .getattr = nfs_getattr, |
| 5745 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5746 | .getxattr = generic_getxattr, |
| 5747 | .setxattr = generic_setxattr, |
| 5748 | .listxattr = generic_listxattr, |
| 5749 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5750 | }; |
| 5751 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5752 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5753 | .version = 4, /* protocol version */ |
| 5754 | .dentry_ops = &nfs4_dentry_operations, |
| 5755 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5756 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5757 | .getroot = nfs4_proc_get_root, |
| 5758 | .getattr = nfs4_proc_getattr, |
| 5759 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5760 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5761 | .lookup = nfs4_proc_lookup, |
| 5762 | .access = nfs4_proc_access, |
| 5763 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | .create = nfs4_proc_create, |
| 5765 | .remove = nfs4_proc_remove, |
| 5766 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5767 | .unlink_done = nfs4_proc_unlink_done, |
| 5768 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 5769 | .rename_setup = nfs4_proc_rename_setup, |
| 5770 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | .link = nfs4_proc_link, |
| 5772 | .symlink = nfs4_proc_symlink, |
| 5773 | .mkdir = nfs4_proc_mkdir, |
| 5774 | .rmdir = nfs4_proc_remove, |
| 5775 | .readdir = nfs4_proc_readdir, |
| 5776 | .mknod = nfs4_proc_mknod, |
| 5777 | .statfs = nfs4_proc_statfs, |
| 5778 | .fsinfo = nfs4_proc_fsinfo, |
| 5779 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5780 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5781 | .decode_dirent = nfs4_decode_dirent, |
| 5782 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5783 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5785 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5786 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5787 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5788 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5789 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5790 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 5791 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 5792 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame^] | 5793 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | }; |
| 5795 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5796 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 5797 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 5798 | .list = nfs4_xattr_list_nfs4_acl, |
| 5799 | .get = nfs4_xattr_get_nfs4_acl, |
| 5800 | .set = nfs4_xattr_set_nfs4_acl, |
| 5801 | }; |
| 5802 | |
| 5803 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 5804 | &nfs4_xattr_nfs4_acl_handler, |
| 5805 | NULL |
| 5806 | }; |
| 5807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | /* |
| 5809 | * Local variables: |
| 5810 | * c-basic-offset: 8 |
| 5811 | * End: |
| 5812 | */ |