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