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> |
| 42 | #include <linux/sunrpc/clnt.h> |
| 43 | #include <linux/nfs.h> |
| 44 | #include <linux/nfs4.h> |
| 45 | #include <linux/nfs_fs.h> |
| 46 | #include <linux/nfs_page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 48 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 49 | #include <linux/module.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 50 | #include <linux/sunrpc/bc_xprt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 52 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 54 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 55 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 56 | #include "callback.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 59 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 60 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 62 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 63 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 64 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 65 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 66 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 67 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | 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] | 69 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 70 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
| 71 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 74 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 76 | if (err >= -1000) |
| 77 | return err; |
| 78 | switch (err) { |
| 79 | case -NFS4ERR_RESOURCE: |
| 80 | return -EREMOTEIO; |
| 81 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 83 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 84 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 86 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* |
| 90 | * This is our standard bitmap for GETATTR requests. |
| 91 | */ |
| 92 | const u32 nfs4_fattr_bitmap[2] = { |
| 93 | FATTR4_WORD0_TYPE |
| 94 | | FATTR4_WORD0_CHANGE |
| 95 | | FATTR4_WORD0_SIZE |
| 96 | | FATTR4_WORD0_FSID |
| 97 | | FATTR4_WORD0_FILEID, |
| 98 | FATTR4_WORD1_MODE |
| 99 | | FATTR4_WORD1_NUMLINKS |
| 100 | | FATTR4_WORD1_OWNER |
| 101 | | FATTR4_WORD1_OWNER_GROUP |
| 102 | | FATTR4_WORD1_RAWDEV |
| 103 | | FATTR4_WORD1_SPACE_USED |
| 104 | | FATTR4_WORD1_TIME_ACCESS |
| 105 | | FATTR4_WORD1_TIME_METADATA |
| 106 | | FATTR4_WORD1_TIME_MODIFY |
| 107 | }; |
| 108 | |
| 109 | const u32 nfs4_statfs_bitmap[2] = { |
| 110 | FATTR4_WORD0_FILES_AVAIL |
| 111 | | FATTR4_WORD0_FILES_FREE |
| 112 | | FATTR4_WORD0_FILES_TOTAL, |
| 113 | FATTR4_WORD1_SPACE_AVAIL |
| 114 | | FATTR4_WORD1_SPACE_FREE |
| 115 | | FATTR4_WORD1_SPACE_TOTAL |
| 116 | }; |
| 117 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 118 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | FATTR4_WORD0_MAXLINK |
| 120 | | FATTR4_WORD0_MAXNAME, |
| 121 | 0 |
| 122 | }; |
| 123 | |
| 124 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 125 | | FATTR4_WORD0_MAXREAD |
| 126 | | FATTR4_WORD0_MAXWRITE |
| 127 | | FATTR4_WORD0_LEASE_TIME, |
| 128 | 0 |
| 129 | }; |
| 130 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 131 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 132 | FATTR4_WORD0_TYPE |
| 133 | | FATTR4_WORD0_CHANGE |
| 134 | | FATTR4_WORD0_SIZE |
| 135 | | FATTR4_WORD0_FSID |
| 136 | | FATTR4_WORD0_FILEID |
| 137 | | FATTR4_WORD0_FS_LOCATIONS, |
| 138 | FATTR4_WORD1_MODE |
| 139 | | FATTR4_WORD1_NUMLINKS |
| 140 | | FATTR4_WORD1_OWNER |
| 141 | | FATTR4_WORD1_OWNER_GROUP |
| 142 | | FATTR4_WORD1_RAWDEV |
| 143 | | FATTR4_WORD1_SPACE_USED |
| 144 | | FATTR4_WORD1_TIME_ACCESS |
| 145 | | FATTR4_WORD1_TIME_METADATA |
| 146 | | FATTR4_WORD1_TIME_MODIFY |
| 147 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 148 | }; |
| 149 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 150 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | struct nfs4_readdir_arg *readdir) |
| 152 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 153 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | BUG_ON(readdir->count < 80); |
| 156 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 157 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | readdir->cookie = 0; |
| 163 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 164 | if (cookie == 2) |
| 165 | return; |
| 166 | |
| 167 | /* |
| 168 | * NFSv4 servers do not return entries for '.' and '..' |
| 169 | * Therefore, we fake these entries here. We let '.' |
| 170 | * have cookie 0 and '..' have cookie 1. Note that |
| 171 | * when talking to the server, we always send cookie 0 |
| 172 | * instead of 1 or 2. |
| 173 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 174 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | if (cookie == 0) { |
| 177 | *p++ = xdr_one; /* next */ |
| 178 | *p++ = xdr_zero; /* cookie, first word */ |
| 179 | *p++ = xdr_one; /* cookie, second word */ |
| 180 | *p++ = xdr_one; /* entry len */ |
| 181 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 182 | p++; |
| 183 | *p++ = xdr_one; /* bitmap length */ |
| 184 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 185 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 186 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | *p++ = xdr_one; /* next */ |
| 190 | *p++ = xdr_zero; /* cookie, first word */ |
| 191 | *p++ = xdr_two; /* cookie, second word */ |
| 192 | *p++ = xdr_two; /* entry len */ |
| 193 | memcpy(p, "..\0\0", 4); /* entry */ |
| 194 | p++; |
| 195 | *p++ = xdr_one; /* bitmap length */ |
| 196 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 197 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 198 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | readdir->pgbase = (char *)p - (char *)start; |
| 201 | readdir->count -= readdir->pgbase; |
| 202 | kunmap_atomic(start, KM_USER0); |
| 203 | } |
| 204 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 205 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 206 | { |
| 207 | int res; |
| 208 | |
| 209 | might_sleep(); |
| 210 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 211 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 212 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 213 | return res; |
| 214 | } |
| 215 | |
| 216 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 217 | { |
| 218 | int res = 0; |
| 219 | |
| 220 | might_sleep(); |
| 221 | |
| 222 | if (*timeout <= 0) |
| 223 | *timeout = NFS4_POLL_RETRY_MIN; |
| 224 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 225 | *timeout = NFS4_POLL_RETRY_MAX; |
| 226 | schedule_timeout_killable(*timeout); |
| 227 | if (fatal_signal_pending(current)) |
| 228 | res = -ERESTARTSYS; |
| 229 | *timeout <<= 1; |
| 230 | return res; |
| 231 | } |
| 232 | |
| 233 | /* This is the error handling routine for processes that are allowed |
| 234 | * to sleep. |
| 235 | */ |
| 236 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 237 | { |
| 238 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 239 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 240 | int ret = errorcode; |
| 241 | |
| 242 | exception->retry = 0; |
| 243 | switch(errorcode) { |
| 244 | case 0: |
| 245 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 246 | case -NFS4ERR_ADMIN_REVOKED: |
| 247 | case -NFS4ERR_BAD_STATEID: |
| 248 | case -NFS4ERR_OPENMODE: |
| 249 | if (state == NULL) |
| 250 | break; |
| 251 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 252 | goto do_state_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 253 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 254 | if (state == NULL) |
| 255 | break; |
| 256 | nfs4_state_mark_reclaim_reboot(clp, state); |
| 257 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 258 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 259 | goto do_state_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 260 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 261 | case -NFS4ERR_BADSESSION: |
| 262 | case -NFS4ERR_BADSLOT: |
| 263 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 264 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 265 | case -NFS4ERR_DEADSESSION: |
| 266 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 267 | case -NFS4ERR_SEQ_MISORDERED: |
| 268 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 269 | errorcode); |
Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 270 | nfs4_schedule_state_recovery(clp); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 271 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 272 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 273 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 274 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 275 | if (exception->timeout > HZ) { |
| 276 | /* We have retried a decent amount, time to |
| 277 | * fail |
| 278 | */ |
| 279 | ret = -EBUSY; |
| 280 | break; |
| 281 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 282 | case -NFS4ERR_GRACE: |
| 283 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame^] | 284 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 285 | ret = nfs4_delay(server->client, &exception->timeout); |
| 286 | if (ret != 0) |
| 287 | break; |
| 288 | case -NFS4ERR_OLD_STATEID: |
| 289 | exception->retry = 1; |
| 290 | } |
| 291 | /* We failed to handle the error */ |
| 292 | return nfs4_map_errors(ret); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 293 | do_state_recovery: |
| 294 | nfs4_schedule_state_recovery(clp); |
| 295 | ret = nfs4_wait_clnt_recover(clp); |
| 296 | if (ret == 0) |
| 297 | exception->retry = 1; |
| 298 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 302 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 304 | struct nfs_client *clp = server->nfs_client; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | spin_lock(&clp->cl_lock); |
| 306 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 307 | clp->cl_last_renewal = timestamp; |
| 308 | spin_unlock(&clp->cl_lock); |
| 309 | } |
| 310 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 311 | #if defined(CONFIG_NFS_V4_1) |
| 312 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 313 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 314 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 315 | * |
| 316 | * freeing a slot is trivially done by clearing its respective bit |
| 317 | * in the bitmap. |
| 318 | * If the freed slotid equals highest_used_slotid we want to update it |
| 319 | * so that the server would be able to size down the slot table if needed, |
| 320 | * otherwise we know that the highest_used_slotid is still in use. |
| 321 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 322 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 323 | * highest slotid in use. |
| 324 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 325 | * |
| 326 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 327 | */ |
| 328 | static void |
| 329 | nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid) |
| 330 | { |
| 331 | int slotid = free_slotid; |
| 332 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 333 | /* clear used bit in bitmap */ |
| 334 | __clear_bit(slotid, tbl->used_slots); |
| 335 | |
| 336 | /* update highest_used_slotid when it is freed */ |
| 337 | if (slotid == tbl->highest_used_slotid) { |
| 338 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 339 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 340 | tbl->highest_used_slotid = slotid; |
| 341 | else |
| 342 | tbl->highest_used_slotid = -1; |
| 343 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 344 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 345 | free_slotid, tbl->highest_used_slotid); |
| 346 | } |
| 347 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 348 | /* |
| 349 | * Signal state manager thread if session is drained |
| 350 | */ |
| 351 | static void nfs41_check_drain_session_complete(struct nfs4_session *ses) |
| 352 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 353 | struct rpc_task *task; |
| 354 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 355 | if (!test_bit(NFS4CLNT_SESSION_DRAINING, &ses->clp->cl_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 356 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 357 | if (task) |
| 358 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 359 | return; |
| 360 | } |
| 361 | |
| 362 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 363 | return; |
| 364 | |
| 365 | dprintk("%s COMPLETE: Session Drained\n", __func__); |
| 366 | complete(&ses->complete); |
| 367 | } |
| 368 | |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 369 | static void nfs41_sequence_free_slot(const struct nfs_client *clp, |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 370 | struct nfs4_sequence_res *res) |
| 371 | { |
| 372 | struct nfs4_slot_table *tbl; |
| 373 | |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 374 | tbl = &clp->cl_session->fc_slot_table; |
| 375 | if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 376 | /* just wake up the next guy waiting since |
| 377 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 378 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 379 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 380 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 381 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 382 | spin_lock(&tbl->slot_tbl_lock); |
| 383 | nfs4_free_slot(tbl, res->sr_slotid); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 384 | nfs41_check_drain_session_complete(clp->cl_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 385 | spin_unlock(&tbl->slot_tbl_lock); |
| 386 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 387 | } |
| 388 | |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 389 | static void nfs41_sequence_done(struct nfs_client *clp, |
| 390 | struct nfs4_sequence_res *res, |
| 391 | int rpc_status) |
| 392 | { |
| 393 | unsigned long timestamp; |
| 394 | struct nfs4_slot_table *tbl; |
| 395 | struct nfs4_slot *slot; |
| 396 | |
| 397 | /* |
| 398 | * sr_status remains 1 if an RPC level error occurred. The server |
| 399 | * may or may not have processed the sequence operation.. |
| 400 | * Proceed as if the server received and processed the sequence |
| 401 | * operation. |
| 402 | */ |
| 403 | if (res->sr_status == 1) |
| 404 | res->sr_status = NFS_OK; |
| 405 | |
| 406 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
| 407 | if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) |
| 408 | goto out; |
| 409 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 410 | /* Check the SEQUENCE operation status */ |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 411 | if (res->sr_status == 0) { |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 412 | tbl = &clp->cl_session->fc_slot_table; |
| 413 | slot = tbl->slots + res->sr_slotid; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 414 | /* Update the slot's sequence and clientid lease timer */ |
| 415 | ++slot->seq_nr; |
| 416 | timestamp = res->sr_renewal_time; |
| 417 | spin_lock(&clp->cl_lock); |
| 418 | if (time_before(clp->cl_last_renewal, timestamp)) |
| 419 | clp->cl_last_renewal = timestamp; |
| 420 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 421 | /* Check sequence flags */ |
| 422 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 423 | } |
| 424 | out: |
| 425 | /* The session may be reset by one of the error handlers. */ |
| 426 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
| 427 | nfs41_sequence_free_slot(clp, res); |
| 428 | } |
| 429 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 430 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 431 | * nfs4_find_slot - efficiently look for a free slot |
| 432 | * |
| 433 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 434 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 435 | * and respectively set up the sequence operation args. |
| 436 | * 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] | 437 | * |
| 438 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 439 | */ |
| 440 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 441 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 442 | { |
| 443 | int slotid; |
| 444 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 445 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 446 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 447 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 448 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 449 | tbl->max_slots); |
| 450 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 451 | if (slotid >= tbl->max_slots) |
| 452 | goto out; |
| 453 | __set_bit(slotid, tbl->used_slots); |
| 454 | if (slotid > tbl->highest_used_slotid) |
| 455 | tbl->highest_used_slotid = slotid; |
| 456 | ret_id = slotid; |
| 457 | out: |
| 458 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 459 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 460 | return ret_id; |
| 461 | } |
| 462 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 463 | static int nfs41_setup_sequence(struct nfs4_session *session, |
| 464 | struct nfs4_sequence_args *args, |
| 465 | struct nfs4_sequence_res *res, |
| 466 | int cache_reply, |
| 467 | struct rpc_task *task) |
| 468 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 469 | struct nfs4_slot *slot; |
| 470 | struct nfs4_slot_table *tbl; |
| 471 | u8 slotid; |
| 472 | |
| 473 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 474 | /* slot already allocated? */ |
| 475 | if (res->sr_slotid != NFS4_MAX_SLOT_TABLE) |
| 476 | return 0; |
| 477 | |
| 478 | memset(res, 0, sizeof(*res)); |
| 479 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 480 | tbl = &session->fc_slot_table; |
| 481 | |
| 482 | spin_lock(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 483 | if (test_bit(NFS4CLNT_SESSION_DRAINING, &session->clp->cl_state) && |
| 484 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 485 | /* |
| 486 | * The state manager will wait until the slot table is empty. |
| 487 | * Schedule the reset thread |
| 488 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 489 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 490 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 491 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 492 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 493 | } |
| 494 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 495 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 496 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 497 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 498 | spin_unlock(&tbl->slot_tbl_lock); |
| 499 | dprintk("%s enforce FIFO order\n", __func__); |
| 500 | return -EAGAIN; |
| 501 | } |
| 502 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 503 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 504 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 505 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 506 | spin_unlock(&tbl->slot_tbl_lock); |
| 507 | dprintk("<-- %s: no free slots\n", __func__); |
| 508 | return -EAGAIN; |
| 509 | } |
| 510 | spin_unlock(&tbl->slot_tbl_lock); |
| 511 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 512 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 513 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 514 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 515 | args->sa_slotid = slotid; |
| 516 | args->sa_cache_this = cache_reply; |
| 517 | |
| 518 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 519 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 520 | res->sr_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 521 | res->sr_slotid = slotid; |
| 522 | res->sr_renewal_time = jiffies; |
| 523 | /* |
| 524 | * sr_status is only set in decode_sequence, and so will remain |
| 525 | * set to 1 if an rpc level failure occurs. |
| 526 | */ |
| 527 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | int nfs4_setup_sequence(struct nfs_client *clp, |
| 532 | struct nfs4_sequence_args *args, |
| 533 | struct nfs4_sequence_res *res, |
| 534 | int cache_reply, |
| 535 | struct rpc_task *task) |
| 536 | { |
| 537 | int ret = 0; |
| 538 | |
| 539 | dprintk("--> %s clp %p session %p sr_slotid %d\n", |
| 540 | __func__, clp, clp->cl_session, res->sr_slotid); |
| 541 | |
| 542 | if (!nfs4_has_session(clp)) |
| 543 | goto out; |
| 544 | ret = nfs41_setup_sequence(clp->cl_session, args, res, cache_reply, |
| 545 | task); |
Andy Adamson | 2628edd | 2009-12-04 15:55:35 -0500 | [diff] [blame] | 546 | if (ret && ret != -EAGAIN) { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 547 | /* terminate rpc task */ |
| 548 | task->tk_status = ret; |
| 549 | task->tk_action = NULL; |
| 550 | } |
| 551 | out: |
| 552 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 553 | return ret; |
| 554 | } |
| 555 | |
| 556 | struct nfs41_call_sync_data { |
| 557 | struct nfs_client *clp; |
| 558 | struct nfs4_sequence_args *seq_args; |
| 559 | struct nfs4_sequence_res *seq_res; |
| 560 | int cache_reply; |
| 561 | }; |
| 562 | |
| 563 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 564 | { |
| 565 | struct nfs41_call_sync_data *data = calldata; |
| 566 | |
| 567 | dprintk("--> %s data->clp->cl_session %p\n", __func__, |
| 568 | data->clp->cl_session); |
| 569 | if (nfs4_setup_sequence(data->clp, data->seq_args, |
| 570 | data->seq_res, data->cache_reply, task)) |
| 571 | return; |
| 572 | rpc_call_start(task); |
| 573 | } |
| 574 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 575 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 576 | { |
| 577 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 578 | nfs41_call_sync_prepare(task, calldata); |
| 579 | } |
| 580 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 581 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 582 | { |
| 583 | struct nfs41_call_sync_data *data = calldata; |
| 584 | |
| 585 | nfs41_sequence_done(data->clp, data->seq_res, task->tk_status); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 586 | } |
| 587 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 588 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 589 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 590 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 591 | }; |
| 592 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 593 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 594 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 595 | .rpc_call_done = nfs41_call_sync_done, |
| 596 | }; |
| 597 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 598 | static int nfs4_call_sync_sequence(struct nfs_client *clp, |
| 599 | struct rpc_clnt *clnt, |
| 600 | struct rpc_message *msg, |
| 601 | struct nfs4_sequence_args *args, |
| 602 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 603 | int cache_reply, |
| 604 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 605 | { |
| 606 | int ret; |
| 607 | struct rpc_task *task; |
| 608 | struct nfs41_call_sync_data data = { |
| 609 | .clp = clp, |
| 610 | .seq_args = args, |
| 611 | .seq_res = res, |
| 612 | .cache_reply = cache_reply, |
| 613 | }; |
| 614 | struct rpc_task_setup task_setup = { |
| 615 | .rpc_client = clnt, |
| 616 | .rpc_message = msg, |
| 617 | .callback_ops = &nfs41_call_sync_ops, |
| 618 | .callback_data = &data |
| 619 | }; |
| 620 | |
| 621 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 622 | if (privileged) |
| 623 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 624 | task = rpc_run_task(&task_setup); |
| 625 | if (IS_ERR(task)) |
| 626 | ret = PTR_ERR(task); |
| 627 | else { |
| 628 | ret = task->tk_status; |
| 629 | rpc_put_task(task); |
| 630 | } |
| 631 | return ret; |
| 632 | } |
| 633 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 634 | int _nfs4_call_sync_session(struct nfs_server *server, |
| 635 | struct rpc_message *msg, |
| 636 | struct nfs4_sequence_args *args, |
| 637 | struct nfs4_sequence_res *res, |
| 638 | int cache_reply) |
| 639 | { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 640 | return nfs4_call_sync_sequence(server->nfs_client, server->client, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 641 | msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | #endif /* CONFIG_NFS_V4_1 */ |
| 645 | |
| 646 | int _nfs4_call_sync(struct nfs_server *server, |
| 647 | struct rpc_message *msg, |
| 648 | struct nfs4_sequence_args *args, |
| 649 | struct nfs4_sequence_res *res, |
| 650 | int cache_reply) |
| 651 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 652 | args->sa_session = res->sr_session = NULL; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 653 | return rpc_call_sync(server->client, msg, 0); |
| 654 | } |
| 655 | |
| 656 | #define nfs4_call_sync(server, msg, args, res, cache_reply) \ |
| 657 | (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \ |
| 658 | &(res)->seq_res, (cache_reply)) |
| 659 | |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 660 | static void nfs4_sequence_done(const struct nfs_server *server, |
| 661 | struct nfs4_sequence_res *res, int rpc_status) |
| 662 | { |
| 663 | #ifdef CONFIG_NFS_V4_1 |
| 664 | if (nfs4_has_session(server->nfs_client)) |
| 665 | nfs41_sequence_done(server->nfs_client, res, rpc_status); |
| 666 | #endif /* CONFIG_NFS_V4_1 */ |
| 667 | } |
| 668 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 669 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 671 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 673 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 674 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 675 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 676 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 677 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 678 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 681 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 682 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 683 | struct nfs_openargs o_arg; |
| 684 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 685 | struct nfs_open_confirmargs c_arg; |
| 686 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 687 | struct nfs_fattr f_attr; |
| 688 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 689 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 690 | struct dentry *dir; |
| 691 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 692 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 693 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 694 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 695 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 696 | int rpc_status; |
| 697 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 698 | }; |
| 699 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 700 | |
| 701 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 702 | { |
| 703 | p->o_res.f_attr = &p->f_attr; |
| 704 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 705 | p->o_res.seqid = p->o_arg.seqid; |
| 706 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 707 | p->o_res.server = p->o_arg.server; |
| 708 | nfs_fattr_init(&p->f_attr); |
| 709 | nfs_fattr_init(&p->dir_attr); |
Benny Halevy | 578e458 | 2009-06-18 22:01:23 -0400 | [diff] [blame] | 710 | p->o_res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 711 | } |
| 712 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 713 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 714 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 715 | const struct iattr *attrs) |
| 716 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 717 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 718 | struct inode *dir = parent->d_inode; |
| 719 | struct nfs_server *server = NFS_SERVER(dir); |
| 720 | struct nfs4_opendata *p; |
| 721 | |
| 722 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
| 723 | if (p == NULL) |
| 724 | goto err; |
| 725 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid); |
| 726 | if (p->o_arg.seqid == NULL) |
| 727 | goto err_free; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 728 | p->path.mnt = mntget(path->mnt); |
| 729 | p->path.dentry = dget(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 730 | p->dir = parent; |
| 731 | p->owner = sp; |
| 732 | atomic_inc(&sp->so_count); |
| 733 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 734 | p->o_arg.open_flags = flags; |
| 735 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 736 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 737 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 738 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 739 | p->o_arg.server = server; |
| 740 | p->o_arg.bitmask = server->attr_bitmask; |
| 741 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 742 | if (flags & O_EXCL) { |
Alexandros Batsakis | 4882ef7 | 2009-12-05 13:30:21 -0500 | [diff] [blame] | 743 | if (nfs4_has_persistent_session(server->nfs_client)) { |
| 744 | /* GUARDED */ |
| 745 | p->o_arg.u.attrs = &p->attrs; |
| 746 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
| 747 | } else { /* EXCLUSIVE4_1 */ |
| 748 | u32 *s = (u32 *) p->o_arg.u.verifier.data; |
| 749 | s[0] = jiffies; |
| 750 | s[1] = current->pid; |
| 751 | } |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 752 | } else if (flags & O_CREAT) { |
| 753 | p->o_arg.u.attrs = &p->attrs; |
| 754 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
| 755 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 756 | p->c_arg.fh = &p->o_res.fh; |
| 757 | p->c_arg.stateid = &p->o_res.stateid; |
| 758 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 759 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 760 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 761 | return p; |
| 762 | err_free: |
| 763 | kfree(p); |
| 764 | err: |
| 765 | dput(parent); |
| 766 | return NULL; |
| 767 | } |
| 768 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 769 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 770 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 771 | struct nfs4_opendata *p = container_of(kref, |
| 772 | struct nfs4_opendata, kref); |
| 773 | |
| 774 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 775 | if (p->state != NULL) |
| 776 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 777 | nfs4_put_state_owner(p->owner); |
| 778 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 779 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 780 | kfree(p); |
| 781 | } |
| 782 | |
| 783 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 784 | { |
| 785 | if (p != NULL) |
| 786 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 787 | } |
| 788 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 789 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 790 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 791 | int ret; |
| 792 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 793 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 794 | return ret; |
| 795 | } |
| 796 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 797 | 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] | 798 | { |
| 799 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 800 | |
| 801 | if (open_mode & O_EXCL) |
| 802 | goto out; |
| 803 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 804 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 805 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 806 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 807 | break; |
| 808 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 809 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 810 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 811 | break; |
| 812 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 813 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 814 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 815 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 816 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 817 | return ret; |
| 818 | } |
| 819 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 820 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 821 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 822 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 823 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 824 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 825 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 826 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 827 | return 1; |
| 828 | } |
| 829 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 830 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 831 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 832 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 833 | case FMODE_WRITE: |
| 834 | state->n_wronly++; |
| 835 | break; |
| 836 | case FMODE_READ: |
| 837 | state->n_rdonly++; |
| 838 | break; |
| 839 | case FMODE_READ|FMODE_WRITE: |
| 840 | state->n_rdwr++; |
| 841 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 842 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 843 | } |
| 844 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 845 | 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] | 846 | { |
| 847 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 848 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 849 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 850 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 851 | case FMODE_READ: |
| 852 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 853 | break; |
| 854 | case FMODE_WRITE: |
| 855 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 856 | break; |
| 857 | case FMODE_READ|FMODE_WRITE: |
| 858 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 859 | } |
| 860 | } |
| 861 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 862 | 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] | 863 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 864 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 865 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 866 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 867 | } |
| 868 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 869 | 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] | 870 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 871 | /* |
| 872 | * Protect the call to nfs4_state_set_mode_locked and |
| 873 | * serialise the stateid update |
| 874 | */ |
| 875 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 876 | if (deleg_stateid != NULL) { |
| 877 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 878 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 879 | } |
| 880 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 881 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 882 | write_sequnlock(&state->seqlock); |
| 883 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 884 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 885 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 888 | 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] | 889 | { |
| 890 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 891 | struct nfs_delegation *deleg_cur; |
| 892 | int ret = 0; |
| 893 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 894 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 895 | |
| 896 | rcu_read_lock(); |
| 897 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 898 | if (deleg_cur == NULL) |
| 899 | goto no_delegation; |
| 900 | |
| 901 | spin_lock(&deleg_cur->lock); |
| 902 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 903 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 904 | goto no_delegation_unlock; |
| 905 | |
| 906 | if (delegation == NULL) |
| 907 | delegation = &deleg_cur->stateid; |
| 908 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 909 | goto no_delegation_unlock; |
| 910 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 911 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 912 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 913 | ret = 1; |
| 914 | no_delegation_unlock: |
| 915 | spin_unlock(&deleg_cur->lock); |
| 916 | no_delegation: |
| 917 | rcu_read_unlock(); |
| 918 | |
| 919 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 921 | ret = 1; |
| 922 | } |
| 923 | |
| 924 | return ret; |
| 925 | } |
| 926 | |
| 927 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 928 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 929 | { |
| 930 | struct nfs_delegation *delegation; |
| 931 | |
| 932 | rcu_read_lock(); |
| 933 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 934 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 935 | rcu_read_unlock(); |
| 936 | return; |
| 937 | } |
| 938 | rcu_read_unlock(); |
| 939 | nfs_inode_return_delegation(inode); |
| 940 | } |
| 941 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 942 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 943 | { |
| 944 | struct nfs4_state *state = opendata->state; |
| 945 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 946 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 948 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 949 | nfs4_stateid stateid; |
| 950 | int ret = -EAGAIN; |
| 951 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 952 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 953 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 954 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 955 | if (can_open_cached(state, fmode, open_mode)) { |
| 956 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 957 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 958 | goto out_return_state; |
| 959 | } |
| 960 | spin_unlock(&state->owner->so_lock); |
| 961 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 962 | rcu_read_lock(); |
| 963 | delegation = rcu_dereference(nfsi->delegation); |
| 964 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 965 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 966 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 967 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 968 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 969 | /* Save the delegation */ |
| 970 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 971 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 972 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 973 | if (ret != 0) |
| 974 | goto out; |
| 975 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 976 | |
| 977 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 978 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 979 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 980 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 981 | out: |
| 982 | return ERR_PTR(ret); |
| 983 | out_return_state: |
| 984 | atomic_inc(&state->count); |
| 985 | return state; |
| 986 | } |
| 987 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 988 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 989 | { |
| 990 | struct inode *inode; |
| 991 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 992 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 993 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 994 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 995 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 996 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 997 | goto out; |
| 998 | } |
| 999 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1000 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1001 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1002 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1003 | 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] | 1004 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1005 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1006 | goto err; |
| 1007 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1008 | state = nfs4_get_open_state(inode, data->owner); |
| 1009 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1010 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1011 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1012 | int delegation_flags = 0; |
| 1013 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1014 | rcu_read_lock(); |
| 1015 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1016 | if (delegation) |
| 1017 | delegation_flags = delegation->flags; |
| 1018 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1019 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1020 | nfs_inode_set_delegation(state->inode, |
| 1021 | data->owner->so_cred, |
| 1022 | &data->o_res); |
| 1023 | else |
| 1024 | nfs_inode_reclaim_delegation(state->inode, |
| 1025 | data->owner->so_cred, |
| 1026 | &data->o_res); |
| 1027 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1028 | |
| 1029 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1030 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1031 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1032 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1033 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1034 | err_put_inode: |
| 1035 | iput(inode); |
| 1036 | err: |
| 1037 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1038 | } |
| 1039 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1040 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1041 | { |
| 1042 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1043 | struct nfs_open_context *ctx; |
| 1044 | |
| 1045 | spin_lock(&state->inode->i_lock); |
| 1046 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1047 | if (ctx->state != state) |
| 1048 | continue; |
| 1049 | get_nfs_open_context(ctx); |
| 1050 | spin_unlock(&state->inode->i_lock); |
| 1051 | return ctx; |
| 1052 | } |
| 1053 | spin_unlock(&state->inode->i_lock); |
| 1054 | return ERR_PTR(-ENOENT); |
| 1055 | } |
| 1056 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1057 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1058 | { |
| 1059 | struct nfs4_opendata *opendata; |
| 1060 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1061 | opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1062 | if (opendata == NULL) |
| 1063 | return ERR_PTR(-ENOMEM); |
| 1064 | opendata->state = state; |
| 1065 | atomic_inc(&state->count); |
| 1066 | return opendata; |
| 1067 | } |
| 1068 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1069 | 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] | 1070 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1071 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1072 | int ret; |
| 1073 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1074 | opendata->o_arg.open_flags = 0; |
| 1075 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1076 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1077 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1078 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1079 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1080 | if (ret != 0) |
| 1081 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1082 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1083 | if (IS_ERR(newstate)) |
| 1084 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1085 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1086 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1091 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1092 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1093 | int ret; |
| 1094 | |
| 1095 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1096 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1097 | smp_rmb(); |
| 1098 | if (state->n_rdwr != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1099 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1100 | if (ret != 0) |
| 1101 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1102 | if (newstate != state) |
| 1103 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1104 | } |
| 1105 | if (state->n_wronly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1106 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1107 | if (ret != 0) |
| 1108 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1109 | if (newstate != state) |
| 1110 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1111 | } |
| 1112 | if (state->n_rdonly != 0) { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1113 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1114 | if (ret != 0) |
| 1115 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1116 | if (newstate != state) |
| 1117 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1118 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1119 | /* |
| 1120 | * We may have performed cached opens for all three recoveries. |
| 1121 | * Check if we need to update the current stateid. |
| 1122 | */ |
| 1123 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1124 | 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] | 1125 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1126 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1127 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1128 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1129 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1130 | return 0; |
| 1131 | } |
| 1132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | /* |
| 1134 | * OPEN_RECLAIM: |
| 1135 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1137 | 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] | 1138 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1139 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1140 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1141 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | int status; |
| 1143 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1144 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1145 | if (IS_ERR(opendata)) |
| 1146 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1147 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1148 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1149 | rcu_read_lock(); |
| 1150 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1151 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1152 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1153 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1154 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1155 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1156 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | return status; |
| 1158 | } |
| 1159 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1160 | 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] | 1161 | { |
| 1162 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1163 | struct nfs4_exception exception = { }; |
| 1164 | int err; |
| 1165 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1166 | err = _nfs4_do_open_reclaim(ctx, state); |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame^] | 1167 | if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1168 | break; |
| 1169 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } while (exception.retry); |
| 1171 | return err; |
| 1172 | } |
| 1173 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1174 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1175 | { |
| 1176 | struct nfs_open_context *ctx; |
| 1177 | int ret; |
| 1178 | |
| 1179 | ctx = nfs4_state_find_open_context(state); |
| 1180 | if (IS_ERR(ctx)) |
| 1181 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1182 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1183 | put_nfs_open_context(ctx); |
| 1184 | return ret; |
| 1185 | } |
| 1186 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1187 | 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] | 1188 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1189 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1190 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1192 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1193 | if (IS_ERR(opendata)) |
| 1194 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1195 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1196 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1197 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1198 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1199 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1200 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1203 | 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] | 1204 | { |
| 1205 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1206 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | int err; |
| 1208 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1209 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | switch (err) { |
| 1211 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1212 | case -ENOENT: |
| 1213 | case -ESTALE: |
| 1214 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1215 | case -NFS4ERR_BADSESSION: |
| 1216 | case -NFS4ERR_BADSLOT: |
| 1217 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1218 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1219 | case -NFS4ERR_DEADSESSION: |
| 1220 | nfs4_schedule_state_recovery( |
| 1221 | server->nfs_client); |
| 1222 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | case -NFS4ERR_STALE_CLIENTID: |
| 1224 | case -NFS4ERR_STALE_STATEID: |
| 1225 | case -NFS4ERR_EXPIRED: |
| 1226 | /* Don't recall a delegation if it was lost */ |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1227 | nfs4_schedule_state_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1228 | goto out; |
| 1229 | case -ERESTARTSYS: |
| 1230 | /* |
| 1231 | * The show must go on: exit, but mark the |
| 1232 | * stateid as needing recovery. |
| 1233 | */ |
| 1234 | case -NFS4ERR_ADMIN_REVOKED: |
| 1235 | case -NFS4ERR_BAD_STATEID: |
| 1236 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
| 1237 | case -ENOMEM: |
| 1238 | err = 0; |
| 1239 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | } |
| 1241 | err = nfs4_handle_exception(server, err, &exception); |
| 1242 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1243 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | return err; |
| 1245 | } |
| 1246 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1247 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1248 | { |
| 1249 | struct nfs4_opendata *data = calldata; |
| 1250 | |
| 1251 | data->rpc_status = task->tk_status; |
| 1252 | if (RPC_ASSASSINATED(task)) |
| 1253 | return; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1254 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1255 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1256 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1257 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1258 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1259 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1260 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | static void nfs4_open_confirm_release(void *calldata) |
| 1264 | { |
| 1265 | struct nfs4_opendata *data = calldata; |
| 1266 | struct nfs4_state *state = NULL; |
| 1267 | |
| 1268 | /* If this request hasn't been cancelled, do nothing */ |
| 1269 | if (data->cancelled == 0) |
| 1270 | goto out_free; |
| 1271 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1272 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1273 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1274 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1275 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1276 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1277 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1278 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1282 | .rpc_call_done = nfs4_open_confirm_done, |
| 1283 | .rpc_release = nfs4_open_confirm_release, |
| 1284 | }; |
| 1285 | |
| 1286 | /* |
| 1287 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1288 | */ |
| 1289 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1290 | { |
| 1291 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1292 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1293 | struct rpc_message msg = { |
| 1294 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1295 | .rpc_argp = &data->c_arg, |
| 1296 | .rpc_resp = &data->c_res, |
| 1297 | .rpc_cred = data->owner->so_cred, |
| 1298 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1299 | struct rpc_task_setup task_setup_data = { |
| 1300 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1301 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1302 | .callback_ops = &nfs4_open_confirm_ops, |
| 1303 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1304 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1305 | .flags = RPC_TASK_ASYNC, |
| 1306 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | int status; |
| 1308 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1309 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1310 | data->rpc_done = 0; |
| 1311 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1312 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1313 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1314 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1315 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1316 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1317 | if (status != 0) { |
| 1318 | data->cancelled = 1; |
| 1319 | smp_wmb(); |
| 1320 | } else |
| 1321 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1322 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | return status; |
| 1324 | } |
| 1325 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1326 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1328 | struct nfs4_opendata *data = calldata; |
| 1329 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1330 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1331 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1332 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1333 | /* |
| 1334 | * Check if we still need to send an OPEN call, or if we can use |
| 1335 | * a delegation instead. |
| 1336 | */ |
| 1337 | if (data->state != NULL) { |
| 1338 | struct nfs_delegation *delegation; |
| 1339 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1340 | 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] | 1341 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1342 | rcu_read_lock(); |
| 1343 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1344 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1345 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1346 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1347 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1348 | } |
| 1349 | rcu_read_unlock(); |
| 1350 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1351 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1352 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1353 | data->o_arg.clientid = sp->so_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1354 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1355 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1356 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1357 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1358 | data->timestamp = jiffies; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1359 | if (nfs4_setup_sequence(data->o_arg.server->nfs_client, |
| 1360 | &data->o_arg.seq_args, |
| 1361 | &data->o_res.seq_res, 1, task)) |
| 1362 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1363 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1364 | return; |
| 1365 | out_no_action: |
| 1366 | task->tk_action = NULL; |
| 1367 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1370 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1371 | { |
| 1372 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1373 | nfs4_open_prepare(task, calldata); |
| 1374 | } |
| 1375 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1376 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1377 | { |
| 1378 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1380 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1381 | |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 1382 | nfs4_sequence_done(data->o_arg.server, &data->o_res.seq_res, |
| 1383 | task->tk_status); |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1384 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1385 | if (RPC_ASSASSINATED(task)) |
| 1386 | return; |
| 1387 | if (task->tk_status == 0) { |
| 1388 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1389 | case S_IFREG: |
| 1390 | break; |
| 1391 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1392 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1393 | break; |
| 1394 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1395 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1396 | break; |
| 1397 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1398 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1399 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1400 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1401 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1402 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1403 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1404 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1405 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1406 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1407 | static void nfs4_open_release(void *calldata) |
| 1408 | { |
| 1409 | struct nfs4_opendata *data = calldata; |
| 1410 | struct nfs4_state *state = NULL; |
| 1411 | |
| 1412 | /* If this request hasn't been cancelled, do nothing */ |
| 1413 | if (data->cancelled == 0) |
| 1414 | goto out_free; |
| 1415 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1416 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1417 | goto out_free; |
| 1418 | /* In case we need an open_confirm, no cleanup! */ |
| 1419 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1420 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1421 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1422 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1423 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1424 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1425 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1429 | .rpc_call_prepare = nfs4_open_prepare, |
| 1430 | .rpc_call_done = nfs4_open_done, |
| 1431 | .rpc_release = nfs4_open_release, |
| 1432 | }; |
| 1433 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1434 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1435 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1436 | .rpc_call_done = nfs4_open_done, |
| 1437 | .rpc_release = nfs4_open_release, |
| 1438 | }; |
| 1439 | |
| 1440 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1441 | { |
| 1442 | struct inode *dir = data->dir->d_inode; |
| 1443 | struct nfs_server *server = NFS_SERVER(dir); |
| 1444 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1445 | struct nfs_openres *o_res = &data->o_res; |
| 1446 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1447 | struct rpc_message msg = { |
| 1448 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1449 | .rpc_argp = o_arg, |
| 1450 | .rpc_resp = o_res, |
| 1451 | .rpc_cred = data->owner->so_cred, |
| 1452 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1453 | struct rpc_task_setup task_setup_data = { |
| 1454 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1455 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1456 | .callback_ops = &nfs4_open_ops, |
| 1457 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1458 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1459 | .flags = RPC_TASK_ASYNC, |
| 1460 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1461 | int status; |
| 1462 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1463 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1464 | data->rpc_done = 0; |
| 1465 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1466 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1467 | if (isrecover) |
| 1468 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1469 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1470 | if (IS_ERR(task)) |
| 1471 | return PTR_ERR(task); |
| 1472 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1473 | if (status != 0) { |
| 1474 | data->cancelled = 1; |
| 1475 | smp_wmb(); |
| 1476 | } else |
| 1477 | status = data->rpc_status; |
| 1478 | rpc_put_task(task); |
| 1479 | |
| 1480 | return status; |
| 1481 | } |
| 1482 | |
| 1483 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1484 | { |
| 1485 | struct inode *dir = data->dir->d_inode; |
| 1486 | struct nfs_openres *o_res = &data->o_res; |
| 1487 | int status; |
| 1488 | |
| 1489 | status = nfs4_run_open_task(data, 1); |
| 1490 | if (status != 0 || !data->rpc_done) |
| 1491 | return status; |
| 1492 | |
| 1493 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1494 | |
| 1495 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1496 | status = _nfs4_proc_open_confirm(data); |
| 1497 | if (status != 0) |
| 1498 | return status; |
| 1499 | } |
| 1500 | |
| 1501 | return status; |
| 1502 | } |
| 1503 | |
| 1504 | /* |
| 1505 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1506 | */ |
| 1507 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1508 | { |
| 1509 | struct inode *dir = data->dir->d_inode; |
| 1510 | struct nfs_server *server = NFS_SERVER(dir); |
| 1511 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1512 | struct nfs_openres *o_res = &data->o_res; |
| 1513 | int status; |
| 1514 | |
| 1515 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1516 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1517 | return status; |
| 1518 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1519 | if (o_arg->open_flags & O_CREAT) { |
| 1520 | update_changeattr(dir, &o_res->cinfo); |
| 1521 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1522 | } else |
| 1523 | nfs_refresh_inode(dir, o_res->dir_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1525 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1527 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | } |
| 1529 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1530 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1531 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Trond Myklebust | 10afec90 | 2007-05-14 17:16:04 -0400 | [diff] [blame] | 1534 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1535 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1536 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1537 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1538 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1539 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1540 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1541 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1542 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1543 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1544 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1545 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1546 | break; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1547 | nfs4_schedule_state_recovery(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1548 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1549 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1550 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1551 | } |
| 1552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | /* |
| 1554 | * OPEN_EXPIRED: |
| 1555 | * reclaim state on the server after a network partition. |
| 1556 | * Assumes caller holds the appropriate lock |
| 1557 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1558 | 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] | 1559 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1560 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1561 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1563 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1564 | if (IS_ERR(opendata)) |
| 1565 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1566 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1567 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1568 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1569 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1570 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1573 | 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] | 1574 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1575 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1576 | struct nfs4_exception exception = { }; |
| 1577 | int err; |
| 1578 | |
| 1579 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1580 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1581 | switch (err) { |
| 1582 | default: |
| 1583 | goto out; |
| 1584 | case -NFS4ERR_GRACE: |
| 1585 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame^] | 1586 | case -EKEYEXPIRED: |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1587 | nfs4_handle_exception(server, err, &exception); |
| 1588 | err = 0; |
| 1589 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1590 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1591 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1592 | return err; |
| 1593 | } |
| 1594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1596 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1598 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1600 | ctx = nfs4_state_find_open_context(state); |
| 1601 | if (IS_ERR(ctx)) |
| 1602 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1603 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1604 | put_nfs_open_context(ctx); |
| 1605 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1609 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1610 | * fields corresponding to attributes that were used to store the verifier. |
| 1611 | * Make sure we clobber those fields in the later setattr call |
| 1612 | */ |
| 1613 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1614 | { |
| 1615 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1616 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1617 | sattr->ia_valid |= ATTR_ATIME; |
| 1618 | |
| 1619 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1620 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1621 | sattr->ia_valid |= ATTR_MTIME; |
| 1622 | } |
| 1623 | |
| 1624 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1625 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1627 | 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] | 1628 | { |
| 1629 | struct nfs4_state_owner *sp; |
| 1630 | struct nfs4_state *state = NULL; |
| 1631 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1632 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1633 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | |
| 1635 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | status = -ENOMEM; |
| 1637 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1638 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1639 | goto out_err; |
| 1640 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1641 | status = nfs4_recover_expired_lease(server); |
| 1642 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1643 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1644 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1645 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1646 | status = -ENOMEM; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1647 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1648 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1649 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1651 | if (path->dentry->d_inode != NULL) |
| 1652 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1653 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1654 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1656 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1658 | if (opendata->o_arg.open_flags & O_EXCL) |
| 1659 | nfs4_exclusive_attrset(opendata, sattr); |
| 1660 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1661 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1662 | status = PTR_ERR(state); |
| 1663 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1664 | goto err_opendata_put; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1665 | if ((opendata->o_res.rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) != 0) |
| 1666 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1667 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | *res = state; |
| 1670 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1671 | err_opendata_put: |
| 1672 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1673 | err_put_state_owner: |
| 1674 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | *res = NULL; |
| 1677 | return status; |
| 1678 | } |
| 1679 | |
| 1680 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1681 | 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] | 1682 | { |
| 1683 | struct nfs4_exception exception = { }; |
| 1684 | struct nfs4_state *res; |
| 1685 | int status; |
| 1686 | |
| 1687 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1688 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | if (status == 0) |
| 1690 | break; |
| 1691 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1692 | * book-keeping w.r.t. state-changing operations |
| 1693 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1694 | * It is actually a sign of a bug on the client or on the server. |
| 1695 | * |
| 1696 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1697 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | * have unhashed the old state_owner for us, and that we can |
| 1699 | * therefore safely retry using a new one. We should still warn |
| 1700 | * the user though... |
| 1701 | */ |
| 1702 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1703 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1704 | " returned a bad sequence-id error!\n", |
| 1705 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | exception.retry = 1; |
| 1707 | continue; |
| 1708 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1709 | /* |
| 1710 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1711 | * state before it received the OPEN_CONFIRM. |
| 1712 | * Recover by retrying the request as per the discussion |
| 1713 | * on Page 181 of RFC3530. |
| 1714 | */ |
| 1715 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1716 | exception.retry = 1; |
| 1717 | continue; |
| 1718 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1719 | if (status == -EAGAIN) { |
| 1720 | /* We must have found a delegation */ |
| 1721 | exception.retry = 1; |
| 1722 | continue; |
| 1723 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1725 | status, &exception)); |
| 1726 | } while (exception.retry); |
| 1727 | return res; |
| 1728 | } |
| 1729 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1730 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1731 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1732 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1734 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1736 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | .iap = sattr, |
| 1738 | .server = server, |
| 1739 | .bitmask = server->attr_bitmask, |
| 1740 | }; |
| 1741 | struct nfs_setattrres res = { |
| 1742 | .fattr = fattr, |
| 1743 | .server = server, |
| 1744 | }; |
| 1745 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1746 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1747 | .rpc_argp = &arg, |
| 1748 | .rpc_resp = &res, |
| 1749 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1751 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1752 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1754 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1756 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1757 | /* Use that stateid */ |
| 1758 | } else if (state != NULL) { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1759 | nfs4_copy_stateid(&arg.stateid, state, current->files); |
| 1760 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1762 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1763 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1764 | if (status == 0 && state != NULL) |
| 1765 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1766 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1769 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1770 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1771 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1773 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | struct nfs4_exception exception = { }; |
| 1775 | int err; |
| 1776 | do { |
| 1777 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1778 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | &exception); |
| 1780 | } while (exception.retry); |
| 1781 | return err; |
| 1782 | } |
| 1783 | |
| 1784 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1785 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | struct inode *inode; |
| 1787 | struct nfs4_state *state; |
| 1788 | struct nfs_closeargs arg; |
| 1789 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1790 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1791 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | }; |
| 1793 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1794 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1795 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1796 | struct nfs4_closedata *calldata = data; |
| 1797 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1798 | |
| 1799 | nfs4_put_open_state(calldata->state); |
| 1800 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1801 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1802 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1803 | kfree(calldata); |
| 1804 | } |
| 1805 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1806 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1807 | fmode_t fmode) |
| 1808 | { |
| 1809 | spin_lock(&state->owner->so_lock); |
| 1810 | if (!(fmode & FMODE_READ)) |
| 1811 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1812 | if (!(fmode & FMODE_WRITE)) |
| 1813 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1814 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1815 | spin_unlock(&state->owner->so_lock); |
| 1816 | } |
| 1817 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1818 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1820 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1823 | |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1824 | nfs4_sequence_done(server, &calldata->res.seq_res, task->tk_status); |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1825 | if (RPC_ASSASSINATED(task)) |
| 1826 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | /* hmm. we are done with the inode, and in the process of freeing |
| 1828 | * the state_owner. we keep this around to process errors |
| 1829 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | switch (task->tk_status) { |
| 1831 | case 0: |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1832 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1833 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1834 | nfs4_close_clear_stateid_flags(state, |
| 1835 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | break; |
| 1837 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1838 | case -NFS4ERR_OLD_STATEID: |
| 1839 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1841 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1842 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1844 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1845 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1847 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1848 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1851 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1853 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1854 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1855 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1856 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1857 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1858 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1859 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1860 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1861 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1862 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1863 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1864 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1865 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1866 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1867 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1868 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1869 | } |
| 1870 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1871 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1872 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1873 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1874 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1875 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1876 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1877 | |
| 1878 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1879 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1880 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1881 | return; |
| 1882 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1883 | |
| 1884 | if (calldata->arg.fmode == 0) |
| 1885 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
| 1886 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1887 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1888 | calldata->timestamp = jiffies; |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1889 | if (nfs4_setup_sequence((NFS_SERVER(calldata->inode))->nfs_client, |
| 1890 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1891 | 1, task)) |
| 1892 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1893 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1896 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1897 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1898 | .rpc_call_done = nfs4_close_done, |
| 1899 | .rpc_release = nfs4_free_closedata, |
| 1900 | }; |
| 1901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | /* |
| 1903 | * It is possible for data to be read/written from a mem-mapped file |
| 1904 | * after the sys_close call (which hits the vfs layer as a flush). |
| 1905 | * This means that we can't safely call nfsv4 close on a file until |
| 1906 | * the inode is cleared. This in turn means that we are not good |
| 1907 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 1908 | * share state even when we are done with one of the three share |
| 1909 | * stateid's in the inode. |
| 1910 | * |
| 1911 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 1912 | */ |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1913 | int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1915 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1917 | struct nfs4_state_owner *sp = state->owner; |
| 1918 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1919 | struct rpc_message msg = { |
| 1920 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 1921 | .rpc_cred = state->owner->so_cred, |
| 1922 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1923 | struct rpc_task_setup task_setup_data = { |
| 1924 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1925 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1926 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1927 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1928 | .flags = RPC_TASK_ASYNC, |
| 1929 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1930 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1932 | calldata = kzalloc(sizeof(*calldata), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1934 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1935 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1937 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1938 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | /* Serialization for the sequence id */ |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1940 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1941 | if (calldata->arg.seqid == NULL) |
| 1942 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1943 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 1944 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1945 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 1946 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1947 | calldata->res.server = server; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 1948 | calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1949 | calldata->path.mnt = mntget(path->mnt); |
| 1950 | calldata->path.dentry = dget(path->dentry); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1951 | |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1952 | msg.rpc_argp = &calldata->arg, |
| 1953 | msg.rpc_resp = &calldata->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1954 | task_setup_data.callback_data = calldata; |
| 1955 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1956 | if (IS_ERR(task)) |
| 1957 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1958 | status = 0; |
| 1959 | if (wait) |
| 1960 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1961 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1962 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1963 | out_free_calldata: |
| 1964 | kfree(calldata); |
| 1965 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1966 | nfs4_put_open_state(state); |
| 1967 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1968 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1971 | static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1972 | { |
| 1973 | struct file *filp; |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1974 | int ret; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1975 | |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1976 | /* If the open_intent is for execute, we have an extra check to make */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1977 | if (fmode & FMODE_EXEC) { |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1978 | ret = nfs_may_open(state->inode, |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1979 | state->owner->so_cred, |
| 1980 | nd->intent.open.flags); |
| 1981 | if (ret < 0) |
| 1982 | goto out_close; |
| 1983 | } |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1984 | filp = lookup_instantiate_filp(nd, path->dentry, NULL); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1985 | if (!IS_ERR(filp)) { |
| 1986 | struct nfs_open_context *ctx; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 1987 | ctx = nfs_file_open_context(filp); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1988 | ctx->state = state; |
Trond Myklebust | 95cf959 | 2006-04-18 13:14:06 -0400 | [diff] [blame] | 1989 | return 0; |
| 1990 | } |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1991 | ret = PTR_ERR(filp); |
| 1992 | out_close: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1993 | nfs4_close_sync(path, state, fmode & (FMODE_READ|FMODE_WRITE)); |
Trond Myklebust | 1b45c46 | 2007-07-03 13:04:56 -0400 | [diff] [blame] | 1994 | return ret; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | struct dentry * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
| 1999 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2000 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 2001 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2002 | .dentry = dentry, |
| 2003 | }; |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 2004 | struct dentry *parent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | struct iattr attr; |
| 2006 | struct rpc_cred *cred; |
| 2007 | struct nfs4_state *state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2008 | struct dentry *res; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2009 | fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | |
| 2011 | if (nd->flags & LOOKUP_CREATE) { |
| 2012 | attr.ia_mode = nd->intent.open.create_mode; |
| 2013 | attr.ia_valid = ATTR_MODE; |
| 2014 | if (!IS_POSIXACL(dir)) |
Al Viro | ce3b0f8 | 2009-03-29 19:08:22 -0400 | [diff] [blame] | 2015 | attr.ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | } else { |
| 2017 | attr.ia_valid = 0; |
| 2018 | BUG_ON(nd->intent.open.flags & O_CREAT); |
| 2019 | } |
| 2020 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 2021 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | if (IS_ERR(cred)) |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2023 | return (struct dentry *)cred; |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2024 | parent = dentry->d_parent; |
| 2025 | /* Protect against concurrent sillydeletes */ |
| 2026 | nfs_block_sillyrename(parent); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2027 | state = nfs4_do_open(dir, &path, fmode, nd->intent.open.flags, &attr, cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | put_rpccred(cred); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2029 | if (IS_ERR(state)) { |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2030 | if (PTR_ERR(state) == -ENOENT) { |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2031 | d_add(dentry, NULL); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2032 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
| 2033 | } |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2034 | nfs_unblock_sillyrename(parent); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2035 | return (struct dentry *)state; |
| 2036 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2037 | res = d_add_unique(dentry, igrab(state->inode)); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2038 | if (res != NULL) |
Trond Myklebust | deee936 | 2007-08-27 11:33:00 -0400 | [diff] [blame] | 2039 | path.dentry = res; |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2040 | nfs_set_verifier(path.dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2041 | nfs_unblock_sillyrename(parent); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2042 | nfs4_intent_set_file(nd, &path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2043 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | int |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2047 | nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2049 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 2050 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2051 | .dentry = dentry, |
| 2052 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | struct rpc_cred *cred; |
| 2054 | struct nfs4_state *state; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2055 | fmode_t fmode = openflags & (FMODE_READ | FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 2057 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | if (IS_ERR(cred)) |
| 2059 | return PTR_ERR(cred); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2060 | state = nfs4_do_open(dir, &path, fmode, openflags, NULL, cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | put_rpccred(cred); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2062 | if (IS_ERR(state)) { |
| 2063 | switch (PTR_ERR(state)) { |
| 2064 | case -EPERM: |
| 2065 | case -EACCES: |
| 2066 | case -EDQUOT: |
| 2067 | case -ENOSPC: |
| 2068 | case -EROFS: |
| 2069 | lookup_instantiate_filp(nd, (struct dentry *)state, NULL); |
| 2070 | return 1; |
Chuck Lever | b87c0ad | 2006-10-19 23:28:42 -0700 | [diff] [blame] | 2071 | default: |
| 2072 | goto out_drop; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2073 | } |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2074 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2075 | if (state->inode == dentry->d_inode) { |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2076 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2077 | nfs4_intent_set_file(nd, &path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | return 1; |
| 2079 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2080 | nfs4_close_sync(&path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2081 | out_drop: |
| 2082 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | return 0; |
| 2084 | } |
| 2085 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2086 | 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] | 2087 | { |
| 2088 | if (ctx->state == NULL) |
| 2089 | return; |
| 2090 | if (is_sync) |
| 2091 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2092 | else |
| 2093 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2094 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | |
| 2096 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2097 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2098 | struct nfs4_server_caps_arg args = { |
| 2099 | .fhandle = fhandle, |
| 2100 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | struct nfs4_server_caps_res res = {}; |
| 2102 | struct rpc_message msg = { |
| 2103 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2104 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | .rpc_resp = &res, |
| 2106 | }; |
| 2107 | int status; |
| 2108 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2109 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | if (status == 0) { |
| 2111 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2112 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2113 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2114 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2115 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2116 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2118 | server->caps |= NFS_CAP_ACLS; |
| 2119 | if (res.has_links != 0) |
| 2120 | server->caps |= NFS_CAP_HARDLINKS; |
| 2121 | if (res.has_symlinks != 0) |
| 2122 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2123 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2124 | server->caps |= NFS_CAP_FILEID; |
| 2125 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2126 | server->caps |= NFS_CAP_MODE; |
| 2127 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2128 | server->caps |= NFS_CAP_NLINK; |
| 2129 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2130 | server->caps |= NFS_CAP_OWNER; |
| 2131 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2132 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2133 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2134 | server->caps |= NFS_CAP_ATIME; |
| 2135 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2136 | server->caps |= NFS_CAP_CTIME; |
| 2137 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2138 | server->caps |= NFS_CAP_MTIME; |
| 2139 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2140 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2141 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2142 | 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] | 2143 | server->acl_bitmask = res.acl_bitmask; |
| 2144 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | return status; |
| 2147 | } |
| 2148 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2149 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | { |
| 2151 | struct nfs4_exception exception = { }; |
| 2152 | int err; |
| 2153 | do { |
| 2154 | err = nfs4_handle_exception(server, |
| 2155 | _nfs4_server_capabilities(server, fhandle), |
| 2156 | &exception); |
| 2157 | } while (exception.retry); |
| 2158 | return err; |
| 2159 | } |
| 2160 | |
| 2161 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2162 | struct nfs_fsinfo *info) |
| 2163 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | struct nfs4_lookup_root_arg args = { |
| 2165 | .bitmask = nfs4_fattr_bitmap, |
| 2166 | }; |
| 2167 | struct nfs4_lookup_res res = { |
| 2168 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2169 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | .fh = fhandle, |
| 2171 | }; |
| 2172 | struct rpc_message msg = { |
| 2173 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2174 | .rpc_argp = &args, |
| 2175 | .rpc_resp = &res, |
| 2176 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2177 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2178 | nfs_fattr_init(info->fattr); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 2179 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2183 | struct nfs_fsinfo *info) |
| 2184 | { |
| 2185 | struct nfs4_exception exception = { }; |
| 2186 | int err; |
| 2187 | do { |
| 2188 | err = nfs4_handle_exception(server, |
| 2189 | _nfs4_lookup_root(server, fhandle, info), |
| 2190 | &exception); |
| 2191 | } while (exception.retry); |
| 2192 | return err; |
| 2193 | } |
| 2194 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2195 | /* |
| 2196 | * get the file handle for the "/" directory on the server |
| 2197 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | 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] | 2199 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | int status; |
| 2202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | if (status == 0) |
| 2205 | status = nfs4_server_capabilities(server, fhandle); |
| 2206 | if (status == 0) |
| 2207 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2208 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | } |
| 2210 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2211 | /* |
| 2212 | * Get locations and (maybe) other attributes of a referral. |
| 2213 | * Note that we'll actually follow the referral later when |
| 2214 | * we detect fsid mismatch in inode revalidation |
| 2215 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2216 | 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] | 2217 | { |
| 2218 | int status = -ENOMEM; |
| 2219 | struct page *page = NULL; |
| 2220 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2221 | |
| 2222 | page = alloc_page(GFP_KERNEL); |
| 2223 | if (page == NULL) |
| 2224 | goto out; |
| 2225 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2226 | if (locations == NULL) |
| 2227 | goto out; |
| 2228 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2229 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2230 | if (status != 0) |
| 2231 | goto out; |
| 2232 | /* Make sure server returned a different fsid for the referral */ |
| 2233 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2234 | 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] | 2235 | status = -EIO; |
| 2236 | goto out; |
| 2237 | } |
| 2238 | |
| 2239 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2240 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2241 | if (!fattr->mode) |
| 2242 | fattr->mode = S_IFDIR; |
| 2243 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2244 | out: |
| 2245 | if (page) |
| 2246 | __free_page(page); |
| 2247 | if (locations) |
| 2248 | kfree(locations); |
| 2249 | return status; |
| 2250 | } |
| 2251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2253 | { |
| 2254 | struct nfs4_getattr_arg args = { |
| 2255 | .fh = fhandle, |
| 2256 | .bitmask = server->attr_bitmask, |
| 2257 | }; |
| 2258 | struct nfs4_getattr_res res = { |
| 2259 | .fattr = fattr, |
| 2260 | .server = server, |
| 2261 | }; |
| 2262 | struct rpc_message msg = { |
| 2263 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2264 | .rpc_argp = &args, |
| 2265 | .rpc_resp = &res, |
| 2266 | }; |
| 2267 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2268 | nfs_fattr_init(fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2269 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2273 | { |
| 2274 | struct nfs4_exception exception = { }; |
| 2275 | int err; |
| 2276 | do { |
| 2277 | err = nfs4_handle_exception(server, |
| 2278 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2279 | &exception); |
| 2280 | } while (exception.retry); |
| 2281 | return err; |
| 2282 | } |
| 2283 | |
| 2284 | /* |
| 2285 | * The file is not closed if it is opened due to the a request to change |
| 2286 | * the size of the file. The open call will not be needed once the |
| 2287 | * VFS layer lookup-intents are implemented. |
| 2288 | * |
| 2289 | * Close is called when the inode is destroyed. |
| 2290 | * If we haven't opened the file for O_WRONLY, we |
| 2291 | * need to in the size_change case to obtain a stateid. |
| 2292 | * |
| 2293 | * Got race? |
| 2294 | * Because OPEN is always done by name in nfsv4, it is |
| 2295 | * possible that we opened a different file by the same |
| 2296 | * name. We can recognize this race condition, but we |
| 2297 | * can't do anything about it besides returning an error. |
| 2298 | * |
| 2299 | * This will be fixed with VFS changes (lookup-intent). |
| 2300 | */ |
| 2301 | static int |
| 2302 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2303 | struct iattr *sattr) |
| 2304 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2305 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2306 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2307 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | int status; |
| 2309 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2310 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2312 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2313 | if (sattr->ia_valid & ATTR_FILE) { |
| 2314 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2315 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2316 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2317 | if (ctx) { |
| 2318 | cred = ctx->cred; |
| 2319 | state = ctx->state; |
| 2320 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2324 | if (status == 0) |
| 2325 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | return status; |
| 2327 | } |
| 2328 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2329 | static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh, |
| 2330 | const struct qstr *name, struct nfs_fh *fhandle, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2331 | struct nfs_fattr *fattr) |
| 2332 | { |
| 2333 | int status; |
| 2334 | struct nfs4_lookup_arg args = { |
| 2335 | .bitmask = server->attr_bitmask, |
| 2336 | .dir_fh = dirfh, |
| 2337 | .name = name, |
| 2338 | }; |
| 2339 | struct nfs4_lookup_res res = { |
| 2340 | .server = server, |
| 2341 | .fattr = fattr, |
| 2342 | .fh = fhandle, |
| 2343 | }; |
| 2344 | struct rpc_message msg = { |
| 2345 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2346 | .rpc_argp = &args, |
| 2347 | .rpc_resp = &res, |
| 2348 | }; |
| 2349 | |
| 2350 | nfs_fattr_init(fattr); |
| 2351 | |
| 2352 | dprintk("NFS call lookupfh %s\n", name->name); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2353 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2354 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2355 | return status; |
| 2356 | } |
| 2357 | |
| 2358 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2359 | struct qstr *name, struct nfs_fh *fhandle, |
| 2360 | struct nfs_fattr *fattr) |
| 2361 | { |
| 2362 | struct nfs4_exception exception = { }; |
| 2363 | int err; |
| 2364 | do { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2365 | err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); |
| 2366 | /* FIXME: !!!! */ |
| 2367 | if (err == -NFS4ERR_MOVED) { |
| 2368 | err = -EREMOTE; |
| 2369 | break; |
| 2370 | } |
| 2371 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2372 | } while (exception.retry); |
| 2373 | return err; |
| 2374 | } |
| 2375 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2376 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2378 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2379 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | |
| 2381 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2382 | status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2383 | if (status == -NFS4ERR_MOVED) |
| 2384 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | dprintk("NFS reply lookup: %d\n", status); |
| 2386 | return status; |
| 2387 | } |
| 2388 | |
| 2389 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2390 | { |
| 2391 | struct nfs4_exception exception = { }; |
| 2392 | int err; |
| 2393 | do { |
| 2394 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2395 | _nfs4_proc_lookup(dir, name, fhandle, fattr), |
| 2396 | &exception); |
| 2397 | } while (exception.retry); |
| 2398 | return err; |
| 2399 | } |
| 2400 | |
| 2401 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2402 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2403 | struct nfs_server *server = NFS_SERVER(inode); |
| 2404 | struct nfs_fattr fattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | struct nfs4_accessargs args = { |
| 2406 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2407 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2409 | struct nfs4_accessres res = { |
| 2410 | .server = server, |
| 2411 | .fattr = &fattr, |
| 2412 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | struct rpc_message msg = { |
| 2414 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2415 | .rpc_argp = &args, |
| 2416 | .rpc_resp = &res, |
| 2417 | .rpc_cred = entry->cred, |
| 2418 | }; |
| 2419 | int mode = entry->mask; |
| 2420 | int status; |
| 2421 | |
| 2422 | /* |
| 2423 | * Determine which access bits we want to ask for... |
| 2424 | */ |
| 2425 | if (mode & MAY_READ) |
| 2426 | args.access |= NFS4_ACCESS_READ; |
| 2427 | if (S_ISDIR(inode->i_mode)) { |
| 2428 | if (mode & MAY_WRITE) |
| 2429 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2430 | if (mode & MAY_EXEC) |
| 2431 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2432 | } else { |
| 2433 | if (mode & MAY_WRITE) |
| 2434 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2435 | if (mode & MAY_EXEC) |
| 2436 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2437 | } |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2438 | nfs_fattr_init(&fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2439 | status = nfs4_call_sync(server, &msg, &args, &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 | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2448 | nfs_refresh_inode(inode, &fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | } |
| 2450 | return status; |
| 2451 | } |
| 2452 | |
| 2453 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2454 | { |
| 2455 | struct nfs4_exception exception = { }; |
| 2456 | int err; |
| 2457 | do { |
| 2458 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2459 | _nfs4_proc_access(inode, entry), |
| 2460 | &exception); |
| 2461 | } while (exception.retry); |
| 2462 | return err; |
| 2463 | } |
| 2464 | |
| 2465 | /* |
| 2466 | * TODO: For the time being, we don't try to get any attributes |
| 2467 | * along with any of the zero-copy operations READ, READDIR, |
| 2468 | * READLINK, WRITE. |
| 2469 | * |
| 2470 | * In the case of the first three, we want to put the GETATTR |
| 2471 | * after the read-type operation -- this is because it is hard |
| 2472 | * to predict the length of a GETATTR response in v4, and thus |
| 2473 | * align the READ data correctly. This means that the GETATTR |
| 2474 | * may end up partially falling into the page cache, and we should |
| 2475 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2476 | * To do this efficiently, we need to know the total length |
| 2477 | * of data received, which doesn't seem to be available outside |
| 2478 | * of the RPC layer. |
| 2479 | * |
| 2480 | * In the case of WRITE, we also want to put the GETATTR after |
| 2481 | * the operation -- in this case because we want to make sure |
| 2482 | * we get the post-operation mtime and size. This means that |
| 2483 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2484 | * of it which would leave room in the 'tail' iovec. |
| 2485 | * |
| 2486 | * Both of these changes to the XDR layer would in fact be quite |
| 2487 | * minor, but I decided to leave them for a subsequent patch. |
| 2488 | */ |
| 2489 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2490 | unsigned int pgbase, unsigned int pglen) |
| 2491 | { |
| 2492 | struct nfs4_readlink args = { |
| 2493 | .fh = NFS_FH(inode), |
| 2494 | .pgbase = pgbase, |
| 2495 | .pglen = pglen, |
| 2496 | .pages = &page, |
| 2497 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2498 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | struct rpc_message msg = { |
| 2500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2501 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2502 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2503 | }; |
| 2504 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2505 | return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2509 | unsigned int pgbase, unsigned int pglen) |
| 2510 | { |
| 2511 | struct nfs4_exception exception = { }; |
| 2512 | int err; |
| 2513 | do { |
| 2514 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2515 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2516 | &exception); |
| 2517 | } while (exception.retry); |
| 2518 | return err; |
| 2519 | } |
| 2520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | /* |
| 2522 | * Got race? |
| 2523 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2524 | * Until then, this create/open method is prone to inefficiency and race |
| 2525 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2526 | * placed on the wire. |
| 2527 | * |
| 2528 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2529 | * The file will be opened again in the subsequent VFS open call |
| 2530 | * (nfs4_proc_file_open). |
| 2531 | * |
| 2532 | * The open for read will just hang around to be used by any process that |
| 2533 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2534 | */ |
| 2535 | |
| 2536 | static int |
| 2537 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2538 | int flags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2540 | struct path path = { |
Jan Blunck | 4ac9137 | 2008-02-14 19:34:32 -0800 | [diff] [blame] | 2541 | .mnt = nd->path.mnt, |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2542 | .dentry = dentry, |
| 2543 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | struct nfs4_state *state; |
| 2545 | struct rpc_cred *cred; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2546 | fmode_t fmode = flags & (FMODE_READ | FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | int status = 0; |
| 2548 | |
Trond Myklebust | 98a8e32 | 2008-03-12 12:25:28 -0400 | [diff] [blame] | 2549 | cred = rpc_lookup_cred(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | if (IS_ERR(cred)) { |
| 2551 | status = PTR_ERR(cred); |
| 2552 | goto out; |
| 2553 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2554 | state = nfs4_do_open(dir, &path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2555 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | if (IS_ERR(state)) { |
| 2557 | status = PTR_ERR(state); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2558 | goto out_putcred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2560 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2561 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | if (flags & O_EXCL) { |
| 2563 | struct nfs_fattr fattr; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2564 | status = nfs4_do_setattr(state->inode, cred, &fattr, sattr, state); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2565 | if (status == 0) |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2566 | nfs_setattr_update_inode(state->inode, sattr); |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 2567 | nfs_post_op_update_inode(state->inode, &fattr); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2568 | } |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2569 | if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2570 | status = nfs4_intent_set_file(nd, &path, state, fmode); |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2571 | else |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2572 | nfs4_close_sync(&path, state, fmode); |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2573 | out_putcred: |
| 2574 | put_rpccred(cred); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | out: |
| 2576 | return status; |
| 2577 | } |
| 2578 | |
| 2579 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2580 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2581 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2582 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2584 | .name.len = name->len, |
| 2585 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2586 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2588 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2589 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2590 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2592 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2593 | .rpc_argp = &args, |
| 2594 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | }; |
| 2596 | int status; |
| 2597 | |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2598 | nfs_fattr_init(&res.dir_attr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2599 | status = nfs4_call_sync(server, &msg, &args, &res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2600 | if (status == 0) { |
| 2601 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2602 | nfs_post_op_update_inode(dir, &res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2603 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | return status; |
| 2605 | } |
| 2606 | |
| 2607 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2608 | { |
| 2609 | struct nfs4_exception exception = { }; |
| 2610 | int err; |
| 2611 | do { |
| 2612 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2613 | _nfs4_proc_remove(dir, name), |
| 2614 | &exception); |
| 2615 | } while (exception.retry); |
| 2616 | return err; |
| 2617 | } |
| 2618 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2619 | 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] | 2620 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2621 | struct nfs_server *server = NFS_SERVER(dir); |
| 2622 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2623 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2625 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2626 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | } |
| 2629 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2630 | 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] | 2631 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2632 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2633 | |
Andy Adamson | 472cfbd | 2009-04-01 09:22:24 -0400 | [diff] [blame] | 2634 | nfs4_sequence_done(res->server, &res->seq_res, task->tk_status); |
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); |
| 2638 | nfs_post_op_update_inode(dir, &res->dir_attr); |
| 2639 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2643 | struct inode *new_dir, struct qstr *new_name) |
| 2644 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2645 | struct nfs_server *server = NFS_SERVER(old_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | struct nfs4_rename_arg arg = { |
| 2647 | .old_dir = NFS_FH(old_dir), |
| 2648 | .new_dir = NFS_FH(new_dir), |
| 2649 | .old_name = old_name, |
| 2650 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2651 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | }; |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2653 | struct nfs_fattr old_fattr, new_fattr; |
| 2654 | struct nfs4_rename_res res = { |
| 2655 | .server = server, |
| 2656 | .old_fattr = &old_fattr, |
| 2657 | .new_fattr = &new_fattr, |
| 2658 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | struct rpc_message msg = { |
| 2660 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2661 | .rpc_argp = &arg, |
| 2662 | .rpc_resp = &res, |
| 2663 | }; |
| 2664 | int status; |
| 2665 | |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2666 | nfs_fattr_init(res.old_fattr); |
| 2667 | nfs_fattr_init(res.new_fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2668 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | |
| 2670 | if (!status) { |
| 2671 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2672 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2674 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | } |
| 2676 | return status; |
| 2677 | } |
| 2678 | |
| 2679 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2680 | struct inode *new_dir, struct qstr *new_name) |
| 2681 | { |
| 2682 | struct nfs4_exception exception = { }; |
| 2683 | int err; |
| 2684 | do { |
| 2685 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2686 | _nfs4_proc_rename(old_dir, old_name, |
| 2687 | new_dir, new_name), |
| 2688 | &exception); |
| 2689 | } while (exception.retry); |
| 2690 | return err; |
| 2691 | } |
| 2692 | |
| 2693 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2694 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2695 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | struct nfs4_link_arg arg = { |
| 2697 | .fh = NFS_FH(inode), |
| 2698 | .dir_fh = NFS_FH(dir), |
| 2699 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2700 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2702 | struct nfs_fattr fattr, dir_attr; |
| 2703 | struct nfs4_link_res res = { |
| 2704 | .server = server, |
| 2705 | .fattr = &fattr, |
| 2706 | .dir_attr = &dir_attr, |
| 2707 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | struct rpc_message msg = { |
| 2709 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2710 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2711 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | }; |
| 2713 | int status; |
| 2714 | |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2715 | nfs_fattr_init(res.fattr); |
| 2716 | nfs_fattr_init(res.dir_attr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2717 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2718 | if (!status) { |
| 2719 | update_changeattr(dir, &res.cinfo); |
| 2720 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2721 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2722 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | |
| 2724 | return status; |
| 2725 | } |
| 2726 | |
| 2727 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2728 | { |
| 2729 | struct nfs4_exception exception = { }; |
| 2730 | int err; |
| 2731 | do { |
| 2732 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2733 | _nfs4_proc_link(inode, dir, name), |
| 2734 | &exception); |
| 2735 | } while (exception.retry); |
| 2736 | return err; |
| 2737 | } |
| 2738 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2739 | struct nfs4_createdata { |
| 2740 | struct rpc_message msg; |
| 2741 | struct nfs4_create_arg arg; |
| 2742 | struct nfs4_create_res res; |
| 2743 | struct nfs_fh fh; |
| 2744 | struct nfs_fattr fattr; |
| 2745 | struct nfs_fattr dir_fattr; |
| 2746 | }; |
| 2747 | |
| 2748 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2749 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2750 | { |
| 2751 | struct nfs4_createdata *data; |
| 2752 | |
| 2753 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2754 | if (data != NULL) { |
| 2755 | struct nfs_server *server = NFS_SERVER(dir); |
| 2756 | |
| 2757 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2758 | data->msg.rpc_argp = &data->arg; |
| 2759 | data->msg.rpc_resp = &data->res; |
| 2760 | data->arg.dir_fh = NFS_FH(dir); |
| 2761 | data->arg.server = server; |
| 2762 | data->arg.name = name; |
| 2763 | data->arg.attrs = sattr; |
| 2764 | data->arg.ftype = ftype; |
| 2765 | data->arg.bitmask = server->attr_bitmask; |
| 2766 | data->res.server = server; |
| 2767 | data->res.fh = &data->fh; |
| 2768 | data->res.fattr = &data->fattr; |
| 2769 | data->res.dir_fattr = &data->dir_fattr; |
| 2770 | nfs_fattr_init(data->res.fattr); |
| 2771 | nfs_fattr_init(data->res.dir_fattr); |
| 2772 | } |
| 2773 | return data; |
| 2774 | } |
| 2775 | |
| 2776 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2777 | { |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2778 | int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg, |
| 2779 | &data->arg, &data->res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2780 | if (status == 0) { |
| 2781 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2782 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2783 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2784 | } |
| 2785 | return status; |
| 2786 | } |
| 2787 | |
| 2788 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2789 | { |
| 2790 | kfree(data); |
| 2791 | } |
| 2792 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2793 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2794 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2796 | struct nfs4_createdata *data; |
| 2797 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2799 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2800 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2801 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2802 | status = -ENOMEM; |
| 2803 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2804 | if (data == NULL) |
| 2805 | goto out; |
| 2806 | |
| 2807 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2808 | data->arg.u.symlink.pages = &page; |
| 2809 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2811 | status = nfs4_do_create(dir, dentry, data); |
| 2812 | |
| 2813 | nfs4_free_createdata(data); |
| 2814 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | return status; |
| 2816 | } |
| 2817 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2818 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2819 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | { |
| 2821 | struct nfs4_exception exception = { }; |
| 2822 | int err; |
| 2823 | do { |
| 2824 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2825 | _nfs4_proc_symlink(dir, dentry, page, |
| 2826 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | &exception); |
| 2828 | } while (exception.retry); |
| 2829 | return err; |
| 2830 | } |
| 2831 | |
| 2832 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2833 | struct iattr *sattr) |
| 2834 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2835 | struct nfs4_createdata *data; |
| 2836 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2838 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2839 | if (data == NULL) |
| 2840 | goto out; |
| 2841 | |
| 2842 | status = nfs4_do_create(dir, dentry, data); |
| 2843 | |
| 2844 | nfs4_free_createdata(data); |
| 2845 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | return status; |
| 2847 | } |
| 2848 | |
| 2849 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2850 | struct iattr *sattr) |
| 2851 | { |
| 2852 | struct nfs4_exception exception = { }; |
| 2853 | int err; |
| 2854 | do { |
| 2855 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2856 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2857 | &exception); |
| 2858 | } while (exception.retry); |
| 2859 | return err; |
| 2860 | } |
| 2861 | |
| 2862 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 2863 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 2864 | { |
| 2865 | struct inode *dir = dentry->d_inode; |
| 2866 | struct nfs4_readdir_arg args = { |
| 2867 | .fh = NFS_FH(dir), |
| 2868 | .pages = &page, |
| 2869 | .pgbase = 0, |
| 2870 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2871 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | }; |
| 2873 | struct nfs4_readdir_res res; |
| 2874 | struct rpc_message msg = { |
| 2875 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2876 | .rpc_argp = &args, |
| 2877 | .rpc_resp = &res, |
| 2878 | .rpc_cred = cred, |
| 2879 | }; |
| 2880 | int status; |
| 2881 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2882 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2883 | dentry->d_parent->d_name.name, |
| 2884 | dentry->d_name.name, |
| 2885 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2887 | res.pgbase = args.pgbase; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2888 | status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | if (status == 0) |
| 2890 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2891 | |
| 2892 | nfs_invalidate_atime(dir); |
| 2893 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2894 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | return status; |
| 2896 | } |
| 2897 | |
| 2898 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 2899 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 2900 | { |
| 2901 | struct nfs4_exception exception = { }; |
| 2902 | int err; |
| 2903 | do { |
| 2904 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2905 | _nfs4_proc_readdir(dentry, cred, cookie, |
| 2906 | page, count, plus), |
| 2907 | &exception); |
| 2908 | } while (exception.retry); |
| 2909 | return err; |
| 2910 | } |
| 2911 | |
| 2912 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2913 | struct iattr *sattr, dev_t rdev) |
| 2914 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2915 | struct nfs4_createdata *data; |
| 2916 | int mode = sattr->ia_mode; |
| 2917 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | |
| 2919 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2920 | 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] | 2921 | |
| 2922 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2923 | if (data == NULL) |
| 2924 | goto out; |
| 2925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2927 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2929 | data->arg.ftype = NF4BLK; |
| 2930 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2931 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | } |
| 2933 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2934 | data->arg.ftype = NF4CHR; |
| 2935 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2936 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2939 | status = nfs4_do_create(dir, dentry, data); |
| 2940 | |
| 2941 | nfs4_free_createdata(data); |
| 2942 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | return status; |
| 2944 | } |
| 2945 | |
| 2946 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2947 | struct iattr *sattr, dev_t rdev) |
| 2948 | { |
| 2949 | struct nfs4_exception exception = { }; |
| 2950 | int err; |
| 2951 | do { |
| 2952 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2953 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 2954 | &exception); |
| 2955 | } while (exception.retry); |
| 2956 | return err; |
| 2957 | } |
| 2958 | |
| 2959 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2960 | struct nfs_fsstat *fsstat) |
| 2961 | { |
| 2962 | struct nfs4_statfs_arg args = { |
| 2963 | .fh = fhandle, |
| 2964 | .bitmask = server->attr_bitmask, |
| 2965 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2966 | struct nfs4_statfs_res res = { |
| 2967 | .fsstat = fsstat, |
| 2968 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | struct rpc_message msg = { |
| 2970 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 2971 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2972 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | }; |
| 2974 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2975 | nfs_fattr_init(fsstat->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2976 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 2980 | { |
| 2981 | struct nfs4_exception exception = { }; |
| 2982 | int err; |
| 2983 | do { |
| 2984 | err = nfs4_handle_exception(server, |
| 2985 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 2986 | &exception); |
| 2987 | } while (exception.retry); |
| 2988 | return err; |
| 2989 | } |
| 2990 | |
| 2991 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2992 | struct nfs_fsinfo *fsinfo) |
| 2993 | { |
| 2994 | struct nfs4_fsinfo_arg args = { |
| 2995 | .fh = fhandle, |
| 2996 | .bitmask = server->attr_bitmask, |
| 2997 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 2998 | struct nfs4_fsinfo_res res = { |
| 2999 | .fsinfo = fsinfo, |
| 3000 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | struct rpc_message msg = { |
| 3002 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3003 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3004 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | }; |
| 3006 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3007 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3011 | { |
| 3012 | struct nfs4_exception exception = { }; |
| 3013 | int err; |
| 3014 | |
| 3015 | do { |
| 3016 | err = nfs4_handle_exception(server, |
| 3017 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3018 | &exception); |
| 3019 | } while (exception.retry); |
| 3020 | return err; |
| 3021 | } |
| 3022 | |
| 3023 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3024 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3025 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3027 | } |
| 3028 | |
| 3029 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3030 | struct nfs_pathconf *pathconf) |
| 3031 | { |
| 3032 | struct nfs4_pathconf_arg args = { |
| 3033 | .fh = fhandle, |
| 3034 | .bitmask = server->attr_bitmask, |
| 3035 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3036 | struct nfs4_pathconf_res res = { |
| 3037 | .pathconf = pathconf, |
| 3038 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | struct rpc_message msg = { |
| 3040 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3041 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3042 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | }; |
| 3044 | |
| 3045 | /* None of the pathconf attributes are mandatory to implement */ |
| 3046 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3047 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3048 | return 0; |
| 3049 | } |
| 3050 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3051 | nfs_fattr_init(pathconf->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3052 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3056 | struct nfs_pathconf *pathconf) |
| 3057 | { |
| 3058 | struct nfs4_exception exception = { }; |
| 3059 | int err; |
| 3060 | |
| 3061 | do { |
| 3062 | err = nfs4_handle_exception(server, |
| 3063 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3064 | &exception); |
| 3065 | } while (exception.retry); |
| 3066 | return err; |
| 3067 | } |
| 3068 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3069 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3071 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3073 | dprintk("--> %s\n", __func__); |
| 3074 | |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3075 | nfs4_sequence_done(server, &data->res.seq_res, task->tk_status); |
| 3076 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3077 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3078 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3079 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3081 | |
| 3082 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3084 | renew_lease(server, data->timestamp); |
| 3085 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | } |
| 3087 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3088 | 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] | 3089 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | data->timestamp = jiffies; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3091 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3094 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | struct inode *inode = data->inode; |
| 3097 | |
Andy Adamson | def6ed7 | 2009-04-01 09:22:26 -0400 | [diff] [blame] | 3098 | nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res, |
| 3099 | task->tk_status); |
| 3100 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3101 | 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] | 3102 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3103 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3105 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3107 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3108 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3109 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | } |
| 3111 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3112 | 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] | 3113 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3114 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3115 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3116 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3117 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | data->timestamp = jiffies; |
| 3119 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3120 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3123 | 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] | 3124 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | struct inode *inode = data->inode; |
| 3126 | |
Andy Adamson | 21d9a85 | 2009-04-01 09:22:27 -0400 | [diff] [blame] | 3127 | nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res, |
| 3128 | task->tk_status); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3129 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3130 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3131 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3133 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3134 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | } |
| 3136 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3137 | 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] | 3138 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3139 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3141 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3142 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3143 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | /* |
| 3147 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3148 | * standalone procedure for queueing an asynchronous RENEW. |
| 3149 | */ |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3150 | static void nfs4_renew_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | { |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3152 | struct nfs_client *clp = (struct nfs_client *)task->tk_msg.rpc_argp; |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3153 | unsigned long timestamp = (unsigned long)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | |
| 3155 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3156 | /* Unless we're shutting down, schedule state recovery! */ |
| 3157 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
| 3158 | nfs4_schedule_state_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | return; |
| 3160 | } |
| 3161 | spin_lock(&clp->cl_lock); |
| 3162 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 3163 | clp->cl_last_renewal = timestamp; |
| 3164 | spin_unlock(&clp->cl_lock); |
| 3165 | } |
| 3166 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3167 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3168 | .rpc_call_done = nfs4_renew_done, |
| 3169 | }; |
| 3170 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3171 | 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] | 3172 | { |
| 3173 | struct rpc_message msg = { |
| 3174 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3175 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3176 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | }; |
| 3178 | |
| 3179 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3180 | &nfs4_renew_ops, (void *)jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | } |
| 3182 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3183 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | { |
| 3185 | struct rpc_message msg = { |
| 3186 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3187 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3188 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | }; |
| 3190 | unsigned long now = jiffies; |
| 3191 | int status; |
| 3192 | |
| 3193 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3194 | if (status < 0) |
| 3195 | return status; |
| 3196 | spin_lock(&clp->cl_lock); |
| 3197 | if (time_before(clp->cl_last_renewal,now)) |
| 3198 | clp->cl_last_renewal = now; |
| 3199 | spin_unlock(&clp->cl_lock); |
| 3200 | return 0; |
| 3201 | } |
| 3202 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3203 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3204 | { |
| 3205 | return (server->caps & NFS_CAP_ACLS) |
| 3206 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3207 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3208 | } |
| 3209 | |
| 3210 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3211 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3212 | * the stack. |
| 3213 | */ |
| 3214 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3215 | |
| 3216 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3217 | struct page **pages, unsigned int *pgbase) |
| 3218 | { |
| 3219 | const void *p = buf; |
| 3220 | |
| 3221 | *pgbase = offset_in_page(buf); |
| 3222 | p -= *pgbase; |
| 3223 | while (p < buf + buflen) { |
| 3224 | *(pages++) = virt_to_page(p); |
| 3225 | p += PAGE_CACHE_SIZE; |
| 3226 | } |
| 3227 | } |
| 3228 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3229 | struct nfs4_cached_acl { |
| 3230 | int cached; |
| 3231 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3232 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3233 | }; |
| 3234 | |
| 3235 | 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] | 3236 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3237 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3238 | |
| 3239 | spin_lock(&inode->i_lock); |
| 3240 | kfree(nfsi->nfs4_acl); |
| 3241 | nfsi->nfs4_acl = acl; |
| 3242 | spin_unlock(&inode->i_lock); |
| 3243 | } |
| 3244 | |
| 3245 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3246 | { |
| 3247 | nfs4_set_cached_acl(inode, NULL); |
| 3248 | } |
| 3249 | |
| 3250 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3251 | { |
| 3252 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3253 | struct nfs4_cached_acl *acl; |
| 3254 | int ret = -ENOENT; |
| 3255 | |
| 3256 | spin_lock(&inode->i_lock); |
| 3257 | acl = nfsi->nfs4_acl; |
| 3258 | if (acl == NULL) |
| 3259 | goto out; |
| 3260 | if (buf == NULL) /* user is just asking for length */ |
| 3261 | goto out_len; |
| 3262 | if (acl->cached == 0) |
| 3263 | goto out; |
| 3264 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3265 | if (acl->len > buflen) |
| 3266 | goto out; |
| 3267 | memcpy(buf, acl->data, acl->len); |
| 3268 | out_len: |
| 3269 | ret = acl->len; |
| 3270 | out: |
| 3271 | spin_unlock(&inode->i_lock); |
| 3272 | return ret; |
| 3273 | } |
| 3274 | |
| 3275 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3276 | { |
| 3277 | struct nfs4_cached_acl *acl; |
| 3278 | |
| 3279 | if (buf && acl_len <= PAGE_SIZE) { |
| 3280 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3281 | if (acl == NULL) |
| 3282 | goto out; |
| 3283 | acl->cached = 1; |
| 3284 | memcpy(acl->data, buf, acl_len); |
| 3285 | } else { |
| 3286 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3287 | if (acl == NULL) |
| 3288 | goto out; |
| 3289 | acl->cached = 0; |
| 3290 | } |
| 3291 | acl->len = acl_len; |
| 3292 | out: |
| 3293 | nfs4_set_cached_acl(inode, acl); |
| 3294 | } |
| 3295 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3296 | 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] | 3297 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3298 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3299 | struct nfs_getaclargs args = { |
| 3300 | .fh = NFS_FH(inode), |
| 3301 | .acl_pages = pages, |
| 3302 | .acl_len = buflen, |
| 3303 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3304 | struct nfs_getaclres res = { |
| 3305 | .acl_len = buflen, |
| 3306 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3307 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3308 | struct rpc_message msg = { |
| 3309 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3310 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3311 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3312 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3313 | struct page *localpage = NULL; |
| 3314 | int ret; |
| 3315 | |
| 3316 | if (buflen < PAGE_SIZE) { |
| 3317 | /* As long as we're doing a round trip to the server anyway, |
| 3318 | * let's be prepared for a page of acl data. */ |
| 3319 | localpage = alloc_page(GFP_KERNEL); |
| 3320 | resp_buf = page_address(localpage); |
| 3321 | if (localpage == NULL) |
| 3322 | return -ENOMEM; |
| 3323 | args.acl_pages[0] = localpage; |
| 3324 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3325 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3326 | } else { |
| 3327 | resp_buf = buf; |
| 3328 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3329 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3330 | ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3331 | if (ret) |
| 3332 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3333 | if (res.acl_len > args.acl_len) |
| 3334 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3335 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3336 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3337 | if (buf) { |
| 3338 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3339 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3340 | goto out_free; |
| 3341 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3342 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3343 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3344 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3345 | out_free: |
| 3346 | if (localpage) |
| 3347 | __free_page(localpage); |
| 3348 | return ret; |
| 3349 | } |
| 3350 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3351 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3352 | { |
| 3353 | struct nfs4_exception exception = { }; |
| 3354 | ssize_t ret; |
| 3355 | do { |
| 3356 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3357 | if (ret >= 0) |
| 3358 | break; |
| 3359 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3360 | } while (exception.retry); |
| 3361 | return ret; |
| 3362 | } |
| 3363 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3364 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3365 | { |
| 3366 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3367 | int ret; |
| 3368 | |
| 3369 | if (!nfs4_server_supports_acls(server)) |
| 3370 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3371 | ret = nfs_revalidate_inode(server, inode); |
| 3372 | if (ret < 0) |
| 3373 | return ret; |
| 3374 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3375 | if (ret != -ENOENT) |
| 3376 | return ret; |
| 3377 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3378 | } |
| 3379 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3380 | 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] | 3381 | { |
| 3382 | struct nfs_server *server = NFS_SERVER(inode); |
| 3383 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3384 | struct nfs_setaclargs arg = { |
| 3385 | .fh = NFS_FH(inode), |
| 3386 | .acl_pages = pages, |
| 3387 | .acl_len = buflen, |
| 3388 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3389 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3390 | struct rpc_message msg = { |
| 3391 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3392 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3393 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3394 | }; |
| 3395 | int ret; |
| 3396 | |
| 3397 | if (!nfs4_server_supports_acls(server)) |
| 3398 | return -EOPNOTSUPP; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3399 | nfs_inode_return_delegation(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3400 | buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3401 | ret = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3402 | nfs_access_zap_cache(inode); |
| 3403 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3404 | return ret; |
| 3405 | } |
| 3406 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3407 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3408 | { |
| 3409 | struct nfs4_exception exception = { }; |
| 3410 | int err; |
| 3411 | do { |
| 3412 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3413 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3414 | &exception); |
| 3415 | } while (exception.retry); |
| 3416 | return err; |
| 3417 | } |
| 3418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | static int |
Andy Adamson | 8328d59 | 2009-04-01 09:22:35 -0400 | [diff] [blame] | 3420 | _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs_client *clp, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | if (!clp || task->tk_status >= 0) |
| 3423 | return 0; |
| 3424 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3425 | case -NFS4ERR_ADMIN_REVOKED: |
| 3426 | case -NFS4ERR_BAD_STATEID: |
| 3427 | case -NFS4ERR_OPENMODE: |
| 3428 | if (state == NULL) |
| 3429 | break; |
| 3430 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3431 | goto do_state_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3433 | if (state == NULL) |
| 3434 | break; |
| 3435 | nfs4_state_mark_reclaim_reboot(clp, state); |
| 3436 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3438 | goto do_state_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3439 | #if defined(CONFIG_NFS_V4_1) |
| 3440 | case -NFS4ERR_BADSESSION: |
| 3441 | case -NFS4ERR_BADSLOT: |
| 3442 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3443 | case -NFS4ERR_DEADSESSION: |
| 3444 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3445 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3446 | case -NFS4ERR_SEQ_MISORDERED: |
| 3447 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3448 | task->tk_status); |
Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 3449 | nfs4_schedule_state_recovery(clp); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3450 | task->tk_status = 0; |
| 3451 | return -EAGAIN; |
| 3452 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | case -NFS4ERR_DELAY: |
Andy Adamson | 8328d59 | 2009-04-01 09:22:35 -0400 | [diff] [blame] | 3454 | if (server) |
| 3455 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3456 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame^] | 3457 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3459 | task->tk_status = 0; |
| 3460 | return -EAGAIN; |
| 3461 | case -NFS4ERR_OLD_STATEID: |
| 3462 | task->tk_status = 0; |
| 3463 | return -EAGAIN; |
| 3464 | } |
| 3465 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3466 | return 0; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3467 | do_state_recovery: |
| 3468 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 3469 | nfs4_schedule_state_recovery(clp); |
| 3470 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3471 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3472 | task->tk_status = 0; |
| 3473 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
Andy Adamson | 8328d59 | 2009-04-01 09:22:35 -0400 | [diff] [blame] | 3476 | static int |
| 3477 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state) |
| 3478 | { |
| 3479 | return _nfs4_async_handle_error(task, server, server->nfs_client, state); |
| 3480 | } |
| 3481 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3482 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short port, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | { |
| 3484 | nfs4_verifier sc_verifier; |
| 3485 | struct nfs4_setclientid setclientid = { |
| 3486 | .sc_verifier = &sc_verifier, |
| 3487 | .sc_prog = program, |
| 3488 | }; |
| 3489 | struct rpc_message msg = { |
| 3490 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3491 | .rpc_argp = &setclientid, |
| 3492 | .rpc_resp = clp, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3493 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3495 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | int loop = 0; |
| 3497 | int status; |
| 3498 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3499 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3501 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3502 | |
| 3503 | for(;;) { |
| 3504 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3505 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3506 | clp->cl_ipaddr, |
| 3507 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3508 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3509 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3510 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3511 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | clp->cl_id_uniquifier); |
| 3513 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3514 | sizeof(setclientid.sc_netid), |
| 3515 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3516 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3518 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3519 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3520 | |
| 3521 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3522 | if (status != -NFS4ERR_CLID_INUSE) |
| 3523 | break; |
| 3524 | if (signalled()) |
| 3525 | break; |
| 3526 | if (loop++ & 1) |
| 3527 | ssleep(clp->cl_lease_time + 1); |
| 3528 | else |
| 3529 | if (++clp->cl_id_uniquifier == 0) |
| 3530 | break; |
| 3531 | } |
| 3532 | return status; |
| 3533 | } |
| 3534 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3535 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | { |
| 3537 | struct nfs_fsinfo fsinfo; |
| 3538 | struct rpc_message msg = { |
| 3539 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
| 3540 | .rpc_argp = clp, |
| 3541 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3542 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | }; |
| 3544 | unsigned long now; |
| 3545 | int status; |
| 3546 | |
| 3547 | now = jiffies; |
| 3548 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3549 | if (status == 0) { |
| 3550 | spin_lock(&clp->cl_lock); |
| 3551 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3552 | clp->cl_last_renewal = now; |
| 3553 | spin_unlock(&clp->cl_lock); |
| 3554 | } |
| 3555 | return status; |
| 3556 | } |
| 3557 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3558 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3559 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3560 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3561 | int err; |
| 3562 | do { |
| 3563 | err = _nfs4_proc_setclientid_confirm(clp, cred); |
| 3564 | switch (err) { |
| 3565 | case 0: |
| 3566 | return err; |
| 3567 | case -NFS4ERR_RESOURCE: |
| 3568 | /* The IBM lawyers misread another document! */ |
| 3569 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame^] | 3570 | case -EKEYEXPIRED: |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3571 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3572 | } |
| 3573 | } while (err == 0); |
| 3574 | return err; |
| 3575 | } |
| 3576 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3577 | struct nfs4_delegreturndata { |
| 3578 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3579 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3580 | struct nfs_fh fh; |
| 3581 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3582 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3583 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3584 | int rpc_status; |
| 3585 | }; |
| 3586 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3587 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3588 | { |
| 3589 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3590 | |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 3591 | nfs4_sequence_done(data->res.server, &data->res.seq_res, |
| 3592 | task->tk_status); |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3593 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3594 | switch (task->tk_status) { |
| 3595 | case -NFS4ERR_STALE_STATEID: |
| 3596 | case -NFS4ERR_EXPIRED: |
| 3597 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3598 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3599 | break; |
| 3600 | default: |
| 3601 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3602 | -EAGAIN) { |
| 3603 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3604 | return; |
| 3605 | } |
| 3606 | } |
| 3607 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | static void nfs4_delegreturn_release(void *calldata) |
| 3611 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3612 | kfree(calldata); |
| 3613 | } |
| 3614 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3615 | #if defined(CONFIG_NFS_V4_1) |
| 3616 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3617 | { |
| 3618 | struct nfs4_delegreturndata *d_data; |
| 3619 | |
| 3620 | d_data = (struct nfs4_delegreturndata *)data; |
| 3621 | |
| 3622 | if (nfs4_setup_sequence(d_data->res.server->nfs_client, |
| 3623 | &d_data->args.seq_args, |
| 3624 | &d_data->res.seq_res, 1, task)) |
| 3625 | return; |
| 3626 | rpc_call_start(task); |
| 3627 | } |
| 3628 | #endif /* CONFIG_NFS_V4_1 */ |
| 3629 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3630 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3631 | #if defined(CONFIG_NFS_V4_1) |
| 3632 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3633 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3634 | .rpc_call_done = nfs4_delegreturn_done, |
| 3635 | .rpc_release = nfs4_delegreturn_release, |
| 3636 | }; |
| 3637 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3638 | 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] | 3639 | { |
| 3640 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3641 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3642 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3643 | struct rpc_message msg = { |
| 3644 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3645 | .rpc_cred = cred, |
| 3646 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3647 | struct rpc_task_setup task_setup_data = { |
| 3648 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3649 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3650 | .callback_ops = &nfs4_delegreturn_ops, |
| 3651 | .flags = RPC_TASK_ASYNC, |
| 3652 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3653 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3654 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3655 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3656 | if (data == NULL) |
| 3657 | return -ENOMEM; |
| 3658 | data->args.fhandle = &data->fh; |
| 3659 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3660 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3661 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3662 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3663 | data->res.fattr = &data->fattr; |
| 3664 | data->res.server = server; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3665 | data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3666 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3667 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3668 | data->rpc_status = 0; |
| 3669 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3670 | task_setup_data.callback_data = data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3671 | msg.rpc_argp = &data->args, |
| 3672 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3673 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3674 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3675 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3676 | if (!issync) |
| 3677 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3678 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3679 | if (status != 0) |
| 3680 | goto out; |
| 3681 | status = data->rpc_status; |
| 3682 | if (status != 0) |
| 3683 | goto out; |
| 3684 | nfs_refresh_inode(inode, &data->fattr); |
| 3685 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3686 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3687 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | } |
| 3689 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3690 | 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] | 3691 | { |
| 3692 | struct nfs_server *server = NFS_SERVER(inode); |
| 3693 | struct nfs4_exception exception = { }; |
| 3694 | int err; |
| 3695 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3696 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | switch (err) { |
| 3698 | case -NFS4ERR_STALE_STATEID: |
| 3699 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 | case 0: |
| 3701 | return 0; |
| 3702 | } |
| 3703 | err = nfs4_handle_exception(server, err, &exception); |
| 3704 | } while (exception.retry); |
| 3705 | return err; |
| 3706 | } |
| 3707 | |
| 3708 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3709 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3710 | |
| 3711 | /* |
| 3712 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3713 | */ |
| 3714 | static unsigned long |
| 3715 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3716 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3717 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | timeout <<= 1; |
| 3719 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3720 | return NFS4_LOCK_MAXTIMEOUT; |
| 3721 | return timeout; |
| 3722 | } |
| 3723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3725 | { |
| 3726 | struct inode *inode = state->inode; |
| 3727 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3728 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3729 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3731 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3733 | struct nfs_lockt_res res = { |
| 3734 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | }; |
| 3736 | struct rpc_message msg = { |
| 3737 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3738 | .rpc_argp = &arg, |
| 3739 | .rpc_resp = &res, |
| 3740 | .rpc_cred = state->owner->so_cred, |
| 3741 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | struct nfs4_lock_state *lsp; |
| 3743 | int status; |
| 3744 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3745 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3746 | status = nfs4_set_lock_state(state, request); |
| 3747 | if (status != 0) |
| 3748 | goto out; |
| 3749 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3750 | arg.lock_owner.id = lsp->ls_id.id; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3751 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3752 | switch (status) { |
| 3753 | case 0: |
| 3754 | request->fl_type = F_UNLCK; |
| 3755 | break; |
| 3756 | case -NFS4ERR_DENIED: |
| 3757 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3759 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3760 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | return status; |
| 3762 | } |
| 3763 | |
| 3764 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3765 | { |
| 3766 | struct nfs4_exception exception = { }; |
| 3767 | int err; |
| 3768 | |
| 3769 | do { |
| 3770 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3771 | _nfs4_proc_getlk(state, cmd, request), |
| 3772 | &exception); |
| 3773 | } while (exception.retry); |
| 3774 | return err; |
| 3775 | } |
| 3776 | |
| 3777 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3778 | { |
| 3779 | int res = 0; |
| 3780 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3781 | case FL_POSIX: |
| 3782 | res = posix_lock_file_wait(file, fl); |
| 3783 | break; |
| 3784 | case FL_FLOCK: |
| 3785 | res = flock_lock_file_wait(file, fl); |
| 3786 | break; |
| 3787 | default: |
| 3788 | BUG(); |
| 3789 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | return res; |
| 3791 | } |
| 3792 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3793 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3794 | struct nfs_locku_args arg; |
| 3795 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3796 | struct nfs4_lock_state *lsp; |
| 3797 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3798 | struct file_lock fl; |
| 3799 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3800 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3801 | }; |
| 3802 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3803 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 3804 | struct nfs_open_context *ctx, |
| 3805 | struct nfs4_lock_state *lsp, |
| 3806 | struct nfs_seqid *seqid) |
| 3807 | { |
| 3808 | struct nfs4_unlockdata *p; |
| 3809 | struct inode *inode = lsp->ls_state->inode; |
| 3810 | |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3811 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3812 | if (p == NULL) |
| 3813 | return NULL; |
| 3814 | p->arg.fh = NFS_FH(inode); |
| 3815 | p->arg.fl = &p->fl; |
| 3816 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3817 | p->res.seqid = seqid; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3818 | p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3819 | p->arg.stateid = &lsp->ls_stateid; |
| 3820 | p->lsp = lsp; |
| 3821 | atomic_inc(&lsp->ls_count); |
| 3822 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3823 | p->ctx = get_nfs_open_context(ctx); |
| 3824 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3825 | p->server = NFS_SERVER(inode); |
| 3826 | return p; |
| 3827 | } |
| 3828 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3829 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3830 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3831 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3832 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3833 | nfs4_put_lock_state(calldata->lsp); |
| 3834 | put_nfs_open_context(calldata->ctx); |
| 3835 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3836 | } |
| 3837 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3838 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3839 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3840 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3841 | |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3842 | nfs4_sequence_done(calldata->server, &calldata->res.seq_res, |
| 3843 | task->tk_status); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3844 | if (RPC_ASSASSINATED(task)) |
| 3845 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3846 | switch (task->tk_status) { |
| 3847 | case 0: |
| 3848 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3849 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3850 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3851 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3852 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3853 | case -NFS4ERR_BAD_STATEID: |
| 3854 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3855 | case -NFS4ERR_STALE_STATEID: |
| 3856 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3857 | break; |
| 3858 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3859 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3860 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 3861 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3862 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3865 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3866 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3867 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3869 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3870 | return; |
| 3871 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3872 | /* Note: exit _without_ running nfs4_locku_done */ |
| 3873 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3874 | return; |
| 3875 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3876 | calldata->timestamp = jiffies; |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3877 | if (nfs4_setup_sequence(calldata->server->nfs_client, |
| 3878 | &calldata->arg.seq_args, |
| 3879 | &calldata->res.seq_res, 1, task)) |
| 3880 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3881 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3884 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3885 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3886 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3887 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3888 | }; |
| 3889 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3890 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 3891 | struct nfs_open_context *ctx, |
| 3892 | struct nfs4_lock_state *lsp, |
| 3893 | struct nfs_seqid *seqid) |
| 3894 | { |
| 3895 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3896 | struct rpc_message msg = { |
| 3897 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 3898 | .rpc_cred = ctx->cred, |
| 3899 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3900 | struct rpc_task_setup task_setup_data = { |
| 3901 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3902 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3903 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3904 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3905 | .flags = RPC_TASK_ASYNC, |
| 3906 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3907 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 3908 | /* Ensure this is an unlock - when canceling a lock, the |
| 3909 | * canceled lock is passed in, and it won't be an unlock. |
| 3910 | */ |
| 3911 | fl->fl_type = F_UNLCK; |
| 3912 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3913 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 3914 | if (data == NULL) { |
| 3915 | nfs_free_seqid(seqid); |
| 3916 | return ERR_PTR(-ENOMEM); |
| 3917 | } |
| 3918 | |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3919 | msg.rpc_argp = &data->arg, |
| 3920 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3921 | task_setup_data.callback_data = data; |
| 3922 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3923 | } |
| 3924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3926 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3927 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3928 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3929 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3930 | struct rpc_task *task; |
| 3931 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3932 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3934 | status = nfs4_set_lock_state(state, request); |
| 3935 | /* Unlock _before_ we do the RPC call */ |
| 3936 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3937 | down_read(&nfsi->rwsem); |
| 3938 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 3939 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3940 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3941 | } |
| 3942 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3943 | if (status != 0) |
| 3944 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3945 | /* Is this a delegated lock? */ |
| 3946 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3947 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3948 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3949 | seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3950 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3951 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3952 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 3953 | 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] | 3954 | status = PTR_ERR(task); |
| 3955 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3956 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3957 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3958 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3959 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3960 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3961 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | } |
| 3963 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3964 | struct nfs4_lockdata { |
| 3965 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3966 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3967 | struct nfs4_lock_state *lsp; |
| 3968 | struct nfs_open_context *ctx; |
| 3969 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3970 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3971 | int rpc_status; |
| 3972 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 3973 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3974 | }; |
| 3975 | |
| 3976 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
| 3977 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp) |
| 3978 | { |
| 3979 | struct nfs4_lockdata *p; |
| 3980 | struct inode *inode = lsp->ls_state->inode; |
| 3981 | struct nfs_server *server = NFS_SERVER(inode); |
| 3982 | |
| 3983 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
| 3984 | if (p == NULL) |
| 3985 | return NULL; |
| 3986 | |
| 3987 | p->arg.fh = NFS_FH(inode); |
| 3988 | p->arg.fl = &p->fl; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3989 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid); |
| 3990 | if (p->arg.open_seqid == NULL) |
| 3991 | goto out_free; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3992 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); |
| 3993 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3994 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3995 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3996 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3997 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3998 | p->res.lock_seqid = p->arg.lock_seqid; |
Andy Adamson | 5f7dbd5 | 2009-04-01 09:22:05 -0400 | [diff] [blame] | 3999 | p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4000 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4001 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4002 | atomic_inc(&lsp->ls_count); |
| 4003 | p->ctx = get_nfs_open_context(ctx); |
| 4004 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4005 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4006 | out_free_seqid: |
| 4007 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4008 | out_free: |
| 4009 | kfree(p); |
| 4010 | return NULL; |
| 4011 | } |
| 4012 | |
| 4013 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4014 | { |
| 4015 | struct nfs4_lockdata *data = calldata; |
| 4016 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4018 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4019 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4020 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4021 | /* Do we need to do an open_to_lock_owner? */ |
| 4022 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4023 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4024 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4025 | data->arg.open_stateid = &state->stateid; |
| 4026 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4027 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4028 | } else |
| 4029 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4030 | data->timestamp = jiffies; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4031 | if (nfs4_setup_sequence(data->server->nfs_client, &data->arg.seq_args, |
| 4032 | &data->res.seq_res, 1, task)) |
| 4033 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4034 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4035 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4036 | } |
| 4037 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4038 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4039 | { |
| 4040 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4041 | nfs4_lock_prepare(task, calldata); |
| 4042 | } |
| 4043 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4044 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4045 | { |
| 4046 | struct nfs4_lockdata *data = calldata; |
| 4047 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4048 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4049 | |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 4050 | nfs4_sequence_done(data->server, &data->res.seq_res, |
| 4051 | task->tk_status); |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4052 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4053 | data->rpc_status = task->tk_status; |
| 4054 | if (RPC_ASSASSINATED(task)) |
| 4055 | goto out; |
| 4056 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4057 | if (data->rpc_status == 0) |
| 4058 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4059 | else |
| 4060 | goto out; |
| 4061 | } |
| 4062 | if (data->rpc_status == 0) { |
| 4063 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4064 | sizeof(data->lsp->ls_stateid.data)); |
| 4065 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4066 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4067 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4068 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4069 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | static void nfs4_lock_release(void *calldata) |
| 4073 | { |
| 4074 | struct nfs4_lockdata *data = calldata; |
| 4075 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4076 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4077 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4078 | if (data->cancelled != 0) { |
| 4079 | struct rpc_task *task; |
| 4080 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4081 | data->arg.lock_seqid); |
| 4082 | if (!IS_ERR(task)) |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4083 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4084 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4085 | } else |
| 4086 | nfs_free_seqid(data->arg.lock_seqid); |
| 4087 | nfs4_put_lock_state(data->lsp); |
| 4088 | put_nfs_open_context(data->ctx); |
| 4089 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4090 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4094 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4095 | .rpc_call_done = nfs4_lock_done, |
| 4096 | .rpc_release = nfs4_lock_release, |
| 4097 | }; |
| 4098 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4099 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4100 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4101 | .rpc_call_done = nfs4_lock_done, |
| 4102 | .rpc_release = nfs4_lock_release, |
| 4103 | }; |
| 4104 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4105 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4106 | { |
| 4107 | struct nfs_client *clp = server->nfs_client; |
| 4108 | struct nfs4_state *state = lsp->ls_state; |
| 4109 | |
| 4110 | switch (error) { |
| 4111 | case -NFS4ERR_ADMIN_REVOKED: |
| 4112 | case -NFS4ERR_BAD_STATEID: |
| 4113 | case -NFS4ERR_EXPIRED: |
| 4114 | if (new_lock_owner != 0 || |
| 4115 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
| 4116 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 4117 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4118 | break; |
| 4119 | case -NFS4ERR_STALE_STATEID: |
| 4120 | if (new_lock_owner != 0 || |
| 4121 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
| 4122 | nfs4_state_mark_reclaim_reboot(clp, state); |
| 4123 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4124 | }; |
| 4125 | } |
| 4126 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4127 | 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] | 4128 | { |
| 4129 | struct nfs4_lockdata *data; |
| 4130 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4131 | struct rpc_message msg = { |
| 4132 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4133 | .rpc_cred = state->owner->so_cred, |
| 4134 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4135 | struct rpc_task_setup task_setup_data = { |
| 4136 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4137 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4138 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4139 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4140 | .flags = RPC_TASK_ASYNC, |
| 4141 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4142 | int ret; |
| 4143 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4144 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4145 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4146 | fl->fl_u.nfs4_fl.owner); |
| 4147 | if (data == NULL) |
| 4148 | return -ENOMEM; |
| 4149 | if (IS_SETLKW(cmd)) |
| 4150 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4151 | if (recovery_type > NFS_LOCK_NEW) { |
| 4152 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4153 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4154 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4155 | } |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4156 | msg.rpc_argp = &data->arg, |
| 4157 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4158 | task_setup_data.callback_data = data; |
| 4159 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4160 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4161 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4162 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4163 | if (ret == 0) { |
| 4164 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4165 | if (ret) |
| 4166 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4167 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4168 | } else |
| 4169 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4170 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4171 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4172 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4176 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4177 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4178 | struct nfs4_exception exception = { }; |
| 4179 | int err; |
| 4180 | |
| 4181 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4182 | /* Cache the lock if possible... */ |
| 4183 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4184 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4185 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame^] | 4186 | if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4187 | break; |
| 4188 | nfs4_handle_exception(server, err, &exception); |
| 4189 | } while (exception.retry); |
| 4190 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4194 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4195 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4196 | struct nfs4_exception exception = { }; |
| 4197 | int err; |
| 4198 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4199 | err = nfs4_set_lock_state(state, request); |
| 4200 | if (err != 0) |
| 4201 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4202 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4203 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4204 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4205 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4206 | switch (err) { |
| 4207 | default: |
| 4208 | goto out; |
| 4209 | case -NFS4ERR_GRACE: |
| 4210 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame^] | 4211 | case -EKEYEXPIRED: |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4212 | nfs4_handle_exception(server, err, &exception); |
| 4213 | err = 0; |
| 4214 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4215 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4216 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4217 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | } |
| 4219 | |
| 4220 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4221 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4222 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4223 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4224 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4226 | if ((fl_flags & FL_POSIX) && |
| 4227 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4228 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4229 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4230 | status = nfs4_set_lock_state(state, request); |
| 4231 | if (status != 0) |
| 4232 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4233 | request->fl_flags |= FL_ACCESS; |
| 4234 | status = do_vfs_lock(request->fl_file, request); |
| 4235 | if (status < 0) |
| 4236 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4237 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4238 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4239 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4240 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4241 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4242 | status = do_vfs_lock(request->fl_file, request); |
| 4243 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4244 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4245 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4246 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4247 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4248 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4249 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4250 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4251 | 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] | 4252 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4253 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4254 | out: |
| 4255 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | return status; |
| 4257 | } |
| 4258 | |
| 4259 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4260 | { |
| 4261 | struct nfs4_exception exception = { }; |
| 4262 | int err; |
| 4263 | |
| 4264 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4265 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4266 | if (err == -NFS4ERR_DENIED) |
| 4267 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4269 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | } while (exception.retry); |
| 4271 | return err; |
| 4272 | } |
| 4273 | |
| 4274 | static int |
| 4275 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4276 | { |
| 4277 | struct nfs_open_context *ctx; |
| 4278 | struct nfs4_state *state; |
| 4279 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4280 | int status; |
| 4281 | |
| 4282 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4283 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | state = ctx->state; |
| 4285 | |
| 4286 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4287 | return -EINVAL; |
| 4288 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4289 | if (IS_GETLK(cmd)) { |
| 4290 | if (state != NULL) |
| 4291 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4292 | return 0; |
| 4293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | |
| 4295 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4296 | return -EINVAL; |
| 4297 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4298 | if (request->fl_type == F_UNLCK) { |
| 4299 | if (state != NULL) |
| 4300 | return nfs4_proc_unlck(state, cmd, request); |
| 4301 | return 0; |
| 4302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4304 | if (state == NULL) |
| 4305 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | do { |
| 4307 | status = nfs4_proc_setlk(state, cmd, request); |
| 4308 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4309 | break; |
| 4310 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4311 | status = -ERESTARTSYS; |
| 4312 | if (signalled()) |
| 4313 | break; |
| 4314 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | return status; |
| 4316 | } |
| 4317 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4318 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4319 | { |
| 4320 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4321 | struct nfs4_exception exception = { }; |
| 4322 | int err; |
| 4323 | |
| 4324 | err = nfs4_set_lock_state(state, fl); |
| 4325 | if (err != 0) |
| 4326 | goto out; |
| 4327 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4328 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4329 | switch (err) { |
| 4330 | default: |
| 4331 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4332 | __func__, err); |
| 4333 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4334 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4335 | goto out; |
| 4336 | case -NFS4ERR_EXPIRED: |
| 4337 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4338 | case -NFS4ERR_STALE_STATEID: |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4339 | case -NFS4ERR_BADSESSION: |
| 4340 | case -NFS4ERR_BADSLOT: |
| 4341 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4342 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4343 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4344 | nfs4_schedule_state_recovery(server->nfs_client); |
| 4345 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4346 | case -ERESTARTSYS: |
| 4347 | /* |
| 4348 | * The show must go on: exit, but mark the |
| 4349 | * stateid as needing recovery. |
| 4350 | */ |
| 4351 | case -NFS4ERR_ADMIN_REVOKED: |
| 4352 | case -NFS4ERR_BAD_STATEID: |
| 4353 | case -NFS4ERR_OPENMODE: |
| 4354 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
| 4355 | err = 0; |
| 4356 | goto out; |
| 4357 | case -ENOMEM: |
| 4358 | case -NFS4ERR_DENIED: |
| 4359 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4360 | err = 0; |
| 4361 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4362 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame^] | 4363 | case -EKEYEXPIRED: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4364 | break; |
| 4365 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4366 | err = nfs4_handle_exception(server, err, &exception); |
| 4367 | } while (exception.retry); |
| 4368 | out: |
| 4369 | return err; |
| 4370 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4371 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4372 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4373 | |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4374 | int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf, |
| 4375 | size_t buflen, int flags) |
| 4376 | { |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4377 | struct inode *inode = dentry->d_inode; |
| 4378 | |
| 4379 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
| 4380 | return -EOPNOTSUPP; |
| 4381 | |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4382 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4383 | } |
| 4384 | |
| 4385 | /* The getxattr man page suggests returning -ENODATA for unknown attributes, |
| 4386 | * and that's what we'll do for e.g. user attributes that haven't been set. |
| 4387 | * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported |
| 4388 | * attributes in kernel-managed attribute namespaces. */ |
| 4389 | ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf, |
| 4390 | size_t buflen) |
| 4391 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4392 | struct inode *inode = dentry->d_inode; |
| 4393 | |
| 4394 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
| 4395 | return -EOPNOTSUPP; |
| 4396 | |
| 4397 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4398 | } |
| 4399 | |
| 4400 | ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen) |
| 4401 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4402 | size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4403 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4404 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4405 | return 0; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4406 | if (buf && buflen < len) |
| 4407 | return -ERANGE; |
| 4408 | if (buf) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4409 | memcpy(buf, XATTR_NAME_NFSV4_ACL, len); |
| 4410 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4411 | } |
| 4412 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4413 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4414 | { |
| 4415 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4416 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4417 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4418 | return; |
| 4419 | |
| 4420 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4421 | NFS_ATTR_FATTR_NLINK; |
| 4422 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4423 | fattr->nlink = 2; |
| 4424 | } |
| 4425 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4426 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4427 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4428 | { |
| 4429 | struct nfs_server *server = NFS_SERVER(dir); |
| 4430 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4431 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4432 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4433 | }; |
| 4434 | struct nfs4_fs_locations_arg args = { |
| 4435 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4436 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4437 | .page = page, |
| 4438 | .bitmask = bitmask, |
| 4439 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4440 | struct nfs4_fs_locations_res res = { |
| 4441 | .fs_locations = fs_locations, |
| 4442 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4443 | struct rpc_message msg = { |
| 4444 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4445 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4446 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4447 | }; |
| 4448 | int status; |
| 4449 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4450 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4451 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4452 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4453 | fs_locations->nlocations = 0; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 4454 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4455 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4456 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4457 | return status; |
| 4458 | } |
| 4459 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4460 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4461 | /* |
| 4462 | * nfs4_proc_exchange_id() |
| 4463 | * |
| 4464 | * Since the clientid has expired, all compounds using sessions |
| 4465 | * associated with the stale clientid will be returning |
| 4466 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4467 | * be in some phase of session reset. |
| 4468 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4469 | 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] | 4470 | { |
| 4471 | nfs4_verifier verifier; |
| 4472 | struct nfs41_exchange_id_args args = { |
| 4473 | .client = clp, |
| 4474 | .flags = clp->cl_exchange_flags, |
| 4475 | }; |
| 4476 | struct nfs41_exchange_id_res res = { |
| 4477 | .client = clp, |
| 4478 | }; |
| 4479 | int status; |
| 4480 | struct rpc_message msg = { |
| 4481 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4482 | .rpc_argp = &args, |
| 4483 | .rpc_resp = &res, |
| 4484 | .rpc_cred = cred, |
| 4485 | }; |
| 4486 | __be32 *p; |
| 4487 | |
| 4488 | dprintk("--> %s\n", __func__); |
| 4489 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4490 | |
Alexandros Batsakis | 7b183d0 | 2009-12-05 13:33:25 -0500 | [diff] [blame] | 4491 | /* Remove server-only flags */ |
| 4492 | args.flags &= ~EXCHGID4_FLAG_CONFIRMED_R; |
| 4493 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4494 | p = (u32 *)verifier.data; |
| 4495 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4496 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4497 | args.verifier = &verifier; |
| 4498 | |
| 4499 | while (1) { |
| 4500 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4501 | "%s/%s %u", |
| 4502 | clp->cl_ipaddr, |
| 4503 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4504 | RPC_DISPLAY_ADDR), |
| 4505 | clp->cl_id_uniquifier); |
| 4506 | |
| 4507 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4508 | |
| 4509 | if (status != NFS4ERR_CLID_INUSE) |
| 4510 | break; |
| 4511 | |
| 4512 | if (signalled()) |
| 4513 | break; |
| 4514 | |
| 4515 | if (++clp->cl_id_uniquifier == 0) |
| 4516 | break; |
| 4517 | } |
| 4518 | |
| 4519 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4520 | return status; |
| 4521 | } |
| 4522 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4523 | struct nfs4_get_lease_time_data { |
| 4524 | struct nfs4_get_lease_time_args *args; |
| 4525 | struct nfs4_get_lease_time_res *res; |
| 4526 | struct nfs_client *clp; |
| 4527 | }; |
| 4528 | |
| 4529 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4530 | void *calldata) |
| 4531 | { |
| 4532 | int ret; |
| 4533 | struct nfs4_get_lease_time_data *data = |
| 4534 | (struct nfs4_get_lease_time_data *)calldata; |
| 4535 | |
| 4536 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4537 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4538 | /* just setup sequence, do not trigger session recovery |
| 4539 | since we're invoked within one */ |
| 4540 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4541 | &data->args->la_seq_args, |
| 4542 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4543 | |
| 4544 | BUG_ON(ret == -EAGAIN); |
| 4545 | rpc_call_start(task); |
| 4546 | dprintk("<-- %s\n", __func__); |
| 4547 | } |
| 4548 | |
| 4549 | /* |
| 4550 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4551 | * from sequence operation or clientid errors. |
| 4552 | */ |
| 4553 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4554 | { |
| 4555 | struct nfs4_get_lease_time_data *data = |
| 4556 | (struct nfs4_get_lease_time_data *)calldata; |
| 4557 | |
| 4558 | dprintk("--> %s\n", __func__); |
| 4559 | nfs41_sequence_done(data->clp, &data->res->lr_seq_res, task->tk_status); |
| 4560 | switch (task->tk_status) { |
| 4561 | case -NFS4ERR_DELAY: |
| 4562 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame^] | 4563 | case -EKEYEXPIRED: |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4564 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4565 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4566 | task->tk_status = 0; |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4567 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4568 | return; |
| 4569 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4570 | dprintk("<-- %s\n", __func__); |
| 4571 | } |
| 4572 | |
| 4573 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4574 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4575 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4576 | }; |
| 4577 | |
| 4578 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4579 | { |
| 4580 | struct rpc_task *task; |
| 4581 | struct nfs4_get_lease_time_args args; |
| 4582 | struct nfs4_get_lease_time_res res = { |
| 4583 | .lr_fsinfo = fsinfo, |
| 4584 | }; |
| 4585 | struct nfs4_get_lease_time_data data = { |
| 4586 | .args = &args, |
| 4587 | .res = &res, |
| 4588 | .clp = clp, |
| 4589 | }; |
| 4590 | struct rpc_message msg = { |
| 4591 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4592 | .rpc_argp = &args, |
| 4593 | .rpc_resp = &res, |
| 4594 | }; |
| 4595 | struct rpc_task_setup task_setup = { |
| 4596 | .rpc_client = clp->cl_rpcclient, |
| 4597 | .rpc_message = &msg, |
| 4598 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4599 | .callback_data = &data |
| 4600 | }; |
| 4601 | int status; |
| 4602 | |
| 4603 | res.lr_seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 4604 | dprintk("--> %s\n", __func__); |
| 4605 | task = rpc_run_task(&task_setup); |
| 4606 | |
| 4607 | if (IS_ERR(task)) |
| 4608 | status = PTR_ERR(task); |
| 4609 | else { |
| 4610 | status = task->tk_status; |
| 4611 | rpc_put_task(task); |
| 4612 | } |
| 4613 | dprintk("<-- %s return %d\n", __func__, status); |
| 4614 | |
| 4615 | return status; |
| 4616 | } |
| 4617 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4618 | /* |
| 4619 | * Reset a slot table |
| 4620 | */ |
| 4621 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, int max_slots, |
| 4622 | int old_max_slots, int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4623 | { |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4624 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4625 | int ret = 0; |
| 4626 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4627 | dprintk("--> %s: max_reqs=%u, tbl %p\n", __func__, max_slots, tbl); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4628 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4629 | /* |
| 4630 | * Until we have dynamic slot table adjustment, insist |
| 4631 | * upon the same slot table size |
| 4632 | */ |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4633 | if (max_slots != old_max_slots) { |
| 4634 | dprintk("%s reset slot table does't match old\n", |
| 4635 | __func__); |
| 4636 | ret = -EINVAL; /*XXX NFS4ERR_REQ_TOO_BIG ? */ |
| 4637 | goto out; |
| 4638 | } |
| 4639 | spin_lock(&tbl->slot_tbl_lock); |
| 4640 | for (i = 0; i < max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4641 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4642 | spin_unlock(&tbl->slot_tbl_lock); |
| 4643 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4644 | tbl, tbl->slots, tbl->max_slots); |
| 4645 | out: |
| 4646 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4647 | return ret; |
| 4648 | } |
| 4649 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4650 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4651 | * Reset the forechannel and backchannel slot tables |
| 4652 | */ |
| 4653 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4654 | { |
| 4655 | int status; |
| 4656 | |
| 4657 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
| 4658 | session->fc_attrs.max_reqs, |
| 4659 | session->fc_slot_table.max_slots, |
| 4660 | 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4661 | if (status) |
| 4662 | return status; |
| 4663 | |
| 4664 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
| 4665 | session->bc_attrs.max_reqs, |
| 4666 | session->bc_slot_table.max_slots, |
| 4667 | 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4668 | return status; |
| 4669 | } |
| 4670 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4671 | /* Destroy the slot table */ |
| 4672 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4673 | { |
| 4674 | if (session->fc_slot_table.slots != NULL) { |
| 4675 | kfree(session->fc_slot_table.slots); |
| 4676 | session->fc_slot_table.slots = NULL; |
| 4677 | } |
| 4678 | if (session->bc_slot_table.slots != NULL) { |
| 4679 | kfree(session->bc_slot_table.slots); |
| 4680 | session->bc_slot_table.slots = NULL; |
| 4681 | } |
| 4682 | return; |
| 4683 | } |
| 4684 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4685 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4686 | * Initialize slot table |
| 4687 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4688 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4689 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4690 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4691 | struct nfs4_slot *slot; |
| 4692 | int ret = -ENOMEM; |
| 4693 | |
| 4694 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4695 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4696 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4697 | |
| 4698 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_KERNEL); |
| 4699 | if (!slot) |
| 4700 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4701 | ret = 0; |
| 4702 | |
| 4703 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4704 | tbl->max_slots = max_slots; |
| 4705 | tbl->slots = slot; |
| 4706 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4707 | spin_unlock(&tbl->slot_tbl_lock); |
| 4708 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4709 | tbl, tbl->slots, tbl->max_slots); |
| 4710 | out: |
| 4711 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4712 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4713 | } |
| 4714 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4715 | /* |
| 4716 | * Initialize the forechannel and backchannel tables |
| 4717 | */ |
| 4718 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4719 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4720 | struct nfs4_slot_table *tbl; |
| 4721 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4722 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4723 | tbl = &session->fc_slot_table; |
| 4724 | if (tbl->slots == NULL) { |
| 4725 | status = nfs4_init_slot_table(tbl, |
| 4726 | session->fc_attrs.max_reqs, 1); |
| 4727 | if (status) |
| 4728 | return status; |
| 4729 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4730 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4731 | tbl = &session->bc_slot_table; |
| 4732 | if (tbl->slots == NULL) { |
| 4733 | status = nfs4_init_slot_table(tbl, |
| 4734 | session->bc_attrs.max_reqs, 0); |
| 4735 | if (status) |
| 4736 | nfs4_destroy_slot_tables(session); |
| 4737 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4738 | |
| 4739 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 4743 | { |
| 4744 | struct nfs4_session *session; |
| 4745 | struct nfs4_slot_table *tbl; |
| 4746 | |
| 4747 | session = kzalloc(sizeof(struct nfs4_session), GFP_KERNEL); |
| 4748 | if (!session) |
| 4749 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4750 | |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4751 | /* |
| 4752 | * The create session reply races with the server back |
| 4753 | * channel probe. Mark the client NFS_CS_SESSION_INITING |
| 4754 | * so that the client back channel can find the |
| 4755 | * nfs_client struct |
| 4756 | */ |
| 4757 | clp->cl_cons_state = NFS_CS_SESSION_INITING; |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 4758 | init_completion(&session->complete); |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4759 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4760 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4761 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4762 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4763 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4764 | |
| 4765 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4766 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4767 | spin_lock_init(&tbl->slot_tbl_lock); |
| 4768 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
| 4769 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4770 | session->clp = clp; |
| 4771 | return session; |
| 4772 | } |
| 4773 | |
| 4774 | void nfs4_destroy_session(struct nfs4_session *session) |
| 4775 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 4776 | nfs4_proc_destroy_session(session); |
| 4777 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 4778 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 4779 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 4780 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4781 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4782 | kfree(session); |
| 4783 | } |
| 4784 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4785 | /* |
| 4786 | * Initialize the values to be used by the client in CREATE_SESSION |
| 4787 | * If nfs4_init_session set the fore channel request and response sizes, |
| 4788 | * use them. |
| 4789 | * |
| 4790 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 4791 | * always set csa_cachethis to FALSE because the current implementation |
| 4792 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 4793 | */ |
| 4794 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 4795 | { |
| 4796 | struct nfs4_session *session = args->client->cl_session; |
| 4797 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 4798 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 4799 | |
| 4800 | if (mxrqst_sz == 0) |
| 4801 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 4802 | if (mxresp_sz == 0) |
| 4803 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 4804 | /* Fore channel attributes */ |
| 4805 | args->fc_attrs.headerpadsz = 0; |
| 4806 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 4807 | args->fc_attrs.max_resp_sz = mxresp_sz; |
| 4808 | args->fc_attrs.max_resp_sz_cached = mxresp_sz; |
| 4809 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 4810 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 4811 | |
| 4812 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 4813 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 4814 | __func__, |
| 4815 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
| 4816 | args->fc_attrs.max_resp_sz_cached, args->fc_attrs.max_ops, |
| 4817 | args->fc_attrs.max_reqs); |
| 4818 | |
| 4819 | /* Back channel attributes */ |
| 4820 | args->bc_attrs.headerpadsz = 0; |
| 4821 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 4822 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 4823 | args->bc_attrs.max_resp_sz_cached = 0; |
| 4824 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 4825 | args->bc_attrs.max_reqs = 1; |
| 4826 | |
| 4827 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 4828 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 4829 | __func__, |
| 4830 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 4831 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 4832 | args->bc_attrs.max_reqs); |
| 4833 | } |
| 4834 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4835 | static int _verify_channel_attr(char *chan, char *attr_name, u32 sent, u32 rcvd) |
| 4836 | { |
| 4837 | if (rcvd <= sent) |
| 4838 | return 0; |
| 4839 | printk(KERN_WARNING "%s: Session INVALID: %s channel %s increased. " |
| 4840 | "sent=%u rcvd=%u\n", __func__, chan, attr_name, sent, rcvd); |
| 4841 | return -EINVAL; |
| 4842 | } |
| 4843 | |
| 4844 | #define _verify_fore_channel_attr(_name_) \ |
| 4845 | _verify_channel_attr("fore", #_name_, \ |
| 4846 | args->fc_attrs._name_, \ |
| 4847 | session->fc_attrs._name_) |
| 4848 | |
| 4849 | #define _verify_back_channel_attr(_name_) \ |
| 4850 | _verify_channel_attr("back", #_name_, \ |
| 4851 | args->bc_attrs._name_, \ |
| 4852 | session->bc_attrs._name_) |
| 4853 | |
| 4854 | /* |
| 4855 | * The server is not allowed to increase the fore channel header pad size, |
| 4856 | * maximum response size, or maximum number of operations. |
| 4857 | * |
| 4858 | * The back channel attributes are only negotiatied down: We send what the |
| 4859 | * (back channel) server insists upon. |
| 4860 | */ |
| 4861 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 4862 | struct nfs4_session *session) |
| 4863 | { |
| 4864 | int ret = 0; |
| 4865 | |
| 4866 | ret |= _verify_fore_channel_attr(headerpadsz); |
| 4867 | ret |= _verify_fore_channel_attr(max_resp_sz); |
| 4868 | ret |= _verify_fore_channel_attr(max_ops); |
| 4869 | |
| 4870 | ret |= _verify_back_channel_attr(headerpadsz); |
| 4871 | ret |= _verify_back_channel_attr(max_rqst_sz); |
| 4872 | ret |= _verify_back_channel_attr(max_resp_sz); |
| 4873 | ret |= _verify_back_channel_attr(max_resp_sz_cached); |
| 4874 | ret |= _verify_back_channel_attr(max_ops); |
| 4875 | ret |= _verify_back_channel_attr(max_reqs); |
| 4876 | |
| 4877 | return ret; |
| 4878 | } |
| 4879 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4880 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 4881 | { |
| 4882 | struct nfs4_session *session = clp->cl_session; |
| 4883 | struct nfs41_create_session_args args = { |
| 4884 | .client = clp, |
| 4885 | .cb_program = NFS4_CALLBACK, |
| 4886 | }; |
| 4887 | struct nfs41_create_session_res res = { |
| 4888 | .client = clp, |
| 4889 | }; |
| 4890 | struct rpc_message msg = { |
| 4891 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 4892 | .rpc_argp = &args, |
| 4893 | .rpc_resp = &res, |
| 4894 | }; |
| 4895 | int status; |
| 4896 | |
| 4897 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 4898 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4899 | |
| 4900 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 4901 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4902 | if (!status) |
| 4903 | /* Verify the session's negotiated channel_attrs values */ |
| 4904 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4905 | if (!status) { |
| 4906 | /* Increment the clientid slot sequence id */ |
| 4907 | clp->cl_seqid++; |
| 4908 | } |
| 4909 | |
| 4910 | return status; |
| 4911 | } |
| 4912 | |
| 4913 | /* |
| 4914 | * Issues a CREATE_SESSION operation to the server. |
| 4915 | * It is the responsibility of the caller to verify the session is |
| 4916 | * expired before calling this routine. |
| 4917 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4918 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4919 | { |
| 4920 | int status; |
| 4921 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4922 | struct nfs4_session *session = clp->cl_session; |
| 4923 | |
| 4924 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 4925 | |
| 4926 | status = _nfs4_proc_create_session(clp); |
| 4927 | if (status) |
| 4928 | goto out; |
| 4929 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4930 | /* Init and reset the fore channel */ |
| 4931 | status = nfs4_init_slot_tables(session); |
| 4932 | dprintk("slot table initialization returned %d\n", status); |
| 4933 | if (status) |
| 4934 | goto out; |
| 4935 | status = nfs4_reset_slot_tables(session); |
| 4936 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4937 | if (status) |
| 4938 | goto out; |
| 4939 | |
| 4940 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 4941 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 4942 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4943 | out: |
| 4944 | dprintk("<-- %s\n", __func__); |
| 4945 | return status; |
| 4946 | } |
| 4947 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 4948 | /* |
| 4949 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 4950 | * The caller must serialize access to this routine. |
| 4951 | */ |
| 4952 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 4953 | { |
| 4954 | int status = 0; |
| 4955 | struct rpc_message msg; |
| 4956 | |
| 4957 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 4958 | |
| 4959 | /* session is still being setup */ |
| 4960 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 4961 | return status; |
| 4962 | |
| 4963 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 4964 | msg.rpc_argp = session; |
| 4965 | msg.rpc_resp = NULL; |
| 4966 | msg.rpc_cred = NULL; |
| 4967 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 4968 | |
| 4969 | if (status) |
| 4970 | printk(KERN_WARNING |
| 4971 | "Got error %d from the server on DESTROY_SESSION. " |
| 4972 | "Session has been destroyed regardless...\n", status); |
| 4973 | |
| 4974 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 4975 | return status; |
| 4976 | } |
| 4977 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 4978 | int nfs4_init_session(struct nfs_server *server) |
| 4979 | { |
| 4980 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 4981 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 4982 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 4983 | int ret; |
| 4984 | |
| 4985 | if (!nfs4_has_session(clp)) |
| 4986 | return 0; |
| 4987 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 4988 | rsize = server->rsize; |
| 4989 | if (rsize == 0) |
| 4990 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 4991 | wsize = server->wsize; |
| 4992 | if (wsize == 0) |
| 4993 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 4994 | |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 4995 | session = clp->cl_session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 4996 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 4997 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 4998 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 4999 | ret = nfs4_recover_expired_lease(server); |
| 5000 | if (!ret) |
| 5001 | ret = nfs4_check_client_ready(clp); |
| 5002 | return ret; |
| 5003 | } |
| 5004 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5005 | /* |
| 5006 | * Renew the cl_session lease. |
| 5007 | */ |
| 5008 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5009 | { |
| 5010 | struct nfs4_sequence_args args; |
| 5011 | struct nfs4_sequence_res res; |
| 5012 | |
| 5013 | struct rpc_message msg = { |
| 5014 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5015 | .rpc_argp = &args, |
| 5016 | .rpc_resp = &res, |
| 5017 | .rpc_cred = cred, |
| 5018 | }; |
| 5019 | |
| 5020 | args.sa_cache_this = 0; |
| 5021 | |
| 5022 | return nfs4_call_sync_sequence(clp, clp->cl_rpcclient, &msg, &args, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5023 | &res, args.sa_cache_this, 1); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5024 | } |
| 5025 | |
| 5026 | void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
| 5027 | { |
| 5028 | struct nfs_client *clp = (struct nfs_client *)data; |
| 5029 | |
| 5030 | nfs41_sequence_done(clp, task->tk_msg.rpc_resp, task->tk_status); |
| 5031 | |
| 5032 | if (task->tk_status < 0) { |
| 5033 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
| 5034 | |
| 5035 | if (_nfs4_async_handle_error(task, NULL, clp, NULL) |
| 5036 | == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 5037 | nfs_restart_rpc(task, clp); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5038 | return; |
| 5039 | } |
| 5040 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5041 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
| 5042 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5043 | kfree(task->tk_msg.rpc_argp); |
| 5044 | kfree(task->tk_msg.rpc_resp); |
| 5045 | |
| 5046 | dprintk("<-- %s\n", __func__); |
| 5047 | } |
| 5048 | |
| 5049 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5050 | { |
| 5051 | struct nfs_client *clp; |
| 5052 | struct nfs4_sequence_args *args; |
| 5053 | struct nfs4_sequence_res *res; |
| 5054 | |
| 5055 | clp = (struct nfs_client *)data; |
| 5056 | args = task->tk_msg.rpc_argp; |
| 5057 | res = task->tk_msg.rpc_resp; |
| 5058 | |
| 5059 | if (nfs4_setup_sequence(clp, args, res, 0, task)) |
| 5060 | return; |
| 5061 | rpc_call_start(task); |
| 5062 | } |
| 5063 | |
| 5064 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5065 | .rpc_call_done = nfs41_sequence_call_done, |
| 5066 | .rpc_call_prepare = nfs41_sequence_prepare, |
| 5067 | }; |
| 5068 | |
| 5069 | static int nfs41_proc_async_sequence(struct nfs_client *clp, |
| 5070 | struct rpc_cred *cred) |
| 5071 | { |
| 5072 | struct nfs4_sequence_args *args; |
| 5073 | struct nfs4_sequence_res *res; |
| 5074 | struct rpc_message msg = { |
| 5075 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5076 | .rpc_cred = cred, |
| 5077 | }; |
| 5078 | |
| 5079 | args = kzalloc(sizeof(*args), GFP_KERNEL); |
| 5080 | if (!args) |
| 5081 | return -ENOMEM; |
| 5082 | res = kzalloc(sizeof(*res), GFP_KERNEL); |
| 5083 | if (!res) { |
| 5084 | kfree(args); |
| 5085 | return -ENOMEM; |
| 5086 | } |
| 5087 | res->sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 5088 | msg.rpc_argp = args; |
| 5089 | msg.rpc_resp = res; |
| 5090 | |
| 5091 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
| 5092 | &nfs41_sequence_ops, (void *)clp); |
| 5093 | } |
| 5094 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5095 | struct nfs4_reclaim_complete_data { |
| 5096 | struct nfs_client *clp; |
| 5097 | struct nfs41_reclaim_complete_args arg; |
| 5098 | struct nfs41_reclaim_complete_res res; |
| 5099 | }; |
| 5100 | |
| 5101 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5102 | { |
| 5103 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5104 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5105 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5106 | if (nfs4_setup_sequence(calldata->clp, &calldata->arg.seq_args, |
| 5107 | &calldata->res.seq_res, 0, task)) |
| 5108 | return; |
| 5109 | |
| 5110 | rpc_call_start(task); |
| 5111 | } |
| 5112 | |
| 5113 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5114 | { |
| 5115 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5116 | struct nfs_client *clp = calldata->clp; |
| 5117 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5118 | |
| 5119 | dprintk("--> %s\n", __func__); |
| 5120 | nfs41_sequence_done(clp, res, task->tk_status); |
| 5121 | switch (task->tk_status) { |
| 5122 | case 0: |
| 5123 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5124 | break; |
| 5125 | case -NFS4ERR_BADSESSION: |
| 5126 | case -NFS4ERR_DEADSESSION: |
| 5127 | /* |
| 5128 | * Handle the session error, but do not retry the operation, as |
| 5129 | * we have no way of telling whether the clientid had to be |
| 5130 | * reset before we got our reply. If reset, a new wave of |
| 5131 | * reclaim operations will follow, containing their own reclaim |
| 5132 | * complete. We don't want our retry to get on the way of |
| 5133 | * recovery by incorrectly indicating to the server that we're |
| 5134 | * done reclaiming state since the process had to be restarted. |
| 5135 | */ |
| 5136 | _nfs4_async_handle_error(task, NULL, clp, NULL); |
| 5137 | break; |
| 5138 | default: |
| 5139 | if (_nfs4_async_handle_error( |
| 5140 | task, NULL, clp, NULL) == -EAGAIN) { |
| 5141 | rpc_restart_call_prepare(task); |
| 5142 | return; |
| 5143 | } |
| 5144 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5145 | |
| 5146 | dprintk("<-- %s\n", __func__); |
| 5147 | } |
| 5148 | |
| 5149 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5150 | { |
| 5151 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5152 | |
| 5153 | kfree(calldata); |
| 5154 | } |
| 5155 | |
| 5156 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5157 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5158 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5159 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5160 | }; |
| 5161 | |
| 5162 | /* |
| 5163 | * Issue a global reclaim complete. |
| 5164 | */ |
| 5165 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5166 | { |
| 5167 | struct nfs4_reclaim_complete_data *calldata; |
| 5168 | struct rpc_task *task; |
| 5169 | struct rpc_message msg = { |
| 5170 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5171 | }; |
| 5172 | struct rpc_task_setup task_setup_data = { |
| 5173 | .rpc_client = clp->cl_rpcclient, |
| 5174 | .rpc_message = &msg, |
| 5175 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5176 | .flags = RPC_TASK_ASYNC, |
| 5177 | }; |
| 5178 | int status = -ENOMEM; |
| 5179 | |
| 5180 | dprintk("--> %s\n", __func__); |
| 5181 | calldata = kzalloc(sizeof(*calldata), GFP_KERNEL); |
| 5182 | if (calldata == NULL) |
| 5183 | goto out; |
| 5184 | calldata->clp = clp; |
| 5185 | calldata->arg.one_fs = 0; |
| 5186 | calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE; |
| 5187 | |
| 5188 | msg.rpc_argp = &calldata->arg; |
| 5189 | msg.rpc_resp = &calldata->res; |
| 5190 | task_setup_data.callback_data = calldata; |
| 5191 | task = rpc_run_task(&task_setup_data); |
| 5192 | if (IS_ERR(task)) |
| 5193 | status = PTR_ERR(task); |
| 5194 | rpc_put_task(task); |
| 5195 | out: |
| 5196 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5197 | return status; |
| 5198 | } |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5199 | #endif /* CONFIG_NFS_V4_1 */ |
| 5200 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5201 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5202 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5203 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5204 | .recover_open = nfs4_open_reclaim, |
| 5205 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5206 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5207 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | }; |
| 5209 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5210 | #if defined(CONFIG_NFS_V4_1) |
| 5211 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5212 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5213 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5214 | .recover_open = nfs4_open_reclaim, |
| 5215 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5216 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5217 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5218 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5219 | }; |
| 5220 | #endif /* CONFIG_NFS_V4_1 */ |
| 5221 | |
| 5222 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5223 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5224 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5225 | .recover_open = nfs4_open_expired, |
| 5226 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5227 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5228 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | }; |
| 5230 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5231 | #if defined(CONFIG_NFS_V4_1) |
| 5232 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5233 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5234 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5235 | .recover_open = nfs4_open_expired, |
| 5236 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5237 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5238 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5239 | }; |
| 5240 | #endif /* CONFIG_NFS_V4_1 */ |
| 5241 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5242 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5243 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5244 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5245 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5246 | }; |
| 5247 | |
| 5248 | #if defined(CONFIG_NFS_V4_1) |
| 5249 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5250 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5251 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5252 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5253 | }; |
| 5254 | #endif |
| 5255 | |
| 5256 | /* |
| 5257 | * Per minor version reboot and network partition recovery ops |
| 5258 | */ |
| 5259 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5260 | struct nfs4_state_recovery_ops *nfs4_reboot_recovery_ops[] = { |
| 5261 | &nfs40_reboot_recovery_ops, |
| 5262 | #if defined(CONFIG_NFS_V4_1) |
| 5263 | &nfs41_reboot_recovery_ops, |
| 5264 | #endif |
| 5265 | }; |
| 5266 | |
| 5267 | struct nfs4_state_recovery_ops *nfs4_nograce_recovery_ops[] = { |
| 5268 | &nfs40_nograce_recovery_ops, |
| 5269 | #if defined(CONFIG_NFS_V4_1) |
| 5270 | &nfs41_nograce_recovery_ops, |
| 5271 | #endif |
| 5272 | }; |
| 5273 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5274 | struct nfs4_state_maintenance_ops *nfs4_state_renewal_ops[] = { |
| 5275 | &nfs40_state_renewal_ops, |
| 5276 | #if defined(CONFIG_NFS_V4_1) |
| 5277 | &nfs41_state_renewal_ops, |
| 5278 | #endif |
| 5279 | }; |
| 5280 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5281 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5282 | .permission = nfs_permission, |
| 5283 | .getattr = nfs_getattr, |
| 5284 | .setattr = nfs_setattr, |
| 5285 | .getxattr = nfs4_getxattr, |
| 5286 | .setxattr = nfs4_setxattr, |
| 5287 | .listxattr = nfs4_listxattr, |
| 5288 | }; |
| 5289 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5290 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5291 | .version = 4, /* protocol version */ |
| 5292 | .dentry_ops = &nfs4_dentry_operations, |
| 5293 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5294 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5295 | .getroot = nfs4_proc_get_root, |
| 5296 | .getattr = nfs4_proc_getattr, |
| 5297 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5298 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | .lookup = nfs4_proc_lookup, |
| 5300 | .access = nfs4_proc_access, |
| 5301 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 | .create = nfs4_proc_create, |
| 5303 | .remove = nfs4_proc_remove, |
| 5304 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5305 | .unlink_done = nfs4_proc_unlink_done, |
| 5306 | .rename = nfs4_proc_rename, |
| 5307 | .link = nfs4_proc_link, |
| 5308 | .symlink = nfs4_proc_symlink, |
| 5309 | .mkdir = nfs4_proc_mkdir, |
| 5310 | .rmdir = nfs4_proc_remove, |
| 5311 | .readdir = nfs4_proc_readdir, |
| 5312 | .mknod = nfs4_proc_mknod, |
| 5313 | .statfs = nfs4_proc_statfs, |
| 5314 | .fsinfo = nfs4_proc_fsinfo, |
| 5315 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5316 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5317 | .decode_dirent = nfs4_decode_dirent, |
| 5318 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5319 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5321 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5322 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5323 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5324 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5325 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5326 | .close_context = nfs4_close_context, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5327 | }; |
| 5328 | |
| 5329 | /* |
| 5330 | * Local variables: |
| 5331 | * c-basic-offset: 8 |
| 5332 | * End: |
| 5333 | */ |