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