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