Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/sunrpc/clnt.h> |
| 44 | #include <linux/nfs.h> |
| 45 | #include <linux/nfs4.h> |
| 46 | #include <linux/nfs_fs.h> |
| 47 | #include <linux/nfs_page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 49 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 50 | #include <linux/module.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 51 | #include <linux/sunrpc/bc_xprt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 53 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 55 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 56 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 57 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 58 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 61 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 62 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 64 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 65 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 66 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 67 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 68 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 69 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | 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] | 71 | 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] | 72 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
| 73 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 74 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 75 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 76 | struct nfs4_state *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 79 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 81 | if (err >= -1000) |
| 82 | return err; |
| 83 | switch (err) { |
| 84 | case -NFS4ERR_RESOURCE: |
| 85 | return -EREMOTEIO; |
| 86 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 88 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 89 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 91 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* |
| 95 | * This is our standard bitmap for GETATTR requests. |
| 96 | */ |
| 97 | const u32 nfs4_fattr_bitmap[2] = { |
| 98 | FATTR4_WORD0_TYPE |
| 99 | | FATTR4_WORD0_CHANGE |
| 100 | | FATTR4_WORD0_SIZE |
| 101 | | FATTR4_WORD0_FSID |
| 102 | | FATTR4_WORD0_FILEID, |
| 103 | FATTR4_WORD1_MODE |
| 104 | | FATTR4_WORD1_NUMLINKS |
| 105 | | FATTR4_WORD1_OWNER |
| 106 | | FATTR4_WORD1_OWNER_GROUP |
| 107 | | FATTR4_WORD1_RAWDEV |
| 108 | | FATTR4_WORD1_SPACE_USED |
| 109 | | FATTR4_WORD1_TIME_ACCESS |
| 110 | | FATTR4_WORD1_TIME_METADATA |
| 111 | | FATTR4_WORD1_TIME_MODIFY |
| 112 | }; |
| 113 | |
| 114 | const u32 nfs4_statfs_bitmap[2] = { |
| 115 | FATTR4_WORD0_FILES_AVAIL |
| 116 | | FATTR4_WORD0_FILES_FREE |
| 117 | | FATTR4_WORD0_FILES_TOTAL, |
| 118 | FATTR4_WORD1_SPACE_AVAIL |
| 119 | | FATTR4_WORD1_SPACE_FREE |
| 120 | | FATTR4_WORD1_SPACE_TOTAL |
| 121 | }; |
| 122 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 123 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | FATTR4_WORD0_MAXLINK |
| 125 | | FATTR4_WORD0_MAXNAME, |
| 126 | 0 |
| 127 | }; |
| 128 | |
| 129 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 130 | | FATTR4_WORD0_MAXREAD |
| 131 | | FATTR4_WORD0_MAXWRITE |
| 132 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 133 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 134 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 137 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 138 | FATTR4_WORD0_TYPE |
| 139 | | FATTR4_WORD0_CHANGE |
| 140 | | FATTR4_WORD0_SIZE |
| 141 | | FATTR4_WORD0_FSID |
| 142 | | FATTR4_WORD0_FILEID |
| 143 | | FATTR4_WORD0_FS_LOCATIONS, |
| 144 | FATTR4_WORD1_MODE |
| 145 | | FATTR4_WORD1_NUMLINKS |
| 146 | | FATTR4_WORD1_OWNER |
| 147 | | FATTR4_WORD1_OWNER_GROUP |
| 148 | | FATTR4_WORD1_RAWDEV |
| 149 | | FATTR4_WORD1_SPACE_USED |
| 150 | | FATTR4_WORD1_TIME_ACCESS |
| 151 | | FATTR4_WORD1_TIME_METADATA |
| 152 | | FATTR4_WORD1_TIME_MODIFY |
| 153 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 154 | }; |
| 155 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 156 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | struct nfs4_readdir_arg *readdir) |
| 158 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 159 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | BUG_ON(readdir->count < 80); |
| 162 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 163 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | readdir->cookie = 0; |
| 169 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 170 | if (cookie == 2) |
| 171 | return; |
| 172 | |
| 173 | /* |
| 174 | * NFSv4 servers do not return entries for '.' and '..' |
| 175 | * Therefore, we fake these entries here. We let '.' |
| 176 | * have cookie 0 and '..' have cookie 1. Note that |
| 177 | * when talking to the server, we always send cookie 0 |
| 178 | * instead of 1 or 2. |
| 179 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 180 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | if (cookie == 0) { |
| 183 | *p++ = xdr_one; /* next */ |
| 184 | *p++ = xdr_zero; /* cookie, first word */ |
| 185 | *p++ = xdr_one; /* cookie, second word */ |
| 186 | *p++ = xdr_one; /* entry len */ |
| 187 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 188 | p++; |
| 189 | *p++ = xdr_one; /* bitmap length */ |
| 190 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 191 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 192 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | *p++ = xdr_one; /* next */ |
| 196 | *p++ = xdr_zero; /* cookie, first word */ |
| 197 | *p++ = xdr_two; /* cookie, second word */ |
| 198 | *p++ = xdr_two; /* entry len */ |
| 199 | memcpy(p, "..\0\0", 4); /* entry */ |
| 200 | p++; |
| 201 | *p++ = xdr_one; /* bitmap length */ |
| 202 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 203 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 204 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | readdir->pgbase = (char *)p - (char *)start; |
| 207 | readdir->count -= readdir->pgbase; |
| 208 | kunmap_atomic(start, KM_USER0); |
| 209 | } |
| 210 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 211 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 212 | { |
| 213 | int res; |
| 214 | |
| 215 | might_sleep(); |
| 216 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 217 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 218 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 219 | return res; |
| 220 | } |
| 221 | |
| 222 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 223 | { |
| 224 | int res = 0; |
| 225 | |
| 226 | might_sleep(); |
| 227 | |
| 228 | if (*timeout <= 0) |
| 229 | *timeout = NFS4_POLL_RETRY_MIN; |
| 230 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 231 | *timeout = NFS4_POLL_RETRY_MAX; |
| 232 | schedule_timeout_killable(*timeout); |
| 233 | if (fatal_signal_pending(current)) |
| 234 | res = -ERESTARTSYS; |
| 235 | *timeout <<= 1; |
| 236 | return res; |
| 237 | } |
| 238 | |
| 239 | /* This is the error handling routine for processes that are allowed |
| 240 | * to sleep. |
| 241 | */ |
| 242 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 243 | { |
| 244 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 245 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 246 | int ret = errorcode; |
| 247 | |
| 248 | exception->retry = 0; |
| 249 | switch(errorcode) { |
| 250 | case 0: |
| 251 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 252 | case -NFS4ERR_ADMIN_REVOKED: |
| 253 | case -NFS4ERR_BAD_STATEID: |
| 254 | case -NFS4ERR_OPENMODE: |
| 255 | if (state == NULL) |
| 256 | break; |
| 257 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 258 | goto do_state_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 259 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 260 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 261 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 262 | goto do_state_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 263 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 264 | case -NFS4ERR_BADSESSION: |
| 265 | case -NFS4ERR_BADSLOT: |
| 266 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 267 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 268 | case -NFS4ERR_DEADSESSION: |
| 269 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 270 | case -NFS4ERR_SEQ_MISORDERED: |
| 271 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 272 | errorcode); |
Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 273 | nfs4_schedule_state_recovery(clp); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 274 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 275 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 276 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 277 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 278 | if (exception->timeout > HZ) { |
| 279 | /* We have retried a decent amount, time to |
| 280 | * fail |
| 281 | */ |
| 282 | ret = -EBUSY; |
| 283 | break; |
| 284 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 285 | case -NFS4ERR_GRACE: |
| 286 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 287 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 288 | ret = nfs4_delay(server->client, &exception->timeout); |
| 289 | if (ret != 0) |
| 290 | break; |
| 291 | case -NFS4ERR_OLD_STATEID: |
| 292 | exception->retry = 1; |
| 293 | } |
| 294 | /* We failed to handle the error */ |
| 295 | return nfs4_map_errors(ret); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 296 | do_state_recovery: |
| 297 | nfs4_schedule_state_recovery(clp); |
| 298 | ret = nfs4_wait_clnt_recover(clp); |
| 299 | if (ret == 0) |
| 300 | exception->retry = 1; |
| 301 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 305 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | spin_lock(&clp->cl_lock); |
| 308 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 309 | clp->cl_last_renewal = timestamp; |
| 310 | spin_unlock(&clp->cl_lock); |
| 311 | } |
| 312 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 313 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 314 | { |
| 315 | do_renew_lease(server->nfs_client, timestamp); |
| 316 | } |
| 317 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 318 | #if defined(CONFIG_NFS_V4_1) |
| 319 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 320 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 321 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 322 | * |
| 323 | * freeing a slot is trivially done by clearing its respective bit |
| 324 | * in the bitmap. |
| 325 | * If the freed slotid equals highest_used_slotid we want to update it |
| 326 | * so that the server would be able to size down the slot table if needed, |
| 327 | * otherwise we know that the highest_used_slotid is still in use. |
| 328 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 329 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 330 | * highest slotid in use. |
| 331 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 332 | * |
| 333 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 334 | */ |
| 335 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 336 | nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *free_slot) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 337 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 338 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 339 | int slotid = free_slotid; |
| 340 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 341 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 342 | /* clear used bit in bitmap */ |
| 343 | __clear_bit(slotid, tbl->used_slots); |
| 344 | |
| 345 | /* update highest_used_slotid when it is freed */ |
| 346 | if (slotid == tbl->highest_used_slotid) { |
| 347 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 348 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 349 | tbl->highest_used_slotid = slotid; |
| 350 | else |
| 351 | tbl->highest_used_slotid = -1; |
| 352 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 353 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 354 | free_slotid, tbl->highest_used_slotid); |
| 355 | } |
| 356 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 357 | /* |
| 358 | * Signal state manager thread if session is drained |
| 359 | */ |
| 360 | static void nfs41_check_drain_session_complete(struct nfs4_session *ses) |
| 361 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 362 | struct rpc_task *task; |
| 363 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 364 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 365 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 366 | if (task) |
| 367 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 368 | return; |
| 369 | } |
| 370 | |
| 371 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 372 | return; |
| 373 | |
| 374 | dprintk("%s COMPLETE: Session Drained\n", __func__); |
| 375 | complete(&ses->complete); |
| 376 | } |
| 377 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 378 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 379 | { |
| 380 | struct nfs4_slot_table *tbl; |
| 381 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 382 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 383 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 384 | /* just wake up the next guy waiting since |
| 385 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 386 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 387 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 388 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 389 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 390 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 391 | nfs4_free_slot(tbl, res->sr_slot); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 392 | nfs41_check_drain_session_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 393 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 394 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 395 | } |
| 396 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 397 | static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 398 | { |
| 399 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 400 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 401 | |
| 402 | /* |
| 403 | * sr_status remains 1 if an RPC level error occurred. The server |
| 404 | * may or may not have processed the sequence operation.. |
| 405 | * Proceed as if the server received and processed the sequence |
| 406 | * operation. |
| 407 | */ |
| 408 | if (res->sr_status == 1) |
| 409 | res->sr_status = NFS_OK; |
| 410 | |
| 411 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 412 | if (!res->sr_slot) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 413 | goto out; |
| 414 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 415 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 416 | switch (res->sr_status) { |
| 417 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 418 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 419 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 420 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 421 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 422 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 423 | /* Check sequence flags */ |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 424 | if (atomic_read(&clp->cl_count) > 1) |
| 425 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 426 | break; |
| 427 | case -NFS4ERR_DELAY: |
| 428 | /* The server detected a resend of the RPC call and |
| 429 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 430 | * of RFC5661. |
| 431 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 432 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 433 | __func__, |
| 434 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 435 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 436 | goto out_retry; |
| 437 | default: |
| 438 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 439 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 440 | } |
| 441 | out: |
| 442 | /* The session may be reset by one of the error handlers. */ |
| 443 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 444 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 445 | return 1; |
| 446 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 447 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 448 | goto out; |
| 449 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 450 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 451 | } |
| 452 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 453 | static int nfs4_sequence_done(struct rpc_task *task, |
| 454 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 455 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 456 | if (res->sr_session == NULL) |
| 457 | return 1; |
| 458 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 459 | } |
| 460 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 461 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 462 | * nfs4_find_slot - efficiently look for a free slot |
| 463 | * |
| 464 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 465 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 466 | * and respectively set up the sequence operation args. |
| 467 | * 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] | 468 | * |
| 469 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 470 | */ |
| 471 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 472 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 473 | { |
| 474 | int slotid; |
| 475 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 476 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 477 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 478 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 479 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 480 | tbl->max_slots); |
| 481 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 482 | if (slotid >= tbl->max_slots) |
| 483 | goto out; |
| 484 | __set_bit(slotid, tbl->used_slots); |
| 485 | if (slotid > tbl->highest_used_slotid) |
| 486 | tbl->highest_used_slotid = slotid; |
| 487 | ret_id = slotid; |
| 488 | out: |
| 489 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 490 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 491 | return ret_id; |
| 492 | } |
| 493 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 494 | static int nfs41_setup_sequence(struct nfs4_session *session, |
| 495 | struct nfs4_sequence_args *args, |
| 496 | struct nfs4_sequence_res *res, |
| 497 | int cache_reply, |
| 498 | struct rpc_task *task) |
| 499 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 500 | struct nfs4_slot *slot; |
| 501 | struct nfs4_slot_table *tbl; |
| 502 | u8 slotid; |
| 503 | |
| 504 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 505 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 506 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 507 | return 0; |
| 508 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 509 | tbl = &session->fc_slot_table; |
| 510 | |
| 511 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 512 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 513 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 514 | /* |
| 515 | * The state manager will wait until the slot table is empty. |
| 516 | * Schedule the reset thread |
| 517 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 518 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 519 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 520 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 521 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 522 | } |
| 523 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 524 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 525 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 526 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 527 | spin_unlock(&tbl->slot_tbl_lock); |
| 528 | dprintk("%s enforce FIFO order\n", __func__); |
| 529 | return -EAGAIN; |
| 530 | } |
| 531 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 532 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 533 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 534 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 535 | spin_unlock(&tbl->slot_tbl_lock); |
| 536 | dprintk("<-- %s: no free slots\n", __func__); |
| 537 | return -EAGAIN; |
| 538 | } |
| 539 | spin_unlock(&tbl->slot_tbl_lock); |
| 540 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 541 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 542 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 543 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 544 | args->sa_slotid = slotid; |
| 545 | args->sa_cache_this = cache_reply; |
| 546 | |
| 547 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 548 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 549 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 550 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 551 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 552 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 553 | /* |
| 554 | * sr_status is only set in decode_sequence, and so will remain |
| 555 | * set to 1 if an rpc level failure occurs. |
| 556 | */ |
| 557 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 561 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 562 | struct nfs4_sequence_args *args, |
| 563 | struct nfs4_sequence_res *res, |
| 564 | int cache_reply, |
| 565 | struct rpc_task *task) |
| 566 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 567 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 568 | int ret = 0; |
| 569 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 570 | if (session == NULL) { |
| 571 | args->sa_session = NULL; |
| 572 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 573 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 574 | } |
| 575 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 576 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 577 | __func__, session->clp, session, res->sr_slot ? |
| 578 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 579 | |
| 580 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 581 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 582 | out: |
| 583 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 584 | return ret; |
| 585 | } |
| 586 | |
| 587 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 588 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 589 | struct nfs4_sequence_args *seq_args; |
| 590 | struct nfs4_sequence_res *seq_res; |
| 591 | int cache_reply; |
| 592 | }; |
| 593 | |
| 594 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 595 | { |
| 596 | struct nfs41_call_sync_data *data = calldata; |
| 597 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 598 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 599 | |
| 600 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 601 | data->seq_res, data->cache_reply, task)) |
| 602 | return; |
| 603 | rpc_call_start(task); |
| 604 | } |
| 605 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 606 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 607 | { |
| 608 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 609 | nfs41_call_sync_prepare(task, calldata); |
| 610 | } |
| 611 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 612 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 613 | { |
| 614 | struct nfs41_call_sync_data *data = calldata; |
| 615 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 616 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 617 | } |
| 618 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 619 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 620 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 621 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 622 | }; |
| 623 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 624 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 625 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 626 | .rpc_call_done = nfs41_call_sync_done, |
| 627 | }; |
| 628 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 629 | static int nfs4_call_sync_sequence(struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 630 | struct rpc_message *msg, |
| 631 | struct nfs4_sequence_args *args, |
| 632 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 633 | int cache_reply, |
| 634 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 635 | { |
| 636 | int ret; |
| 637 | struct rpc_task *task; |
| 638 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 639 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 640 | .seq_args = args, |
| 641 | .seq_res = res, |
| 642 | .cache_reply = cache_reply, |
| 643 | }; |
| 644 | struct rpc_task_setup task_setup = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 645 | .rpc_client = server->client, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 646 | .rpc_message = msg, |
| 647 | .callback_ops = &nfs41_call_sync_ops, |
| 648 | .callback_data = &data |
| 649 | }; |
| 650 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 651 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 652 | if (privileged) |
| 653 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 654 | task = rpc_run_task(&task_setup); |
| 655 | if (IS_ERR(task)) |
| 656 | ret = PTR_ERR(task); |
| 657 | else { |
| 658 | ret = task->tk_status; |
| 659 | rpc_put_task(task); |
| 660 | } |
| 661 | return ret; |
| 662 | } |
| 663 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 664 | int _nfs4_call_sync_session(struct nfs_server *server, |
| 665 | struct rpc_message *msg, |
| 666 | struct nfs4_sequence_args *args, |
| 667 | struct nfs4_sequence_res *res, |
| 668 | int cache_reply) |
| 669 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 670 | return nfs4_call_sync_sequence(server, msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 671 | } |
| 672 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 673 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 674 | static int nfs4_sequence_done(struct rpc_task *task, |
| 675 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 676 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 677 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 678 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 679 | #endif /* CONFIG_NFS_V4_1 */ |
| 680 | |
| 681 | int _nfs4_call_sync(struct nfs_server *server, |
| 682 | struct rpc_message *msg, |
| 683 | struct nfs4_sequence_args *args, |
| 684 | struct nfs4_sequence_res *res, |
| 685 | int cache_reply) |
| 686 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 687 | args->sa_session = res->sr_session = NULL; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 688 | return rpc_call_sync(server->client, msg, 0); |
| 689 | } |
| 690 | |
| 691 | #define nfs4_call_sync(server, msg, args, res, cache_reply) \ |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 692 | (server)->nfs_client->cl_mvops->call_sync((server), (msg), &(args)->seq_args, \ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 693 | &(res)->seq_res, (cache_reply)) |
| 694 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 695 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 697 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 699 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 700 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 701 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 702 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 703 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 704 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 707 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 708 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 709 | struct nfs_openargs o_arg; |
| 710 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 711 | struct nfs_open_confirmargs c_arg; |
| 712 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 713 | struct nfs_fattr f_attr; |
| 714 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 715 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 716 | struct dentry *dir; |
| 717 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 718 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 719 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 720 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 721 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 722 | int rpc_status; |
| 723 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 724 | }; |
| 725 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 726 | |
| 727 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 728 | { |
| 729 | p->o_res.f_attr = &p->f_attr; |
| 730 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 731 | p->o_res.seqid = p->o_arg.seqid; |
| 732 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 733 | p->o_res.server = p->o_arg.server; |
| 734 | nfs_fattr_init(&p->f_attr); |
| 735 | nfs_fattr_init(&p->dir_attr); |
| 736 | } |
| 737 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 738 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 739 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 740 | const struct iattr *attrs, |
| 741 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 742 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 743 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 744 | struct inode *dir = parent->d_inode; |
| 745 | struct nfs_server *server = NFS_SERVER(dir); |
| 746 | struct nfs4_opendata *p; |
| 747 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 748 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 749 | if (p == NULL) |
| 750 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 751 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 752 | if (p->o_arg.seqid == NULL) |
| 753 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 754 | path_get(path); |
| 755 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 756 | p->dir = parent; |
| 757 | p->owner = sp; |
| 758 | atomic_inc(&sp->so_count); |
| 759 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 760 | p->o_arg.open_flags = flags; |
| 761 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 762 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 763 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 764 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 765 | p->o_arg.server = server; |
| 766 | p->o_arg.bitmask = server->attr_bitmask; |
| 767 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 768 | if (flags & O_CREAT) { |
| 769 | u32 *s; |
| 770 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 771 | p->o_arg.u.attrs = &p->attrs; |
| 772 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 773 | s = (u32 *) p->o_arg.u.verifier.data; |
| 774 | s[0] = jiffies; |
| 775 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 776 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 777 | p->c_arg.fh = &p->o_res.fh; |
| 778 | p->c_arg.stateid = &p->o_res.stateid; |
| 779 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 780 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 781 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 782 | return p; |
| 783 | err_free: |
| 784 | kfree(p); |
| 785 | err: |
| 786 | dput(parent); |
| 787 | return NULL; |
| 788 | } |
| 789 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 790 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 791 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 792 | struct nfs4_opendata *p = container_of(kref, |
| 793 | struct nfs4_opendata, kref); |
| 794 | |
| 795 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 796 | if (p->state != NULL) |
| 797 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 798 | nfs4_put_state_owner(p->owner); |
| 799 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 800 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 801 | kfree(p); |
| 802 | } |
| 803 | |
| 804 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 805 | { |
| 806 | if (p != NULL) |
| 807 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 810 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 811 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 812 | int ret; |
| 813 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 814 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 815 | return ret; |
| 816 | } |
| 817 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 818 | 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] | 819 | { |
| 820 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 821 | |
| 822 | if (open_mode & O_EXCL) |
| 823 | goto out; |
| 824 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 825 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 826 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 827 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 828 | break; |
| 829 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 830 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 831 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 832 | break; |
| 833 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 834 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 835 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 836 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 837 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 838 | return ret; |
| 839 | } |
| 840 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 841 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 842 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 843 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 844 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 845 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 846 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 847 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 848 | return 1; |
| 849 | } |
| 850 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 851 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 852 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 853 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 854 | case FMODE_WRITE: |
| 855 | state->n_wronly++; |
| 856 | break; |
| 857 | case FMODE_READ: |
| 858 | state->n_rdonly++; |
| 859 | break; |
| 860 | case FMODE_READ|FMODE_WRITE: |
| 861 | state->n_rdwr++; |
| 862 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 863 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 864 | } |
| 865 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 866 | 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] | 867 | { |
| 868 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 869 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 870 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 871 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 872 | case FMODE_READ: |
| 873 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 874 | break; |
| 875 | case FMODE_WRITE: |
| 876 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 877 | break; |
| 878 | case FMODE_READ|FMODE_WRITE: |
| 879 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 880 | } |
| 881 | } |
| 882 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 883 | 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] | 884 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 885 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 886 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 887 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 888 | } |
| 889 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 890 | 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] | 891 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 892 | /* |
| 893 | * Protect the call to nfs4_state_set_mode_locked and |
| 894 | * serialise the stateid update |
| 895 | */ |
| 896 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 897 | if (deleg_stateid != NULL) { |
| 898 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 899 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 900 | } |
| 901 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 902 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 903 | write_sequnlock(&state->seqlock); |
| 904 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 905 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 906 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 909 | 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] | 910 | { |
| 911 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 912 | struct nfs_delegation *deleg_cur; |
| 913 | int ret = 0; |
| 914 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 915 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 916 | |
| 917 | rcu_read_lock(); |
| 918 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 919 | if (deleg_cur == NULL) |
| 920 | goto no_delegation; |
| 921 | |
| 922 | spin_lock(&deleg_cur->lock); |
| 923 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 924 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 925 | goto no_delegation_unlock; |
| 926 | |
| 927 | if (delegation == NULL) |
| 928 | delegation = &deleg_cur->stateid; |
| 929 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 930 | goto no_delegation_unlock; |
| 931 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 932 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 933 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 934 | ret = 1; |
| 935 | no_delegation_unlock: |
| 936 | spin_unlock(&deleg_cur->lock); |
| 937 | no_delegation: |
| 938 | rcu_read_unlock(); |
| 939 | |
| 940 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 941 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 942 | ret = 1; |
| 943 | } |
| 944 | |
| 945 | return ret; |
| 946 | } |
| 947 | |
| 948 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 949 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 950 | { |
| 951 | struct nfs_delegation *delegation; |
| 952 | |
| 953 | rcu_read_lock(); |
| 954 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 955 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 956 | rcu_read_unlock(); |
| 957 | return; |
| 958 | } |
| 959 | rcu_read_unlock(); |
| 960 | nfs_inode_return_delegation(inode); |
| 961 | } |
| 962 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 963 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 964 | { |
| 965 | struct nfs4_state *state = opendata->state; |
| 966 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 967 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 968 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 969 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 970 | nfs4_stateid stateid; |
| 971 | int ret = -EAGAIN; |
| 972 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 973 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 974 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 975 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 976 | if (can_open_cached(state, fmode, open_mode)) { |
| 977 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 978 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 979 | goto out_return_state; |
| 980 | } |
| 981 | spin_unlock(&state->owner->so_lock); |
| 982 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 983 | rcu_read_lock(); |
| 984 | delegation = rcu_dereference(nfsi->delegation); |
| 985 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 986 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 987 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 988 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 989 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 990 | /* Save the delegation */ |
| 991 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 992 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 993 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 994 | if (ret != 0) |
| 995 | goto out; |
| 996 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 997 | |
| 998 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 999 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1000 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1001 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1002 | out: |
| 1003 | return ERR_PTR(ret); |
| 1004 | out_return_state: |
| 1005 | atomic_inc(&state->count); |
| 1006 | return state; |
| 1007 | } |
| 1008 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1009 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1010 | { |
| 1011 | struct inode *inode; |
| 1012 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1013 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1014 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1015 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1016 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1017 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1018 | goto out; |
| 1019 | } |
| 1020 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1021 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1022 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1023 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1024 | 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] | 1025 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1026 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1027 | goto err; |
| 1028 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1029 | state = nfs4_get_open_state(inode, data->owner); |
| 1030 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1031 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1032 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1033 | int delegation_flags = 0; |
| 1034 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1035 | rcu_read_lock(); |
| 1036 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1037 | if (delegation) |
| 1038 | delegation_flags = delegation->flags; |
| 1039 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1040 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1041 | nfs_inode_set_delegation(state->inode, |
| 1042 | data->owner->so_cred, |
| 1043 | &data->o_res); |
| 1044 | else |
| 1045 | nfs_inode_reclaim_delegation(state->inode, |
| 1046 | data->owner->so_cred, |
| 1047 | &data->o_res); |
| 1048 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1049 | |
| 1050 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1051 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1052 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1053 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1054 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1055 | err_put_inode: |
| 1056 | iput(inode); |
| 1057 | err: |
| 1058 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1061 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1062 | { |
| 1063 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1064 | struct nfs_open_context *ctx; |
| 1065 | |
| 1066 | spin_lock(&state->inode->i_lock); |
| 1067 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1068 | if (ctx->state != state) |
| 1069 | continue; |
| 1070 | get_nfs_open_context(ctx); |
| 1071 | spin_unlock(&state->inode->i_lock); |
| 1072 | return ctx; |
| 1073 | } |
| 1074 | spin_unlock(&state->inode->i_lock); |
| 1075 | return ERR_PTR(-ENOENT); |
| 1076 | } |
| 1077 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1078 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1079 | { |
| 1080 | struct nfs4_opendata *opendata; |
| 1081 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1082 | opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1083 | if (opendata == NULL) |
| 1084 | return ERR_PTR(-ENOMEM); |
| 1085 | opendata->state = state; |
| 1086 | atomic_inc(&state->count); |
| 1087 | return opendata; |
| 1088 | } |
| 1089 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1090 | 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] | 1091 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1092 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1093 | int ret; |
| 1094 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1095 | opendata->o_arg.open_flags = 0; |
| 1096 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1097 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1098 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1099 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1100 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1101 | if (ret != 0) |
| 1102 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1103 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1104 | if (IS_ERR(newstate)) |
| 1105 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1106 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1107 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1108 | return 0; |
| 1109 | } |
| 1110 | |
| 1111 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1112 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1113 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1114 | int ret; |
| 1115 | |
| 1116 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1117 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1118 | smp_rmb(); |
| 1119 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1120 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1121 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1122 | if (ret != 0) |
| 1123 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1124 | if (newstate != state) |
| 1125 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1126 | } |
| 1127 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1128 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1129 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1130 | if (ret != 0) |
| 1131 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1132 | if (newstate != state) |
| 1133 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1134 | } |
| 1135 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1136 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1137 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1138 | if (ret != 0) |
| 1139 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1140 | if (newstate != state) |
| 1141 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1142 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1143 | /* |
| 1144 | * We may have performed cached opens for all three recoveries. |
| 1145 | * Check if we need to update the current stateid. |
| 1146 | */ |
| 1147 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1148 | memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1149 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1150 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1151 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1152 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1153 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1154 | return 0; |
| 1155 | } |
| 1156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | /* |
| 1158 | * OPEN_RECLAIM: |
| 1159 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1161 | static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1163 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1164 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1165 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | int status; |
| 1167 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1168 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1169 | if (IS_ERR(opendata)) |
| 1170 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1171 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1172 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1173 | rcu_read_lock(); |
| 1174 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1175 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1176 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1177 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1178 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1179 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1180 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | return status; |
| 1182 | } |
| 1183 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1184 | static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | { |
| 1186 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1187 | struct nfs4_exception exception = { }; |
| 1188 | int err; |
| 1189 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1190 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1191 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1192 | break; |
| 1193 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | } while (exception.retry); |
| 1195 | return err; |
| 1196 | } |
| 1197 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1198 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1199 | { |
| 1200 | struct nfs_open_context *ctx; |
| 1201 | int ret; |
| 1202 | |
| 1203 | ctx = nfs4_state_find_open_context(state); |
| 1204 | if (IS_ERR(ctx)) |
| 1205 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1206 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1207 | put_nfs_open_context(ctx); |
| 1208 | return ret; |
| 1209 | } |
| 1210 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1211 | static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1213 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1214 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1216 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1217 | if (IS_ERR(opendata)) |
| 1218 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1219 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1220 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1221 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1222 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1223 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1224 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1227 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | { |
| 1229 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1230 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | int err; |
| 1232 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1233 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | switch (err) { |
| 1235 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1236 | case -ENOENT: |
| 1237 | case -ESTALE: |
| 1238 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1239 | case -NFS4ERR_BADSESSION: |
| 1240 | case -NFS4ERR_BADSLOT: |
| 1241 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1242 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1243 | case -NFS4ERR_DEADSESSION: |
| 1244 | nfs4_schedule_state_recovery( |
| 1245 | server->nfs_client); |
| 1246 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | case -NFS4ERR_STALE_CLIENTID: |
| 1248 | case -NFS4ERR_STALE_STATEID: |
| 1249 | case -NFS4ERR_EXPIRED: |
| 1250 | /* Don't recall a delegation if it was lost */ |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1251 | nfs4_schedule_state_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1252 | goto out; |
| 1253 | case -ERESTARTSYS: |
| 1254 | /* |
| 1255 | * The show must go on: exit, but mark the |
| 1256 | * stateid as needing recovery. |
| 1257 | */ |
| 1258 | case -NFS4ERR_ADMIN_REVOKED: |
| 1259 | case -NFS4ERR_BAD_STATEID: |
| 1260 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1261 | case -EKEYEXPIRED: |
| 1262 | /* |
| 1263 | * User RPCSEC_GSS context has expired. |
| 1264 | * We cannot recover this stateid now, so |
| 1265 | * skip it and allow recovery thread to |
| 1266 | * proceed. |
| 1267 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1268 | case -ENOMEM: |
| 1269 | err = 0; |
| 1270 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | } |
| 1272 | err = nfs4_handle_exception(server, err, &exception); |
| 1273 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1274 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | return err; |
| 1276 | } |
| 1277 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1278 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1279 | { |
| 1280 | struct nfs4_opendata *data = calldata; |
| 1281 | |
| 1282 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1283 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1284 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1285 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1286 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1287 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1288 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1289 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | static void nfs4_open_confirm_release(void *calldata) |
| 1293 | { |
| 1294 | struct nfs4_opendata *data = calldata; |
| 1295 | struct nfs4_state *state = NULL; |
| 1296 | |
| 1297 | /* If this request hasn't been cancelled, do nothing */ |
| 1298 | if (data->cancelled == 0) |
| 1299 | goto out_free; |
| 1300 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1301 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1302 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1303 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1304 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1305 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1306 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1307 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1311 | .rpc_call_done = nfs4_open_confirm_done, |
| 1312 | .rpc_release = nfs4_open_confirm_release, |
| 1313 | }; |
| 1314 | |
| 1315 | /* |
| 1316 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1317 | */ |
| 1318 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1319 | { |
| 1320 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1321 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1322 | struct rpc_message msg = { |
| 1323 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1324 | .rpc_argp = &data->c_arg, |
| 1325 | .rpc_resp = &data->c_res, |
| 1326 | .rpc_cred = data->owner->so_cred, |
| 1327 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1328 | struct rpc_task_setup task_setup_data = { |
| 1329 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1330 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1331 | .callback_ops = &nfs4_open_confirm_ops, |
| 1332 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1333 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1334 | .flags = RPC_TASK_ASYNC, |
| 1335 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | int status; |
| 1337 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1338 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1339 | data->rpc_done = 0; |
| 1340 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1341 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1342 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1343 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1344 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1345 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1346 | if (status != 0) { |
| 1347 | data->cancelled = 1; |
| 1348 | smp_wmb(); |
| 1349 | } else |
| 1350 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1351 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | return status; |
| 1353 | } |
| 1354 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1355 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1357 | struct nfs4_opendata *data = calldata; |
| 1358 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1359 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1360 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1361 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1362 | /* |
| 1363 | * Check if we still need to send an OPEN call, or if we can use |
| 1364 | * a delegation instead. |
| 1365 | */ |
| 1366 | if (data->state != NULL) { |
| 1367 | struct nfs_delegation *delegation; |
| 1368 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1369 | 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] | 1370 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1371 | rcu_read_lock(); |
| 1372 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1373 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1374 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1375 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1376 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1377 | } |
| 1378 | rcu_read_unlock(); |
| 1379 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1380 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1381 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1382 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1383 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1384 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1385 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1386 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1387 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1388 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1389 | &data->o_arg.seq_args, |
| 1390 | &data->o_res.seq_res, 1, task)) |
| 1391 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1392 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1393 | return; |
| 1394 | out_no_action: |
| 1395 | task->tk_action = NULL; |
| 1396 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1399 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1400 | { |
| 1401 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1402 | nfs4_open_prepare(task, calldata); |
| 1403 | } |
| 1404 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1405 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1406 | { |
| 1407 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1409 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1410 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1411 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1412 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1413 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1414 | if (task->tk_status == 0) { |
| 1415 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1416 | case S_IFREG: |
| 1417 | break; |
| 1418 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1419 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1420 | break; |
| 1421 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1422 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1423 | break; |
| 1424 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1425 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1426 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1427 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1428 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1429 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1430 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1431 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1432 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1433 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1434 | static void nfs4_open_release(void *calldata) |
| 1435 | { |
| 1436 | struct nfs4_opendata *data = calldata; |
| 1437 | struct nfs4_state *state = NULL; |
| 1438 | |
| 1439 | /* If this request hasn't been cancelled, do nothing */ |
| 1440 | if (data->cancelled == 0) |
| 1441 | goto out_free; |
| 1442 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1443 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1444 | goto out_free; |
| 1445 | /* In case we need an open_confirm, no cleanup! */ |
| 1446 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1447 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1448 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1449 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1450 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1451 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1452 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1456 | .rpc_call_prepare = nfs4_open_prepare, |
| 1457 | .rpc_call_done = nfs4_open_done, |
| 1458 | .rpc_release = nfs4_open_release, |
| 1459 | }; |
| 1460 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1461 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1462 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1463 | .rpc_call_done = nfs4_open_done, |
| 1464 | .rpc_release = nfs4_open_release, |
| 1465 | }; |
| 1466 | |
| 1467 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1468 | { |
| 1469 | struct inode *dir = data->dir->d_inode; |
| 1470 | struct nfs_server *server = NFS_SERVER(dir); |
| 1471 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1472 | struct nfs_openres *o_res = &data->o_res; |
| 1473 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1474 | struct rpc_message msg = { |
| 1475 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1476 | .rpc_argp = o_arg, |
| 1477 | .rpc_resp = o_res, |
| 1478 | .rpc_cred = data->owner->so_cred, |
| 1479 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1480 | struct rpc_task_setup task_setup_data = { |
| 1481 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1482 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1483 | .callback_ops = &nfs4_open_ops, |
| 1484 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1485 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1486 | .flags = RPC_TASK_ASYNC, |
| 1487 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1488 | int status; |
| 1489 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1490 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1491 | data->rpc_done = 0; |
| 1492 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1493 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1494 | if (isrecover) |
| 1495 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1496 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1497 | if (IS_ERR(task)) |
| 1498 | return PTR_ERR(task); |
| 1499 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1500 | if (status != 0) { |
| 1501 | data->cancelled = 1; |
| 1502 | smp_wmb(); |
| 1503 | } else |
| 1504 | status = data->rpc_status; |
| 1505 | rpc_put_task(task); |
| 1506 | |
| 1507 | return status; |
| 1508 | } |
| 1509 | |
| 1510 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1511 | { |
| 1512 | struct inode *dir = data->dir->d_inode; |
| 1513 | struct nfs_openres *o_res = &data->o_res; |
| 1514 | int status; |
| 1515 | |
| 1516 | status = nfs4_run_open_task(data, 1); |
| 1517 | if (status != 0 || !data->rpc_done) |
| 1518 | return status; |
| 1519 | |
| 1520 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1521 | |
| 1522 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1523 | status = _nfs4_proc_open_confirm(data); |
| 1524 | if (status != 0) |
| 1525 | return status; |
| 1526 | } |
| 1527 | |
| 1528 | return status; |
| 1529 | } |
| 1530 | |
| 1531 | /* |
| 1532 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1533 | */ |
| 1534 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1535 | { |
| 1536 | struct inode *dir = data->dir->d_inode; |
| 1537 | struct nfs_server *server = NFS_SERVER(dir); |
| 1538 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1539 | struct nfs_openres *o_res = &data->o_res; |
| 1540 | int status; |
| 1541 | |
| 1542 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1543 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1544 | return status; |
| 1545 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1546 | if (o_arg->open_flags & O_CREAT) { |
| 1547 | update_changeattr(dir, &o_res->cinfo); |
| 1548 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1549 | } else |
| 1550 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1551 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1552 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1554 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1556 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | } |
| 1558 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1559 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1560 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
Trond Myklebust | 10afec9 | 2007-05-14 17:16:04 -0400 | [diff] [blame] | 1563 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1564 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1565 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1566 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1567 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1568 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1569 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1570 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1571 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1572 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1573 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1574 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1575 | break; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1576 | nfs4_schedule_state_recovery(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1577 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1578 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1579 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1580 | } |
| 1581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | /* |
| 1583 | * OPEN_EXPIRED: |
| 1584 | * reclaim state on the server after a network partition. |
| 1585 | * Assumes caller holds the appropriate lock |
| 1586 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1587 | 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] | 1588 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1589 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1590 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1592 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1593 | if (IS_ERR(opendata)) |
| 1594 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1595 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1596 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1597 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1598 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1599 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1602 | 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] | 1603 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1604 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1605 | struct nfs4_exception exception = { }; |
| 1606 | int err; |
| 1607 | |
| 1608 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1609 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1610 | switch (err) { |
| 1611 | default: |
| 1612 | goto out; |
| 1613 | case -NFS4ERR_GRACE: |
| 1614 | case -NFS4ERR_DELAY: |
| 1615 | nfs4_handle_exception(server, err, &exception); |
| 1616 | err = 0; |
| 1617 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1618 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1619 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1620 | return err; |
| 1621 | } |
| 1622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1624 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1626 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1628 | ctx = nfs4_state_find_open_context(state); |
| 1629 | if (IS_ERR(ctx)) |
| 1630 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1631 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1632 | put_nfs_open_context(ctx); |
| 1633 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1637 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1638 | * fields corresponding to attributes that were used to store the verifier. |
| 1639 | * Make sure we clobber those fields in the later setattr call |
| 1640 | */ |
| 1641 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1642 | { |
| 1643 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1644 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1645 | sattr->ia_valid |= ATTR_ATIME; |
| 1646 | |
| 1647 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1648 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1649 | sattr->ia_valid |= ATTR_MTIME; |
| 1650 | } |
| 1651 | |
| 1652 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1653 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1655 | 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] | 1656 | { |
| 1657 | struct nfs4_state_owner *sp; |
| 1658 | struct nfs4_state *state = NULL; |
| 1659 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1660 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1661 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | |
| 1663 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | status = -ENOMEM; |
| 1665 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1666 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1667 | goto out_err; |
| 1668 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1669 | status = nfs4_recover_expired_lease(server); |
| 1670 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1671 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1672 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1673 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1674 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1675 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1676 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1677 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1679 | if (path->dentry->d_inode != NULL) |
| 1680 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1681 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1682 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1684 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1686 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1687 | status = PTR_ERR(state); |
| 1688 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1689 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1690 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1691 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1692 | |
| 1693 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1694 | nfs4_exclusive_attrset(opendata, sattr); |
| 1695 | |
| 1696 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1697 | status = nfs4_do_setattr(state->inode, cred, |
| 1698 | opendata->o_res.f_attr, sattr, |
| 1699 | state); |
| 1700 | if (status == 0) |
| 1701 | nfs_setattr_update_inode(state->inode, sattr); |
| 1702 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1703 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1704 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | *res = state; |
| 1707 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1708 | err_opendata_put: |
| 1709 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1710 | err_put_state_owner: |
| 1711 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | *res = NULL; |
| 1714 | return status; |
| 1715 | } |
| 1716 | |
| 1717 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1718 | 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] | 1719 | { |
| 1720 | struct nfs4_exception exception = { }; |
| 1721 | struct nfs4_state *res; |
| 1722 | int status; |
| 1723 | |
| 1724 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1725 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | if (status == 0) |
| 1727 | break; |
| 1728 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1729 | * book-keeping w.r.t. state-changing operations |
| 1730 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1731 | * It is actually a sign of a bug on the client or on the server. |
| 1732 | * |
| 1733 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1734 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | * have unhashed the old state_owner for us, and that we can |
| 1736 | * therefore safely retry using a new one. We should still warn |
| 1737 | * the user though... |
| 1738 | */ |
| 1739 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1740 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1741 | " returned a bad sequence-id error!\n", |
| 1742 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | exception.retry = 1; |
| 1744 | continue; |
| 1745 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1746 | /* |
| 1747 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1748 | * state before it received the OPEN_CONFIRM. |
| 1749 | * Recover by retrying the request as per the discussion |
| 1750 | * on Page 181 of RFC3530. |
| 1751 | */ |
| 1752 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1753 | exception.retry = 1; |
| 1754 | continue; |
| 1755 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1756 | if (status == -EAGAIN) { |
| 1757 | /* We must have found a delegation */ |
| 1758 | exception.retry = 1; |
| 1759 | continue; |
| 1760 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1762 | status, &exception)); |
| 1763 | } while (exception.retry); |
| 1764 | return res; |
| 1765 | } |
| 1766 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1767 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1768 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1769 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1771 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1773 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | .iap = sattr, |
| 1775 | .server = server, |
| 1776 | .bitmask = server->attr_bitmask, |
| 1777 | }; |
| 1778 | struct nfs_setattrres res = { |
| 1779 | .fattr = fattr, |
| 1780 | .server = server, |
| 1781 | }; |
| 1782 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1783 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1784 | .rpc_argp = &arg, |
| 1785 | .rpc_resp = &res, |
| 1786 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1788 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1789 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1791 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1793 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1794 | /* Use that stateid */ |
| 1795 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1796 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1797 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1799 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1800 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1801 | if (status == 0 && state != NULL) |
| 1802 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1803 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | } |
| 1805 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1806 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1807 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1808 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1810 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | struct nfs4_exception exception = { }; |
| 1812 | int err; |
| 1813 | do { |
| 1814 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1815 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | &exception); |
| 1817 | } while (exception.retry); |
| 1818 | return err; |
| 1819 | } |
| 1820 | |
| 1821 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1822 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | struct inode *inode; |
| 1824 | struct nfs4_state *state; |
| 1825 | struct nfs_closeargs arg; |
| 1826 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1827 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1828 | unsigned long timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | }; |
| 1830 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1831 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1832 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1833 | struct nfs4_closedata *calldata = data; |
| 1834 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1835 | |
| 1836 | nfs4_put_open_state(calldata->state); |
| 1837 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1838 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1839 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1840 | kfree(calldata); |
| 1841 | } |
| 1842 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1843 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1844 | fmode_t fmode) |
| 1845 | { |
| 1846 | spin_lock(&state->owner->so_lock); |
| 1847 | if (!(fmode & FMODE_READ)) |
| 1848 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1849 | if (!(fmode & FMODE_WRITE)) |
| 1850 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1851 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1852 | spin_unlock(&state->owner->so_lock); |
| 1853 | } |
| 1854 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1855 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1857 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1860 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1861 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1862 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | /* hmm. we are done with the inode, and in the process of freeing |
| 1864 | * the state_owner. we keep this around to process errors |
| 1865 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | switch (task->tk_status) { |
| 1867 | case 0: |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1868 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1869 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1870 | nfs4_close_clear_stateid_flags(state, |
| 1871 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | break; |
| 1873 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1874 | case -NFS4ERR_OLD_STATEID: |
| 1875 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1877 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1878 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1880 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1881 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1883 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1884 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1887 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1889 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1890 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1891 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1892 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1893 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1894 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1895 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1896 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1897 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1898 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1899 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1900 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1901 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1902 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1903 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1904 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1905 | } |
| 1906 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1907 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1908 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1909 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1910 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1911 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1912 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1913 | |
| 1914 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1915 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1916 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1917 | return; |
| 1918 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1919 | |
| 1920 | if (calldata->arg.fmode == 0) |
| 1921 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
| 1922 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1923 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1924 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1925 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1926 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1927 | 1, task)) |
| 1928 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1929 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1932 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1933 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1934 | .rpc_call_done = nfs4_close_done, |
| 1935 | .rpc_release = nfs4_free_closedata, |
| 1936 | }; |
| 1937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | /* |
| 1939 | * It is possible for data to be read/written from a mem-mapped file |
| 1940 | * after the sys_close call (which hits the vfs layer as a flush). |
| 1941 | * This means that we can't safely call nfsv4 close on a file until |
| 1942 | * the inode is cleared. This in turn means that we are not good |
| 1943 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 1944 | * share state even when we are done with one of the three share |
| 1945 | * stateid's in the inode. |
| 1946 | * |
| 1947 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 1948 | */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1949 | int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1951 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1953 | struct nfs4_state_owner *sp = state->owner; |
| 1954 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1955 | struct rpc_message msg = { |
| 1956 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 1957 | .rpc_cred = state->owner->so_cred, |
| 1958 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1959 | struct rpc_task_setup task_setup_data = { |
| 1960 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1961 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1962 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1963 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1964 | .flags = RPC_TASK_ASYNC, |
| 1965 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1966 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1968 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1970 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1971 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1973 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1974 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1976 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1977 | if (calldata->arg.seqid == NULL) |
| 1978 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1979 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 1980 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1981 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 1982 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1983 | calldata->res.server = server; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 1984 | path_get(path); |
| 1985 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1986 | |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1987 | msg.rpc_argp = &calldata->arg, |
| 1988 | msg.rpc_resp = &calldata->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1989 | task_setup_data.callback_data = calldata; |
| 1990 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1991 | if (IS_ERR(task)) |
| 1992 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1993 | status = 0; |
| 1994 | if (wait) |
| 1995 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1996 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 1997 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1998 | out_free_calldata: |
| 1999 | kfree(calldata); |
| 2000 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2001 | nfs4_put_open_state(state); |
| 2002 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2003 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2006 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2007 | nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | struct nfs4_state *state; |
| 2010 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2011 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2012 | state = nfs4_do_open(dir, &ctx->path, ctx->mode, open_flags, attr, ctx->cred); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2013 | if (IS_ERR(state)) |
| 2014 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2015 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2016 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2019 | 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] | 2020 | { |
| 2021 | if (ctx->state == NULL) |
| 2022 | return; |
| 2023 | if (is_sync) |
| 2024 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2025 | else |
| 2026 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2027 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | |
| 2029 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2030 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2031 | struct nfs4_server_caps_arg args = { |
| 2032 | .fhandle = fhandle, |
| 2033 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | struct nfs4_server_caps_res res = {}; |
| 2035 | struct rpc_message msg = { |
| 2036 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2037 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | .rpc_resp = &res, |
| 2039 | }; |
| 2040 | int status; |
| 2041 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2042 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | if (status == 0) { |
| 2044 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2045 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2046 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2047 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2048 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2049 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2051 | server->caps |= NFS_CAP_ACLS; |
| 2052 | if (res.has_links != 0) |
| 2053 | server->caps |= NFS_CAP_HARDLINKS; |
| 2054 | if (res.has_symlinks != 0) |
| 2055 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2056 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2057 | server->caps |= NFS_CAP_FILEID; |
| 2058 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2059 | server->caps |= NFS_CAP_MODE; |
| 2060 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2061 | server->caps |= NFS_CAP_NLINK; |
| 2062 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2063 | server->caps |= NFS_CAP_OWNER; |
| 2064 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2065 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2066 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2067 | server->caps |= NFS_CAP_ATIME; |
| 2068 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2069 | server->caps |= NFS_CAP_CTIME; |
| 2070 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2071 | server->caps |= NFS_CAP_MTIME; |
| 2072 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2073 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2074 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2075 | 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] | 2076 | server->acl_bitmask = res.acl_bitmask; |
| 2077 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | return status; |
| 2080 | } |
| 2081 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2082 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | { |
| 2084 | struct nfs4_exception exception = { }; |
| 2085 | int err; |
| 2086 | do { |
| 2087 | err = nfs4_handle_exception(server, |
| 2088 | _nfs4_server_capabilities(server, fhandle), |
| 2089 | &exception); |
| 2090 | } while (exception.retry); |
| 2091 | return err; |
| 2092 | } |
| 2093 | |
| 2094 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2095 | struct nfs_fsinfo *info) |
| 2096 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | struct nfs4_lookup_root_arg args = { |
| 2098 | .bitmask = nfs4_fattr_bitmap, |
| 2099 | }; |
| 2100 | struct nfs4_lookup_res res = { |
| 2101 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2102 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | .fh = fhandle, |
| 2104 | }; |
| 2105 | struct rpc_message msg = { |
| 2106 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2107 | .rpc_argp = &args, |
| 2108 | .rpc_resp = &res, |
| 2109 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2110 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2111 | nfs_fattr_init(info->fattr); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 2112 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2116 | struct nfs_fsinfo *info) |
| 2117 | { |
| 2118 | struct nfs4_exception exception = { }; |
| 2119 | int err; |
| 2120 | do { |
| 2121 | err = nfs4_handle_exception(server, |
| 2122 | _nfs4_lookup_root(server, fhandle, info), |
| 2123 | &exception); |
| 2124 | } while (exception.retry); |
| 2125 | return err; |
| 2126 | } |
| 2127 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2128 | /* |
| 2129 | * get the file handle for the "/" directory on the server |
| 2130 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | 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] | 2132 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | int status; |
| 2135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | if (status == 0) |
| 2138 | status = nfs4_server_capabilities(server, fhandle); |
| 2139 | if (status == 0) |
| 2140 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2141 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2144 | /* |
| 2145 | * Get locations and (maybe) other attributes of a referral. |
| 2146 | * Note that we'll actually follow the referral later when |
| 2147 | * we detect fsid mismatch in inode revalidation |
| 2148 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2149 | 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] | 2150 | { |
| 2151 | int status = -ENOMEM; |
| 2152 | struct page *page = NULL; |
| 2153 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2154 | |
| 2155 | page = alloc_page(GFP_KERNEL); |
| 2156 | if (page == NULL) |
| 2157 | goto out; |
| 2158 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2159 | if (locations == NULL) |
| 2160 | goto out; |
| 2161 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2162 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2163 | if (status != 0) |
| 2164 | goto out; |
| 2165 | /* Make sure server returned a different fsid for the referral */ |
| 2166 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2167 | 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] | 2168 | status = -EIO; |
| 2169 | goto out; |
| 2170 | } |
| 2171 | |
| 2172 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2173 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2174 | if (!fattr->mode) |
| 2175 | fattr->mode = S_IFDIR; |
| 2176 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2177 | out: |
| 2178 | if (page) |
| 2179 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2180 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2181 | return status; |
| 2182 | } |
| 2183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2185 | { |
| 2186 | struct nfs4_getattr_arg args = { |
| 2187 | .fh = fhandle, |
| 2188 | .bitmask = server->attr_bitmask, |
| 2189 | }; |
| 2190 | struct nfs4_getattr_res res = { |
| 2191 | .fattr = fattr, |
| 2192 | .server = server, |
| 2193 | }; |
| 2194 | struct rpc_message msg = { |
| 2195 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2196 | .rpc_argp = &args, |
| 2197 | .rpc_resp = &res, |
| 2198 | }; |
| 2199 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2200 | nfs_fattr_init(fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2201 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2205 | { |
| 2206 | struct nfs4_exception exception = { }; |
| 2207 | int err; |
| 2208 | do { |
| 2209 | err = nfs4_handle_exception(server, |
| 2210 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2211 | &exception); |
| 2212 | } while (exception.retry); |
| 2213 | return err; |
| 2214 | } |
| 2215 | |
| 2216 | /* |
| 2217 | * The file is not closed if it is opened due to the a request to change |
| 2218 | * the size of the file. The open call will not be needed once the |
| 2219 | * VFS layer lookup-intents are implemented. |
| 2220 | * |
| 2221 | * Close is called when the inode is destroyed. |
| 2222 | * If we haven't opened the file for O_WRONLY, we |
| 2223 | * need to in the size_change case to obtain a stateid. |
| 2224 | * |
| 2225 | * Got race? |
| 2226 | * Because OPEN is always done by name in nfsv4, it is |
| 2227 | * possible that we opened a different file by the same |
| 2228 | * name. We can recognize this race condition, but we |
| 2229 | * can't do anything about it besides returning an error. |
| 2230 | * |
| 2231 | * This will be fixed with VFS changes (lookup-intent). |
| 2232 | */ |
| 2233 | static int |
| 2234 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2235 | struct iattr *sattr) |
| 2236 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2237 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2238 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2239 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | int status; |
| 2241 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2242 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2244 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2245 | if (sattr->ia_valid & ATTR_FILE) { |
| 2246 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2247 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2248 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2249 | if (ctx) { |
| 2250 | cred = ctx->cred; |
| 2251 | state = ctx->state; |
| 2252 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2256 | if (status == 0) |
| 2257 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | return status; |
| 2259 | } |
| 2260 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2261 | static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh, |
| 2262 | const struct qstr *name, struct nfs_fh *fhandle, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2263 | struct nfs_fattr *fattr) |
| 2264 | { |
| 2265 | int status; |
| 2266 | struct nfs4_lookup_arg args = { |
| 2267 | .bitmask = server->attr_bitmask, |
| 2268 | .dir_fh = dirfh, |
| 2269 | .name = name, |
| 2270 | }; |
| 2271 | struct nfs4_lookup_res res = { |
| 2272 | .server = server, |
| 2273 | .fattr = fattr, |
| 2274 | .fh = fhandle, |
| 2275 | }; |
| 2276 | struct rpc_message msg = { |
| 2277 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2278 | .rpc_argp = &args, |
| 2279 | .rpc_resp = &res, |
| 2280 | }; |
| 2281 | |
| 2282 | nfs_fattr_init(fattr); |
| 2283 | |
| 2284 | dprintk("NFS call lookupfh %s\n", name->name); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2285 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2286 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2287 | return status; |
| 2288 | } |
| 2289 | |
| 2290 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2291 | struct qstr *name, struct nfs_fh *fhandle, |
| 2292 | struct nfs_fattr *fattr) |
| 2293 | { |
| 2294 | struct nfs4_exception exception = { }; |
| 2295 | int err; |
| 2296 | do { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2297 | err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); |
| 2298 | /* FIXME: !!!! */ |
| 2299 | if (err == -NFS4ERR_MOVED) { |
| 2300 | err = -EREMOTE; |
| 2301 | break; |
| 2302 | } |
| 2303 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2304 | } while (exception.retry); |
| 2305 | return err; |
| 2306 | } |
| 2307 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2308 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2310 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2311 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | |
| 2313 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2314 | 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] | 2315 | if (status == -NFS4ERR_MOVED) |
| 2316 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | dprintk("NFS reply lookup: %d\n", status); |
| 2318 | return status; |
| 2319 | } |
| 2320 | |
| 2321 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2322 | { |
| 2323 | struct nfs4_exception exception = { }; |
| 2324 | int err; |
| 2325 | do { |
| 2326 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2327 | _nfs4_proc_lookup(dir, name, fhandle, fattr), |
| 2328 | &exception); |
| 2329 | } while (exception.retry); |
| 2330 | return err; |
| 2331 | } |
| 2332 | |
| 2333 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2334 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2335 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | struct nfs4_accessargs args = { |
| 2337 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2338 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2340 | struct nfs4_accessres res = { |
| 2341 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2342 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | struct rpc_message msg = { |
| 2344 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2345 | .rpc_argp = &args, |
| 2346 | .rpc_resp = &res, |
| 2347 | .rpc_cred = entry->cred, |
| 2348 | }; |
| 2349 | int mode = entry->mask; |
| 2350 | int status; |
| 2351 | |
| 2352 | /* |
| 2353 | * Determine which access bits we want to ask for... |
| 2354 | */ |
| 2355 | if (mode & MAY_READ) |
| 2356 | args.access |= NFS4_ACCESS_READ; |
| 2357 | if (S_ISDIR(inode->i_mode)) { |
| 2358 | if (mode & MAY_WRITE) |
| 2359 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2360 | if (mode & MAY_EXEC) |
| 2361 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2362 | } else { |
| 2363 | if (mode & MAY_WRITE) |
| 2364 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2365 | if (mode & MAY_EXEC) |
| 2366 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2367 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2368 | |
| 2369 | res.fattr = nfs_alloc_fattr(); |
| 2370 | if (res.fattr == NULL) |
| 2371 | return -ENOMEM; |
| 2372 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2373 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | if (!status) { |
| 2375 | entry->mask = 0; |
| 2376 | if (res.access & NFS4_ACCESS_READ) |
| 2377 | entry->mask |= MAY_READ; |
| 2378 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2379 | entry->mask |= MAY_WRITE; |
| 2380 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2381 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2382 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2384 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | return status; |
| 2386 | } |
| 2387 | |
| 2388 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2389 | { |
| 2390 | struct nfs4_exception exception = { }; |
| 2391 | int err; |
| 2392 | do { |
| 2393 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2394 | _nfs4_proc_access(inode, entry), |
| 2395 | &exception); |
| 2396 | } while (exception.retry); |
| 2397 | return err; |
| 2398 | } |
| 2399 | |
| 2400 | /* |
| 2401 | * TODO: For the time being, we don't try to get any attributes |
| 2402 | * along with any of the zero-copy operations READ, READDIR, |
| 2403 | * READLINK, WRITE. |
| 2404 | * |
| 2405 | * In the case of the first three, we want to put the GETATTR |
| 2406 | * after the read-type operation -- this is because it is hard |
| 2407 | * to predict the length of a GETATTR response in v4, and thus |
| 2408 | * align the READ data correctly. This means that the GETATTR |
| 2409 | * may end up partially falling into the page cache, and we should |
| 2410 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2411 | * To do this efficiently, we need to know the total length |
| 2412 | * of data received, which doesn't seem to be available outside |
| 2413 | * of the RPC layer. |
| 2414 | * |
| 2415 | * In the case of WRITE, we also want to put the GETATTR after |
| 2416 | * the operation -- in this case because we want to make sure |
| 2417 | * we get the post-operation mtime and size. This means that |
| 2418 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2419 | * of it which would leave room in the 'tail' iovec. |
| 2420 | * |
| 2421 | * Both of these changes to the XDR layer would in fact be quite |
| 2422 | * minor, but I decided to leave them for a subsequent patch. |
| 2423 | */ |
| 2424 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2425 | unsigned int pgbase, unsigned int pglen) |
| 2426 | { |
| 2427 | struct nfs4_readlink args = { |
| 2428 | .fh = NFS_FH(inode), |
| 2429 | .pgbase = pgbase, |
| 2430 | .pglen = pglen, |
| 2431 | .pages = &page, |
| 2432 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2433 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | struct rpc_message msg = { |
| 2435 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2436 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2437 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | }; |
| 2439 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2440 | return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2444 | unsigned int pgbase, unsigned int pglen) |
| 2445 | { |
| 2446 | struct nfs4_exception exception = { }; |
| 2447 | int err; |
| 2448 | do { |
| 2449 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2450 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2451 | &exception); |
| 2452 | } while (exception.retry); |
| 2453 | return err; |
| 2454 | } |
| 2455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | /* |
| 2457 | * Got race? |
| 2458 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2459 | * Until then, this create/open method is prone to inefficiency and race |
| 2460 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2461 | * placed on the wire. |
| 2462 | * |
| 2463 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2464 | * The file will be opened again in the subsequent VFS open call |
| 2465 | * (nfs4_proc_file_open). |
| 2466 | * |
| 2467 | * The open for read will just hang around to be used by any process that |
| 2468 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2469 | */ |
| 2470 | |
| 2471 | static int |
| 2472 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2473 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2475 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2476 | .dentry = dentry, |
| 2477 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2478 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2480 | struct rpc_cred *cred = NULL; |
| 2481 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | int status = 0; |
| 2483 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2484 | if (ctx != NULL) { |
| 2485 | cred = ctx->cred; |
| 2486 | path = &ctx->path; |
| 2487 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | } |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2489 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2490 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | if (IS_ERR(state)) { |
| 2492 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2493 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2495 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2496 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2497 | if (ctx != NULL) |
| 2498 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2499 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2500 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | out: |
| 2502 | return status; |
| 2503 | } |
| 2504 | |
| 2505 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2506 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2507 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2508 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2510 | .name.len = name->len, |
| 2511 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2512 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2514 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2515 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2516 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2518 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2519 | .rpc_argp = &args, |
| 2520 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2522 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2524 | res.dir_attr = nfs_alloc_fattr(); |
| 2525 | if (res.dir_attr == NULL) |
| 2526 | goto out; |
| 2527 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2528 | status = nfs4_call_sync(server, &msg, &args, &res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2529 | if (status == 0) { |
| 2530 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2531 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2532 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2533 | nfs_free_fattr(res.dir_attr); |
| 2534 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | return status; |
| 2536 | } |
| 2537 | |
| 2538 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2539 | { |
| 2540 | struct nfs4_exception exception = { }; |
| 2541 | int err; |
| 2542 | do { |
| 2543 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2544 | _nfs4_proc_remove(dir, name), |
| 2545 | &exception); |
| 2546 | } while (exception.retry); |
| 2547 | return err; |
| 2548 | } |
| 2549 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2550 | 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] | 2551 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2552 | struct nfs_server *server = NFS_SERVER(dir); |
| 2553 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2554 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2556 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2557 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2558 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2562 | 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] | 2563 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2564 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2565 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2566 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2567 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2568 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2569 | return 0; |
| 2570 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2571 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2572 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2575 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2576 | { |
| 2577 | struct nfs_server *server = NFS_SERVER(dir); |
| 2578 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2579 | struct nfs_renameres *res = msg->rpc_resp; |
| 2580 | |
| 2581 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2582 | arg->bitmask = server->attr_bitmask; |
| 2583 | res->server = server; |
| 2584 | } |
| 2585 | |
| 2586 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2587 | struct inode *new_dir) |
| 2588 | { |
| 2589 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2590 | |
| 2591 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2592 | return 0; |
| 2593 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2594 | return 0; |
| 2595 | |
| 2596 | update_changeattr(old_dir, &res->old_cinfo); |
| 2597 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2598 | update_changeattr(new_dir, &res->new_cinfo); |
| 2599 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2600 | return 1; |
| 2601 | } |
| 2602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2604 | struct inode *new_dir, struct qstr *new_name) |
| 2605 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2606 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2607 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | .old_dir = NFS_FH(old_dir), |
| 2609 | .new_dir = NFS_FH(new_dir), |
| 2610 | .old_name = old_name, |
| 2611 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2612 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2614 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2615 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2616 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | struct rpc_message msg = { |
| 2618 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2619 | .rpc_argp = &arg, |
| 2620 | .rpc_resp = &res, |
| 2621 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2622 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2624 | res.old_fattr = nfs_alloc_fattr(); |
| 2625 | res.new_fattr = nfs_alloc_fattr(); |
| 2626 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2627 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2629 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | if (!status) { |
| 2631 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2632 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2634 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2636 | out: |
| 2637 | nfs_free_fattr(res.new_fattr); |
| 2638 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | return status; |
| 2640 | } |
| 2641 | |
| 2642 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2643 | struct inode *new_dir, struct qstr *new_name) |
| 2644 | { |
| 2645 | struct nfs4_exception exception = { }; |
| 2646 | int err; |
| 2647 | do { |
| 2648 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2649 | _nfs4_proc_rename(old_dir, old_name, |
| 2650 | new_dir, new_name), |
| 2651 | &exception); |
| 2652 | } while (exception.retry); |
| 2653 | return err; |
| 2654 | } |
| 2655 | |
| 2656 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2657 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2658 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | struct nfs4_link_arg arg = { |
| 2660 | .fh = NFS_FH(inode), |
| 2661 | .dir_fh = NFS_FH(dir), |
| 2662 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2663 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2665 | struct nfs4_link_res res = { |
| 2666 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2667 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | struct rpc_message msg = { |
| 2669 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2670 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2671 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2673 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2674 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2675 | res.fattr = nfs_alloc_fattr(); |
| 2676 | res.dir_attr = nfs_alloc_fattr(); |
| 2677 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2678 | goto out; |
| 2679 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2680 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2681 | if (!status) { |
| 2682 | update_changeattr(dir, &res.cinfo); |
| 2683 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2684 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2685 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2686 | out: |
| 2687 | nfs_free_fattr(res.dir_attr); |
| 2688 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | return status; |
| 2690 | } |
| 2691 | |
| 2692 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2693 | { |
| 2694 | struct nfs4_exception exception = { }; |
| 2695 | int err; |
| 2696 | do { |
| 2697 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2698 | _nfs4_proc_link(inode, dir, name), |
| 2699 | &exception); |
| 2700 | } while (exception.retry); |
| 2701 | return err; |
| 2702 | } |
| 2703 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2704 | struct nfs4_createdata { |
| 2705 | struct rpc_message msg; |
| 2706 | struct nfs4_create_arg arg; |
| 2707 | struct nfs4_create_res res; |
| 2708 | struct nfs_fh fh; |
| 2709 | struct nfs_fattr fattr; |
| 2710 | struct nfs_fattr dir_fattr; |
| 2711 | }; |
| 2712 | |
| 2713 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2714 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2715 | { |
| 2716 | struct nfs4_createdata *data; |
| 2717 | |
| 2718 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2719 | if (data != NULL) { |
| 2720 | struct nfs_server *server = NFS_SERVER(dir); |
| 2721 | |
| 2722 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2723 | data->msg.rpc_argp = &data->arg; |
| 2724 | data->msg.rpc_resp = &data->res; |
| 2725 | data->arg.dir_fh = NFS_FH(dir); |
| 2726 | data->arg.server = server; |
| 2727 | data->arg.name = name; |
| 2728 | data->arg.attrs = sattr; |
| 2729 | data->arg.ftype = ftype; |
| 2730 | data->arg.bitmask = server->attr_bitmask; |
| 2731 | data->res.server = server; |
| 2732 | data->res.fh = &data->fh; |
| 2733 | data->res.fattr = &data->fattr; |
| 2734 | data->res.dir_fattr = &data->dir_fattr; |
| 2735 | nfs_fattr_init(data->res.fattr); |
| 2736 | nfs_fattr_init(data->res.dir_fattr); |
| 2737 | } |
| 2738 | return data; |
| 2739 | } |
| 2740 | |
| 2741 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2742 | { |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2743 | int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg, |
| 2744 | &data->arg, &data->res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2745 | if (status == 0) { |
| 2746 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2747 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2748 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2749 | } |
| 2750 | return status; |
| 2751 | } |
| 2752 | |
| 2753 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2754 | { |
| 2755 | kfree(data); |
| 2756 | } |
| 2757 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2758 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2759 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2761 | struct nfs4_createdata *data; |
| 2762 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2764 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2765 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2766 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2767 | status = -ENOMEM; |
| 2768 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2769 | if (data == NULL) |
| 2770 | goto out; |
| 2771 | |
| 2772 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2773 | data->arg.u.symlink.pages = &page; |
| 2774 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2776 | status = nfs4_do_create(dir, dentry, data); |
| 2777 | |
| 2778 | nfs4_free_createdata(data); |
| 2779 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | return status; |
| 2781 | } |
| 2782 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2783 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2784 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | { |
| 2786 | struct nfs4_exception exception = { }; |
| 2787 | int err; |
| 2788 | do { |
| 2789 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2790 | _nfs4_proc_symlink(dir, dentry, page, |
| 2791 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | &exception); |
| 2793 | } while (exception.retry); |
| 2794 | return err; |
| 2795 | } |
| 2796 | |
| 2797 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2798 | struct iattr *sattr) |
| 2799 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2800 | struct nfs4_createdata *data; |
| 2801 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2803 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2804 | if (data == NULL) |
| 2805 | goto out; |
| 2806 | |
| 2807 | status = nfs4_do_create(dir, dentry, data); |
| 2808 | |
| 2809 | nfs4_free_createdata(data); |
| 2810 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | return status; |
| 2812 | } |
| 2813 | |
| 2814 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2815 | struct iattr *sattr) |
| 2816 | { |
| 2817 | struct nfs4_exception exception = { }; |
| 2818 | int err; |
| 2819 | do { |
| 2820 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2821 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2822 | &exception); |
| 2823 | } while (exception.retry); |
| 2824 | return err; |
| 2825 | } |
| 2826 | |
| 2827 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2828 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | { |
| 2830 | struct inode *dir = dentry->d_inode; |
| 2831 | struct nfs4_readdir_arg args = { |
| 2832 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2833 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | .pgbase = 0, |
| 2835 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2836 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2837 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | }; |
| 2839 | struct nfs4_readdir_res res; |
| 2840 | struct rpc_message msg = { |
| 2841 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2842 | .rpc_argp = &args, |
| 2843 | .rpc_resp = &res, |
| 2844 | .rpc_cred = cred, |
| 2845 | }; |
| 2846 | int status; |
| 2847 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2848 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2849 | dentry->d_parent->d_name.name, |
| 2850 | dentry->d_name.name, |
| 2851 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2853 | res.pgbase = args.pgbase; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2854 | status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2855 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2857 | status += args.pgbase; |
| 2858 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2859 | |
| 2860 | nfs_invalidate_atime(dir); |
| 2861 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2862 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | return status; |
| 2864 | } |
| 2865 | |
| 2866 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2867 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | { |
| 2869 | struct nfs4_exception exception = { }; |
| 2870 | int err; |
| 2871 | do { |
| 2872 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2873 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2874 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | &exception); |
| 2876 | } while (exception.retry); |
| 2877 | return err; |
| 2878 | } |
| 2879 | |
| 2880 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2881 | struct iattr *sattr, dev_t rdev) |
| 2882 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2883 | struct nfs4_createdata *data; |
| 2884 | int mode = sattr->ia_mode; |
| 2885 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | |
| 2887 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2888 | 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] | 2889 | |
| 2890 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2891 | if (data == NULL) |
| 2892 | goto out; |
| 2893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2895 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2897 | data->arg.ftype = NF4BLK; |
| 2898 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2899 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2900 | } |
| 2901 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2902 | data->arg.ftype = NF4CHR; |
| 2903 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2904 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2907 | status = nfs4_do_create(dir, dentry, data); |
| 2908 | |
| 2909 | nfs4_free_createdata(data); |
| 2910 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | return status; |
| 2912 | } |
| 2913 | |
| 2914 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2915 | struct iattr *sattr, dev_t rdev) |
| 2916 | { |
| 2917 | struct nfs4_exception exception = { }; |
| 2918 | int err; |
| 2919 | do { |
| 2920 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2921 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 2922 | &exception); |
| 2923 | } while (exception.retry); |
| 2924 | return err; |
| 2925 | } |
| 2926 | |
| 2927 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2928 | struct nfs_fsstat *fsstat) |
| 2929 | { |
| 2930 | struct nfs4_statfs_arg args = { |
| 2931 | .fh = fhandle, |
| 2932 | .bitmask = server->attr_bitmask, |
| 2933 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2934 | struct nfs4_statfs_res res = { |
| 2935 | .fsstat = fsstat, |
| 2936 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | struct rpc_message msg = { |
| 2938 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 2939 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2940 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | }; |
| 2942 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2943 | nfs_fattr_init(fsstat->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2944 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 2948 | { |
| 2949 | struct nfs4_exception exception = { }; |
| 2950 | int err; |
| 2951 | do { |
| 2952 | err = nfs4_handle_exception(server, |
| 2953 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 2954 | &exception); |
| 2955 | } while (exception.retry); |
| 2956 | return err; |
| 2957 | } |
| 2958 | |
| 2959 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2960 | struct nfs_fsinfo *fsinfo) |
| 2961 | { |
| 2962 | struct nfs4_fsinfo_arg args = { |
| 2963 | .fh = fhandle, |
| 2964 | .bitmask = server->attr_bitmask, |
| 2965 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 2966 | struct nfs4_fsinfo_res res = { |
| 2967 | .fsinfo = fsinfo, |
| 2968 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | struct rpc_message msg = { |
| 2970 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 2971 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 2972 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | }; |
| 2974 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2975 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 2979 | { |
| 2980 | struct nfs4_exception exception = { }; |
| 2981 | int err; |
| 2982 | |
| 2983 | do { |
| 2984 | err = nfs4_handle_exception(server, |
| 2985 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 2986 | &exception); |
| 2987 | } while (exception.retry); |
| 2988 | return err; |
| 2989 | } |
| 2990 | |
| 2991 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 2992 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2993 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 2995 | } |
| 2996 | |
| 2997 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2998 | struct nfs_pathconf *pathconf) |
| 2999 | { |
| 3000 | struct nfs4_pathconf_arg args = { |
| 3001 | .fh = fhandle, |
| 3002 | .bitmask = server->attr_bitmask, |
| 3003 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3004 | struct nfs4_pathconf_res res = { |
| 3005 | .pathconf = pathconf, |
| 3006 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | struct rpc_message msg = { |
| 3008 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3009 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3010 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | }; |
| 3012 | |
| 3013 | /* None of the pathconf attributes are mandatory to implement */ |
| 3014 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3015 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3016 | return 0; |
| 3017 | } |
| 3018 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3019 | nfs_fattr_init(pathconf->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3020 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3024 | struct nfs_pathconf *pathconf) |
| 3025 | { |
| 3026 | struct nfs4_exception exception = { }; |
| 3027 | int err; |
| 3028 | |
| 3029 | do { |
| 3030 | err = nfs4_handle_exception(server, |
| 3031 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3032 | &exception); |
| 3033 | } while (exception.retry); |
| 3034 | return err; |
| 3035 | } |
| 3036 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3037 | 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] | 3038 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3039 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3041 | dprintk("--> %s\n", __func__); |
| 3042 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3043 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3044 | return -EAGAIN; |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3045 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3046 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3047 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3048 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3050 | |
| 3051 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3053 | renew_lease(server, data->timestamp); |
| 3054 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | } |
| 3056 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3057 | 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] | 3058 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | data->timestamp = jiffies; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3060 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3063 | 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] | 3064 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | struct inode *inode = data->inode; |
| 3066 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3067 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3068 | return -EAGAIN; |
Andy Adamson | def6ed7 | 2009-04-01 09:22:26 -0400 | [diff] [blame] | 3069 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3070 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3071 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3072 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3074 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3076 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3077 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3078 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3081 | 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] | 3082 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3083 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3084 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3085 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3086 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | data->timestamp = jiffies; |
| 3088 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3089 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | } |
| 3091 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3092 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | struct inode *inode = data->inode; |
| 3095 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3096 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3097 | return -EAGAIN; |
| 3098 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3099 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3100 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3101 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3103 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3104 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3107 | 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] | 3108 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3109 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3111 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3112 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3113 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | } |
| 3115 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3116 | struct nfs4_renewdata { |
| 3117 | struct nfs_client *client; |
| 3118 | unsigned long timestamp; |
| 3119 | }; |
| 3120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | /* |
| 3122 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3123 | * standalone procedure for queueing an asynchronous RENEW. |
| 3124 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3125 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3126 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3127 | struct nfs4_renewdata *data = calldata; |
| 3128 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3129 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3130 | if (atomic_read(&clp->cl_count) > 1) |
| 3131 | nfs4_schedule_state_renewal(clp); |
| 3132 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3133 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3134 | } |
| 3135 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3136 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3138 | struct nfs4_renewdata *data = calldata; |
| 3139 | struct nfs_client *clp = data->client; |
| 3140 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | |
| 3142 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3143 | /* Unless we're shutting down, schedule state recovery! */ |
| 3144 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
| 3145 | nfs4_schedule_state_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | return; |
| 3147 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3148 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | } |
| 3150 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3151 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3152 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3153 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3154 | }; |
| 3155 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3156 | 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] | 3157 | { |
| 3158 | struct rpc_message msg = { |
| 3159 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3160 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3161 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3163 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3165 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3166 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3167 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3168 | if (data == NULL) |
| 3169 | return -ENOMEM; |
| 3170 | data->client = clp; |
| 3171 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3173 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3176 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | { |
| 3178 | struct rpc_message msg = { |
| 3179 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3180 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3181 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | }; |
| 3183 | unsigned long now = jiffies; |
| 3184 | int status; |
| 3185 | |
| 3186 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3187 | if (status < 0) |
| 3188 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3189 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | return 0; |
| 3191 | } |
| 3192 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3193 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3194 | { |
| 3195 | return (server->caps & NFS_CAP_ACLS) |
| 3196 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3197 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3198 | } |
| 3199 | |
| 3200 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3201 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3202 | * the stack. |
| 3203 | */ |
| 3204 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3205 | |
| 3206 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3207 | struct page **pages, unsigned int *pgbase) |
| 3208 | { |
| 3209 | const void *p = buf; |
| 3210 | |
| 3211 | *pgbase = offset_in_page(buf); |
| 3212 | p -= *pgbase; |
| 3213 | while (p < buf + buflen) { |
| 3214 | *(pages++) = virt_to_page(p); |
| 3215 | p += PAGE_CACHE_SIZE; |
| 3216 | } |
| 3217 | } |
| 3218 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3219 | struct nfs4_cached_acl { |
| 3220 | int cached; |
| 3221 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3222 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3223 | }; |
| 3224 | |
| 3225 | 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] | 3226 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3227 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3228 | |
| 3229 | spin_lock(&inode->i_lock); |
| 3230 | kfree(nfsi->nfs4_acl); |
| 3231 | nfsi->nfs4_acl = acl; |
| 3232 | spin_unlock(&inode->i_lock); |
| 3233 | } |
| 3234 | |
| 3235 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3236 | { |
| 3237 | nfs4_set_cached_acl(inode, NULL); |
| 3238 | } |
| 3239 | |
| 3240 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3241 | { |
| 3242 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3243 | struct nfs4_cached_acl *acl; |
| 3244 | int ret = -ENOENT; |
| 3245 | |
| 3246 | spin_lock(&inode->i_lock); |
| 3247 | acl = nfsi->nfs4_acl; |
| 3248 | if (acl == NULL) |
| 3249 | goto out; |
| 3250 | if (buf == NULL) /* user is just asking for length */ |
| 3251 | goto out_len; |
| 3252 | if (acl->cached == 0) |
| 3253 | goto out; |
| 3254 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3255 | if (acl->len > buflen) |
| 3256 | goto out; |
| 3257 | memcpy(buf, acl->data, acl->len); |
| 3258 | out_len: |
| 3259 | ret = acl->len; |
| 3260 | out: |
| 3261 | spin_unlock(&inode->i_lock); |
| 3262 | return ret; |
| 3263 | } |
| 3264 | |
| 3265 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3266 | { |
| 3267 | struct nfs4_cached_acl *acl; |
| 3268 | |
| 3269 | if (buf && acl_len <= PAGE_SIZE) { |
| 3270 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3271 | if (acl == NULL) |
| 3272 | goto out; |
| 3273 | acl->cached = 1; |
| 3274 | memcpy(acl->data, buf, acl_len); |
| 3275 | } else { |
| 3276 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3277 | if (acl == NULL) |
| 3278 | goto out; |
| 3279 | acl->cached = 0; |
| 3280 | } |
| 3281 | acl->len = acl_len; |
| 3282 | out: |
| 3283 | nfs4_set_cached_acl(inode, acl); |
| 3284 | } |
| 3285 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3286 | static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3287 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3288 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3289 | struct nfs_getaclargs args = { |
| 3290 | .fh = NFS_FH(inode), |
| 3291 | .acl_pages = pages, |
| 3292 | .acl_len = buflen, |
| 3293 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3294 | struct nfs_getaclres res = { |
| 3295 | .acl_len = buflen, |
| 3296 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3297 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3298 | struct rpc_message msg = { |
| 3299 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3300 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3301 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3302 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3303 | struct page *localpage = NULL; |
| 3304 | int ret; |
| 3305 | |
| 3306 | if (buflen < PAGE_SIZE) { |
| 3307 | /* As long as we're doing a round trip to the server anyway, |
| 3308 | * let's be prepared for a page of acl data. */ |
| 3309 | localpage = alloc_page(GFP_KERNEL); |
| 3310 | resp_buf = page_address(localpage); |
| 3311 | if (localpage == NULL) |
| 3312 | return -ENOMEM; |
| 3313 | args.acl_pages[0] = localpage; |
| 3314 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3315 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3316 | } else { |
| 3317 | resp_buf = buf; |
| 3318 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3319 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3320 | ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3321 | if (ret) |
| 3322 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3323 | if (res.acl_len > args.acl_len) |
| 3324 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3325 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3326 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3327 | if (buf) { |
| 3328 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3329 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3330 | goto out_free; |
| 3331 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3332 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3333 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3334 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3335 | out_free: |
| 3336 | if (localpage) |
| 3337 | __free_page(localpage); |
| 3338 | return ret; |
| 3339 | } |
| 3340 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3341 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3342 | { |
| 3343 | struct nfs4_exception exception = { }; |
| 3344 | ssize_t ret; |
| 3345 | do { |
| 3346 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3347 | if (ret >= 0) |
| 3348 | break; |
| 3349 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3350 | } while (exception.retry); |
| 3351 | return ret; |
| 3352 | } |
| 3353 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3354 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3355 | { |
| 3356 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3357 | int ret; |
| 3358 | |
| 3359 | if (!nfs4_server_supports_acls(server)) |
| 3360 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3361 | ret = nfs_revalidate_inode(server, inode); |
| 3362 | if (ret < 0) |
| 3363 | return ret; |
| 3364 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3365 | if (ret != -ENOENT) |
| 3366 | return ret; |
| 3367 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3368 | } |
| 3369 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3370 | 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] | 3371 | { |
| 3372 | struct nfs_server *server = NFS_SERVER(inode); |
| 3373 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3374 | struct nfs_setaclargs arg = { |
| 3375 | .fh = NFS_FH(inode), |
| 3376 | .acl_pages = pages, |
| 3377 | .acl_len = buflen, |
| 3378 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3379 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3380 | struct rpc_message msg = { |
| 3381 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3382 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3383 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3384 | }; |
| 3385 | int ret; |
| 3386 | |
| 3387 | if (!nfs4_server_supports_acls(server)) |
| 3388 | return -EOPNOTSUPP; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3389 | nfs_inode_return_delegation(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3390 | buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3391 | ret = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3392 | nfs_access_zap_cache(inode); |
| 3393 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3394 | return ret; |
| 3395 | } |
| 3396 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3397 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3398 | { |
| 3399 | struct nfs4_exception exception = { }; |
| 3400 | int err; |
| 3401 | do { |
| 3402 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3403 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3404 | &exception); |
| 3405 | } while (exception.retry); |
| 3406 | return err; |
| 3407 | } |
| 3408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3410 | nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3412 | struct nfs_client *clp = server->nfs_client; |
| 3413 | |
| 3414 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | return 0; |
| 3416 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3417 | case -NFS4ERR_ADMIN_REVOKED: |
| 3418 | case -NFS4ERR_BAD_STATEID: |
| 3419 | case -NFS4ERR_OPENMODE: |
| 3420 | if (state == NULL) |
| 3421 | break; |
| 3422 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3423 | goto do_state_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3425 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3427 | goto do_state_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3428 | #if defined(CONFIG_NFS_V4_1) |
| 3429 | case -NFS4ERR_BADSESSION: |
| 3430 | case -NFS4ERR_BADSLOT: |
| 3431 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3432 | case -NFS4ERR_DEADSESSION: |
| 3433 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3434 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3435 | case -NFS4ERR_SEQ_MISORDERED: |
| 3436 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3437 | task->tk_status); |
Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 3438 | nfs4_schedule_state_recovery(clp); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3439 | task->tk_status = 0; |
| 3440 | return -EAGAIN; |
| 3441 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3443 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3444 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3445 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3447 | task->tk_status = 0; |
| 3448 | return -EAGAIN; |
| 3449 | case -NFS4ERR_OLD_STATEID: |
| 3450 | task->tk_status = 0; |
| 3451 | return -EAGAIN; |
| 3452 | } |
| 3453 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3454 | return 0; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3455 | do_state_recovery: |
| 3456 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 3457 | nfs4_schedule_state_recovery(clp); |
| 3458 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3459 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3460 | task->tk_status = 0; |
| 3461 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3462 | } |
| 3463 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3464 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3465 | unsigned short port, struct rpc_cred *cred, |
| 3466 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | { |
| 3468 | nfs4_verifier sc_verifier; |
| 3469 | struct nfs4_setclientid setclientid = { |
| 3470 | .sc_verifier = &sc_verifier, |
| 3471 | .sc_prog = program, |
| 3472 | }; |
| 3473 | struct rpc_message msg = { |
| 3474 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3475 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3476 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3477 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3479 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3480 | int loop = 0; |
| 3481 | int status; |
| 3482 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3483 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3485 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3486 | |
| 3487 | for(;;) { |
| 3488 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3489 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3490 | clp->cl_ipaddr, |
| 3491 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3492 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3493 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3494 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3495 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | clp->cl_id_uniquifier); |
| 3497 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3498 | sizeof(setclientid.sc_netid), |
| 3499 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3500 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3502 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3504 | |
| 3505 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3506 | if (status != -NFS4ERR_CLID_INUSE) |
| 3507 | break; |
| 3508 | if (signalled()) |
| 3509 | break; |
| 3510 | if (loop++ & 1) |
| 3511 | ssleep(clp->cl_lease_time + 1); |
| 3512 | else |
| 3513 | if (++clp->cl_id_uniquifier == 0) |
| 3514 | break; |
| 3515 | } |
| 3516 | return status; |
| 3517 | } |
| 3518 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3519 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3520 | struct nfs4_setclientid_res *arg, |
| 3521 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | { |
| 3523 | struct nfs_fsinfo fsinfo; |
| 3524 | struct rpc_message msg = { |
| 3525 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3526 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3528 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | }; |
| 3530 | unsigned long now; |
| 3531 | int status; |
| 3532 | |
| 3533 | now = jiffies; |
| 3534 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3535 | if (status == 0) { |
| 3536 | spin_lock(&clp->cl_lock); |
| 3537 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3538 | clp->cl_last_renewal = now; |
| 3539 | spin_unlock(&clp->cl_lock); |
| 3540 | } |
| 3541 | return status; |
| 3542 | } |
| 3543 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3544 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3545 | struct nfs4_setclientid_res *arg, |
| 3546 | struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3547 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3548 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3549 | int err; |
| 3550 | do { |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3551 | err = _nfs4_proc_setclientid_confirm(clp, arg, cred); |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3552 | switch (err) { |
| 3553 | case 0: |
| 3554 | return err; |
| 3555 | case -NFS4ERR_RESOURCE: |
| 3556 | /* The IBM lawyers misread another document! */ |
| 3557 | case -NFS4ERR_DELAY: |
| 3558 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3559 | } |
| 3560 | } while (err == 0); |
| 3561 | return err; |
| 3562 | } |
| 3563 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3564 | struct nfs4_delegreturndata { |
| 3565 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3566 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3567 | struct nfs_fh fh; |
| 3568 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3569 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3570 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3571 | int rpc_status; |
| 3572 | }; |
| 3573 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3574 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3575 | { |
| 3576 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3577 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3578 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3579 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3580 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3581 | switch (task->tk_status) { |
| 3582 | case -NFS4ERR_STALE_STATEID: |
| 3583 | case -NFS4ERR_EXPIRED: |
| 3584 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3585 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3586 | break; |
| 3587 | default: |
| 3588 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3589 | -EAGAIN) { |
| 3590 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3591 | return; |
| 3592 | } |
| 3593 | } |
| 3594 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | static void nfs4_delegreturn_release(void *calldata) |
| 3598 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3599 | kfree(calldata); |
| 3600 | } |
| 3601 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3602 | #if defined(CONFIG_NFS_V4_1) |
| 3603 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3604 | { |
| 3605 | struct nfs4_delegreturndata *d_data; |
| 3606 | |
| 3607 | d_data = (struct nfs4_delegreturndata *)data; |
| 3608 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3609 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3610 | &d_data->args.seq_args, |
| 3611 | &d_data->res.seq_res, 1, task)) |
| 3612 | return; |
| 3613 | rpc_call_start(task); |
| 3614 | } |
| 3615 | #endif /* CONFIG_NFS_V4_1 */ |
| 3616 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3617 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3618 | #if defined(CONFIG_NFS_V4_1) |
| 3619 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3620 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3621 | .rpc_call_done = nfs4_delegreturn_done, |
| 3622 | .rpc_release = nfs4_delegreturn_release, |
| 3623 | }; |
| 3624 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3625 | 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] | 3626 | { |
| 3627 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3628 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3629 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3630 | struct rpc_message msg = { |
| 3631 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3632 | .rpc_cred = cred, |
| 3633 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3634 | struct rpc_task_setup task_setup_data = { |
| 3635 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3636 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3637 | .callback_ops = &nfs4_delegreturn_ops, |
| 3638 | .flags = RPC_TASK_ASYNC, |
| 3639 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3640 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3641 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3642 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3643 | if (data == NULL) |
| 3644 | return -ENOMEM; |
| 3645 | data->args.fhandle = &data->fh; |
| 3646 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3647 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3648 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3649 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3650 | data->res.fattr = &data->fattr; |
| 3651 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3652 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3653 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3654 | data->rpc_status = 0; |
| 3655 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3656 | task_setup_data.callback_data = data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3657 | msg.rpc_argp = &data->args, |
| 3658 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3659 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3660 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3661 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3662 | if (!issync) |
| 3663 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3664 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3665 | if (status != 0) |
| 3666 | goto out; |
| 3667 | status = data->rpc_status; |
| 3668 | if (status != 0) |
| 3669 | goto out; |
| 3670 | nfs_refresh_inode(inode, &data->fattr); |
| 3671 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3672 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3673 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | } |
| 3675 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3676 | 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] | 3677 | { |
| 3678 | struct nfs_server *server = NFS_SERVER(inode); |
| 3679 | struct nfs4_exception exception = { }; |
| 3680 | int err; |
| 3681 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3682 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | switch (err) { |
| 3684 | case -NFS4ERR_STALE_STATEID: |
| 3685 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | case 0: |
| 3687 | return 0; |
| 3688 | } |
| 3689 | err = nfs4_handle_exception(server, err, &exception); |
| 3690 | } while (exception.retry); |
| 3691 | return err; |
| 3692 | } |
| 3693 | |
| 3694 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3695 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3696 | |
| 3697 | /* |
| 3698 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3699 | */ |
| 3700 | static unsigned long |
| 3701 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3702 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3703 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | timeout <<= 1; |
| 3705 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3706 | return NFS4_LOCK_MAXTIMEOUT; |
| 3707 | return timeout; |
| 3708 | } |
| 3709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3711 | { |
| 3712 | struct inode *inode = state->inode; |
| 3713 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3714 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3715 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3717 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3719 | struct nfs_lockt_res res = { |
| 3720 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3721 | }; |
| 3722 | struct rpc_message msg = { |
| 3723 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3724 | .rpc_argp = &arg, |
| 3725 | .rpc_resp = &res, |
| 3726 | .rpc_cred = state->owner->so_cred, |
| 3727 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | struct nfs4_lock_state *lsp; |
| 3729 | int status; |
| 3730 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3731 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3732 | status = nfs4_set_lock_state(state, request); |
| 3733 | if (status != 0) |
| 3734 | goto out; |
| 3735 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3736 | arg.lock_owner.id = lsp->ls_id.id; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3737 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3738 | switch (status) { |
| 3739 | case 0: |
| 3740 | request->fl_type = F_UNLCK; |
| 3741 | break; |
| 3742 | case -NFS4ERR_DENIED: |
| 3743 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3745 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3746 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | return status; |
| 3748 | } |
| 3749 | |
| 3750 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3751 | { |
| 3752 | struct nfs4_exception exception = { }; |
| 3753 | int err; |
| 3754 | |
| 3755 | do { |
| 3756 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3757 | _nfs4_proc_getlk(state, cmd, request), |
| 3758 | &exception); |
| 3759 | } while (exception.retry); |
| 3760 | return err; |
| 3761 | } |
| 3762 | |
| 3763 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3764 | { |
| 3765 | int res = 0; |
| 3766 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3767 | case FL_POSIX: |
| 3768 | res = posix_lock_file_wait(file, fl); |
| 3769 | break; |
| 3770 | case FL_FLOCK: |
| 3771 | res = flock_lock_file_wait(file, fl); |
| 3772 | break; |
| 3773 | default: |
| 3774 | BUG(); |
| 3775 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | return res; |
| 3777 | } |
| 3778 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3779 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3780 | struct nfs_locku_args arg; |
| 3781 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3782 | struct nfs4_lock_state *lsp; |
| 3783 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3784 | struct file_lock fl; |
| 3785 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3786 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3787 | }; |
| 3788 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3789 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(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 *p; |
| 3795 | struct inode *inode = lsp->ls_state->inode; |
| 3796 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3797 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3798 | if (p == NULL) |
| 3799 | return NULL; |
| 3800 | p->arg.fh = NFS_FH(inode); |
| 3801 | p->arg.fl = &p->fl; |
| 3802 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3803 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3804 | p->arg.stateid = &lsp->ls_stateid; |
| 3805 | p->lsp = lsp; |
| 3806 | atomic_inc(&lsp->ls_count); |
| 3807 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3808 | p->ctx = get_nfs_open_context(ctx); |
| 3809 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3810 | p->server = NFS_SERVER(inode); |
| 3811 | return p; |
| 3812 | } |
| 3813 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3814 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3815 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3816 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3817 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3818 | nfs4_put_lock_state(calldata->lsp); |
| 3819 | put_nfs_open_context(calldata->ctx); |
| 3820 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3821 | } |
| 3822 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3823 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3824 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3825 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3826 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3827 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3828 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3829 | switch (task->tk_status) { |
| 3830 | case 0: |
| 3831 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3832 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3833 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3834 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3835 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3836 | case -NFS4ERR_BAD_STATEID: |
| 3837 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3838 | case -NFS4ERR_STALE_STATEID: |
| 3839 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3840 | break; |
| 3841 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3842 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3843 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 3844 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3845 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3846 | } |
| 3847 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3848 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3849 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3850 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3852 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3853 | return; |
| 3854 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3855 | /* Note: exit _without_ running nfs4_locku_done */ |
| 3856 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3857 | return; |
| 3858 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3859 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3860 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3861 | &calldata->arg.seq_args, |
| 3862 | &calldata->res.seq_res, 1, task)) |
| 3863 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3864 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | } |
| 3866 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3867 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3868 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3869 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3870 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3871 | }; |
| 3872 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3873 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 3874 | struct nfs_open_context *ctx, |
| 3875 | struct nfs4_lock_state *lsp, |
| 3876 | struct nfs_seqid *seqid) |
| 3877 | { |
| 3878 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3879 | struct rpc_message msg = { |
| 3880 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 3881 | .rpc_cred = ctx->cred, |
| 3882 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3883 | struct rpc_task_setup task_setup_data = { |
| 3884 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3885 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3886 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3887 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3888 | .flags = RPC_TASK_ASYNC, |
| 3889 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3890 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 3891 | /* Ensure this is an unlock - when canceling a lock, the |
| 3892 | * canceled lock is passed in, and it won't be an unlock. |
| 3893 | */ |
| 3894 | fl->fl_type = F_UNLCK; |
| 3895 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3896 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 3897 | if (data == NULL) { |
| 3898 | nfs_free_seqid(seqid); |
| 3899 | return ERR_PTR(-ENOMEM); |
| 3900 | } |
| 3901 | |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3902 | msg.rpc_argp = &data->arg, |
| 3903 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3904 | task_setup_data.callback_data = data; |
| 3905 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3906 | } |
| 3907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3909 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3910 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3911 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3912 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3913 | struct rpc_task *task; |
| 3914 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3915 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3916 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3917 | status = nfs4_set_lock_state(state, request); |
| 3918 | /* Unlock _before_ we do the RPC call */ |
| 3919 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3920 | down_read(&nfsi->rwsem); |
| 3921 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 3922 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3923 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3924 | } |
| 3925 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3926 | if (status != 0) |
| 3927 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3928 | /* Is this a delegated lock? */ |
| 3929 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3930 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3931 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3932 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3933 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3934 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3935 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 3936 | 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] | 3937 | status = PTR_ERR(task); |
| 3938 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3939 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3940 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3941 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3942 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3943 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3944 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | } |
| 3946 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3947 | struct nfs4_lockdata { |
| 3948 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3949 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3950 | struct nfs4_lock_state *lsp; |
| 3951 | struct nfs_open_context *ctx; |
| 3952 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3953 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3954 | int rpc_status; |
| 3955 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 3956 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3957 | }; |
| 3958 | |
| 3959 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3960 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 3961 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3962 | { |
| 3963 | struct nfs4_lockdata *p; |
| 3964 | struct inode *inode = lsp->ls_state->inode; |
| 3965 | struct nfs_server *server = NFS_SERVER(inode); |
| 3966 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3967 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3968 | if (p == NULL) |
| 3969 | return NULL; |
| 3970 | |
| 3971 | p->arg.fh = NFS_FH(inode); |
| 3972 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3973 | p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3974 | if (p->arg.open_seqid == NULL) |
| 3975 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3976 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3977 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3978 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3979 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3980 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3981 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3982 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3983 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 3984 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3985 | atomic_inc(&lsp->ls_count); |
| 3986 | p->ctx = get_nfs_open_context(ctx); |
| 3987 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3988 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 3989 | out_free_seqid: |
| 3990 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3991 | out_free: |
| 3992 | kfree(p); |
| 3993 | return NULL; |
| 3994 | } |
| 3995 | |
| 3996 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 3997 | { |
| 3998 | struct nfs4_lockdata *data = calldata; |
| 3999 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4001 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4002 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4003 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4004 | /* Do we need to do an open_to_lock_owner? */ |
| 4005 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4006 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4007 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4008 | data->arg.open_stateid = &state->stateid; |
| 4009 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4010 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4011 | } else |
| 4012 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4013 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4014 | if (nfs4_setup_sequence(data->server, |
| 4015 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4016 | &data->res.seq_res, 1, task)) |
| 4017 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4018 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4019 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4020 | } |
| 4021 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4022 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4023 | { |
| 4024 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4025 | nfs4_lock_prepare(task, calldata); |
| 4026 | } |
| 4027 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4028 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4029 | { |
| 4030 | struct nfs4_lockdata *data = calldata; |
| 4031 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4032 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4033 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4034 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4035 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4036 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4037 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4038 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4039 | if (data->rpc_status == 0) |
| 4040 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4041 | else |
| 4042 | goto out; |
| 4043 | } |
| 4044 | if (data->rpc_status == 0) { |
| 4045 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4046 | sizeof(data->lsp->ls_stateid.data)); |
| 4047 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4048 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4049 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4050 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4051 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | static void nfs4_lock_release(void *calldata) |
| 4055 | { |
| 4056 | struct nfs4_lockdata *data = calldata; |
| 4057 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4058 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4059 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4060 | if (data->cancelled != 0) { |
| 4061 | struct rpc_task *task; |
| 4062 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4063 | data->arg.lock_seqid); |
| 4064 | if (!IS_ERR(task)) |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4065 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4066 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4067 | } else |
| 4068 | nfs_free_seqid(data->arg.lock_seqid); |
| 4069 | nfs4_put_lock_state(data->lsp); |
| 4070 | put_nfs_open_context(data->ctx); |
| 4071 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4072 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4076 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4077 | .rpc_call_done = nfs4_lock_done, |
| 4078 | .rpc_release = nfs4_lock_release, |
| 4079 | }; |
| 4080 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4081 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4082 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4083 | .rpc_call_done = nfs4_lock_done, |
| 4084 | .rpc_release = nfs4_lock_release, |
| 4085 | }; |
| 4086 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4087 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4088 | { |
| 4089 | struct nfs_client *clp = server->nfs_client; |
| 4090 | struct nfs4_state *state = lsp->ls_state; |
| 4091 | |
| 4092 | switch (error) { |
| 4093 | case -NFS4ERR_ADMIN_REVOKED: |
| 4094 | case -NFS4ERR_BAD_STATEID: |
| 4095 | case -NFS4ERR_EXPIRED: |
| 4096 | if (new_lock_owner != 0 || |
| 4097 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
| 4098 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 4099 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4100 | break; |
| 4101 | case -NFS4ERR_STALE_STATEID: |
| 4102 | if (new_lock_owner != 0 || |
| 4103 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
| 4104 | nfs4_state_mark_reclaim_reboot(clp, state); |
| 4105 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4106 | }; |
| 4107 | } |
| 4108 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4109 | static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4110 | { |
| 4111 | struct nfs4_lockdata *data; |
| 4112 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4113 | struct rpc_message msg = { |
| 4114 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4115 | .rpc_cred = state->owner->so_cred, |
| 4116 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4117 | struct rpc_task_setup task_setup_data = { |
| 4118 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4119 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4120 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4121 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4122 | .flags = RPC_TASK_ASYNC, |
| 4123 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4124 | int ret; |
| 4125 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4126 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4127 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4128 | fl->fl_u.nfs4_fl.owner, |
| 4129 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4130 | if (data == NULL) |
| 4131 | return -ENOMEM; |
| 4132 | if (IS_SETLKW(cmd)) |
| 4133 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4134 | if (recovery_type > NFS_LOCK_NEW) { |
| 4135 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4136 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4137 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4138 | } |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4139 | msg.rpc_argp = &data->arg, |
| 4140 | msg.rpc_resp = &data->res, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4141 | task_setup_data.callback_data = data; |
| 4142 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4143 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4144 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4145 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4146 | if (ret == 0) { |
| 4147 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4148 | if (ret) |
| 4149 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4150 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4151 | } else |
| 4152 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4153 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4154 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4155 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4159 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4160 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4161 | struct nfs4_exception exception = { }; |
| 4162 | int err; |
| 4163 | |
| 4164 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4165 | /* Cache the lock if possible... */ |
| 4166 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4167 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4168 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4169 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4170 | break; |
| 4171 | nfs4_handle_exception(server, err, &exception); |
| 4172 | } while (exception.retry); |
| 4173 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4177 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4178 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4179 | struct nfs4_exception exception = { }; |
| 4180 | int err; |
| 4181 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4182 | err = nfs4_set_lock_state(state, request); |
| 4183 | if (err != 0) |
| 4184 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4185 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4186 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4187 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4188 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4189 | switch (err) { |
| 4190 | default: |
| 4191 | goto out; |
| 4192 | case -NFS4ERR_GRACE: |
| 4193 | case -NFS4ERR_DELAY: |
| 4194 | nfs4_handle_exception(server, err, &exception); |
| 4195 | err = 0; |
| 4196 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4197 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4198 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4199 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | } |
| 4201 | |
| 4202 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4203 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4204 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4205 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4206 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4208 | if ((fl_flags & FL_POSIX) && |
| 4209 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4210 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4211 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4212 | status = nfs4_set_lock_state(state, request); |
| 4213 | if (status != 0) |
| 4214 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4215 | request->fl_flags |= FL_ACCESS; |
| 4216 | status = do_vfs_lock(request->fl_file, request); |
| 4217 | if (status < 0) |
| 4218 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4219 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4220 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4221 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4222 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4223 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4224 | status = do_vfs_lock(request->fl_file, request); |
| 4225 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4226 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4227 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4228 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4229 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4230 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4231 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4232 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4233 | 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] | 4234 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4235 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4236 | out: |
| 4237 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | return status; |
| 4239 | } |
| 4240 | |
| 4241 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4242 | { |
| 4243 | struct nfs4_exception exception = { }; |
| 4244 | int err; |
| 4245 | |
| 4246 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4247 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4248 | if (err == -NFS4ERR_DENIED) |
| 4249 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4251 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | } while (exception.retry); |
| 4253 | return err; |
| 4254 | } |
| 4255 | |
| 4256 | static int |
| 4257 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4258 | { |
| 4259 | struct nfs_open_context *ctx; |
| 4260 | struct nfs4_state *state; |
| 4261 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4262 | int status; |
| 4263 | |
| 4264 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4265 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | state = ctx->state; |
| 4267 | |
| 4268 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4269 | return -EINVAL; |
| 4270 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4271 | if (IS_GETLK(cmd)) { |
| 4272 | if (state != NULL) |
| 4273 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4274 | return 0; |
| 4275 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | |
| 4277 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4278 | return -EINVAL; |
| 4279 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4280 | if (request->fl_type == F_UNLCK) { |
| 4281 | if (state != NULL) |
| 4282 | return nfs4_proc_unlck(state, cmd, request); |
| 4283 | return 0; |
| 4284 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4286 | if (state == NULL) |
| 4287 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | do { |
| 4289 | status = nfs4_proc_setlk(state, cmd, request); |
| 4290 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4291 | break; |
| 4292 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4293 | status = -ERESTARTSYS; |
| 4294 | if (signalled()) |
| 4295 | break; |
| 4296 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | return status; |
| 4298 | } |
| 4299 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4300 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4301 | { |
| 4302 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4303 | struct nfs4_exception exception = { }; |
| 4304 | int err; |
| 4305 | |
| 4306 | err = nfs4_set_lock_state(state, fl); |
| 4307 | if (err != 0) |
| 4308 | goto out; |
| 4309 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4310 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4311 | switch (err) { |
| 4312 | default: |
| 4313 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4314 | __func__, err); |
| 4315 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4316 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4317 | goto out; |
| 4318 | case -NFS4ERR_EXPIRED: |
| 4319 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4320 | case -NFS4ERR_STALE_STATEID: |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4321 | case -NFS4ERR_BADSESSION: |
| 4322 | case -NFS4ERR_BADSLOT: |
| 4323 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4324 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4325 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4326 | nfs4_schedule_state_recovery(server->nfs_client); |
| 4327 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4328 | case -ERESTARTSYS: |
| 4329 | /* |
| 4330 | * The show must go on: exit, but mark the |
| 4331 | * stateid as needing recovery. |
| 4332 | */ |
| 4333 | case -NFS4ERR_ADMIN_REVOKED: |
| 4334 | case -NFS4ERR_BAD_STATEID: |
| 4335 | case -NFS4ERR_OPENMODE: |
| 4336 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
| 4337 | err = 0; |
| 4338 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4339 | case -EKEYEXPIRED: |
| 4340 | /* |
| 4341 | * User RPCSEC_GSS context has expired. |
| 4342 | * We cannot recover this stateid now, so |
| 4343 | * skip it and allow recovery thread to |
| 4344 | * proceed. |
| 4345 | */ |
| 4346 | err = 0; |
| 4347 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4348 | case -ENOMEM: |
| 4349 | case -NFS4ERR_DENIED: |
| 4350 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4351 | err = 0; |
| 4352 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4353 | case -NFS4ERR_DELAY: |
| 4354 | break; |
| 4355 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4356 | err = nfs4_handle_exception(server, err, &exception); |
| 4357 | } while (exception.retry); |
| 4358 | out: |
| 4359 | return err; |
| 4360 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4361 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4362 | static void nfs4_release_lockowner_release(void *calldata) |
| 4363 | { |
| 4364 | kfree(calldata); |
| 4365 | } |
| 4366 | |
| 4367 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4368 | .rpc_release = nfs4_release_lockowner_release, |
| 4369 | }; |
| 4370 | |
| 4371 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4372 | { |
| 4373 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4374 | struct nfs_release_lockowner_args *args; |
| 4375 | struct rpc_message msg = { |
| 4376 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4377 | }; |
| 4378 | |
| 4379 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4380 | return; |
| 4381 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4382 | if (!args) |
| 4383 | return; |
| 4384 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4385 | args->lock_owner.id = lsp->ls_id.id; |
| 4386 | msg.rpc_argp = args; |
| 4387 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4388 | } |
| 4389 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4390 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4391 | |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4392 | int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf, |
| 4393 | size_t buflen, int flags) |
| 4394 | { |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4395 | struct inode *inode = dentry->d_inode; |
| 4396 | |
| 4397 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
| 4398 | return -EOPNOTSUPP; |
| 4399 | |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4400 | return nfs4_proc_set_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | /* The getxattr man page suggests returning -ENODATA for unknown attributes, |
| 4404 | * and that's what we'll do for e.g. user attributes that haven't been set. |
| 4405 | * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported |
| 4406 | * attributes in kernel-managed attribute namespaces. */ |
| 4407 | ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf, |
| 4408 | size_t buflen) |
| 4409 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4410 | struct inode *inode = dentry->d_inode; |
| 4411 | |
| 4412 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) |
| 4413 | return -EOPNOTSUPP; |
| 4414 | |
| 4415 | return nfs4_proc_get_acl(inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen) |
| 4419 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4420 | size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4421 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4422 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4423 | return 0; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4424 | if (buf && buflen < len) |
| 4425 | return -ERANGE; |
| 4426 | if (buf) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4427 | memcpy(buf, XATTR_NAME_NFSV4_ACL, len); |
| 4428 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4429 | } |
| 4430 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4431 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4432 | { |
| 4433 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4434 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4435 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4436 | return; |
| 4437 | |
| 4438 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4439 | NFS_ATTR_FATTR_NLINK; |
| 4440 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4441 | fattr->nlink = 2; |
| 4442 | } |
| 4443 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4444 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4445 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4446 | { |
| 4447 | struct nfs_server *server = NFS_SERVER(dir); |
| 4448 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4449 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4450 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4451 | }; |
| 4452 | struct nfs4_fs_locations_arg args = { |
| 4453 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4454 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4455 | .page = page, |
| 4456 | .bitmask = bitmask, |
| 4457 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4458 | struct nfs4_fs_locations_res res = { |
| 4459 | .fs_locations = fs_locations, |
| 4460 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4461 | struct rpc_message msg = { |
| 4462 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4463 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4464 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4465 | }; |
| 4466 | int status; |
| 4467 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4468 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4469 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4470 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4471 | fs_locations->nlocations = 0; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 4472 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4473 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4474 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4475 | return status; |
| 4476 | } |
| 4477 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4478 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4479 | /* |
| 4480 | * nfs4_proc_exchange_id() |
| 4481 | * |
| 4482 | * Since the clientid has expired, all compounds using sessions |
| 4483 | * associated with the stale clientid will be returning |
| 4484 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4485 | * be in some phase of session reset. |
| 4486 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4487 | 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] | 4488 | { |
| 4489 | nfs4_verifier verifier; |
| 4490 | struct nfs41_exchange_id_args args = { |
| 4491 | .client = clp, |
| 4492 | .flags = clp->cl_exchange_flags, |
| 4493 | }; |
| 4494 | struct nfs41_exchange_id_res res = { |
| 4495 | .client = clp, |
| 4496 | }; |
| 4497 | int status; |
| 4498 | struct rpc_message msg = { |
| 4499 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4500 | .rpc_argp = &args, |
| 4501 | .rpc_resp = &res, |
| 4502 | .rpc_cred = cred, |
| 4503 | }; |
| 4504 | __be32 *p; |
| 4505 | |
| 4506 | dprintk("--> %s\n", __func__); |
| 4507 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4508 | |
Alexandros Batsakis | 7b183d0 | 2009-12-05 13:33:25 -0500 | [diff] [blame] | 4509 | /* Remove server-only flags */ |
| 4510 | args.flags &= ~EXCHGID4_FLAG_CONFIRMED_R; |
| 4511 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4512 | p = (u32 *)verifier.data; |
| 4513 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4514 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4515 | args.verifier = &verifier; |
| 4516 | |
| 4517 | while (1) { |
| 4518 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4519 | "%s/%s %u", |
| 4520 | clp->cl_ipaddr, |
| 4521 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4522 | RPC_DISPLAY_ADDR), |
| 4523 | clp->cl_id_uniquifier); |
| 4524 | |
| 4525 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4526 | |
Andy Adamson | 180b62a | 2010-03-02 13:19:36 -0500 | [diff] [blame] | 4527 | if (status != -NFS4ERR_CLID_INUSE) |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4528 | break; |
| 4529 | |
| 4530 | if (signalled()) |
| 4531 | break; |
| 4532 | |
| 4533 | if (++clp->cl_id_uniquifier == 0) |
| 4534 | break; |
| 4535 | } |
| 4536 | |
| 4537 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4538 | return status; |
| 4539 | } |
| 4540 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4541 | struct nfs4_get_lease_time_data { |
| 4542 | struct nfs4_get_lease_time_args *args; |
| 4543 | struct nfs4_get_lease_time_res *res; |
| 4544 | struct nfs_client *clp; |
| 4545 | }; |
| 4546 | |
| 4547 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4548 | void *calldata) |
| 4549 | { |
| 4550 | int ret; |
| 4551 | struct nfs4_get_lease_time_data *data = |
| 4552 | (struct nfs4_get_lease_time_data *)calldata; |
| 4553 | |
| 4554 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4555 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4556 | /* just setup sequence, do not trigger session recovery |
| 4557 | since we're invoked within one */ |
| 4558 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4559 | &data->args->la_seq_args, |
| 4560 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4561 | |
| 4562 | BUG_ON(ret == -EAGAIN); |
| 4563 | rpc_call_start(task); |
| 4564 | dprintk("<-- %s\n", __func__); |
| 4565 | } |
| 4566 | |
| 4567 | /* |
| 4568 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4569 | * from sequence operation or clientid errors. |
| 4570 | */ |
| 4571 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4572 | { |
| 4573 | struct nfs4_get_lease_time_data *data = |
| 4574 | (struct nfs4_get_lease_time_data *)calldata; |
| 4575 | |
| 4576 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4577 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4578 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4579 | switch (task->tk_status) { |
| 4580 | case -NFS4ERR_DELAY: |
| 4581 | case -NFS4ERR_GRACE: |
| 4582 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4583 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4584 | task->tk_status = 0; |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4585 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4586 | return; |
| 4587 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4588 | dprintk("<-- %s\n", __func__); |
| 4589 | } |
| 4590 | |
| 4591 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4592 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4593 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4594 | }; |
| 4595 | |
| 4596 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4597 | { |
| 4598 | struct rpc_task *task; |
| 4599 | struct nfs4_get_lease_time_args args; |
| 4600 | struct nfs4_get_lease_time_res res = { |
| 4601 | .lr_fsinfo = fsinfo, |
| 4602 | }; |
| 4603 | struct nfs4_get_lease_time_data data = { |
| 4604 | .args = &args, |
| 4605 | .res = &res, |
| 4606 | .clp = clp, |
| 4607 | }; |
| 4608 | struct rpc_message msg = { |
| 4609 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4610 | .rpc_argp = &args, |
| 4611 | .rpc_resp = &res, |
| 4612 | }; |
| 4613 | struct rpc_task_setup task_setup = { |
| 4614 | .rpc_client = clp->cl_rpcclient, |
| 4615 | .rpc_message = &msg, |
| 4616 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4617 | .callback_data = &data |
| 4618 | }; |
| 4619 | int status; |
| 4620 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4621 | dprintk("--> %s\n", __func__); |
| 4622 | task = rpc_run_task(&task_setup); |
| 4623 | |
| 4624 | if (IS_ERR(task)) |
| 4625 | status = PTR_ERR(task); |
| 4626 | else { |
| 4627 | status = task->tk_status; |
| 4628 | rpc_put_task(task); |
| 4629 | } |
| 4630 | dprintk("<-- %s return %d\n", __func__, status); |
| 4631 | |
| 4632 | return status; |
| 4633 | } |
| 4634 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4635 | /* |
| 4636 | * Reset a slot table |
| 4637 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4638 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4639 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4640 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4641 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4642 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4643 | int ret = 0; |
| 4644 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4645 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4646 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4647 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4648 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4649 | if (max_reqs != tbl->max_slots) { |
| 4650 | ret = -ENOMEM; |
| 4651 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4652 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4653 | if (!new) |
| 4654 | goto out; |
| 4655 | ret = 0; |
| 4656 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4657 | } |
| 4658 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4659 | if (new) { |
| 4660 | tbl->slots = new; |
| 4661 | tbl->max_slots = max_reqs; |
| 4662 | } |
| 4663 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4664 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4665 | spin_unlock(&tbl->slot_tbl_lock); |
| 4666 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4667 | tbl, tbl->slots, tbl->max_slots); |
| 4668 | out: |
| 4669 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4670 | return ret; |
| 4671 | } |
| 4672 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4673 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4674 | * Reset the forechannel and backchannel slot tables |
| 4675 | */ |
| 4676 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4677 | { |
| 4678 | int status; |
| 4679 | |
| 4680 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4681 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4682 | if (status) |
| 4683 | return status; |
| 4684 | |
| 4685 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4686 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4687 | return status; |
| 4688 | } |
| 4689 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4690 | /* Destroy the slot table */ |
| 4691 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4692 | { |
| 4693 | if (session->fc_slot_table.slots != NULL) { |
| 4694 | kfree(session->fc_slot_table.slots); |
| 4695 | session->fc_slot_table.slots = NULL; |
| 4696 | } |
| 4697 | if (session->bc_slot_table.slots != NULL) { |
| 4698 | kfree(session->bc_slot_table.slots); |
| 4699 | session->bc_slot_table.slots = NULL; |
| 4700 | } |
| 4701 | return; |
| 4702 | } |
| 4703 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4704 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4705 | * Initialize slot table |
| 4706 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4707 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4708 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4709 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4710 | struct nfs4_slot *slot; |
| 4711 | int ret = -ENOMEM; |
| 4712 | |
| 4713 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4714 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4715 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4716 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4717 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4718 | if (!slot) |
| 4719 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4720 | ret = 0; |
| 4721 | |
| 4722 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4723 | tbl->max_slots = max_slots; |
| 4724 | tbl->slots = slot; |
| 4725 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4726 | spin_unlock(&tbl->slot_tbl_lock); |
| 4727 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4728 | tbl, tbl->slots, tbl->max_slots); |
| 4729 | out: |
| 4730 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4731 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4732 | } |
| 4733 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4734 | /* |
| 4735 | * Initialize the forechannel and backchannel tables |
| 4736 | */ |
| 4737 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4738 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4739 | struct nfs4_slot_table *tbl; |
| 4740 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4741 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4742 | tbl = &session->fc_slot_table; |
| 4743 | if (tbl->slots == NULL) { |
| 4744 | status = nfs4_init_slot_table(tbl, |
| 4745 | session->fc_attrs.max_reqs, 1); |
| 4746 | if (status) |
| 4747 | return status; |
| 4748 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4749 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4750 | tbl = &session->bc_slot_table; |
| 4751 | if (tbl->slots == NULL) { |
| 4752 | status = nfs4_init_slot_table(tbl, |
| 4753 | session->bc_attrs.max_reqs, 0); |
| 4754 | if (status) |
| 4755 | nfs4_destroy_slot_tables(session); |
| 4756 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4757 | |
| 4758 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 4762 | { |
| 4763 | struct nfs4_session *session; |
| 4764 | struct nfs4_slot_table *tbl; |
| 4765 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4766 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4767 | if (!session) |
| 4768 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4769 | |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 4770 | init_completion(&session->complete); |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4771 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4772 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4773 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4774 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4775 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4776 | |
| 4777 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4778 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4779 | spin_lock_init(&tbl->slot_tbl_lock); |
| 4780 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
| 4781 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 4782 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 4783 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4784 | session->clp = clp; |
| 4785 | return session; |
| 4786 | } |
| 4787 | |
| 4788 | void nfs4_destroy_session(struct nfs4_session *session) |
| 4789 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 4790 | nfs4_proc_destroy_session(session); |
| 4791 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 4792 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 4793 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 4794 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4795 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4796 | kfree(session); |
| 4797 | } |
| 4798 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4799 | /* |
| 4800 | * Initialize the values to be used by the client in CREATE_SESSION |
| 4801 | * If nfs4_init_session set the fore channel request and response sizes, |
| 4802 | * use them. |
| 4803 | * |
| 4804 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 4805 | * always set csa_cachethis to FALSE because the current implementation |
| 4806 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 4807 | */ |
| 4808 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 4809 | { |
| 4810 | struct nfs4_session *session = args->client->cl_session; |
| 4811 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 4812 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 4813 | |
| 4814 | if (mxrqst_sz == 0) |
| 4815 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 4816 | if (mxresp_sz == 0) |
| 4817 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 4818 | /* Fore channel attributes */ |
| 4819 | args->fc_attrs.headerpadsz = 0; |
| 4820 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 4821 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4822 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 4823 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 4824 | |
| 4825 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4826 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4827 | __func__, |
| 4828 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4829 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4830 | |
| 4831 | /* Back channel attributes */ |
| 4832 | args->bc_attrs.headerpadsz = 0; |
| 4833 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 4834 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 4835 | args->bc_attrs.max_resp_sz_cached = 0; |
| 4836 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 4837 | args->bc_attrs.max_reqs = 1; |
| 4838 | |
| 4839 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 4840 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 4841 | __func__, |
| 4842 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 4843 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 4844 | args->bc_attrs.max_reqs); |
| 4845 | } |
| 4846 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4847 | static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4848 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4849 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 4850 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 4851 | |
| 4852 | if (rcvd->headerpadsz > sent->headerpadsz) |
| 4853 | return -EINVAL; |
| 4854 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 4855 | return -EINVAL; |
| 4856 | /* |
| 4857 | * Our requested max_ops is the minimum we need; we're not |
| 4858 | * prepared to break up compounds into smaller pieces than that. |
| 4859 | * So, no point even trying to continue if the server won't |
| 4860 | * cooperate: |
| 4861 | */ |
| 4862 | if (rcvd->max_ops < sent->max_ops) |
| 4863 | return -EINVAL; |
| 4864 | if (rcvd->max_reqs == 0) |
| 4865 | return -EINVAL; |
| 4866 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4867 | } |
| 4868 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4869 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 4870 | { |
| 4871 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 4872 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4873 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4874 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 4875 | return -EINVAL; |
| 4876 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 4877 | return -EINVAL; |
| 4878 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 4879 | return -EINVAL; |
| 4880 | /* These would render the backchannel useless: */ |
| 4881 | if (rcvd->max_ops == 0) |
| 4882 | return -EINVAL; |
| 4883 | if (rcvd->max_reqs == 0) |
| 4884 | return -EINVAL; |
| 4885 | return 0; |
| 4886 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4887 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4888 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 4889 | struct nfs4_session *session) |
| 4890 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4891 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4892 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4893 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 4894 | if (ret) |
| 4895 | return ret; |
| 4896 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4897 | } |
| 4898 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4899 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 4900 | { |
| 4901 | struct nfs4_session *session = clp->cl_session; |
| 4902 | struct nfs41_create_session_args args = { |
| 4903 | .client = clp, |
| 4904 | .cb_program = NFS4_CALLBACK, |
| 4905 | }; |
| 4906 | struct nfs41_create_session_res res = { |
| 4907 | .client = clp, |
| 4908 | }; |
| 4909 | struct rpc_message msg = { |
| 4910 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 4911 | .rpc_argp = &args, |
| 4912 | .rpc_resp = &res, |
| 4913 | }; |
| 4914 | int status; |
| 4915 | |
| 4916 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 4917 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4918 | |
| 4919 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 4920 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4921 | if (!status) |
| 4922 | /* Verify the session's negotiated channel_attrs values */ |
| 4923 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4924 | if (!status) { |
| 4925 | /* Increment the clientid slot sequence id */ |
| 4926 | clp->cl_seqid++; |
| 4927 | } |
| 4928 | |
| 4929 | return status; |
| 4930 | } |
| 4931 | |
| 4932 | /* |
| 4933 | * Issues a CREATE_SESSION operation to the server. |
| 4934 | * It is the responsibility of the caller to verify the session is |
| 4935 | * expired before calling this routine. |
| 4936 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4937 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4938 | { |
| 4939 | int status; |
| 4940 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4941 | struct nfs4_session *session = clp->cl_session; |
| 4942 | |
| 4943 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 4944 | |
| 4945 | status = _nfs4_proc_create_session(clp); |
| 4946 | if (status) |
| 4947 | goto out; |
| 4948 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4949 | /* Init and reset the fore channel */ |
| 4950 | status = nfs4_init_slot_tables(session); |
| 4951 | dprintk("slot table initialization returned %d\n", status); |
| 4952 | if (status) |
| 4953 | goto out; |
| 4954 | status = nfs4_reset_slot_tables(session); |
| 4955 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4956 | if (status) |
| 4957 | goto out; |
| 4958 | |
| 4959 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 4960 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 4961 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4962 | out: |
| 4963 | dprintk("<-- %s\n", __func__); |
| 4964 | return status; |
| 4965 | } |
| 4966 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 4967 | /* |
| 4968 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 4969 | * The caller must serialize access to this routine. |
| 4970 | */ |
| 4971 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 4972 | { |
| 4973 | int status = 0; |
| 4974 | struct rpc_message msg; |
| 4975 | |
| 4976 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 4977 | |
| 4978 | /* session is still being setup */ |
| 4979 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 4980 | return status; |
| 4981 | |
| 4982 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 4983 | msg.rpc_argp = session; |
| 4984 | msg.rpc_resp = NULL; |
| 4985 | msg.rpc_cred = NULL; |
| 4986 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 4987 | |
| 4988 | if (status) |
| 4989 | printk(KERN_WARNING |
| 4990 | "Got error %d from the server on DESTROY_SESSION. " |
| 4991 | "Session has been destroyed regardless...\n", status); |
| 4992 | |
| 4993 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 4994 | return status; |
| 4995 | } |
| 4996 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 4997 | int nfs4_init_session(struct nfs_server *server) |
| 4998 | { |
| 4999 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5000 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5001 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5002 | int ret; |
| 5003 | |
| 5004 | if (!nfs4_has_session(clp)) |
| 5005 | return 0; |
| 5006 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5007 | session = clp->cl_session; |
| 5008 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5009 | return 0; |
| 5010 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5011 | rsize = server->rsize; |
| 5012 | if (rsize == 0) |
| 5013 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5014 | wsize = server->wsize; |
| 5015 | if (wsize == 0) |
| 5016 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5017 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5018 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5019 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5020 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5021 | ret = nfs4_recover_expired_lease(server); |
| 5022 | if (!ret) |
| 5023 | ret = nfs4_check_client_ready(clp); |
| 5024 | return ret; |
| 5025 | } |
| 5026 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5027 | /* |
| 5028 | * Renew the cl_session lease. |
| 5029 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5030 | struct nfs4_sequence_data { |
| 5031 | struct nfs_client *clp; |
| 5032 | struct nfs4_sequence_args args; |
| 5033 | struct nfs4_sequence_res res; |
| 5034 | }; |
| 5035 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5036 | static void nfs41_sequence_release(void *data) |
| 5037 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5038 | struct nfs4_sequence_data *calldata = data; |
| 5039 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5040 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5041 | if (atomic_read(&clp->cl_count) > 1) |
| 5042 | nfs4_schedule_state_renewal(clp); |
| 5043 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5044 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5045 | } |
| 5046 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5047 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5048 | { |
| 5049 | switch(task->tk_status) { |
| 5050 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5051 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5052 | return -EAGAIN; |
| 5053 | default: |
| 5054 | nfs4_schedule_state_recovery(clp); |
| 5055 | } |
| 5056 | return 0; |
| 5057 | } |
| 5058 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5059 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5060 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5061 | struct nfs4_sequence_data *calldata = data; |
| 5062 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5063 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5064 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5065 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5066 | |
| 5067 | if (task->tk_status < 0) { |
| 5068 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5069 | if (atomic_read(&clp->cl_count) == 1) |
| 5070 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5071 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5072 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5073 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5074 | return; |
| 5075 | } |
| 5076 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5077 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5078 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5079 | dprintk("<-- %s\n", __func__); |
| 5080 | } |
| 5081 | |
| 5082 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5083 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5084 | struct nfs4_sequence_data *calldata = data; |
| 5085 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5086 | struct nfs4_sequence_args *args; |
| 5087 | struct nfs4_sequence_res *res; |
| 5088 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5089 | args = task->tk_msg.rpc_argp; |
| 5090 | res = task->tk_msg.rpc_resp; |
| 5091 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5092 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5093 | return; |
| 5094 | rpc_call_start(task); |
| 5095 | } |
| 5096 | |
| 5097 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5098 | .rpc_call_done = nfs41_sequence_call_done, |
| 5099 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5100 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5101 | }; |
| 5102 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5103 | static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5104 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5105 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5106 | struct rpc_message msg = { |
| 5107 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5108 | .rpc_cred = cred, |
| 5109 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5110 | struct rpc_task_setup task_setup_data = { |
| 5111 | .rpc_client = clp->cl_rpcclient, |
| 5112 | .rpc_message = &msg, |
| 5113 | .callback_ops = &nfs41_sequence_ops, |
| 5114 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5115 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5116 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5117 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5118 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5119 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5120 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5121 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5122 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5123 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5124 | msg.rpc_argp = &calldata->args; |
| 5125 | msg.rpc_resp = &calldata->res; |
| 5126 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5127 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5128 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5129 | return rpc_run_task(&task_setup_data); |
| 5130 | } |
| 5131 | |
| 5132 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5133 | { |
| 5134 | struct rpc_task *task; |
| 5135 | int ret = 0; |
| 5136 | |
| 5137 | task = _nfs41_proc_sequence(clp, cred); |
| 5138 | if (IS_ERR(task)) |
| 5139 | ret = PTR_ERR(task); |
| 5140 | else |
| 5141 | rpc_put_task(task); |
| 5142 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5143 | return ret; |
| 5144 | } |
| 5145 | |
| 5146 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5147 | { |
| 5148 | struct rpc_task *task; |
| 5149 | int ret; |
| 5150 | |
| 5151 | task = _nfs41_proc_sequence(clp, cred); |
| 5152 | if (IS_ERR(task)) { |
| 5153 | ret = PTR_ERR(task); |
| 5154 | goto out; |
| 5155 | } |
| 5156 | ret = rpc_wait_for_completion_task(task); |
| 5157 | if (!ret) |
| 5158 | ret = task->tk_status; |
| 5159 | rpc_put_task(task); |
| 5160 | out: |
| 5161 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5162 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5163 | } |
| 5164 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5165 | struct nfs4_reclaim_complete_data { |
| 5166 | struct nfs_client *clp; |
| 5167 | struct nfs41_reclaim_complete_args arg; |
| 5168 | struct nfs41_reclaim_complete_res res; |
| 5169 | }; |
| 5170 | |
| 5171 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5172 | { |
| 5173 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5174 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5175 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5176 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5177 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5178 | &calldata->res.seq_res, 0, task)) |
| 5179 | return; |
| 5180 | |
| 5181 | rpc_call_start(task); |
| 5182 | } |
| 5183 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5184 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5185 | { |
| 5186 | switch(task->tk_status) { |
| 5187 | case 0: |
| 5188 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5189 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5190 | break; |
| 5191 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5192 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5193 | return -EAGAIN; |
| 5194 | default: |
| 5195 | nfs4_schedule_state_recovery(clp); |
| 5196 | } |
| 5197 | return 0; |
| 5198 | } |
| 5199 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5200 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5201 | { |
| 5202 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5203 | struct nfs_client *clp = calldata->clp; |
| 5204 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5205 | |
| 5206 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5207 | if (!nfs41_sequence_done(task, res)) |
| 5208 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5209 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5210 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5211 | rpc_restart_call_prepare(task); |
| 5212 | return; |
| 5213 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5214 | dprintk("<-- %s\n", __func__); |
| 5215 | } |
| 5216 | |
| 5217 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5218 | { |
| 5219 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5220 | |
| 5221 | kfree(calldata); |
| 5222 | } |
| 5223 | |
| 5224 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5225 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5226 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5227 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5228 | }; |
| 5229 | |
| 5230 | /* |
| 5231 | * Issue a global reclaim complete. |
| 5232 | */ |
| 5233 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5234 | { |
| 5235 | struct nfs4_reclaim_complete_data *calldata; |
| 5236 | struct rpc_task *task; |
| 5237 | struct rpc_message msg = { |
| 5238 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5239 | }; |
| 5240 | struct rpc_task_setup task_setup_data = { |
| 5241 | .rpc_client = clp->cl_rpcclient, |
| 5242 | .rpc_message = &msg, |
| 5243 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5244 | .flags = RPC_TASK_ASYNC, |
| 5245 | }; |
| 5246 | int status = -ENOMEM; |
| 5247 | |
| 5248 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5249 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5250 | if (calldata == NULL) |
| 5251 | goto out; |
| 5252 | calldata->clp = clp; |
| 5253 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5254 | |
| 5255 | msg.rpc_argp = &calldata->arg; |
| 5256 | msg.rpc_resp = &calldata->res; |
| 5257 | task_setup_data.callback_data = calldata; |
| 5258 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5259 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5260 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5261 | goto out; |
| 5262 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5263 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5264 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5265 | out: |
| 5266 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5267 | return status; |
| 5268 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5269 | |
| 5270 | static void |
| 5271 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5272 | { |
| 5273 | struct nfs4_layoutget *lgp = calldata; |
| 5274 | struct inode *ino = lgp->args.inode; |
| 5275 | struct nfs_server *server = NFS_SERVER(ino); |
| 5276 | |
| 5277 | dprintk("--> %s\n", __func__); |
| 5278 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5279 | &lgp->res.seq_res, 0, task)) |
| 5280 | return; |
| 5281 | rpc_call_start(task); |
| 5282 | } |
| 5283 | |
| 5284 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5285 | { |
| 5286 | struct nfs4_layoutget *lgp = calldata; |
| 5287 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5288 | |
| 5289 | dprintk("--> %s\n", __func__); |
| 5290 | |
| 5291 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5292 | return; |
| 5293 | |
| 5294 | switch (task->tk_status) { |
| 5295 | case 0: |
| 5296 | break; |
| 5297 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5298 | case -NFS4ERR_RECALLCONFLICT: |
| 5299 | task->tk_status = -NFS4ERR_DELAY; |
| 5300 | /* Fall through */ |
| 5301 | default: |
| 5302 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5303 | rpc_restart_call_prepare(task); |
| 5304 | return; |
| 5305 | } |
| 5306 | } |
| 5307 | lgp->status = task->tk_status; |
| 5308 | dprintk("<-- %s\n", __func__); |
| 5309 | } |
| 5310 | |
| 5311 | static void nfs4_layoutget_release(void *calldata) |
| 5312 | { |
| 5313 | struct nfs4_layoutget *lgp = calldata; |
| 5314 | |
| 5315 | dprintk("--> %s\n", __func__); |
| 5316 | put_layout_hdr(lgp->args.inode); |
| 5317 | if (lgp->res.layout.buf != NULL) |
| 5318 | free_page((unsigned long) lgp->res.layout.buf); |
| 5319 | put_nfs_open_context(lgp->args.ctx); |
| 5320 | kfree(calldata); |
| 5321 | dprintk("<-- %s\n", __func__); |
| 5322 | } |
| 5323 | |
| 5324 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5325 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5326 | .rpc_call_done = nfs4_layoutget_done, |
| 5327 | .rpc_release = nfs4_layoutget_release, |
| 5328 | }; |
| 5329 | |
| 5330 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5331 | { |
| 5332 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5333 | struct rpc_task *task; |
| 5334 | struct rpc_message msg = { |
| 5335 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5336 | .rpc_argp = &lgp->args, |
| 5337 | .rpc_resp = &lgp->res, |
| 5338 | }; |
| 5339 | struct rpc_task_setup task_setup_data = { |
| 5340 | .rpc_client = server->client, |
| 5341 | .rpc_message = &msg, |
| 5342 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5343 | .callback_data = lgp, |
| 5344 | .flags = RPC_TASK_ASYNC, |
| 5345 | }; |
| 5346 | int status = 0; |
| 5347 | |
| 5348 | dprintk("--> %s\n", __func__); |
| 5349 | |
| 5350 | lgp->res.layout.buf = (void *)__get_free_page(GFP_NOFS); |
| 5351 | if (lgp->res.layout.buf == NULL) { |
| 5352 | nfs4_layoutget_release(lgp); |
| 5353 | return -ENOMEM; |
| 5354 | } |
| 5355 | |
| 5356 | lgp->res.seq_res.sr_slot = NULL; |
| 5357 | task = rpc_run_task(&task_setup_data); |
| 5358 | if (IS_ERR(task)) |
| 5359 | return PTR_ERR(task); |
| 5360 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5361 | if (status != 0) |
| 5362 | goto out; |
| 5363 | status = lgp->status; |
| 5364 | if (status != 0) |
| 5365 | goto out; |
| 5366 | status = pnfs_layout_process(lgp); |
| 5367 | out: |
| 5368 | rpc_put_task(task); |
| 5369 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5370 | return status; |
| 5371 | } |
| 5372 | |
| 5373 | static int |
| 5374 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5375 | { |
| 5376 | struct nfs4_getdeviceinfo_args args = { |
| 5377 | .pdev = pdev, |
| 5378 | }; |
| 5379 | struct nfs4_getdeviceinfo_res res = { |
| 5380 | .pdev = pdev, |
| 5381 | }; |
| 5382 | struct rpc_message msg = { |
| 5383 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5384 | .rpc_argp = &args, |
| 5385 | .rpc_resp = &res, |
| 5386 | }; |
| 5387 | int status; |
| 5388 | |
| 5389 | dprintk("--> %s\n", __func__); |
| 5390 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
| 5391 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5392 | |
| 5393 | return status; |
| 5394 | } |
| 5395 | |
| 5396 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5397 | { |
| 5398 | struct nfs4_exception exception = { }; |
| 5399 | int err; |
| 5400 | |
| 5401 | do { |
| 5402 | err = nfs4_handle_exception(server, |
| 5403 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5404 | &exception); |
| 5405 | } while (exception.retry); |
| 5406 | return err; |
| 5407 | } |
| 5408 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5409 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5410 | #endif /* CONFIG_NFS_V4_1 */ |
| 5411 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5412 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5413 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5414 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5415 | .recover_open = nfs4_open_reclaim, |
| 5416 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5417 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5418 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5419 | }; |
| 5420 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5421 | #if defined(CONFIG_NFS_V4_1) |
| 5422 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5423 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5424 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5425 | .recover_open = nfs4_open_reclaim, |
| 5426 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5427 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5428 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5429 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5430 | }; |
| 5431 | #endif /* CONFIG_NFS_V4_1 */ |
| 5432 | |
| 5433 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5434 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5435 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5436 | .recover_open = nfs4_open_expired, |
| 5437 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5438 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5439 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5440 | }; |
| 5441 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5442 | #if defined(CONFIG_NFS_V4_1) |
| 5443 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5444 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5445 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5446 | .recover_open = nfs4_open_expired, |
| 5447 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5448 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5449 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5450 | }; |
| 5451 | #endif /* CONFIG_NFS_V4_1 */ |
| 5452 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5453 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5454 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5455 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5456 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5457 | }; |
| 5458 | |
| 5459 | #if defined(CONFIG_NFS_V4_1) |
| 5460 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5461 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5462 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5463 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5464 | }; |
| 5465 | #endif |
| 5466 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5467 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 5468 | .minor_version = 0, |
| 5469 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5470 | .validate_stateid = nfs4_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5471 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 5472 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 5473 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5474 | }; |
| 5475 | |
| 5476 | #if defined(CONFIG_NFS_V4_1) |
| 5477 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 5478 | .minor_version = 1, |
| 5479 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5480 | .validate_stateid = nfs41_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5481 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 5482 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 5483 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5484 | }; |
| 5485 | #endif |
| 5486 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5487 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 5488 | [0] = &nfs_v4_0_minor_ops, |
| 5489 | #if defined(CONFIG_NFS_V4_1) |
| 5490 | [1] = &nfs_v4_1_minor_ops, |
| 5491 | #endif |
| 5492 | }; |
| 5493 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5494 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5495 | .permission = nfs_permission, |
| 5496 | .getattr = nfs_getattr, |
| 5497 | .setattr = nfs_setattr, |
| 5498 | .getxattr = nfs4_getxattr, |
| 5499 | .setxattr = nfs4_setxattr, |
| 5500 | .listxattr = nfs4_listxattr, |
| 5501 | }; |
| 5502 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5503 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5504 | .version = 4, /* protocol version */ |
| 5505 | .dentry_ops = &nfs4_dentry_operations, |
| 5506 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5507 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5508 | .getroot = nfs4_proc_get_root, |
| 5509 | .getattr = nfs4_proc_getattr, |
| 5510 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5511 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5512 | .lookup = nfs4_proc_lookup, |
| 5513 | .access = nfs4_proc_access, |
| 5514 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | .create = nfs4_proc_create, |
| 5516 | .remove = nfs4_proc_remove, |
| 5517 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5518 | .unlink_done = nfs4_proc_unlink_done, |
| 5519 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 5520 | .rename_setup = nfs4_proc_rename_setup, |
| 5521 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | .link = nfs4_proc_link, |
| 5523 | .symlink = nfs4_proc_symlink, |
| 5524 | .mkdir = nfs4_proc_mkdir, |
| 5525 | .rmdir = nfs4_proc_remove, |
| 5526 | .readdir = nfs4_proc_readdir, |
| 5527 | .mknod = nfs4_proc_mknod, |
| 5528 | .statfs = nfs4_proc_statfs, |
| 5529 | .fsinfo = nfs4_proc_fsinfo, |
| 5530 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5531 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5532 | .decode_dirent = nfs4_decode_dirent, |
| 5533 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5534 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5535 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5536 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5537 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5538 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5539 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5540 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5541 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 5542 | .open_context = nfs4_atomic_open, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | }; |
| 5544 | |
| 5545 | /* |
| 5546 | * Local variables: |
| 5547 | * c-basic-offset: 8 |
| 5548 | * End: |
| 5549 | */ |