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