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