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