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