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> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 52 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 53 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 55 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 57 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 58 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 59 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 60 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 63 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 64 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 66 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 67 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 68 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 69 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 70 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 71 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | 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] | 73 | 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] | 74 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
| 75 | 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] | 76 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 77 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 78 | struct nfs4_state *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 81 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 83 | if (err >= -1000) |
| 84 | return err; |
| 85 | switch (err) { |
| 86 | case -NFS4ERR_RESOURCE: |
| 87 | return -EREMOTEIO; |
| 88 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 90 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 91 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 93 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* |
| 97 | * This is our standard bitmap for GETATTR requests. |
| 98 | */ |
| 99 | const u32 nfs4_fattr_bitmap[2] = { |
| 100 | FATTR4_WORD0_TYPE |
| 101 | | FATTR4_WORD0_CHANGE |
| 102 | | FATTR4_WORD0_SIZE |
| 103 | | FATTR4_WORD0_FSID |
| 104 | | FATTR4_WORD0_FILEID, |
| 105 | FATTR4_WORD1_MODE |
| 106 | | FATTR4_WORD1_NUMLINKS |
| 107 | | FATTR4_WORD1_OWNER |
| 108 | | FATTR4_WORD1_OWNER_GROUP |
| 109 | | FATTR4_WORD1_RAWDEV |
| 110 | | FATTR4_WORD1_SPACE_USED |
| 111 | | FATTR4_WORD1_TIME_ACCESS |
| 112 | | FATTR4_WORD1_TIME_METADATA |
| 113 | | FATTR4_WORD1_TIME_MODIFY |
| 114 | }; |
| 115 | |
| 116 | const u32 nfs4_statfs_bitmap[2] = { |
| 117 | FATTR4_WORD0_FILES_AVAIL |
| 118 | | FATTR4_WORD0_FILES_FREE |
| 119 | | FATTR4_WORD0_FILES_TOTAL, |
| 120 | FATTR4_WORD1_SPACE_AVAIL |
| 121 | | FATTR4_WORD1_SPACE_FREE |
| 122 | | FATTR4_WORD1_SPACE_TOTAL |
| 123 | }; |
| 124 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 125 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | FATTR4_WORD0_MAXLINK |
| 127 | | FATTR4_WORD0_MAXNAME, |
| 128 | 0 |
| 129 | }; |
| 130 | |
| 131 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 132 | | FATTR4_WORD0_MAXREAD |
| 133 | | FATTR4_WORD0_MAXWRITE |
| 134 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 135 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 136 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 139 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 140 | FATTR4_WORD0_TYPE |
| 141 | | FATTR4_WORD0_CHANGE |
| 142 | | FATTR4_WORD0_SIZE |
| 143 | | FATTR4_WORD0_FSID |
| 144 | | FATTR4_WORD0_FILEID |
| 145 | | FATTR4_WORD0_FS_LOCATIONS, |
| 146 | FATTR4_WORD1_MODE |
| 147 | | FATTR4_WORD1_NUMLINKS |
| 148 | | FATTR4_WORD1_OWNER |
| 149 | | FATTR4_WORD1_OWNER_GROUP |
| 150 | | FATTR4_WORD1_RAWDEV |
| 151 | | FATTR4_WORD1_SPACE_USED |
| 152 | | FATTR4_WORD1_TIME_ACCESS |
| 153 | | FATTR4_WORD1_TIME_METADATA |
| 154 | | FATTR4_WORD1_TIME_MODIFY |
| 155 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 156 | }; |
| 157 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 158 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | struct nfs4_readdir_arg *readdir) |
| 160 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 161 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | BUG_ON(readdir->count < 80); |
| 164 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 165 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | readdir->cookie = 0; |
| 171 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 172 | if (cookie == 2) |
| 173 | return; |
| 174 | |
| 175 | /* |
| 176 | * NFSv4 servers do not return entries for '.' and '..' |
| 177 | * Therefore, we fake these entries here. We let '.' |
| 178 | * have cookie 0 and '..' have cookie 1. Note that |
| 179 | * when talking to the server, we always send cookie 0 |
| 180 | * instead of 1 or 2. |
| 181 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 182 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | if (cookie == 0) { |
| 185 | *p++ = xdr_one; /* next */ |
| 186 | *p++ = xdr_zero; /* cookie, first word */ |
| 187 | *p++ = xdr_one; /* cookie, second word */ |
| 188 | *p++ = xdr_one; /* entry len */ |
| 189 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 190 | p++; |
| 191 | *p++ = xdr_one; /* bitmap length */ |
| 192 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 193 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 194 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | *p++ = xdr_one; /* next */ |
| 198 | *p++ = xdr_zero; /* cookie, first word */ |
| 199 | *p++ = xdr_two; /* cookie, second word */ |
| 200 | *p++ = xdr_two; /* entry len */ |
| 201 | memcpy(p, "..\0\0", 4); /* entry */ |
| 202 | p++; |
| 203 | *p++ = xdr_one; /* bitmap length */ |
| 204 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 205 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 206 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | readdir->pgbase = (char *)p - (char *)start; |
| 209 | readdir->count -= readdir->pgbase; |
| 210 | kunmap_atomic(start, KM_USER0); |
| 211 | } |
| 212 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 213 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 214 | { |
| 215 | int res; |
| 216 | |
| 217 | might_sleep(); |
| 218 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 219 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 220 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 221 | return res; |
| 222 | } |
| 223 | |
| 224 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 225 | { |
| 226 | int res = 0; |
| 227 | |
| 228 | might_sleep(); |
| 229 | |
| 230 | if (*timeout <= 0) |
| 231 | *timeout = NFS4_POLL_RETRY_MIN; |
| 232 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 233 | *timeout = NFS4_POLL_RETRY_MAX; |
| 234 | schedule_timeout_killable(*timeout); |
| 235 | if (fatal_signal_pending(current)) |
| 236 | res = -ERESTARTSYS; |
| 237 | *timeout <<= 1; |
| 238 | return res; |
| 239 | } |
| 240 | |
| 241 | /* This is the error handling routine for processes that are allowed |
| 242 | * to sleep. |
| 243 | */ |
| 244 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 245 | { |
| 246 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 247 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 248 | int ret = errorcode; |
| 249 | |
| 250 | exception->retry = 0; |
| 251 | switch(errorcode) { |
| 252 | case 0: |
| 253 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 254 | case -NFS4ERR_ADMIN_REVOKED: |
| 255 | case -NFS4ERR_BAD_STATEID: |
| 256 | case -NFS4ERR_OPENMODE: |
| 257 | if (state == NULL) |
| 258 | break; |
| 259 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 260 | goto do_state_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 261 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 262 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 263 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 264 | goto do_state_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 265 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 266 | case -NFS4ERR_BADSESSION: |
| 267 | case -NFS4ERR_BADSLOT: |
| 268 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 269 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 270 | case -NFS4ERR_DEADSESSION: |
| 271 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 272 | case -NFS4ERR_SEQ_MISORDERED: |
| 273 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 274 | errorcode); |
Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 275 | nfs4_schedule_state_recovery(clp); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 276 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 277 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 278 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 279 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 280 | if (exception->timeout > HZ) { |
| 281 | /* We have retried a decent amount, time to |
| 282 | * fail |
| 283 | */ |
| 284 | ret = -EBUSY; |
| 285 | break; |
| 286 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 287 | case -NFS4ERR_GRACE: |
| 288 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 289 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 290 | ret = nfs4_delay(server->client, &exception->timeout); |
| 291 | if (ret != 0) |
| 292 | break; |
| 293 | case -NFS4ERR_OLD_STATEID: |
| 294 | exception->retry = 1; |
| 295 | } |
| 296 | /* We failed to handle the error */ |
| 297 | return nfs4_map_errors(ret); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 298 | do_state_recovery: |
| 299 | nfs4_schedule_state_recovery(clp); |
| 300 | ret = nfs4_wait_clnt_recover(clp); |
| 301 | if (ret == 0) |
| 302 | exception->retry = 1; |
| 303 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 307 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | spin_lock(&clp->cl_lock); |
| 310 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 311 | clp->cl_last_renewal = timestamp; |
| 312 | spin_unlock(&clp->cl_lock); |
| 313 | } |
| 314 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 315 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 316 | { |
| 317 | do_renew_lease(server->nfs_client, timestamp); |
| 318 | } |
| 319 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 320 | #if defined(CONFIG_NFS_V4_1) |
| 321 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 322 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 323 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 324 | * |
| 325 | * freeing a slot is trivially done by clearing its respective bit |
| 326 | * in the bitmap. |
| 327 | * If the freed slotid equals highest_used_slotid we want to update it |
| 328 | * so that the server would be able to size down the slot table if needed, |
| 329 | * otherwise we know that the highest_used_slotid is still in use. |
| 330 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 331 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 332 | * highest slotid in use. |
| 333 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 334 | * |
| 335 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 336 | */ |
| 337 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 338 | 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] | 339 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 340 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 341 | int slotid = free_slotid; |
| 342 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 343 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 344 | /* clear used bit in bitmap */ |
| 345 | __clear_bit(slotid, tbl->used_slots); |
| 346 | |
| 347 | /* update highest_used_slotid when it is freed */ |
| 348 | if (slotid == tbl->highest_used_slotid) { |
| 349 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 350 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 351 | tbl->highest_used_slotid = slotid; |
| 352 | else |
| 353 | tbl->highest_used_slotid = -1; |
| 354 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 355 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 356 | free_slotid, tbl->highest_used_slotid); |
| 357 | } |
| 358 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 359 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 360 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 361 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 362 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 363 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 364 | struct rpc_task *task; |
| 365 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 366 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 367 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 368 | if (task) |
| 369 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 370 | return; |
| 371 | } |
| 372 | |
| 373 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 374 | return; |
| 375 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 376 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 377 | complete(&ses->fc_slot_table.complete); |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * Signal state manager thread if session back channel is drained |
| 382 | */ |
| 383 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 384 | { |
| 385 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 386 | ses->bc_slot_table.highest_used_slotid != -1) |
| 387 | return; |
| 388 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 389 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 392 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 393 | { |
| 394 | struct nfs4_slot_table *tbl; |
| 395 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 396 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 397 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 398 | /* just wake up the next guy waiting since |
| 399 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 400 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 401 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 402 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 403 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 404 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 405 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 406 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 407 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 408 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 411 | 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] | 412 | { |
| 413 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 414 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 415 | |
| 416 | /* |
| 417 | * sr_status remains 1 if an RPC level error occurred. The server |
| 418 | * may or may not have processed the sequence operation.. |
| 419 | * Proceed as if the server received and processed the sequence |
| 420 | * operation. |
| 421 | */ |
| 422 | if (res->sr_status == 1) |
| 423 | res->sr_status = NFS_OK; |
| 424 | |
| 425 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 426 | if (!res->sr_slot) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 427 | goto out; |
| 428 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 429 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 430 | switch (res->sr_status) { |
| 431 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 432 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 433 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 434 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 435 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 436 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 437 | /* Check sequence flags */ |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 438 | if (atomic_read(&clp->cl_count) > 1) |
| 439 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 440 | break; |
| 441 | case -NFS4ERR_DELAY: |
| 442 | /* The server detected a resend of the RPC call and |
| 443 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 444 | * of RFC5661. |
| 445 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 446 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 447 | __func__, |
| 448 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 449 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 450 | goto out_retry; |
| 451 | default: |
| 452 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 453 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 454 | } |
| 455 | out: |
| 456 | /* The session may be reset by one of the error handlers. */ |
| 457 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 458 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 459 | return 1; |
| 460 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 461 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 462 | goto out; |
| 463 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 464 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 465 | } |
| 466 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 467 | static int nfs4_sequence_done(struct rpc_task *task, |
| 468 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 469 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 470 | if (res->sr_session == NULL) |
| 471 | return 1; |
| 472 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 473 | } |
| 474 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 475 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 476 | * nfs4_find_slot - efficiently look for a free slot |
| 477 | * |
| 478 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 479 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 480 | * and respectively set up the sequence operation args. |
| 481 | * 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] | 482 | * |
| 483 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 484 | */ |
| 485 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 486 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 487 | { |
| 488 | int slotid; |
| 489 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 490 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 491 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 492 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 493 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 494 | tbl->max_slots); |
| 495 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 496 | if (slotid >= tbl->max_slots) |
| 497 | goto out; |
| 498 | __set_bit(slotid, tbl->used_slots); |
| 499 | if (slotid > tbl->highest_used_slotid) |
| 500 | tbl->highest_used_slotid = slotid; |
| 501 | ret_id = slotid; |
| 502 | out: |
| 503 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 504 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 505 | return ret_id; |
| 506 | } |
| 507 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 508 | static int nfs41_setup_sequence(struct nfs4_session *session, |
| 509 | struct nfs4_sequence_args *args, |
| 510 | struct nfs4_sequence_res *res, |
| 511 | int cache_reply, |
| 512 | struct rpc_task *task) |
| 513 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 514 | struct nfs4_slot *slot; |
| 515 | struct nfs4_slot_table *tbl; |
| 516 | u8 slotid; |
| 517 | |
| 518 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 519 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 520 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 521 | return 0; |
| 522 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 523 | tbl = &session->fc_slot_table; |
| 524 | |
| 525 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 526 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 527 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 528 | /* |
| 529 | * The state manager will wait until the slot table is empty. |
| 530 | * Schedule the reset thread |
| 531 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 532 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 533 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 534 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 535 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 536 | } |
| 537 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 538 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 539 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 540 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 541 | spin_unlock(&tbl->slot_tbl_lock); |
| 542 | dprintk("%s enforce FIFO order\n", __func__); |
| 543 | return -EAGAIN; |
| 544 | } |
| 545 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 546 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 547 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 548 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 549 | spin_unlock(&tbl->slot_tbl_lock); |
| 550 | dprintk("<-- %s: no free slots\n", __func__); |
| 551 | return -EAGAIN; |
| 552 | } |
| 553 | spin_unlock(&tbl->slot_tbl_lock); |
| 554 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 555 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 556 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 557 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 558 | args->sa_slotid = slotid; |
| 559 | args->sa_cache_this = cache_reply; |
| 560 | |
| 561 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 562 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 563 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 564 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 565 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 566 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 567 | /* |
| 568 | * sr_status is only set in decode_sequence, and so will remain |
| 569 | * set to 1 if an rpc level failure occurs. |
| 570 | */ |
| 571 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 572 | return 0; |
| 573 | } |
| 574 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 575 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 576 | struct nfs4_sequence_args *args, |
| 577 | struct nfs4_sequence_res *res, |
| 578 | int cache_reply, |
| 579 | struct rpc_task *task) |
| 580 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 581 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 582 | int ret = 0; |
| 583 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 584 | if (session == NULL) { |
| 585 | args->sa_session = NULL; |
| 586 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 587 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 588 | } |
| 589 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 590 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 591 | __func__, session->clp, session, res->sr_slot ? |
| 592 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 593 | |
| 594 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 595 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 596 | out: |
| 597 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 598 | return ret; |
| 599 | } |
| 600 | |
| 601 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 602 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 603 | struct nfs4_sequence_args *seq_args; |
| 604 | struct nfs4_sequence_res *seq_res; |
| 605 | int cache_reply; |
| 606 | }; |
| 607 | |
| 608 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 609 | { |
| 610 | struct nfs41_call_sync_data *data = calldata; |
| 611 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 612 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 613 | |
| 614 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 615 | data->seq_res, data->cache_reply, task)) |
| 616 | return; |
| 617 | rpc_call_start(task); |
| 618 | } |
| 619 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 620 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 621 | { |
| 622 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 623 | nfs41_call_sync_prepare(task, calldata); |
| 624 | } |
| 625 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 626 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 627 | { |
| 628 | struct nfs41_call_sync_data *data = calldata; |
| 629 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 630 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 631 | } |
| 632 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 633 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 634 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 635 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 636 | }; |
| 637 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 638 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 639 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 640 | .rpc_call_done = nfs41_call_sync_done, |
| 641 | }; |
| 642 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 643 | static int nfs4_call_sync_sequence(struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 644 | struct rpc_message *msg, |
| 645 | struct nfs4_sequence_args *args, |
| 646 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 647 | int cache_reply, |
| 648 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 649 | { |
| 650 | int ret; |
| 651 | struct rpc_task *task; |
| 652 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 653 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 654 | .seq_args = args, |
| 655 | .seq_res = res, |
| 656 | .cache_reply = cache_reply, |
| 657 | }; |
| 658 | struct rpc_task_setup task_setup = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 659 | .rpc_client = server->client, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 660 | .rpc_message = msg, |
| 661 | .callback_ops = &nfs41_call_sync_ops, |
| 662 | .callback_data = &data |
| 663 | }; |
| 664 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 665 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 666 | if (privileged) |
| 667 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 668 | task = rpc_run_task(&task_setup); |
| 669 | if (IS_ERR(task)) |
| 670 | ret = PTR_ERR(task); |
| 671 | else { |
| 672 | ret = task->tk_status; |
| 673 | rpc_put_task(task); |
| 674 | } |
| 675 | return ret; |
| 676 | } |
| 677 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 678 | int _nfs4_call_sync_session(struct nfs_server *server, |
| 679 | struct rpc_message *msg, |
| 680 | struct nfs4_sequence_args *args, |
| 681 | struct nfs4_sequence_res *res, |
| 682 | int cache_reply) |
| 683 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 684 | return nfs4_call_sync_sequence(server, msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 685 | } |
| 686 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 687 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 688 | static int nfs4_sequence_done(struct rpc_task *task, |
| 689 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 690 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 691 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 692 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 693 | #endif /* CONFIG_NFS_V4_1 */ |
| 694 | |
| 695 | int _nfs4_call_sync(struct nfs_server *server, |
| 696 | struct rpc_message *msg, |
| 697 | struct nfs4_sequence_args *args, |
| 698 | struct nfs4_sequence_res *res, |
| 699 | int cache_reply) |
| 700 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 701 | args->sa_session = res->sr_session = NULL; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 702 | return rpc_call_sync(server->client, msg, 0); |
| 703 | } |
| 704 | |
| 705 | #define nfs4_call_sync(server, msg, args, res, cache_reply) \ |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 706 | (server)->nfs_client->cl_mvops->call_sync((server), (msg), &(args)->seq_args, \ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 707 | &(res)->seq_res, (cache_reply)) |
| 708 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 709 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 711 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 713 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 714 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 715 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 716 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 717 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 718 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 721 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 722 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 723 | struct nfs_openargs o_arg; |
| 724 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 725 | struct nfs_open_confirmargs c_arg; |
| 726 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 727 | struct nfs_fattr f_attr; |
| 728 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 729 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 730 | struct dentry *dir; |
| 731 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 732 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 733 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 734 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 735 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 736 | int rpc_status; |
| 737 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 738 | }; |
| 739 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 740 | |
| 741 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 742 | { |
| 743 | p->o_res.f_attr = &p->f_attr; |
| 744 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 745 | p->o_res.seqid = p->o_arg.seqid; |
| 746 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 747 | p->o_res.server = p->o_arg.server; |
| 748 | nfs_fattr_init(&p->f_attr); |
| 749 | nfs_fattr_init(&p->dir_attr); |
| 750 | } |
| 751 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 752 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 753 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 754 | const struct iattr *attrs, |
| 755 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 756 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 757 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 758 | struct inode *dir = parent->d_inode; |
| 759 | struct nfs_server *server = NFS_SERVER(dir); |
| 760 | struct nfs4_opendata *p; |
| 761 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 762 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 763 | if (p == NULL) |
| 764 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 765 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 766 | if (p->o_arg.seqid == NULL) |
| 767 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 768 | path_get(path); |
| 769 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 770 | p->dir = parent; |
| 771 | p->owner = sp; |
| 772 | atomic_inc(&sp->so_count); |
| 773 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 774 | p->o_arg.open_flags = flags; |
| 775 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 776 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 777 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 778 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 779 | p->o_arg.server = server; |
| 780 | p->o_arg.bitmask = server->attr_bitmask; |
| 781 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 782 | if (flags & O_CREAT) { |
| 783 | u32 *s; |
| 784 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 785 | p->o_arg.u.attrs = &p->attrs; |
| 786 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 787 | s = (u32 *) p->o_arg.u.verifier.data; |
| 788 | s[0] = jiffies; |
| 789 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 790 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 791 | p->c_arg.fh = &p->o_res.fh; |
| 792 | p->c_arg.stateid = &p->o_res.stateid; |
| 793 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 794 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 795 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 796 | return p; |
| 797 | err_free: |
| 798 | kfree(p); |
| 799 | err: |
| 800 | dput(parent); |
| 801 | return NULL; |
| 802 | } |
| 803 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 804 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 805 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 806 | struct nfs4_opendata *p = container_of(kref, |
| 807 | struct nfs4_opendata, kref); |
| 808 | |
| 809 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 810 | if (p->state != NULL) |
| 811 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 812 | nfs4_put_state_owner(p->owner); |
| 813 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 814 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 815 | kfree(p); |
| 816 | } |
| 817 | |
| 818 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 819 | { |
| 820 | if (p != NULL) |
| 821 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | } |
| 823 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 824 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 825 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 826 | int ret; |
| 827 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 828 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 829 | return ret; |
| 830 | } |
| 831 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 832 | 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] | 833 | { |
| 834 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 835 | |
| 836 | if (open_mode & O_EXCL) |
| 837 | goto out; |
| 838 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 839 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 840 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 841 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 842 | break; |
| 843 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 844 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 845 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 846 | break; |
| 847 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 848 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 849 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 850 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 851 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 852 | return ret; |
| 853 | } |
| 854 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 855 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 856 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 857 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 858 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 859 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 860 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 861 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 862 | return 1; |
| 863 | } |
| 864 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 865 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 866 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 867 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 868 | case FMODE_WRITE: |
| 869 | state->n_wronly++; |
| 870 | break; |
| 871 | case FMODE_READ: |
| 872 | state->n_rdonly++; |
| 873 | break; |
| 874 | case FMODE_READ|FMODE_WRITE: |
| 875 | state->n_rdwr++; |
| 876 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 877 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 878 | } |
| 879 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 880 | 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] | 881 | { |
| 882 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 883 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 884 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 885 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 886 | case FMODE_READ: |
| 887 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 888 | break; |
| 889 | case FMODE_WRITE: |
| 890 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 891 | break; |
| 892 | case FMODE_READ|FMODE_WRITE: |
| 893 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 894 | } |
| 895 | } |
| 896 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 897 | 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] | 898 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 899 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 900 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 901 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 902 | } |
| 903 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 904 | 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] | 905 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 906 | /* |
| 907 | * Protect the call to nfs4_state_set_mode_locked and |
| 908 | * serialise the stateid update |
| 909 | */ |
| 910 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 911 | if (deleg_stateid != NULL) { |
| 912 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 913 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 914 | } |
| 915 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 916 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 917 | write_sequnlock(&state->seqlock); |
| 918 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 919 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 920 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 923 | 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] | 924 | { |
| 925 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 926 | struct nfs_delegation *deleg_cur; |
| 927 | int ret = 0; |
| 928 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 929 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 930 | |
| 931 | rcu_read_lock(); |
| 932 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 933 | if (deleg_cur == NULL) |
| 934 | goto no_delegation; |
| 935 | |
| 936 | spin_lock(&deleg_cur->lock); |
| 937 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 938 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 939 | goto no_delegation_unlock; |
| 940 | |
| 941 | if (delegation == NULL) |
| 942 | delegation = &deleg_cur->stateid; |
| 943 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 944 | goto no_delegation_unlock; |
| 945 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 946 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 947 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 948 | ret = 1; |
| 949 | no_delegation_unlock: |
| 950 | spin_unlock(&deleg_cur->lock); |
| 951 | no_delegation: |
| 952 | rcu_read_unlock(); |
| 953 | |
| 954 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 955 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 956 | ret = 1; |
| 957 | } |
| 958 | |
| 959 | return ret; |
| 960 | } |
| 961 | |
| 962 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 964 | { |
| 965 | struct nfs_delegation *delegation; |
| 966 | |
| 967 | rcu_read_lock(); |
| 968 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 969 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 970 | rcu_read_unlock(); |
| 971 | return; |
| 972 | } |
| 973 | rcu_read_unlock(); |
| 974 | nfs_inode_return_delegation(inode); |
| 975 | } |
| 976 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 977 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 978 | { |
| 979 | struct nfs4_state *state = opendata->state; |
| 980 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 981 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 982 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 983 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 984 | nfs4_stateid stateid; |
| 985 | int ret = -EAGAIN; |
| 986 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 987 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 988 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 989 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 990 | if (can_open_cached(state, fmode, open_mode)) { |
| 991 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 992 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 993 | goto out_return_state; |
| 994 | } |
| 995 | spin_unlock(&state->owner->so_lock); |
| 996 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 997 | rcu_read_lock(); |
| 998 | delegation = rcu_dereference(nfsi->delegation); |
| 999 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1000 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1001 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1002 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1003 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1004 | /* Save the delegation */ |
| 1005 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1006 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1007 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1008 | if (ret != 0) |
| 1009 | goto out; |
| 1010 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1011 | |
| 1012 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1013 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1014 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1015 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1016 | out: |
| 1017 | return ERR_PTR(ret); |
| 1018 | out_return_state: |
| 1019 | atomic_inc(&state->count); |
| 1020 | return state; |
| 1021 | } |
| 1022 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1023 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1024 | { |
| 1025 | struct inode *inode; |
| 1026 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1027 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1028 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1029 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1030 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1031 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1032 | goto out; |
| 1033 | } |
| 1034 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1035 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1036 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1037 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1038 | 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] | 1039 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1040 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1041 | goto err; |
| 1042 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1043 | state = nfs4_get_open_state(inode, data->owner); |
| 1044 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1045 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1046 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1047 | int delegation_flags = 0; |
| 1048 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1049 | rcu_read_lock(); |
| 1050 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1051 | if (delegation) |
| 1052 | delegation_flags = delegation->flags; |
| 1053 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1054 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1055 | nfs_inode_set_delegation(state->inode, |
| 1056 | data->owner->so_cred, |
| 1057 | &data->o_res); |
| 1058 | else |
| 1059 | nfs_inode_reclaim_delegation(state->inode, |
| 1060 | data->owner->so_cred, |
| 1061 | &data->o_res); |
| 1062 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1063 | |
| 1064 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1065 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1066 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1067 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1068 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1069 | err_put_inode: |
| 1070 | iput(inode); |
| 1071 | err: |
| 1072 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1075 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1076 | { |
| 1077 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1078 | struct nfs_open_context *ctx; |
| 1079 | |
| 1080 | spin_lock(&state->inode->i_lock); |
| 1081 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1082 | if (ctx->state != state) |
| 1083 | continue; |
| 1084 | get_nfs_open_context(ctx); |
| 1085 | spin_unlock(&state->inode->i_lock); |
| 1086 | return ctx; |
| 1087 | } |
| 1088 | spin_unlock(&state->inode->i_lock); |
| 1089 | return ERR_PTR(-ENOENT); |
| 1090 | } |
| 1091 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1092 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1093 | { |
| 1094 | struct nfs4_opendata *opendata; |
| 1095 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1096 | 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] | 1097 | if (opendata == NULL) |
| 1098 | return ERR_PTR(-ENOMEM); |
| 1099 | opendata->state = state; |
| 1100 | atomic_inc(&state->count); |
| 1101 | return opendata; |
| 1102 | } |
| 1103 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1104 | 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] | 1105 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1106 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1107 | int ret; |
| 1108 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1109 | opendata->o_arg.open_flags = 0; |
| 1110 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1111 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1112 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1113 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1114 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1115 | if (ret != 0) |
| 1116 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1117 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1118 | if (IS_ERR(newstate)) |
| 1119 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1120 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1121 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1122 | return 0; |
| 1123 | } |
| 1124 | |
| 1125 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1126 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1127 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1128 | int ret; |
| 1129 | |
| 1130 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1131 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1132 | smp_rmb(); |
| 1133 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1134 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1135 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1136 | if (ret != 0) |
| 1137 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1138 | if (newstate != state) |
| 1139 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1140 | } |
| 1141 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1142 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1143 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1144 | if (ret != 0) |
| 1145 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1146 | if (newstate != state) |
| 1147 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1148 | } |
| 1149 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1150 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1151 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1152 | if (ret != 0) |
| 1153 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1154 | if (newstate != state) |
| 1155 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1156 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1157 | /* |
| 1158 | * We may have performed cached opens for all three recoveries. |
| 1159 | * Check if we need to update the current stateid. |
| 1160 | */ |
| 1161 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1162 | 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] | 1163 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1164 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1165 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1166 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1167 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1168 | return 0; |
| 1169 | } |
| 1170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | /* |
| 1172 | * OPEN_RECLAIM: |
| 1173 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1175 | 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] | 1176 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1177 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1178 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1179 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | int status; |
| 1181 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1182 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1183 | if (IS_ERR(opendata)) |
| 1184 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1185 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1186 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1187 | rcu_read_lock(); |
| 1188 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1189 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1190 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1191 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1192 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1193 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1194 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | return status; |
| 1196 | } |
| 1197 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1198 | 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] | 1199 | { |
| 1200 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1201 | struct nfs4_exception exception = { }; |
| 1202 | int err; |
| 1203 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1204 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1205 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1206 | break; |
| 1207 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | } while (exception.retry); |
| 1209 | return err; |
| 1210 | } |
| 1211 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1212 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1213 | { |
| 1214 | struct nfs_open_context *ctx; |
| 1215 | int ret; |
| 1216 | |
| 1217 | ctx = nfs4_state_find_open_context(state); |
| 1218 | if (IS_ERR(ctx)) |
| 1219 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1220 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1221 | put_nfs_open_context(ctx); |
| 1222 | return ret; |
| 1223 | } |
| 1224 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1225 | 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] | 1226 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1227 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1228 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1230 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1231 | if (IS_ERR(opendata)) |
| 1232 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1233 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1234 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1235 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1236 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1237 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1238 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1241 | 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] | 1242 | { |
| 1243 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1244 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | int err; |
| 1246 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1247 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | switch (err) { |
| 1249 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1250 | case -ENOENT: |
| 1251 | case -ESTALE: |
| 1252 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1253 | case -NFS4ERR_BADSESSION: |
| 1254 | case -NFS4ERR_BADSLOT: |
| 1255 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1256 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1257 | case -NFS4ERR_DEADSESSION: |
| 1258 | nfs4_schedule_state_recovery( |
| 1259 | server->nfs_client); |
| 1260 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | case -NFS4ERR_STALE_CLIENTID: |
| 1262 | case -NFS4ERR_STALE_STATEID: |
| 1263 | case -NFS4ERR_EXPIRED: |
| 1264 | /* Don't recall a delegation if it was lost */ |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1265 | nfs4_schedule_state_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1266 | goto out; |
| 1267 | case -ERESTARTSYS: |
| 1268 | /* |
| 1269 | * The show must go on: exit, but mark the |
| 1270 | * stateid as needing recovery. |
| 1271 | */ |
| 1272 | case -NFS4ERR_ADMIN_REVOKED: |
| 1273 | case -NFS4ERR_BAD_STATEID: |
| 1274 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1275 | case -EKEYEXPIRED: |
| 1276 | /* |
| 1277 | * User RPCSEC_GSS context has expired. |
| 1278 | * We cannot recover this stateid now, so |
| 1279 | * skip it and allow recovery thread to |
| 1280 | * proceed. |
| 1281 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1282 | case -ENOMEM: |
| 1283 | err = 0; |
| 1284 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | } |
| 1286 | err = nfs4_handle_exception(server, err, &exception); |
| 1287 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1288 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | return err; |
| 1290 | } |
| 1291 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1292 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1293 | { |
| 1294 | struct nfs4_opendata *data = calldata; |
| 1295 | |
| 1296 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1297 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1298 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1299 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1300 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1301 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1302 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1303 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | static void nfs4_open_confirm_release(void *calldata) |
| 1307 | { |
| 1308 | struct nfs4_opendata *data = calldata; |
| 1309 | struct nfs4_state *state = NULL; |
| 1310 | |
| 1311 | /* If this request hasn't been cancelled, do nothing */ |
| 1312 | if (data->cancelled == 0) |
| 1313 | goto out_free; |
| 1314 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1315 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1316 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1317 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1318 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1319 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1320 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1321 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1325 | .rpc_call_done = nfs4_open_confirm_done, |
| 1326 | .rpc_release = nfs4_open_confirm_release, |
| 1327 | }; |
| 1328 | |
| 1329 | /* |
| 1330 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1331 | */ |
| 1332 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1333 | { |
| 1334 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1335 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1336 | struct rpc_message msg = { |
| 1337 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1338 | .rpc_argp = &data->c_arg, |
| 1339 | .rpc_resp = &data->c_res, |
| 1340 | .rpc_cred = data->owner->so_cred, |
| 1341 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1342 | struct rpc_task_setup task_setup_data = { |
| 1343 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1344 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1345 | .callback_ops = &nfs4_open_confirm_ops, |
| 1346 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1347 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1348 | .flags = RPC_TASK_ASYNC, |
| 1349 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | int status; |
| 1351 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1352 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1353 | data->rpc_done = 0; |
| 1354 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1355 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1356 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1357 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1358 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1359 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1360 | if (status != 0) { |
| 1361 | data->cancelled = 1; |
| 1362 | smp_wmb(); |
| 1363 | } else |
| 1364 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1365 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | return status; |
| 1367 | } |
| 1368 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1369 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1371 | struct nfs4_opendata *data = calldata; |
| 1372 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1373 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1374 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1375 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1376 | /* |
| 1377 | * Check if we still need to send an OPEN call, or if we can use |
| 1378 | * a delegation instead. |
| 1379 | */ |
| 1380 | if (data->state != NULL) { |
| 1381 | struct nfs_delegation *delegation; |
| 1382 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1383 | 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] | 1384 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1385 | rcu_read_lock(); |
| 1386 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1387 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1388 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1389 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1390 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1391 | } |
| 1392 | rcu_read_unlock(); |
| 1393 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1394 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1395 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1396 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1397 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1398 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1399 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1400 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1401 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1402 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1403 | &data->o_arg.seq_args, |
| 1404 | &data->o_res.seq_res, 1, task)) |
| 1405 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1406 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1407 | return; |
| 1408 | out_no_action: |
| 1409 | task->tk_action = NULL; |
| 1410 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1413 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1414 | { |
| 1415 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1416 | nfs4_open_prepare(task, calldata); |
| 1417 | } |
| 1418 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1419 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1420 | { |
| 1421 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1423 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1424 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1425 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1426 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1427 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1428 | if (task->tk_status == 0) { |
| 1429 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1430 | case S_IFREG: |
| 1431 | break; |
| 1432 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1433 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1434 | break; |
| 1435 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1436 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1437 | break; |
| 1438 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1439 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1440 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1441 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1442 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1443 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1444 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1445 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1446 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1447 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1448 | static void nfs4_open_release(void *calldata) |
| 1449 | { |
| 1450 | struct nfs4_opendata *data = calldata; |
| 1451 | struct nfs4_state *state = NULL; |
| 1452 | |
| 1453 | /* If this request hasn't been cancelled, do nothing */ |
| 1454 | if (data->cancelled == 0) |
| 1455 | goto out_free; |
| 1456 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1457 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1458 | goto out_free; |
| 1459 | /* In case we need an open_confirm, no cleanup! */ |
| 1460 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1461 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1462 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1463 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1464 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1465 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1466 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1470 | .rpc_call_prepare = nfs4_open_prepare, |
| 1471 | .rpc_call_done = nfs4_open_done, |
| 1472 | .rpc_release = nfs4_open_release, |
| 1473 | }; |
| 1474 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1475 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1476 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1477 | .rpc_call_done = nfs4_open_done, |
| 1478 | .rpc_release = nfs4_open_release, |
| 1479 | }; |
| 1480 | |
| 1481 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1482 | { |
| 1483 | struct inode *dir = data->dir->d_inode; |
| 1484 | struct nfs_server *server = NFS_SERVER(dir); |
| 1485 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1486 | struct nfs_openres *o_res = &data->o_res; |
| 1487 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1488 | struct rpc_message msg = { |
| 1489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1490 | .rpc_argp = o_arg, |
| 1491 | .rpc_resp = o_res, |
| 1492 | .rpc_cred = data->owner->so_cred, |
| 1493 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1494 | struct rpc_task_setup task_setup_data = { |
| 1495 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1496 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1497 | .callback_ops = &nfs4_open_ops, |
| 1498 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1499 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1500 | .flags = RPC_TASK_ASYNC, |
| 1501 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1502 | int status; |
| 1503 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1504 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1505 | data->rpc_done = 0; |
| 1506 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1507 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1508 | if (isrecover) |
| 1509 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1510 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1511 | if (IS_ERR(task)) |
| 1512 | return PTR_ERR(task); |
| 1513 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1514 | if (status != 0) { |
| 1515 | data->cancelled = 1; |
| 1516 | smp_wmb(); |
| 1517 | } else |
| 1518 | status = data->rpc_status; |
| 1519 | rpc_put_task(task); |
| 1520 | |
| 1521 | return status; |
| 1522 | } |
| 1523 | |
| 1524 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1525 | { |
| 1526 | struct inode *dir = data->dir->d_inode; |
| 1527 | struct nfs_openres *o_res = &data->o_res; |
| 1528 | int status; |
| 1529 | |
| 1530 | status = nfs4_run_open_task(data, 1); |
| 1531 | if (status != 0 || !data->rpc_done) |
| 1532 | return status; |
| 1533 | |
| 1534 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1535 | |
| 1536 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1537 | status = _nfs4_proc_open_confirm(data); |
| 1538 | if (status != 0) |
| 1539 | return status; |
| 1540 | } |
| 1541 | |
| 1542 | return status; |
| 1543 | } |
| 1544 | |
| 1545 | /* |
| 1546 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1547 | */ |
| 1548 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1549 | { |
| 1550 | struct inode *dir = data->dir->d_inode; |
| 1551 | struct nfs_server *server = NFS_SERVER(dir); |
| 1552 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1553 | struct nfs_openres *o_res = &data->o_res; |
| 1554 | int status; |
| 1555 | |
| 1556 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1557 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1558 | return status; |
| 1559 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1560 | if (o_arg->open_flags & O_CREAT) { |
| 1561 | update_changeattr(dir, &o_res->cinfo); |
| 1562 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1563 | } else |
| 1564 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1565 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1566 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1568 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1570 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | } |
| 1572 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1573 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1574 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Trond Myklebust | 10afec9 | 2007-05-14 17:16:04 -0400 | [diff] [blame] | 1577 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1578 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1579 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1580 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1581 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1582 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1583 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1584 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1585 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1586 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1587 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1588 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1589 | break; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1590 | nfs4_schedule_state_recovery(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1591 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1592 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1593 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1594 | } |
| 1595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | /* |
| 1597 | * OPEN_EXPIRED: |
| 1598 | * reclaim state on the server after a network partition. |
| 1599 | * Assumes caller holds the appropriate lock |
| 1600 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1601 | 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] | 1602 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1603 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1604 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1606 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1607 | if (IS_ERR(opendata)) |
| 1608 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1609 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1610 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1611 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1612 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1613 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1616 | 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] | 1617 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1618 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1619 | struct nfs4_exception exception = { }; |
| 1620 | int err; |
| 1621 | |
| 1622 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1623 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1624 | switch (err) { |
| 1625 | default: |
| 1626 | goto out; |
| 1627 | case -NFS4ERR_GRACE: |
| 1628 | case -NFS4ERR_DELAY: |
| 1629 | nfs4_handle_exception(server, err, &exception); |
| 1630 | err = 0; |
| 1631 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1632 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1633 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1634 | return err; |
| 1635 | } |
| 1636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1638 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1640 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1642 | ctx = nfs4_state_find_open_context(state); |
| 1643 | if (IS_ERR(ctx)) |
| 1644 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1645 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1646 | put_nfs_open_context(ctx); |
| 1647 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1651 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1652 | * fields corresponding to attributes that were used to store the verifier. |
| 1653 | * Make sure we clobber those fields in the later setattr call |
| 1654 | */ |
| 1655 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1656 | { |
| 1657 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1658 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1659 | sattr->ia_valid |= ATTR_ATIME; |
| 1660 | |
| 1661 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1662 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1663 | sattr->ia_valid |= ATTR_MTIME; |
| 1664 | } |
| 1665 | |
| 1666 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1667 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1669 | 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] | 1670 | { |
| 1671 | struct nfs4_state_owner *sp; |
| 1672 | struct nfs4_state *state = NULL; |
| 1673 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1674 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1675 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | |
| 1677 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | status = -ENOMEM; |
| 1679 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1680 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1681 | goto out_err; |
| 1682 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1683 | status = nfs4_recover_expired_lease(server); |
| 1684 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1685 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1686 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1687 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1688 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1689 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1690 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1691 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1693 | if (path->dentry->d_inode != NULL) |
| 1694 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1695 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1696 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1698 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1700 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1701 | status = PTR_ERR(state); |
| 1702 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1703 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1704 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1705 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1706 | |
| 1707 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1708 | nfs4_exclusive_attrset(opendata, sattr); |
| 1709 | |
| 1710 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1711 | status = nfs4_do_setattr(state->inode, cred, |
| 1712 | opendata->o_res.f_attr, sattr, |
| 1713 | state); |
| 1714 | if (status == 0) |
| 1715 | nfs_setattr_update_inode(state->inode, sattr); |
| 1716 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1717 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1718 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | *res = state; |
| 1721 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1722 | err_opendata_put: |
| 1723 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1724 | err_put_state_owner: |
| 1725 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | *res = NULL; |
| 1728 | return status; |
| 1729 | } |
| 1730 | |
| 1731 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1732 | 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] | 1733 | { |
| 1734 | struct nfs4_exception exception = { }; |
| 1735 | struct nfs4_state *res; |
| 1736 | int status; |
| 1737 | |
| 1738 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1739 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | if (status == 0) |
| 1741 | break; |
| 1742 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1743 | * book-keeping w.r.t. state-changing operations |
| 1744 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1745 | * It is actually a sign of a bug on the client or on the server. |
| 1746 | * |
| 1747 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1748 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | * have unhashed the old state_owner for us, and that we can |
| 1750 | * therefore safely retry using a new one. We should still warn |
| 1751 | * the user though... |
| 1752 | */ |
| 1753 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1754 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1755 | " returned a bad sequence-id error!\n", |
| 1756 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | exception.retry = 1; |
| 1758 | continue; |
| 1759 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1760 | /* |
| 1761 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1762 | * state before it received the OPEN_CONFIRM. |
| 1763 | * Recover by retrying the request as per the discussion |
| 1764 | * on Page 181 of RFC3530. |
| 1765 | */ |
| 1766 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1767 | exception.retry = 1; |
| 1768 | continue; |
| 1769 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1770 | if (status == -EAGAIN) { |
| 1771 | /* We must have found a delegation */ |
| 1772 | exception.retry = 1; |
| 1773 | continue; |
| 1774 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1776 | status, &exception)); |
| 1777 | } while (exception.retry); |
| 1778 | return res; |
| 1779 | } |
| 1780 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1781 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1782 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1783 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1785 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1787 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | .iap = sattr, |
| 1789 | .server = server, |
| 1790 | .bitmask = server->attr_bitmask, |
| 1791 | }; |
| 1792 | struct nfs_setattrres res = { |
| 1793 | .fattr = fattr, |
| 1794 | .server = server, |
| 1795 | }; |
| 1796 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1797 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1798 | .rpc_argp = &arg, |
| 1799 | .rpc_resp = &res, |
| 1800 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1802 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1803 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1805 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1807 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1808 | /* Use that stateid */ |
| 1809 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1810 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1811 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1813 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1814 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1815 | if (status == 0 && state != NULL) |
| 1816 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1817 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1820 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1821 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1822 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1824 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | struct nfs4_exception exception = { }; |
| 1826 | int err; |
| 1827 | do { |
| 1828 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1829 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | &exception); |
| 1831 | } while (exception.retry); |
| 1832 | return err; |
| 1833 | } |
| 1834 | |
| 1835 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1836 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | struct inode *inode; |
| 1838 | struct nfs4_state *state; |
| 1839 | struct nfs_closeargs arg; |
| 1840 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1841 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1842 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1843 | bool roc; |
| 1844 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | }; |
| 1846 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1847 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1848 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1849 | struct nfs4_closedata *calldata = data; |
| 1850 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1851 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1852 | if (calldata->roc) |
| 1853 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1854 | nfs4_put_open_state(calldata->state); |
| 1855 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1856 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1857 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1858 | kfree(calldata); |
| 1859 | } |
| 1860 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1861 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1862 | fmode_t fmode) |
| 1863 | { |
| 1864 | spin_lock(&state->owner->so_lock); |
| 1865 | if (!(fmode & FMODE_READ)) |
| 1866 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1867 | if (!(fmode & FMODE_WRITE)) |
| 1868 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1869 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1870 | spin_unlock(&state->owner->so_lock); |
| 1871 | } |
| 1872 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1873 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1875 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1878 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1879 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1880 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | /* hmm. we are done with the inode, and in the process of freeing |
| 1882 | * the state_owner. we keep this around to process errors |
| 1883 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | switch (task->tk_status) { |
| 1885 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1886 | if (calldata->roc) |
| 1887 | pnfs_roc_set_barrier(state->inode, |
| 1888 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1889 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1890 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1891 | nfs4_close_clear_stateid_flags(state, |
| 1892 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | break; |
| 1894 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1895 | case -NFS4ERR_OLD_STATEID: |
| 1896 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1898 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1899 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1901 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1902 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1904 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1905 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1908 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1910 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1911 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1912 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1913 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1914 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1915 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1916 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1917 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1918 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1919 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1920 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1921 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1922 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1923 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1924 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1925 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1926 | } |
| 1927 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1928 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1929 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1930 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1931 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1932 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1933 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1934 | |
| 1935 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1936 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1937 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1938 | return; |
| 1939 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1940 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1941 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1942 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1943 | if (calldata->roc && |
| 1944 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 1945 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 1946 | task, NULL); |
| 1947 | return; |
| 1948 | } |
| 1949 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1950 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1951 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1952 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1953 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1954 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1955 | 1, task)) |
| 1956 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1957 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1960 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1961 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1962 | .rpc_call_done = nfs4_close_done, |
| 1963 | .rpc_release = nfs4_free_closedata, |
| 1964 | }; |
| 1965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | /* |
| 1967 | * It is possible for data to be read/written from a mem-mapped file |
| 1968 | * after the sys_close call (which hits the vfs layer as a flush). |
| 1969 | * This means that we can't safely call nfsv4 close on a file until |
| 1970 | * the inode is cleared. This in turn means that we are not good |
| 1971 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 1972 | * share state even when we are done with one of the three share |
| 1973 | * stateid's in the inode. |
| 1974 | * |
| 1975 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 1976 | */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1977 | int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1979 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1981 | struct nfs4_state_owner *sp = state->owner; |
| 1982 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1983 | struct rpc_message msg = { |
| 1984 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 1985 | .rpc_cred = state->owner->so_cred, |
| 1986 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1987 | struct rpc_task_setup task_setup_data = { |
| 1988 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1989 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1990 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1991 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1992 | .flags = RPC_TASK_ASYNC, |
| 1993 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1994 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1996 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1998 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1999 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2001 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2002 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2004 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2005 | if (calldata->arg.seqid == NULL) |
| 2006 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2007 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2008 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2009 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2010 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2011 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2012 | calldata->roc = roc; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2013 | path_get(path); |
| 2014 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2015 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2016 | msg.rpc_argp = &calldata->arg; |
| 2017 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2018 | task_setup_data.callback_data = calldata; |
| 2019 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2020 | if (IS_ERR(task)) |
| 2021 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2022 | status = 0; |
| 2023 | if (wait) |
| 2024 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2025 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2026 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2027 | out_free_calldata: |
| 2028 | kfree(calldata); |
| 2029 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2030 | if (roc) |
| 2031 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2032 | nfs4_put_open_state(state); |
| 2033 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2034 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } |
| 2036 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2037 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2038 | 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] | 2039 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | struct nfs4_state *state; |
| 2041 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2042 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2043 | 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] | 2044 | if (IS_ERR(state)) |
| 2045 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2046 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2047 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2050 | 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] | 2051 | { |
| 2052 | if (ctx->state == NULL) |
| 2053 | return; |
| 2054 | if (is_sync) |
| 2055 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2056 | else |
| 2057 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2058 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | |
| 2060 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2061 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2062 | struct nfs4_server_caps_arg args = { |
| 2063 | .fhandle = fhandle, |
| 2064 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | struct nfs4_server_caps_res res = {}; |
| 2066 | struct rpc_message msg = { |
| 2067 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2068 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | .rpc_resp = &res, |
| 2070 | }; |
| 2071 | int status; |
| 2072 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2073 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | if (status == 0) { |
| 2075 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2076 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2077 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2078 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2079 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2080 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2082 | server->caps |= NFS_CAP_ACLS; |
| 2083 | if (res.has_links != 0) |
| 2084 | server->caps |= NFS_CAP_HARDLINKS; |
| 2085 | if (res.has_symlinks != 0) |
| 2086 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2087 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2088 | server->caps |= NFS_CAP_FILEID; |
| 2089 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2090 | server->caps |= NFS_CAP_MODE; |
| 2091 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2092 | server->caps |= NFS_CAP_NLINK; |
| 2093 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2094 | server->caps |= NFS_CAP_OWNER; |
| 2095 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2096 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2097 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2098 | server->caps |= NFS_CAP_ATIME; |
| 2099 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2100 | server->caps |= NFS_CAP_CTIME; |
| 2101 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2102 | server->caps |= NFS_CAP_MTIME; |
| 2103 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2104 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2105 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2106 | 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] | 2107 | server->acl_bitmask = res.acl_bitmask; |
| 2108 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | return status; |
| 2111 | } |
| 2112 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2113 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | { |
| 2115 | struct nfs4_exception exception = { }; |
| 2116 | int err; |
| 2117 | do { |
| 2118 | err = nfs4_handle_exception(server, |
| 2119 | _nfs4_server_capabilities(server, fhandle), |
| 2120 | &exception); |
| 2121 | } while (exception.retry); |
| 2122 | return err; |
| 2123 | } |
| 2124 | |
| 2125 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2126 | struct nfs_fsinfo *info) |
| 2127 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | struct nfs4_lookup_root_arg args = { |
| 2129 | .bitmask = nfs4_fattr_bitmap, |
| 2130 | }; |
| 2131 | struct nfs4_lookup_res res = { |
| 2132 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2133 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | .fh = fhandle, |
| 2135 | }; |
| 2136 | struct rpc_message msg = { |
| 2137 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2138 | .rpc_argp = &args, |
| 2139 | .rpc_resp = &res, |
| 2140 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2141 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2142 | nfs_fattr_init(info->fattr); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 2143 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2147 | struct nfs_fsinfo *info) |
| 2148 | { |
| 2149 | struct nfs4_exception exception = { }; |
| 2150 | int err; |
| 2151 | do { |
| 2152 | err = nfs4_handle_exception(server, |
| 2153 | _nfs4_lookup_root(server, fhandle, info), |
| 2154 | &exception); |
| 2155 | } while (exception.retry); |
| 2156 | return err; |
| 2157 | } |
| 2158 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2159 | /* |
| 2160 | * get the file handle for the "/" directory on the server |
| 2161 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | 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] | 2163 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | int status; |
| 2166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | if (status == 0) |
| 2169 | status = nfs4_server_capabilities(server, fhandle); |
| 2170 | if (status == 0) |
| 2171 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2172 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2175 | /* |
| 2176 | * Get locations and (maybe) other attributes of a referral. |
| 2177 | * Note that we'll actually follow the referral later when |
| 2178 | * we detect fsid mismatch in inode revalidation |
| 2179 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2180 | 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] | 2181 | { |
| 2182 | int status = -ENOMEM; |
| 2183 | struct page *page = NULL; |
| 2184 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2185 | |
| 2186 | page = alloc_page(GFP_KERNEL); |
| 2187 | if (page == NULL) |
| 2188 | goto out; |
| 2189 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2190 | if (locations == NULL) |
| 2191 | goto out; |
| 2192 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2193 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2194 | if (status != 0) |
| 2195 | goto out; |
| 2196 | /* Make sure server returned a different fsid for the referral */ |
| 2197 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2198 | 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] | 2199 | status = -EIO; |
| 2200 | goto out; |
| 2201 | } |
| 2202 | |
| 2203 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2204 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2205 | if (!fattr->mode) |
| 2206 | fattr->mode = S_IFDIR; |
| 2207 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2208 | out: |
| 2209 | if (page) |
| 2210 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2211 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2212 | return status; |
| 2213 | } |
| 2214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2216 | { |
| 2217 | struct nfs4_getattr_arg args = { |
| 2218 | .fh = fhandle, |
| 2219 | .bitmask = server->attr_bitmask, |
| 2220 | }; |
| 2221 | struct nfs4_getattr_res res = { |
| 2222 | .fattr = fattr, |
| 2223 | .server = server, |
| 2224 | }; |
| 2225 | struct rpc_message msg = { |
| 2226 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2227 | .rpc_argp = &args, |
| 2228 | .rpc_resp = &res, |
| 2229 | }; |
| 2230 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2231 | nfs_fattr_init(fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2232 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2236 | { |
| 2237 | struct nfs4_exception exception = { }; |
| 2238 | int err; |
| 2239 | do { |
| 2240 | err = nfs4_handle_exception(server, |
| 2241 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2242 | &exception); |
| 2243 | } while (exception.retry); |
| 2244 | return err; |
| 2245 | } |
| 2246 | |
| 2247 | /* |
| 2248 | * The file is not closed if it is opened due to the a request to change |
| 2249 | * the size of the file. The open call will not be needed once the |
| 2250 | * VFS layer lookup-intents are implemented. |
| 2251 | * |
| 2252 | * Close is called when the inode is destroyed. |
| 2253 | * If we haven't opened the file for O_WRONLY, we |
| 2254 | * need to in the size_change case to obtain a stateid. |
| 2255 | * |
| 2256 | * Got race? |
| 2257 | * Because OPEN is always done by name in nfsv4, it is |
| 2258 | * possible that we opened a different file by the same |
| 2259 | * name. We can recognize this race condition, but we |
| 2260 | * can't do anything about it besides returning an error. |
| 2261 | * |
| 2262 | * This will be fixed with VFS changes (lookup-intent). |
| 2263 | */ |
| 2264 | static int |
| 2265 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2266 | struct iattr *sattr) |
| 2267 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2268 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2269 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2270 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | int status; |
| 2272 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2273 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2275 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2276 | if (sattr->ia_valid & ATTR_FILE) { |
| 2277 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2278 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2279 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2280 | if (ctx) { |
| 2281 | cred = ctx->cred; |
| 2282 | state = ctx->state; |
| 2283 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2287 | if (status == 0) |
| 2288 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | return status; |
| 2290 | } |
| 2291 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2292 | static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh, |
| 2293 | const struct qstr *name, struct nfs_fh *fhandle, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2294 | struct nfs_fattr *fattr) |
| 2295 | { |
| 2296 | int status; |
| 2297 | struct nfs4_lookup_arg args = { |
| 2298 | .bitmask = server->attr_bitmask, |
| 2299 | .dir_fh = dirfh, |
| 2300 | .name = name, |
| 2301 | }; |
| 2302 | struct nfs4_lookup_res res = { |
| 2303 | .server = server, |
| 2304 | .fattr = fattr, |
| 2305 | .fh = fhandle, |
| 2306 | }; |
| 2307 | struct rpc_message msg = { |
| 2308 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2309 | .rpc_argp = &args, |
| 2310 | .rpc_resp = &res, |
| 2311 | }; |
| 2312 | |
| 2313 | nfs_fattr_init(fattr); |
| 2314 | |
| 2315 | dprintk("NFS call lookupfh %s\n", name->name); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2316 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2317 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2318 | return status; |
| 2319 | } |
| 2320 | |
| 2321 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2322 | struct qstr *name, struct nfs_fh *fhandle, |
| 2323 | struct nfs_fattr *fattr) |
| 2324 | { |
| 2325 | struct nfs4_exception exception = { }; |
| 2326 | int err; |
| 2327 | do { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2328 | err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); |
| 2329 | /* FIXME: !!!! */ |
| 2330 | if (err == -NFS4ERR_MOVED) { |
| 2331 | err = -EREMOTE; |
| 2332 | break; |
| 2333 | } |
| 2334 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2335 | } while (exception.retry); |
| 2336 | return err; |
| 2337 | } |
| 2338 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2339 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2341 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2342 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | |
| 2344 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2345 | 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] | 2346 | if (status == -NFS4ERR_MOVED) |
| 2347 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | dprintk("NFS reply lookup: %d\n", status); |
| 2349 | return status; |
| 2350 | } |
| 2351 | |
| 2352 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2353 | { |
| 2354 | struct nfs4_exception exception = { }; |
| 2355 | int err; |
| 2356 | do { |
| 2357 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2358 | _nfs4_proc_lookup(dir, name, fhandle, fattr), |
| 2359 | &exception); |
| 2360 | } while (exception.retry); |
| 2361 | return err; |
| 2362 | } |
| 2363 | |
| 2364 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2365 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2366 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | struct nfs4_accessargs args = { |
| 2368 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2369 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2371 | struct nfs4_accessres res = { |
| 2372 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2373 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | struct rpc_message msg = { |
| 2375 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2376 | .rpc_argp = &args, |
| 2377 | .rpc_resp = &res, |
| 2378 | .rpc_cred = entry->cred, |
| 2379 | }; |
| 2380 | int mode = entry->mask; |
| 2381 | int status; |
| 2382 | |
| 2383 | /* |
| 2384 | * Determine which access bits we want to ask for... |
| 2385 | */ |
| 2386 | if (mode & MAY_READ) |
| 2387 | args.access |= NFS4_ACCESS_READ; |
| 2388 | if (S_ISDIR(inode->i_mode)) { |
| 2389 | if (mode & MAY_WRITE) |
| 2390 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2391 | if (mode & MAY_EXEC) |
| 2392 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2393 | } else { |
| 2394 | if (mode & MAY_WRITE) |
| 2395 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2396 | if (mode & MAY_EXEC) |
| 2397 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2398 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2399 | |
| 2400 | res.fattr = nfs_alloc_fattr(); |
| 2401 | if (res.fattr == NULL) |
| 2402 | return -ENOMEM; |
| 2403 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2404 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | if (!status) { |
| 2406 | entry->mask = 0; |
| 2407 | if (res.access & NFS4_ACCESS_READ) |
| 2408 | entry->mask |= MAY_READ; |
| 2409 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2410 | entry->mask |= MAY_WRITE; |
| 2411 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2412 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2413 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2415 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | return status; |
| 2417 | } |
| 2418 | |
| 2419 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2420 | { |
| 2421 | struct nfs4_exception exception = { }; |
| 2422 | int err; |
| 2423 | do { |
| 2424 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2425 | _nfs4_proc_access(inode, entry), |
| 2426 | &exception); |
| 2427 | } while (exception.retry); |
| 2428 | return err; |
| 2429 | } |
| 2430 | |
| 2431 | /* |
| 2432 | * TODO: For the time being, we don't try to get any attributes |
| 2433 | * along with any of the zero-copy operations READ, READDIR, |
| 2434 | * READLINK, WRITE. |
| 2435 | * |
| 2436 | * In the case of the first three, we want to put the GETATTR |
| 2437 | * after the read-type operation -- this is because it is hard |
| 2438 | * to predict the length of a GETATTR response in v4, and thus |
| 2439 | * align the READ data correctly. This means that the GETATTR |
| 2440 | * may end up partially falling into the page cache, and we should |
| 2441 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2442 | * To do this efficiently, we need to know the total length |
| 2443 | * of data received, which doesn't seem to be available outside |
| 2444 | * of the RPC layer. |
| 2445 | * |
| 2446 | * In the case of WRITE, we also want to put the GETATTR after |
| 2447 | * the operation -- in this case because we want to make sure |
| 2448 | * we get the post-operation mtime and size. This means that |
| 2449 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2450 | * of it which would leave room in the 'tail' iovec. |
| 2451 | * |
| 2452 | * Both of these changes to the XDR layer would in fact be quite |
| 2453 | * minor, but I decided to leave them for a subsequent patch. |
| 2454 | */ |
| 2455 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2456 | unsigned int pgbase, unsigned int pglen) |
| 2457 | { |
| 2458 | struct nfs4_readlink args = { |
| 2459 | .fh = NFS_FH(inode), |
| 2460 | .pgbase = pgbase, |
| 2461 | .pglen = pglen, |
| 2462 | .pages = &page, |
| 2463 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2464 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | struct rpc_message msg = { |
| 2466 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2467 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2468 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | }; |
| 2470 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2471 | return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2475 | unsigned int pgbase, unsigned int pglen) |
| 2476 | { |
| 2477 | struct nfs4_exception exception = { }; |
| 2478 | int err; |
| 2479 | do { |
| 2480 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2481 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2482 | &exception); |
| 2483 | } while (exception.retry); |
| 2484 | return err; |
| 2485 | } |
| 2486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | /* |
| 2488 | * Got race? |
| 2489 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2490 | * Until then, this create/open method is prone to inefficiency and race |
| 2491 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2492 | * placed on the wire. |
| 2493 | * |
| 2494 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2495 | * The file will be opened again in the subsequent VFS open call |
| 2496 | * (nfs4_proc_file_open). |
| 2497 | * |
| 2498 | * The open for read will just hang around to be used by any process that |
| 2499 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2500 | */ |
| 2501 | |
| 2502 | static int |
| 2503 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2504 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2506 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2507 | .dentry = dentry, |
| 2508 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2509 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2511 | struct rpc_cred *cred = NULL; |
| 2512 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | int status = 0; |
| 2514 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2515 | if (ctx != NULL) { |
| 2516 | cred = ctx->cred; |
| 2517 | path = &ctx->path; |
| 2518 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2520 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2521 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2522 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | if (IS_ERR(state)) { |
| 2524 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2525 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2527 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2528 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2529 | if (ctx != NULL) |
| 2530 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2531 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2532 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | out: |
| 2534 | return status; |
| 2535 | } |
| 2536 | |
| 2537 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2538 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2539 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2540 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2542 | .name.len = name->len, |
| 2543 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2544 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2546 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2547 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2548 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2550 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2551 | .rpc_argp = &args, |
| 2552 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2554 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2556 | res.dir_attr = nfs_alloc_fattr(); |
| 2557 | if (res.dir_attr == NULL) |
| 2558 | goto out; |
| 2559 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2560 | status = nfs4_call_sync(server, &msg, &args, &res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2561 | if (status == 0) { |
| 2562 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2563 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2564 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2565 | nfs_free_fattr(res.dir_attr); |
| 2566 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | return status; |
| 2568 | } |
| 2569 | |
| 2570 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2571 | { |
| 2572 | struct nfs4_exception exception = { }; |
| 2573 | int err; |
| 2574 | do { |
| 2575 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2576 | _nfs4_proc_remove(dir, name), |
| 2577 | &exception); |
| 2578 | } while (exception.retry); |
| 2579 | return err; |
| 2580 | } |
| 2581 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2582 | 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] | 2583 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2584 | struct nfs_server *server = NFS_SERVER(dir); |
| 2585 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2586 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2588 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2589 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2590 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2594 | 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] | 2595 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2596 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2597 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2598 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2599 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2600 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2601 | return 0; |
| 2602 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2603 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2604 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2607 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2608 | { |
| 2609 | struct nfs_server *server = NFS_SERVER(dir); |
| 2610 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2611 | struct nfs_renameres *res = msg->rpc_resp; |
| 2612 | |
| 2613 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2614 | arg->bitmask = server->attr_bitmask; |
| 2615 | res->server = server; |
| 2616 | } |
| 2617 | |
| 2618 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2619 | struct inode *new_dir) |
| 2620 | { |
| 2621 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2622 | |
| 2623 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2624 | return 0; |
| 2625 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2626 | return 0; |
| 2627 | |
| 2628 | update_changeattr(old_dir, &res->old_cinfo); |
| 2629 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2630 | update_changeattr(new_dir, &res->new_cinfo); |
| 2631 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2632 | return 1; |
| 2633 | } |
| 2634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2636 | struct inode *new_dir, struct qstr *new_name) |
| 2637 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2638 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2639 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | .old_dir = NFS_FH(old_dir), |
| 2641 | .new_dir = NFS_FH(new_dir), |
| 2642 | .old_name = old_name, |
| 2643 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2644 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2646 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2647 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2648 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | struct rpc_message msg = { |
| 2650 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2651 | .rpc_argp = &arg, |
| 2652 | .rpc_resp = &res, |
| 2653 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2654 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2656 | res.old_fattr = nfs_alloc_fattr(); |
| 2657 | res.new_fattr = nfs_alloc_fattr(); |
| 2658 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2659 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2661 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | if (!status) { |
| 2663 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2664 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2666 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2668 | out: |
| 2669 | nfs_free_fattr(res.new_fattr); |
| 2670 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | return status; |
| 2672 | } |
| 2673 | |
| 2674 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2675 | struct inode *new_dir, struct qstr *new_name) |
| 2676 | { |
| 2677 | struct nfs4_exception exception = { }; |
| 2678 | int err; |
| 2679 | do { |
| 2680 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2681 | _nfs4_proc_rename(old_dir, old_name, |
| 2682 | new_dir, new_name), |
| 2683 | &exception); |
| 2684 | } while (exception.retry); |
| 2685 | return err; |
| 2686 | } |
| 2687 | |
| 2688 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2689 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2690 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | struct nfs4_link_arg arg = { |
| 2692 | .fh = NFS_FH(inode), |
| 2693 | .dir_fh = NFS_FH(dir), |
| 2694 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2695 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2697 | struct nfs4_link_res res = { |
| 2698 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2699 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | struct rpc_message msg = { |
| 2701 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2702 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2703 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2705 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2707 | res.fattr = nfs_alloc_fattr(); |
| 2708 | res.dir_attr = nfs_alloc_fattr(); |
| 2709 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2710 | goto out; |
| 2711 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2712 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2713 | if (!status) { |
| 2714 | update_changeattr(dir, &res.cinfo); |
| 2715 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2716 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2717 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2718 | out: |
| 2719 | nfs_free_fattr(res.dir_attr); |
| 2720 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | return status; |
| 2722 | } |
| 2723 | |
| 2724 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2725 | { |
| 2726 | struct nfs4_exception exception = { }; |
| 2727 | int err; |
| 2728 | do { |
| 2729 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2730 | _nfs4_proc_link(inode, dir, name), |
| 2731 | &exception); |
| 2732 | } while (exception.retry); |
| 2733 | return err; |
| 2734 | } |
| 2735 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2736 | struct nfs4_createdata { |
| 2737 | struct rpc_message msg; |
| 2738 | struct nfs4_create_arg arg; |
| 2739 | struct nfs4_create_res res; |
| 2740 | struct nfs_fh fh; |
| 2741 | struct nfs_fattr fattr; |
| 2742 | struct nfs_fattr dir_fattr; |
| 2743 | }; |
| 2744 | |
| 2745 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2746 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2747 | { |
| 2748 | struct nfs4_createdata *data; |
| 2749 | |
| 2750 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2751 | if (data != NULL) { |
| 2752 | struct nfs_server *server = NFS_SERVER(dir); |
| 2753 | |
| 2754 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2755 | data->msg.rpc_argp = &data->arg; |
| 2756 | data->msg.rpc_resp = &data->res; |
| 2757 | data->arg.dir_fh = NFS_FH(dir); |
| 2758 | data->arg.server = server; |
| 2759 | data->arg.name = name; |
| 2760 | data->arg.attrs = sattr; |
| 2761 | data->arg.ftype = ftype; |
| 2762 | data->arg.bitmask = server->attr_bitmask; |
| 2763 | data->res.server = server; |
| 2764 | data->res.fh = &data->fh; |
| 2765 | data->res.fattr = &data->fattr; |
| 2766 | data->res.dir_fattr = &data->dir_fattr; |
| 2767 | nfs_fattr_init(data->res.fattr); |
| 2768 | nfs_fattr_init(data->res.dir_fattr); |
| 2769 | } |
| 2770 | return data; |
| 2771 | } |
| 2772 | |
| 2773 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2774 | { |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2775 | int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg, |
| 2776 | &data->arg, &data->res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2777 | if (status == 0) { |
| 2778 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2779 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2780 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2781 | } |
| 2782 | return status; |
| 2783 | } |
| 2784 | |
| 2785 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2786 | { |
| 2787 | kfree(data); |
| 2788 | } |
| 2789 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2790 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2791 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2793 | struct nfs4_createdata *data; |
| 2794 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2796 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2797 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2798 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2799 | status = -ENOMEM; |
| 2800 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2801 | if (data == NULL) |
| 2802 | goto out; |
| 2803 | |
| 2804 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2805 | data->arg.u.symlink.pages = &page; |
| 2806 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2808 | status = nfs4_do_create(dir, dentry, data); |
| 2809 | |
| 2810 | nfs4_free_createdata(data); |
| 2811 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | return status; |
| 2813 | } |
| 2814 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2815 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2816 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | { |
| 2818 | struct nfs4_exception exception = { }; |
| 2819 | int err; |
| 2820 | do { |
| 2821 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2822 | _nfs4_proc_symlink(dir, dentry, page, |
| 2823 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | &exception); |
| 2825 | } while (exception.retry); |
| 2826 | return err; |
| 2827 | } |
| 2828 | |
| 2829 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2830 | struct iattr *sattr) |
| 2831 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2832 | struct nfs4_createdata *data; |
| 2833 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2835 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2836 | if (data == NULL) |
| 2837 | goto out; |
| 2838 | |
| 2839 | status = nfs4_do_create(dir, dentry, data); |
| 2840 | |
| 2841 | nfs4_free_createdata(data); |
| 2842 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | return status; |
| 2844 | } |
| 2845 | |
| 2846 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2847 | struct iattr *sattr) |
| 2848 | { |
| 2849 | struct nfs4_exception exception = { }; |
| 2850 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2851 | |
| 2852 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | do { |
| 2854 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2855 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2856 | &exception); |
| 2857 | } while (exception.retry); |
| 2858 | return err; |
| 2859 | } |
| 2860 | |
| 2861 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2862 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | { |
| 2864 | struct inode *dir = dentry->d_inode; |
| 2865 | struct nfs4_readdir_arg args = { |
| 2866 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2867 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | .pgbase = 0, |
| 2869 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2870 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2871 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | }; |
| 2873 | struct nfs4_readdir_res res; |
| 2874 | struct rpc_message msg = { |
| 2875 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2876 | .rpc_argp = &args, |
| 2877 | .rpc_resp = &res, |
| 2878 | .rpc_cred = cred, |
| 2879 | }; |
| 2880 | int status; |
| 2881 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2882 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2883 | dentry->d_parent->d_name.name, |
| 2884 | dentry->d_name.name, |
| 2885 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2887 | res.pgbase = args.pgbase; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2888 | status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2889 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2891 | status += args.pgbase; |
| 2892 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2893 | |
| 2894 | nfs_invalidate_atime(dir); |
| 2895 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2896 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | return status; |
| 2898 | } |
| 2899 | |
| 2900 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2901 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | { |
| 2903 | struct nfs4_exception exception = { }; |
| 2904 | int err; |
| 2905 | do { |
| 2906 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2907 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2908 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | &exception); |
| 2910 | } while (exception.retry); |
| 2911 | return err; |
| 2912 | } |
| 2913 | |
| 2914 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2915 | struct iattr *sattr, dev_t rdev) |
| 2916 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2917 | struct nfs4_createdata *data; |
| 2918 | int mode = sattr->ia_mode; |
| 2919 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | |
| 2921 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2922 | 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] | 2923 | |
| 2924 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2925 | if (data == NULL) |
| 2926 | goto out; |
| 2927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2929 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2931 | data->arg.ftype = NF4BLK; |
| 2932 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2933 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | } |
| 2935 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2936 | data->arg.ftype = NF4CHR; |
| 2937 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2938 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2941 | status = nfs4_do_create(dir, dentry, data); |
| 2942 | |
| 2943 | nfs4_free_createdata(data); |
| 2944 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | return status; |
| 2946 | } |
| 2947 | |
| 2948 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2949 | struct iattr *sattr, dev_t rdev) |
| 2950 | { |
| 2951 | struct nfs4_exception exception = { }; |
| 2952 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2953 | |
| 2954 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | do { |
| 2956 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2957 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 2958 | &exception); |
| 2959 | } while (exception.retry); |
| 2960 | return err; |
| 2961 | } |
| 2962 | |
| 2963 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2964 | struct nfs_fsstat *fsstat) |
| 2965 | { |
| 2966 | struct nfs4_statfs_arg args = { |
| 2967 | .fh = fhandle, |
| 2968 | .bitmask = server->attr_bitmask, |
| 2969 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2970 | struct nfs4_statfs_res res = { |
| 2971 | .fsstat = fsstat, |
| 2972 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | struct rpc_message msg = { |
| 2974 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 2975 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2976 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | }; |
| 2978 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2979 | nfs_fattr_init(fsstat->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2980 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | } |
| 2982 | |
| 2983 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 2984 | { |
| 2985 | struct nfs4_exception exception = { }; |
| 2986 | int err; |
| 2987 | do { |
| 2988 | err = nfs4_handle_exception(server, |
| 2989 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 2990 | &exception); |
| 2991 | } while (exception.retry); |
| 2992 | return err; |
| 2993 | } |
| 2994 | |
| 2995 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2996 | struct nfs_fsinfo *fsinfo) |
| 2997 | { |
| 2998 | struct nfs4_fsinfo_arg args = { |
| 2999 | .fh = fhandle, |
| 3000 | .bitmask = server->attr_bitmask, |
| 3001 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3002 | struct nfs4_fsinfo_res res = { |
| 3003 | .fsinfo = fsinfo, |
| 3004 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | struct rpc_message msg = { |
| 3006 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3007 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3008 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | }; |
| 3010 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3011 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3015 | { |
| 3016 | struct nfs4_exception exception = { }; |
| 3017 | int err; |
| 3018 | |
| 3019 | do { |
| 3020 | err = nfs4_handle_exception(server, |
| 3021 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3022 | &exception); |
| 3023 | } while (exception.retry); |
| 3024 | return err; |
| 3025 | } |
| 3026 | |
| 3027 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3028 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3029 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3031 | } |
| 3032 | |
| 3033 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3034 | struct nfs_pathconf *pathconf) |
| 3035 | { |
| 3036 | struct nfs4_pathconf_arg args = { |
| 3037 | .fh = fhandle, |
| 3038 | .bitmask = server->attr_bitmask, |
| 3039 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3040 | struct nfs4_pathconf_res res = { |
| 3041 | .pathconf = pathconf, |
| 3042 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | struct rpc_message msg = { |
| 3044 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3045 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3046 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | }; |
| 3048 | |
| 3049 | /* None of the pathconf attributes are mandatory to implement */ |
| 3050 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3051 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3052 | return 0; |
| 3053 | } |
| 3054 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3055 | nfs_fattr_init(pathconf->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3056 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3060 | struct nfs_pathconf *pathconf) |
| 3061 | { |
| 3062 | struct nfs4_exception exception = { }; |
| 3063 | int err; |
| 3064 | |
| 3065 | do { |
| 3066 | err = nfs4_handle_exception(server, |
| 3067 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3068 | &exception); |
| 3069 | } while (exception.retry); |
| 3070 | return err; |
| 3071 | } |
| 3072 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3073 | 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] | 3074 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3075 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3077 | dprintk("--> %s\n", __func__); |
| 3078 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3079 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3080 | return -EAGAIN; |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3081 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3082 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3083 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3084 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3086 | |
| 3087 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3089 | renew_lease(server, data->timestamp); |
| 3090 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | } |
| 3092 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3093 | 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] | 3094 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | data->timestamp = jiffies; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3096 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | } |
| 3098 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3099 | 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] | 3100 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | struct inode *inode = data->inode; |
| 3102 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3103 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3104 | return -EAGAIN; |
Andy Adamson | def6ed7 | 2009-04-01 09:22:26 -0400 | [diff] [blame] | 3105 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3106 | 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] | 3107 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3108 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3110 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3112 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3113 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3114 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3117 | 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] | 3118 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3119 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3120 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3121 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3122 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | data->timestamp = jiffies; |
| 3124 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3125 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | } |
| 3127 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3128 | 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] | 3129 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | struct inode *inode = data->inode; |
| 3131 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3132 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3133 | return -EAGAIN; |
| 3134 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3135 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3136 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3137 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3139 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3140 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | } |
| 3142 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3143 | 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] | 3144 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3145 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3147 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3148 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3149 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | } |
| 3151 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3152 | struct nfs4_renewdata { |
| 3153 | struct nfs_client *client; |
| 3154 | unsigned long timestamp; |
| 3155 | }; |
| 3156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | /* |
| 3158 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3159 | * standalone procedure for queueing an asynchronous RENEW. |
| 3160 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3161 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3162 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3163 | struct nfs4_renewdata *data = calldata; |
| 3164 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3165 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3166 | if (atomic_read(&clp->cl_count) > 1) |
| 3167 | nfs4_schedule_state_renewal(clp); |
| 3168 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3169 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3170 | } |
| 3171 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3172 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3174 | struct nfs4_renewdata *data = calldata; |
| 3175 | struct nfs_client *clp = data->client; |
| 3176 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | |
| 3178 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3179 | /* Unless we're shutting down, schedule state recovery! */ |
| 3180 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
| 3181 | nfs4_schedule_state_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | return; |
| 3183 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3184 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3187 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3188 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3189 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3190 | }; |
| 3191 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3192 | 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] | 3193 | { |
| 3194 | struct rpc_message msg = { |
| 3195 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3196 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3197 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3199 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3201 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3202 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3203 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3204 | if (data == NULL) |
| 3205 | return -ENOMEM; |
| 3206 | data->client = clp; |
| 3207 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3209 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | } |
| 3211 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3212 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | { |
| 3214 | struct rpc_message msg = { |
| 3215 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3216 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3217 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | }; |
| 3219 | unsigned long now = jiffies; |
| 3220 | int status; |
| 3221 | |
| 3222 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3223 | if (status < 0) |
| 3224 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3225 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | return 0; |
| 3227 | } |
| 3228 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3229 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3230 | { |
| 3231 | return (server->caps & NFS_CAP_ACLS) |
| 3232 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3233 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3234 | } |
| 3235 | |
| 3236 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3237 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3238 | * the stack. |
| 3239 | */ |
| 3240 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3241 | |
| 3242 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3243 | struct page **pages, unsigned int *pgbase) |
| 3244 | { |
| 3245 | const void *p = buf; |
| 3246 | |
| 3247 | *pgbase = offset_in_page(buf); |
| 3248 | p -= *pgbase; |
| 3249 | while (p < buf + buflen) { |
| 3250 | *(pages++) = virt_to_page(p); |
| 3251 | p += PAGE_CACHE_SIZE; |
| 3252 | } |
| 3253 | } |
| 3254 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3255 | struct nfs4_cached_acl { |
| 3256 | int cached; |
| 3257 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3258 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3259 | }; |
| 3260 | |
| 3261 | 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] | 3262 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3263 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3264 | |
| 3265 | spin_lock(&inode->i_lock); |
| 3266 | kfree(nfsi->nfs4_acl); |
| 3267 | nfsi->nfs4_acl = acl; |
| 3268 | spin_unlock(&inode->i_lock); |
| 3269 | } |
| 3270 | |
| 3271 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3272 | { |
| 3273 | nfs4_set_cached_acl(inode, NULL); |
| 3274 | } |
| 3275 | |
| 3276 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3277 | { |
| 3278 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3279 | struct nfs4_cached_acl *acl; |
| 3280 | int ret = -ENOENT; |
| 3281 | |
| 3282 | spin_lock(&inode->i_lock); |
| 3283 | acl = nfsi->nfs4_acl; |
| 3284 | if (acl == NULL) |
| 3285 | goto out; |
| 3286 | if (buf == NULL) /* user is just asking for length */ |
| 3287 | goto out_len; |
| 3288 | if (acl->cached == 0) |
| 3289 | goto out; |
| 3290 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3291 | if (acl->len > buflen) |
| 3292 | goto out; |
| 3293 | memcpy(buf, acl->data, acl->len); |
| 3294 | out_len: |
| 3295 | ret = acl->len; |
| 3296 | out: |
| 3297 | spin_unlock(&inode->i_lock); |
| 3298 | return ret; |
| 3299 | } |
| 3300 | |
| 3301 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3302 | { |
| 3303 | struct nfs4_cached_acl *acl; |
| 3304 | |
| 3305 | if (buf && acl_len <= PAGE_SIZE) { |
| 3306 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3307 | if (acl == NULL) |
| 3308 | goto out; |
| 3309 | acl->cached = 1; |
| 3310 | memcpy(acl->data, buf, acl_len); |
| 3311 | } else { |
| 3312 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3313 | if (acl == NULL) |
| 3314 | goto out; |
| 3315 | acl->cached = 0; |
| 3316 | } |
| 3317 | acl->len = acl_len; |
| 3318 | out: |
| 3319 | nfs4_set_cached_acl(inode, acl); |
| 3320 | } |
| 3321 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3322 | 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] | 3323 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3324 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3325 | struct nfs_getaclargs args = { |
| 3326 | .fh = NFS_FH(inode), |
| 3327 | .acl_pages = pages, |
| 3328 | .acl_len = buflen, |
| 3329 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3330 | struct nfs_getaclres res = { |
| 3331 | .acl_len = buflen, |
| 3332 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3333 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3334 | struct rpc_message msg = { |
| 3335 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3336 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3337 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3338 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3339 | struct page *localpage = NULL; |
| 3340 | int ret; |
| 3341 | |
| 3342 | if (buflen < PAGE_SIZE) { |
| 3343 | /* As long as we're doing a round trip to the server anyway, |
| 3344 | * let's be prepared for a page of acl data. */ |
| 3345 | localpage = alloc_page(GFP_KERNEL); |
| 3346 | resp_buf = page_address(localpage); |
| 3347 | if (localpage == NULL) |
| 3348 | return -ENOMEM; |
| 3349 | args.acl_pages[0] = localpage; |
| 3350 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3351 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3352 | } else { |
| 3353 | resp_buf = buf; |
| 3354 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3355 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3356 | ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3357 | if (ret) |
| 3358 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3359 | if (res.acl_len > args.acl_len) |
| 3360 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3361 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3362 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3363 | if (buf) { |
| 3364 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3365 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3366 | goto out_free; |
| 3367 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3368 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3369 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3370 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3371 | out_free: |
| 3372 | if (localpage) |
| 3373 | __free_page(localpage); |
| 3374 | return ret; |
| 3375 | } |
| 3376 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3377 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3378 | { |
| 3379 | struct nfs4_exception exception = { }; |
| 3380 | ssize_t ret; |
| 3381 | do { |
| 3382 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3383 | if (ret >= 0) |
| 3384 | break; |
| 3385 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3386 | } while (exception.retry); |
| 3387 | return ret; |
| 3388 | } |
| 3389 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3390 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3391 | { |
| 3392 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3393 | int ret; |
| 3394 | |
| 3395 | if (!nfs4_server_supports_acls(server)) |
| 3396 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3397 | ret = nfs_revalidate_inode(server, inode); |
| 3398 | if (ret < 0) |
| 3399 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3400 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3401 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3402 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3403 | if (ret != -ENOENT) |
| 3404 | return ret; |
| 3405 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3406 | } |
| 3407 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3408 | 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] | 3409 | { |
| 3410 | struct nfs_server *server = NFS_SERVER(inode); |
| 3411 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3412 | struct nfs_setaclargs arg = { |
| 3413 | .fh = NFS_FH(inode), |
| 3414 | .acl_pages = pages, |
| 3415 | .acl_len = buflen, |
| 3416 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3417 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3418 | struct rpc_message msg = { |
| 3419 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3420 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3421 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3422 | }; |
| 3423 | int ret; |
| 3424 | |
| 3425 | if (!nfs4_server_supports_acls(server)) |
| 3426 | return -EOPNOTSUPP; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3427 | nfs_inode_return_delegation(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3428 | buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3429 | ret = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3430 | /* |
| 3431 | * Acl update can result in inode attribute update. |
| 3432 | * so mark the attribute cache invalid. |
| 3433 | */ |
| 3434 | spin_lock(&inode->i_lock); |
| 3435 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3436 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3437 | nfs_access_zap_cache(inode); |
| 3438 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3439 | return ret; |
| 3440 | } |
| 3441 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3442 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3443 | { |
| 3444 | struct nfs4_exception exception = { }; |
| 3445 | int err; |
| 3446 | do { |
| 3447 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3448 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3449 | &exception); |
| 3450 | } while (exception.retry); |
| 3451 | return err; |
| 3452 | } |
| 3453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3455 | 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] | 3456 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3457 | struct nfs_client *clp = server->nfs_client; |
| 3458 | |
| 3459 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | return 0; |
| 3461 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3462 | case -NFS4ERR_ADMIN_REVOKED: |
| 3463 | case -NFS4ERR_BAD_STATEID: |
| 3464 | case -NFS4ERR_OPENMODE: |
| 3465 | if (state == NULL) |
| 3466 | break; |
| 3467 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3468 | goto do_state_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3470 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3472 | goto do_state_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3473 | #if defined(CONFIG_NFS_V4_1) |
| 3474 | case -NFS4ERR_BADSESSION: |
| 3475 | case -NFS4ERR_BADSLOT: |
| 3476 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3477 | case -NFS4ERR_DEADSESSION: |
| 3478 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3479 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3480 | case -NFS4ERR_SEQ_MISORDERED: |
| 3481 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3482 | task->tk_status); |
Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 3483 | nfs4_schedule_state_recovery(clp); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3484 | task->tk_status = 0; |
| 3485 | return -EAGAIN; |
| 3486 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3488 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3489 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3490 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3492 | task->tk_status = 0; |
| 3493 | return -EAGAIN; |
| 3494 | case -NFS4ERR_OLD_STATEID: |
| 3495 | task->tk_status = 0; |
| 3496 | return -EAGAIN; |
| 3497 | } |
| 3498 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3499 | return 0; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3500 | do_state_recovery: |
| 3501 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 3502 | nfs4_schedule_state_recovery(clp); |
| 3503 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3504 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3505 | task->tk_status = 0; |
| 3506 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | } |
| 3508 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3509 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3510 | unsigned short port, struct rpc_cred *cred, |
| 3511 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | { |
| 3513 | nfs4_verifier sc_verifier; |
| 3514 | struct nfs4_setclientid setclientid = { |
| 3515 | .sc_verifier = &sc_verifier, |
| 3516 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3517 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | }; |
| 3519 | struct rpc_message msg = { |
| 3520 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3521 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3522 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3523 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3525 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | int loop = 0; |
| 3527 | int status; |
| 3528 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3529 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3531 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3532 | |
| 3533 | for(;;) { |
| 3534 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3535 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3536 | clp->cl_ipaddr, |
| 3537 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3538 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3539 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3540 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3541 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | clp->cl_id_uniquifier); |
| 3543 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3544 | sizeof(setclientid.sc_netid), |
| 3545 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3546 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3548 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3550 | |
| 3551 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3552 | if (status != -NFS4ERR_CLID_INUSE) |
| 3553 | break; |
| 3554 | if (signalled()) |
| 3555 | break; |
| 3556 | if (loop++ & 1) |
J. Bruce Fields | 611c96c | 2010-12-13 19:05:46 -0500 | [diff] [blame] | 3557 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | else |
| 3559 | if (++clp->cl_id_uniquifier == 0) |
| 3560 | break; |
| 3561 | } |
| 3562 | return status; |
| 3563 | } |
| 3564 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3565 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3566 | struct nfs4_setclientid_res *arg, |
| 3567 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3568 | { |
| 3569 | struct nfs_fsinfo fsinfo; |
| 3570 | struct rpc_message msg = { |
| 3571 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3572 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3574 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3575 | }; |
| 3576 | unsigned long now; |
| 3577 | int status; |
| 3578 | |
| 3579 | now = jiffies; |
| 3580 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3581 | if (status == 0) { |
| 3582 | spin_lock(&clp->cl_lock); |
| 3583 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3584 | clp->cl_last_renewal = now; |
| 3585 | spin_unlock(&clp->cl_lock); |
| 3586 | } |
| 3587 | return status; |
| 3588 | } |
| 3589 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3590 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3591 | struct nfs4_setclientid_res *arg, |
| 3592 | struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3593 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3594 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3595 | int err; |
| 3596 | do { |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3597 | err = _nfs4_proc_setclientid_confirm(clp, arg, cred); |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3598 | switch (err) { |
| 3599 | case 0: |
| 3600 | return err; |
| 3601 | case -NFS4ERR_RESOURCE: |
| 3602 | /* The IBM lawyers misread another document! */ |
| 3603 | case -NFS4ERR_DELAY: |
| 3604 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3605 | } |
| 3606 | } while (err == 0); |
| 3607 | return err; |
| 3608 | } |
| 3609 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3610 | struct nfs4_delegreturndata { |
| 3611 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3612 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3613 | struct nfs_fh fh; |
| 3614 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3615 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3616 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3617 | int rpc_status; |
| 3618 | }; |
| 3619 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3620 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3621 | { |
| 3622 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3623 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3624 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3625 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3626 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3627 | switch (task->tk_status) { |
| 3628 | case -NFS4ERR_STALE_STATEID: |
| 3629 | case -NFS4ERR_EXPIRED: |
| 3630 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3631 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3632 | break; |
| 3633 | default: |
| 3634 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3635 | -EAGAIN) { |
| 3636 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3637 | return; |
| 3638 | } |
| 3639 | } |
| 3640 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | static void nfs4_delegreturn_release(void *calldata) |
| 3644 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3645 | kfree(calldata); |
| 3646 | } |
| 3647 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3648 | #if defined(CONFIG_NFS_V4_1) |
| 3649 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3650 | { |
| 3651 | struct nfs4_delegreturndata *d_data; |
| 3652 | |
| 3653 | d_data = (struct nfs4_delegreturndata *)data; |
| 3654 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3655 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3656 | &d_data->args.seq_args, |
| 3657 | &d_data->res.seq_res, 1, task)) |
| 3658 | return; |
| 3659 | rpc_call_start(task); |
| 3660 | } |
| 3661 | #endif /* CONFIG_NFS_V4_1 */ |
| 3662 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3663 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3664 | #if defined(CONFIG_NFS_V4_1) |
| 3665 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3666 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3667 | .rpc_call_done = nfs4_delegreturn_done, |
| 3668 | .rpc_release = nfs4_delegreturn_release, |
| 3669 | }; |
| 3670 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3671 | 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] | 3672 | { |
| 3673 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3674 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3675 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3676 | struct rpc_message msg = { |
| 3677 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3678 | .rpc_cred = cred, |
| 3679 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3680 | struct rpc_task_setup task_setup_data = { |
| 3681 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3682 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3683 | .callback_ops = &nfs4_delegreturn_ops, |
| 3684 | .flags = RPC_TASK_ASYNC, |
| 3685 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3686 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3687 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3688 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3689 | if (data == NULL) |
| 3690 | return -ENOMEM; |
| 3691 | data->args.fhandle = &data->fh; |
| 3692 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3693 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3694 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3695 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3696 | data->res.fattr = &data->fattr; |
| 3697 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3698 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3699 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3700 | data->rpc_status = 0; |
| 3701 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3702 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3703 | msg.rpc_argp = &data->args; |
| 3704 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3705 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3706 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3707 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3708 | if (!issync) |
| 3709 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3710 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3711 | if (status != 0) |
| 3712 | goto out; |
| 3713 | status = data->rpc_status; |
| 3714 | if (status != 0) |
| 3715 | goto out; |
| 3716 | nfs_refresh_inode(inode, &data->fattr); |
| 3717 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3718 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3719 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | } |
| 3721 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3722 | 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] | 3723 | { |
| 3724 | struct nfs_server *server = NFS_SERVER(inode); |
| 3725 | struct nfs4_exception exception = { }; |
| 3726 | int err; |
| 3727 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3728 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | switch (err) { |
| 3730 | case -NFS4ERR_STALE_STATEID: |
| 3731 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | case 0: |
| 3733 | return 0; |
| 3734 | } |
| 3735 | err = nfs4_handle_exception(server, err, &exception); |
| 3736 | } while (exception.retry); |
| 3737 | return err; |
| 3738 | } |
| 3739 | |
| 3740 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3741 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3742 | |
| 3743 | /* |
| 3744 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3745 | */ |
| 3746 | static unsigned long |
| 3747 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3748 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3749 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | timeout <<= 1; |
| 3751 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3752 | return NFS4_LOCK_MAXTIMEOUT; |
| 3753 | return timeout; |
| 3754 | } |
| 3755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3757 | { |
| 3758 | struct inode *inode = state->inode; |
| 3759 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3760 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3761 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3763 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3765 | struct nfs_lockt_res res = { |
| 3766 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | }; |
| 3768 | struct rpc_message msg = { |
| 3769 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3770 | .rpc_argp = &arg, |
| 3771 | .rpc_resp = &res, |
| 3772 | .rpc_cred = state->owner->so_cred, |
| 3773 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | struct nfs4_lock_state *lsp; |
| 3775 | int status; |
| 3776 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3777 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3778 | status = nfs4_set_lock_state(state, request); |
| 3779 | if (status != 0) |
| 3780 | goto out; |
| 3781 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3782 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3783 | arg.lock_owner.s_dev = server->s_dev; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3784 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3785 | switch (status) { |
| 3786 | case 0: |
| 3787 | request->fl_type = F_UNLCK; |
| 3788 | break; |
| 3789 | case -NFS4ERR_DENIED: |
| 3790 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3792 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3793 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | return status; |
| 3795 | } |
| 3796 | |
| 3797 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3798 | { |
| 3799 | struct nfs4_exception exception = { }; |
| 3800 | int err; |
| 3801 | |
| 3802 | do { |
| 3803 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3804 | _nfs4_proc_getlk(state, cmd, request), |
| 3805 | &exception); |
| 3806 | } while (exception.retry); |
| 3807 | return err; |
| 3808 | } |
| 3809 | |
| 3810 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3811 | { |
| 3812 | int res = 0; |
| 3813 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3814 | case FL_POSIX: |
| 3815 | res = posix_lock_file_wait(file, fl); |
| 3816 | break; |
| 3817 | case FL_FLOCK: |
| 3818 | res = flock_lock_file_wait(file, fl); |
| 3819 | break; |
| 3820 | default: |
| 3821 | BUG(); |
| 3822 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | return res; |
| 3824 | } |
| 3825 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3826 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3827 | struct nfs_locku_args arg; |
| 3828 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3829 | struct nfs4_lock_state *lsp; |
| 3830 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3831 | struct file_lock fl; |
| 3832 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3833 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3834 | }; |
| 3835 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3836 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 3837 | struct nfs_open_context *ctx, |
| 3838 | struct nfs4_lock_state *lsp, |
| 3839 | struct nfs_seqid *seqid) |
| 3840 | { |
| 3841 | struct nfs4_unlockdata *p; |
| 3842 | struct inode *inode = lsp->ls_state->inode; |
| 3843 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3844 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3845 | if (p == NULL) |
| 3846 | return NULL; |
| 3847 | p->arg.fh = NFS_FH(inode); |
| 3848 | p->arg.fl = &p->fl; |
| 3849 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3850 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3851 | p->arg.stateid = &lsp->ls_stateid; |
| 3852 | p->lsp = lsp; |
| 3853 | atomic_inc(&lsp->ls_count); |
| 3854 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3855 | p->ctx = get_nfs_open_context(ctx); |
| 3856 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3857 | p->server = NFS_SERVER(inode); |
| 3858 | return p; |
| 3859 | } |
| 3860 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3861 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3862 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3863 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3864 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3865 | nfs4_put_lock_state(calldata->lsp); |
| 3866 | put_nfs_open_context(calldata->ctx); |
| 3867 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3868 | } |
| 3869 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3870 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3871 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3872 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3873 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3874 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3875 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3876 | switch (task->tk_status) { |
| 3877 | case 0: |
| 3878 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3879 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3880 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3881 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3882 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3883 | case -NFS4ERR_BAD_STATEID: |
| 3884 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3885 | case -NFS4ERR_STALE_STATEID: |
| 3886 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3887 | break; |
| 3888 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3889 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3890 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 3891 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3892 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3893 | } |
| 3894 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3895 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3896 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3897 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3899 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3900 | return; |
| 3901 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3902 | /* Note: exit _without_ running nfs4_locku_done */ |
| 3903 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3904 | return; |
| 3905 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3906 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3907 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3908 | &calldata->arg.seq_args, |
| 3909 | &calldata->res.seq_res, 1, task)) |
| 3910 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3911 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3914 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3915 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3916 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3917 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3918 | }; |
| 3919 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3920 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 3921 | struct nfs_open_context *ctx, |
| 3922 | struct nfs4_lock_state *lsp, |
| 3923 | struct nfs_seqid *seqid) |
| 3924 | { |
| 3925 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3926 | struct rpc_message msg = { |
| 3927 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 3928 | .rpc_cred = ctx->cred, |
| 3929 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3930 | struct rpc_task_setup task_setup_data = { |
| 3931 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3932 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3933 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3934 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3935 | .flags = RPC_TASK_ASYNC, |
| 3936 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3937 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 3938 | /* Ensure this is an unlock - when canceling a lock, the |
| 3939 | * canceled lock is passed in, and it won't be an unlock. |
| 3940 | */ |
| 3941 | fl->fl_type = F_UNLCK; |
| 3942 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3943 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 3944 | if (data == NULL) { |
| 3945 | nfs_free_seqid(seqid); |
| 3946 | return ERR_PTR(-ENOMEM); |
| 3947 | } |
| 3948 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3949 | msg.rpc_argp = &data->arg; |
| 3950 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3951 | task_setup_data.callback_data = data; |
| 3952 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3953 | } |
| 3954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3955 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3956 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3957 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3958 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3959 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3960 | struct rpc_task *task; |
| 3961 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3962 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3964 | status = nfs4_set_lock_state(state, request); |
| 3965 | /* Unlock _before_ we do the RPC call */ |
| 3966 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3967 | down_read(&nfsi->rwsem); |
| 3968 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 3969 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3970 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3971 | } |
| 3972 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3973 | if (status != 0) |
| 3974 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 3975 | /* Is this a delegated lock? */ |
| 3976 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3977 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3978 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3979 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3980 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3981 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3982 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 3983 | 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] | 3984 | status = PTR_ERR(task); |
| 3985 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3986 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3987 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3988 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 3989 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 3990 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3991 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3992 | } |
| 3993 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3994 | struct nfs4_lockdata { |
| 3995 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3996 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3997 | struct nfs4_lock_state *lsp; |
| 3998 | struct nfs_open_context *ctx; |
| 3999 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4000 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4001 | int rpc_status; |
| 4002 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4003 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4004 | }; |
| 4005 | |
| 4006 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4007 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4008 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4009 | { |
| 4010 | struct nfs4_lockdata *p; |
| 4011 | struct inode *inode = lsp->ls_state->inode; |
| 4012 | struct nfs_server *server = NFS_SERVER(inode); |
| 4013 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4014 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4015 | if (p == NULL) |
| 4016 | return NULL; |
| 4017 | |
| 4018 | p->arg.fh = NFS_FH(inode); |
| 4019 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4020 | 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] | 4021 | if (p->arg.open_seqid == NULL) |
| 4022 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4023 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4024 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4025 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4026 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4027 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4028 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4029 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4030 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4031 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4032 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4033 | atomic_inc(&lsp->ls_count); |
| 4034 | p->ctx = get_nfs_open_context(ctx); |
| 4035 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4036 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4037 | out_free_seqid: |
| 4038 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4039 | out_free: |
| 4040 | kfree(p); |
| 4041 | return NULL; |
| 4042 | } |
| 4043 | |
| 4044 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4045 | { |
| 4046 | struct nfs4_lockdata *data = calldata; |
| 4047 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4049 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4050 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4051 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4052 | /* Do we need to do an open_to_lock_owner? */ |
| 4053 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4054 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4055 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4056 | data->arg.open_stateid = &state->stateid; |
| 4057 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4058 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4059 | } else |
| 4060 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4061 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4062 | if (nfs4_setup_sequence(data->server, |
| 4063 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4064 | &data->res.seq_res, 1, task)) |
| 4065 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4066 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4067 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4068 | } |
| 4069 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4070 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4071 | { |
| 4072 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4073 | nfs4_lock_prepare(task, calldata); |
| 4074 | } |
| 4075 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4076 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4077 | { |
| 4078 | struct nfs4_lockdata *data = calldata; |
| 4079 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4080 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4081 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4082 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4083 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4084 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4085 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4086 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4087 | if (data->rpc_status == 0) |
| 4088 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4089 | else |
| 4090 | goto out; |
| 4091 | } |
| 4092 | if (data->rpc_status == 0) { |
| 4093 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4094 | sizeof(data->lsp->ls_stateid.data)); |
| 4095 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4096 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4097 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4098 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4099 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | static void nfs4_lock_release(void *calldata) |
| 4103 | { |
| 4104 | struct nfs4_lockdata *data = calldata; |
| 4105 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4106 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4107 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4108 | if (data->cancelled != 0) { |
| 4109 | struct rpc_task *task; |
| 4110 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4111 | data->arg.lock_seqid); |
| 4112 | if (!IS_ERR(task)) |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4113 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4114 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4115 | } else |
| 4116 | nfs_free_seqid(data->arg.lock_seqid); |
| 4117 | nfs4_put_lock_state(data->lsp); |
| 4118 | put_nfs_open_context(data->ctx); |
| 4119 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4120 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4124 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4125 | .rpc_call_done = nfs4_lock_done, |
| 4126 | .rpc_release = nfs4_lock_release, |
| 4127 | }; |
| 4128 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4129 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4130 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4131 | .rpc_call_done = nfs4_lock_done, |
| 4132 | .rpc_release = nfs4_lock_release, |
| 4133 | }; |
| 4134 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4135 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4136 | { |
| 4137 | struct nfs_client *clp = server->nfs_client; |
| 4138 | struct nfs4_state *state = lsp->ls_state; |
| 4139 | |
| 4140 | switch (error) { |
| 4141 | case -NFS4ERR_ADMIN_REVOKED: |
| 4142 | case -NFS4ERR_BAD_STATEID: |
| 4143 | case -NFS4ERR_EXPIRED: |
| 4144 | if (new_lock_owner != 0 || |
| 4145 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
| 4146 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 4147 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4148 | break; |
| 4149 | case -NFS4ERR_STALE_STATEID: |
| 4150 | if (new_lock_owner != 0 || |
| 4151 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
| 4152 | nfs4_state_mark_reclaim_reboot(clp, state); |
| 4153 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4154 | }; |
| 4155 | } |
| 4156 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4157 | 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] | 4158 | { |
| 4159 | struct nfs4_lockdata *data; |
| 4160 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4161 | struct rpc_message msg = { |
| 4162 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4163 | .rpc_cred = state->owner->so_cred, |
| 4164 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4165 | struct rpc_task_setup task_setup_data = { |
| 4166 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4167 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4168 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4169 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4170 | .flags = RPC_TASK_ASYNC, |
| 4171 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4172 | int ret; |
| 4173 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4174 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4175 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4176 | fl->fl_u.nfs4_fl.owner, |
| 4177 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4178 | if (data == NULL) |
| 4179 | return -ENOMEM; |
| 4180 | if (IS_SETLKW(cmd)) |
| 4181 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4182 | if (recovery_type > NFS_LOCK_NEW) { |
| 4183 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4184 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4185 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4186 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4187 | msg.rpc_argp = &data->arg; |
| 4188 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4189 | task_setup_data.callback_data = data; |
| 4190 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4191 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4192 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4193 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4194 | if (ret == 0) { |
| 4195 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4196 | if (ret) |
| 4197 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4198 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4199 | } else |
| 4200 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4201 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4202 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4203 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
| 4206 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4207 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4208 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4209 | struct nfs4_exception exception = { }; |
| 4210 | int err; |
| 4211 | |
| 4212 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4213 | /* Cache the lock if possible... */ |
| 4214 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4215 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4216 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4217 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4218 | break; |
| 4219 | nfs4_handle_exception(server, err, &exception); |
| 4220 | } while (exception.retry); |
| 4221 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4225 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4226 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4227 | struct nfs4_exception exception = { }; |
| 4228 | int err; |
| 4229 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4230 | err = nfs4_set_lock_state(state, request); |
| 4231 | if (err != 0) |
| 4232 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4233 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4234 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4235 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4236 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4237 | switch (err) { |
| 4238 | default: |
| 4239 | goto out; |
| 4240 | case -NFS4ERR_GRACE: |
| 4241 | case -NFS4ERR_DELAY: |
| 4242 | nfs4_handle_exception(server, err, &exception); |
| 4243 | err = 0; |
| 4244 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4245 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4246 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4247 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | } |
| 4249 | |
| 4250 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4251 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4252 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4253 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4254 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4255 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4256 | if ((fl_flags & FL_POSIX) && |
| 4257 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4258 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4259 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4260 | status = nfs4_set_lock_state(state, request); |
| 4261 | if (status != 0) |
| 4262 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4263 | request->fl_flags |= FL_ACCESS; |
| 4264 | status = do_vfs_lock(request->fl_file, request); |
| 4265 | if (status < 0) |
| 4266 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4267 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4268 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4269 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4270 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4271 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4272 | status = do_vfs_lock(request->fl_file, request); |
| 4273 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4274 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4275 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4276 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4277 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4278 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4279 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4280 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4281 | 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] | 4282 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4283 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4284 | out: |
| 4285 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | return status; |
| 4287 | } |
| 4288 | |
| 4289 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4290 | { |
| 4291 | struct nfs4_exception exception = { }; |
| 4292 | int err; |
| 4293 | |
| 4294 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4295 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4296 | if (err == -NFS4ERR_DENIED) |
| 4297 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4299 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | } while (exception.retry); |
| 4301 | return err; |
| 4302 | } |
| 4303 | |
| 4304 | static int |
| 4305 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4306 | { |
| 4307 | struct nfs_open_context *ctx; |
| 4308 | struct nfs4_state *state; |
| 4309 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4310 | int status; |
| 4311 | |
| 4312 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4313 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | state = ctx->state; |
| 4315 | |
| 4316 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4317 | return -EINVAL; |
| 4318 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4319 | if (IS_GETLK(cmd)) { |
| 4320 | if (state != NULL) |
| 4321 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4322 | return 0; |
| 4323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | |
| 4325 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4326 | return -EINVAL; |
| 4327 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4328 | if (request->fl_type == F_UNLCK) { |
| 4329 | if (state != NULL) |
| 4330 | return nfs4_proc_unlck(state, cmd, request); |
| 4331 | return 0; |
| 4332 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4334 | if (state == NULL) |
| 4335 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | do { |
| 4337 | status = nfs4_proc_setlk(state, cmd, request); |
| 4338 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4339 | break; |
| 4340 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4341 | status = -ERESTARTSYS; |
| 4342 | if (signalled()) |
| 4343 | break; |
| 4344 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | return status; |
| 4346 | } |
| 4347 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4348 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4349 | { |
| 4350 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4351 | struct nfs4_exception exception = { }; |
| 4352 | int err; |
| 4353 | |
| 4354 | err = nfs4_set_lock_state(state, fl); |
| 4355 | if (err != 0) |
| 4356 | goto out; |
| 4357 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4358 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4359 | switch (err) { |
| 4360 | default: |
| 4361 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4362 | __func__, err); |
| 4363 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4364 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4365 | goto out; |
| 4366 | case -NFS4ERR_EXPIRED: |
| 4367 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4368 | case -NFS4ERR_STALE_STATEID: |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4369 | case -NFS4ERR_BADSESSION: |
| 4370 | case -NFS4ERR_BADSLOT: |
| 4371 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4372 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4373 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4374 | nfs4_schedule_state_recovery(server->nfs_client); |
| 4375 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4376 | case -ERESTARTSYS: |
| 4377 | /* |
| 4378 | * The show must go on: exit, but mark the |
| 4379 | * stateid as needing recovery. |
| 4380 | */ |
| 4381 | case -NFS4ERR_ADMIN_REVOKED: |
| 4382 | case -NFS4ERR_BAD_STATEID: |
| 4383 | case -NFS4ERR_OPENMODE: |
| 4384 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
| 4385 | err = 0; |
| 4386 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4387 | case -EKEYEXPIRED: |
| 4388 | /* |
| 4389 | * User RPCSEC_GSS context has expired. |
| 4390 | * We cannot recover this stateid now, so |
| 4391 | * skip it and allow recovery thread to |
| 4392 | * proceed. |
| 4393 | */ |
| 4394 | err = 0; |
| 4395 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4396 | case -ENOMEM: |
| 4397 | case -NFS4ERR_DENIED: |
| 4398 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4399 | err = 0; |
| 4400 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4401 | case -NFS4ERR_DELAY: |
| 4402 | break; |
| 4403 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4404 | err = nfs4_handle_exception(server, err, &exception); |
| 4405 | } while (exception.retry); |
| 4406 | out: |
| 4407 | return err; |
| 4408 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4409 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4410 | static void nfs4_release_lockowner_release(void *calldata) |
| 4411 | { |
| 4412 | kfree(calldata); |
| 4413 | } |
| 4414 | |
| 4415 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4416 | .rpc_release = nfs4_release_lockowner_release, |
| 4417 | }; |
| 4418 | |
| 4419 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4420 | { |
| 4421 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4422 | struct nfs_release_lockowner_args *args; |
| 4423 | struct rpc_message msg = { |
| 4424 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4425 | }; |
| 4426 | |
| 4427 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4428 | return; |
| 4429 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4430 | if (!args) |
| 4431 | return; |
| 4432 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4433 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4434 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4435 | msg.rpc_argp = args; |
| 4436 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4437 | } |
| 4438 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4439 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4440 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4441 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4442 | const void *buf, size_t buflen, |
| 4443 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4444 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4445 | if (strcmp(key, "") != 0) |
| 4446 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4447 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4448 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4449 | } |
| 4450 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4451 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4452 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4453 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4454 | if (strcmp(key, "") != 0) |
| 4455 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4456 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4457 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4458 | } |
| 4459 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4460 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4461 | size_t list_len, const char *name, |
| 4462 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4463 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4464 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4465 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4466 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4467 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4468 | |
| 4469 | if (list && len <= list_len) |
| 4470 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4471 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4472 | } |
| 4473 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4474 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4475 | { |
| 4476 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4477 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4478 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4479 | return; |
| 4480 | |
| 4481 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4482 | NFS_ATTR_FATTR_NLINK; |
| 4483 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4484 | fattr->nlink = 2; |
| 4485 | } |
| 4486 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4487 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4488 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4489 | { |
| 4490 | struct nfs_server *server = NFS_SERVER(dir); |
| 4491 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4492 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4493 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4494 | }; |
| 4495 | struct nfs4_fs_locations_arg args = { |
| 4496 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4497 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4498 | .page = page, |
| 4499 | .bitmask = bitmask, |
| 4500 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4501 | struct nfs4_fs_locations_res res = { |
| 4502 | .fs_locations = fs_locations, |
| 4503 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4504 | struct rpc_message msg = { |
| 4505 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4506 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4507 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4508 | }; |
| 4509 | int status; |
| 4510 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4511 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4512 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4513 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4514 | fs_locations->nlocations = 0; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 4515 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4516 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4517 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4518 | return status; |
| 4519 | } |
| 4520 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4521 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4522 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4523 | * Check the exchange flags returned by the server for invalid flags, having |
| 4524 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4525 | * DS flags set. |
| 4526 | */ |
| 4527 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4528 | { |
| 4529 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4530 | goto out_inval; |
| 4531 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4532 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4533 | goto out_inval; |
| 4534 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4535 | goto out_inval; |
| 4536 | return NFS_OK; |
| 4537 | out_inval: |
| 4538 | return -NFS4ERR_INVAL; |
| 4539 | } |
| 4540 | |
| 4541 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4542 | * nfs4_proc_exchange_id() |
| 4543 | * |
| 4544 | * Since the clientid has expired, all compounds using sessions |
| 4545 | * associated with the stale clientid will be returning |
| 4546 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4547 | * be in some phase of session reset. |
| 4548 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4549 | 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] | 4550 | { |
| 4551 | nfs4_verifier verifier; |
| 4552 | struct nfs41_exchange_id_args args = { |
| 4553 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4554 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4555 | }; |
| 4556 | struct nfs41_exchange_id_res res = { |
| 4557 | .client = clp, |
| 4558 | }; |
| 4559 | int status; |
| 4560 | struct rpc_message msg = { |
| 4561 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4562 | .rpc_argp = &args, |
| 4563 | .rpc_resp = &res, |
| 4564 | .rpc_cred = cred, |
| 4565 | }; |
| 4566 | __be32 *p; |
| 4567 | |
| 4568 | dprintk("--> %s\n", __func__); |
| 4569 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4570 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4571 | p = (u32 *)verifier.data; |
| 4572 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4573 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4574 | args.verifier = &verifier; |
| 4575 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4576 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4577 | "%s/%s.%s/%u", |
| 4578 | clp->cl_ipaddr, |
| 4579 | init_utsname()->nodename, |
| 4580 | init_utsname()->domainname, |
| 4581 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4582 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4583 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4584 | if (!status) |
| 4585 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4586 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4587 | return status; |
| 4588 | } |
| 4589 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4590 | struct nfs4_get_lease_time_data { |
| 4591 | struct nfs4_get_lease_time_args *args; |
| 4592 | struct nfs4_get_lease_time_res *res; |
| 4593 | struct nfs_client *clp; |
| 4594 | }; |
| 4595 | |
| 4596 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4597 | void *calldata) |
| 4598 | { |
| 4599 | int ret; |
| 4600 | struct nfs4_get_lease_time_data *data = |
| 4601 | (struct nfs4_get_lease_time_data *)calldata; |
| 4602 | |
| 4603 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4604 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4605 | /* just setup sequence, do not trigger session recovery |
| 4606 | since we're invoked within one */ |
| 4607 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4608 | &data->args->la_seq_args, |
| 4609 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4610 | |
| 4611 | BUG_ON(ret == -EAGAIN); |
| 4612 | rpc_call_start(task); |
| 4613 | dprintk("<-- %s\n", __func__); |
| 4614 | } |
| 4615 | |
| 4616 | /* |
| 4617 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4618 | * from sequence operation or clientid errors. |
| 4619 | */ |
| 4620 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4621 | { |
| 4622 | struct nfs4_get_lease_time_data *data = |
| 4623 | (struct nfs4_get_lease_time_data *)calldata; |
| 4624 | |
| 4625 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4626 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4627 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4628 | switch (task->tk_status) { |
| 4629 | case -NFS4ERR_DELAY: |
| 4630 | case -NFS4ERR_GRACE: |
| 4631 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4632 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4633 | task->tk_status = 0; |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4634 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4635 | return; |
| 4636 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4637 | dprintk("<-- %s\n", __func__); |
| 4638 | } |
| 4639 | |
| 4640 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4641 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4642 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4643 | }; |
| 4644 | |
| 4645 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4646 | { |
| 4647 | struct rpc_task *task; |
| 4648 | struct nfs4_get_lease_time_args args; |
| 4649 | struct nfs4_get_lease_time_res res = { |
| 4650 | .lr_fsinfo = fsinfo, |
| 4651 | }; |
| 4652 | struct nfs4_get_lease_time_data data = { |
| 4653 | .args = &args, |
| 4654 | .res = &res, |
| 4655 | .clp = clp, |
| 4656 | }; |
| 4657 | struct rpc_message msg = { |
| 4658 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4659 | .rpc_argp = &args, |
| 4660 | .rpc_resp = &res, |
| 4661 | }; |
| 4662 | struct rpc_task_setup task_setup = { |
| 4663 | .rpc_client = clp->cl_rpcclient, |
| 4664 | .rpc_message = &msg, |
| 4665 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4666 | .callback_data = &data |
| 4667 | }; |
| 4668 | int status; |
| 4669 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4670 | dprintk("--> %s\n", __func__); |
| 4671 | task = rpc_run_task(&task_setup); |
| 4672 | |
| 4673 | if (IS_ERR(task)) |
| 4674 | status = PTR_ERR(task); |
| 4675 | else { |
| 4676 | status = task->tk_status; |
| 4677 | rpc_put_task(task); |
| 4678 | } |
| 4679 | dprintk("<-- %s return %d\n", __func__, status); |
| 4680 | |
| 4681 | return status; |
| 4682 | } |
| 4683 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4684 | /* |
| 4685 | * Reset a slot table |
| 4686 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4687 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4688 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4689 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4690 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4691 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4692 | int ret = 0; |
| 4693 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4694 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4695 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4696 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4697 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4698 | if (max_reqs != tbl->max_slots) { |
| 4699 | ret = -ENOMEM; |
| 4700 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4701 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4702 | if (!new) |
| 4703 | goto out; |
| 4704 | ret = 0; |
| 4705 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4706 | } |
| 4707 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4708 | if (new) { |
| 4709 | tbl->slots = new; |
| 4710 | tbl->max_slots = max_reqs; |
| 4711 | } |
| 4712 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4713 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4714 | spin_unlock(&tbl->slot_tbl_lock); |
| 4715 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4716 | tbl, tbl->slots, tbl->max_slots); |
| 4717 | out: |
| 4718 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4719 | return ret; |
| 4720 | } |
| 4721 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4722 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4723 | * Reset the forechannel and backchannel slot tables |
| 4724 | */ |
| 4725 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4726 | { |
| 4727 | int status; |
| 4728 | |
| 4729 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4730 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4731 | if (status) |
| 4732 | return status; |
| 4733 | |
| 4734 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4735 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4736 | return status; |
| 4737 | } |
| 4738 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4739 | /* Destroy the slot table */ |
| 4740 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4741 | { |
| 4742 | if (session->fc_slot_table.slots != NULL) { |
| 4743 | kfree(session->fc_slot_table.slots); |
| 4744 | session->fc_slot_table.slots = NULL; |
| 4745 | } |
| 4746 | if (session->bc_slot_table.slots != NULL) { |
| 4747 | kfree(session->bc_slot_table.slots); |
| 4748 | session->bc_slot_table.slots = NULL; |
| 4749 | } |
| 4750 | return; |
| 4751 | } |
| 4752 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4753 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4754 | * Initialize slot table |
| 4755 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4756 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4757 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4758 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4759 | struct nfs4_slot *slot; |
| 4760 | int ret = -ENOMEM; |
| 4761 | |
| 4762 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4763 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4764 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4765 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4766 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4767 | if (!slot) |
| 4768 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4769 | ret = 0; |
| 4770 | |
| 4771 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4772 | tbl->max_slots = max_slots; |
| 4773 | tbl->slots = slot; |
| 4774 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4775 | spin_unlock(&tbl->slot_tbl_lock); |
| 4776 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4777 | tbl, tbl->slots, tbl->max_slots); |
| 4778 | out: |
| 4779 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4780 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4781 | } |
| 4782 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4783 | /* |
| 4784 | * Initialize the forechannel and backchannel tables |
| 4785 | */ |
| 4786 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4787 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4788 | struct nfs4_slot_table *tbl; |
| 4789 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4790 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4791 | tbl = &session->fc_slot_table; |
| 4792 | if (tbl->slots == NULL) { |
| 4793 | status = nfs4_init_slot_table(tbl, |
| 4794 | session->fc_attrs.max_reqs, 1); |
| 4795 | if (status) |
| 4796 | return status; |
| 4797 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4798 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4799 | tbl = &session->bc_slot_table; |
| 4800 | if (tbl->slots == NULL) { |
| 4801 | status = nfs4_init_slot_table(tbl, |
| 4802 | session->bc_attrs.max_reqs, 0); |
| 4803 | if (status) |
| 4804 | nfs4_destroy_slot_tables(session); |
| 4805 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4806 | |
| 4807 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 4811 | { |
| 4812 | struct nfs4_session *session; |
| 4813 | struct nfs4_slot_table *tbl; |
| 4814 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4815 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4816 | if (!session) |
| 4817 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4818 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4819 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4820 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4821 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4822 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4823 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4824 | |
| 4825 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4826 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4827 | spin_lock_init(&tbl->slot_tbl_lock); |
| 4828 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4829 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4830 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 4831 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 4832 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4833 | session->clp = clp; |
| 4834 | return session; |
| 4835 | } |
| 4836 | |
| 4837 | void nfs4_destroy_session(struct nfs4_session *session) |
| 4838 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 4839 | nfs4_proc_destroy_session(session); |
| 4840 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 4841 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 4842 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 4843 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4844 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4845 | kfree(session); |
| 4846 | } |
| 4847 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4848 | /* |
| 4849 | * Initialize the values to be used by the client in CREATE_SESSION |
| 4850 | * If nfs4_init_session set the fore channel request and response sizes, |
| 4851 | * use them. |
| 4852 | * |
| 4853 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 4854 | * always set csa_cachethis to FALSE because the current implementation |
| 4855 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 4856 | */ |
| 4857 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 4858 | { |
| 4859 | struct nfs4_session *session = args->client->cl_session; |
| 4860 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 4861 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 4862 | |
| 4863 | if (mxrqst_sz == 0) |
| 4864 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 4865 | if (mxresp_sz == 0) |
| 4866 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 4867 | /* Fore channel attributes */ |
| 4868 | args->fc_attrs.headerpadsz = 0; |
| 4869 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 4870 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4871 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 4872 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 4873 | |
| 4874 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4875 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4876 | __func__, |
| 4877 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4878 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4879 | |
| 4880 | /* Back channel attributes */ |
| 4881 | args->bc_attrs.headerpadsz = 0; |
| 4882 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 4883 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 4884 | args->bc_attrs.max_resp_sz_cached = 0; |
| 4885 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 4886 | args->bc_attrs.max_reqs = 1; |
| 4887 | |
| 4888 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 4889 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 4890 | __func__, |
| 4891 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 4892 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 4893 | args->bc_attrs.max_reqs); |
| 4894 | } |
| 4895 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4896 | 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] | 4897 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4898 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 4899 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 4900 | |
| 4901 | if (rcvd->headerpadsz > sent->headerpadsz) |
| 4902 | return -EINVAL; |
| 4903 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 4904 | return -EINVAL; |
| 4905 | /* |
| 4906 | * Our requested max_ops is the minimum we need; we're not |
| 4907 | * prepared to break up compounds into smaller pieces than that. |
| 4908 | * So, no point even trying to continue if the server won't |
| 4909 | * cooperate: |
| 4910 | */ |
| 4911 | if (rcvd->max_ops < sent->max_ops) |
| 4912 | return -EINVAL; |
| 4913 | if (rcvd->max_reqs == 0) |
| 4914 | return -EINVAL; |
| 4915 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4916 | } |
| 4917 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4918 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 4919 | { |
| 4920 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 4921 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4922 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4923 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 4924 | return -EINVAL; |
| 4925 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 4926 | return -EINVAL; |
| 4927 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 4928 | return -EINVAL; |
| 4929 | /* These would render the backchannel useless: */ |
| 4930 | if (rcvd->max_ops == 0) |
| 4931 | return -EINVAL; |
| 4932 | if (rcvd->max_reqs == 0) |
| 4933 | return -EINVAL; |
| 4934 | return 0; |
| 4935 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4936 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4937 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 4938 | struct nfs4_session *session) |
| 4939 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4940 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4941 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4942 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 4943 | if (ret) |
| 4944 | return ret; |
| 4945 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4946 | } |
| 4947 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4948 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 4949 | { |
| 4950 | struct nfs4_session *session = clp->cl_session; |
| 4951 | struct nfs41_create_session_args args = { |
| 4952 | .client = clp, |
| 4953 | .cb_program = NFS4_CALLBACK, |
| 4954 | }; |
| 4955 | struct nfs41_create_session_res res = { |
| 4956 | .client = clp, |
| 4957 | }; |
| 4958 | struct rpc_message msg = { |
| 4959 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 4960 | .rpc_argp = &args, |
| 4961 | .rpc_resp = &res, |
| 4962 | }; |
| 4963 | int status; |
| 4964 | |
| 4965 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 4966 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4967 | |
| 4968 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 4969 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4970 | if (!status) |
| 4971 | /* Verify the session's negotiated channel_attrs values */ |
| 4972 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4973 | if (!status) { |
| 4974 | /* Increment the clientid slot sequence id */ |
| 4975 | clp->cl_seqid++; |
| 4976 | } |
| 4977 | |
| 4978 | return status; |
| 4979 | } |
| 4980 | |
| 4981 | /* |
| 4982 | * Issues a CREATE_SESSION operation to the server. |
| 4983 | * It is the responsibility of the caller to verify the session is |
| 4984 | * expired before calling this routine. |
| 4985 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4986 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4987 | { |
| 4988 | int status; |
| 4989 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4990 | struct nfs4_session *session = clp->cl_session; |
| 4991 | |
| 4992 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 4993 | |
| 4994 | status = _nfs4_proc_create_session(clp); |
| 4995 | if (status) |
| 4996 | goto out; |
| 4997 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4998 | /* Init and reset the fore channel */ |
| 4999 | status = nfs4_init_slot_tables(session); |
| 5000 | dprintk("slot table initialization returned %d\n", status); |
| 5001 | if (status) |
| 5002 | goto out; |
| 5003 | status = nfs4_reset_slot_tables(session); |
| 5004 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5005 | if (status) |
| 5006 | goto out; |
| 5007 | |
| 5008 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5009 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5010 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5011 | out: |
| 5012 | dprintk("<-- %s\n", __func__); |
| 5013 | return status; |
| 5014 | } |
| 5015 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5016 | /* |
| 5017 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5018 | * The caller must serialize access to this routine. |
| 5019 | */ |
| 5020 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5021 | { |
| 5022 | int status = 0; |
| 5023 | struct rpc_message msg; |
| 5024 | |
| 5025 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5026 | |
| 5027 | /* session is still being setup */ |
| 5028 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5029 | return status; |
| 5030 | |
| 5031 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5032 | msg.rpc_argp = session; |
| 5033 | msg.rpc_resp = NULL; |
| 5034 | msg.rpc_cred = NULL; |
| 5035 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5036 | |
| 5037 | if (status) |
| 5038 | printk(KERN_WARNING |
| 5039 | "Got error %d from the server on DESTROY_SESSION. " |
| 5040 | "Session has been destroyed regardless...\n", status); |
| 5041 | |
| 5042 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5043 | return status; |
| 5044 | } |
| 5045 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5046 | int nfs4_init_session(struct nfs_server *server) |
| 5047 | { |
| 5048 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5049 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5050 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5051 | int ret; |
| 5052 | |
| 5053 | if (!nfs4_has_session(clp)) |
| 5054 | return 0; |
| 5055 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5056 | session = clp->cl_session; |
| 5057 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5058 | return 0; |
| 5059 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5060 | rsize = server->rsize; |
| 5061 | if (rsize == 0) |
| 5062 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5063 | wsize = server->wsize; |
| 5064 | if (wsize == 0) |
| 5065 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5066 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5067 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5068 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5069 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5070 | ret = nfs4_recover_expired_lease(server); |
| 5071 | if (!ret) |
| 5072 | ret = nfs4_check_client_ready(clp); |
| 5073 | return ret; |
| 5074 | } |
| 5075 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5076 | /* |
| 5077 | * Renew the cl_session lease. |
| 5078 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5079 | struct nfs4_sequence_data { |
| 5080 | struct nfs_client *clp; |
| 5081 | struct nfs4_sequence_args args; |
| 5082 | struct nfs4_sequence_res res; |
| 5083 | }; |
| 5084 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5085 | static void nfs41_sequence_release(void *data) |
| 5086 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5087 | struct nfs4_sequence_data *calldata = data; |
| 5088 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5089 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5090 | if (atomic_read(&clp->cl_count) > 1) |
| 5091 | nfs4_schedule_state_renewal(clp); |
| 5092 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5093 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5094 | } |
| 5095 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5096 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5097 | { |
| 5098 | switch(task->tk_status) { |
| 5099 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5100 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5101 | return -EAGAIN; |
| 5102 | default: |
| 5103 | nfs4_schedule_state_recovery(clp); |
| 5104 | } |
| 5105 | return 0; |
| 5106 | } |
| 5107 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5108 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5109 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5110 | struct nfs4_sequence_data *calldata = data; |
| 5111 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5112 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5113 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5114 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5115 | |
| 5116 | if (task->tk_status < 0) { |
| 5117 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5118 | if (atomic_read(&clp->cl_count) == 1) |
| 5119 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5120 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5121 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5122 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5123 | return; |
| 5124 | } |
| 5125 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5126 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5127 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5128 | dprintk("<-- %s\n", __func__); |
| 5129 | } |
| 5130 | |
| 5131 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5132 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5133 | struct nfs4_sequence_data *calldata = data; |
| 5134 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5135 | struct nfs4_sequence_args *args; |
| 5136 | struct nfs4_sequence_res *res; |
| 5137 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5138 | args = task->tk_msg.rpc_argp; |
| 5139 | res = task->tk_msg.rpc_resp; |
| 5140 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5141 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5142 | return; |
| 5143 | rpc_call_start(task); |
| 5144 | } |
| 5145 | |
| 5146 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5147 | .rpc_call_done = nfs41_sequence_call_done, |
| 5148 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5149 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5150 | }; |
| 5151 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5152 | 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] | 5153 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5154 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5155 | struct rpc_message msg = { |
| 5156 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5157 | .rpc_cred = cred, |
| 5158 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5159 | struct rpc_task_setup task_setup_data = { |
| 5160 | .rpc_client = clp->cl_rpcclient, |
| 5161 | .rpc_message = &msg, |
| 5162 | .callback_ops = &nfs41_sequence_ops, |
| 5163 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5164 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5165 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5166 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5167 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5168 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5169 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5170 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5171 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5172 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5173 | msg.rpc_argp = &calldata->args; |
| 5174 | msg.rpc_resp = &calldata->res; |
| 5175 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5176 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5177 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5178 | return rpc_run_task(&task_setup_data); |
| 5179 | } |
| 5180 | |
| 5181 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5182 | { |
| 5183 | struct rpc_task *task; |
| 5184 | int ret = 0; |
| 5185 | |
| 5186 | task = _nfs41_proc_sequence(clp, cred); |
| 5187 | if (IS_ERR(task)) |
| 5188 | ret = PTR_ERR(task); |
| 5189 | else |
| 5190 | rpc_put_task(task); |
| 5191 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5192 | return ret; |
| 5193 | } |
| 5194 | |
| 5195 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5196 | { |
| 5197 | struct rpc_task *task; |
| 5198 | int ret; |
| 5199 | |
| 5200 | task = _nfs41_proc_sequence(clp, cred); |
| 5201 | if (IS_ERR(task)) { |
| 5202 | ret = PTR_ERR(task); |
| 5203 | goto out; |
| 5204 | } |
| 5205 | ret = rpc_wait_for_completion_task(task); |
| 5206 | if (!ret) |
| 5207 | ret = task->tk_status; |
| 5208 | rpc_put_task(task); |
| 5209 | out: |
| 5210 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5211 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5212 | } |
| 5213 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5214 | struct nfs4_reclaim_complete_data { |
| 5215 | struct nfs_client *clp; |
| 5216 | struct nfs41_reclaim_complete_args arg; |
| 5217 | struct nfs41_reclaim_complete_res res; |
| 5218 | }; |
| 5219 | |
| 5220 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5221 | { |
| 5222 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5223 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5224 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5225 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5226 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5227 | &calldata->res.seq_res, 0, task)) |
| 5228 | return; |
| 5229 | |
| 5230 | rpc_call_start(task); |
| 5231 | } |
| 5232 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5233 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5234 | { |
| 5235 | switch(task->tk_status) { |
| 5236 | case 0: |
| 5237 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5238 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5239 | break; |
| 5240 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5241 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5242 | return -EAGAIN; |
| 5243 | default: |
| 5244 | nfs4_schedule_state_recovery(clp); |
| 5245 | } |
| 5246 | return 0; |
| 5247 | } |
| 5248 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5249 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5250 | { |
| 5251 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5252 | struct nfs_client *clp = calldata->clp; |
| 5253 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5254 | |
| 5255 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5256 | if (!nfs41_sequence_done(task, res)) |
| 5257 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5258 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5259 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5260 | rpc_restart_call_prepare(task); |
| 5261 | return; |
| 5262 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5263 | dprintk("<-- %s\n", __func__); |
| 5264 | } |
| 5265 | |
| 5266 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5267 | { |
| 5268 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5269 | |
| 5270 | kfree(calldata); |
| 5271 | } |
| 5272 | |
| 5273 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5274 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5275 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5276 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5277 | }; |
| 5278 | |
| 5279 | /* |
| 5280 | * Issue a global reclaim complete. |
| 5281 | */ |
| 5282 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5283 | { |
| 5284 | struct nfs4_reclaim_complete_data *calldata; |
| 5285 | struct rpc_task *task; |
| 5286 | struct rpc_message msg = { |
| 5287 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5288 | }; |
| 5289 | struct rpc_task_setup task_setup_data = { |
| 5290 | .rpc_client = clp->cl_rpcclient, |
| 5291 | .rpc_message = &msg, |
| 5292 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5293 | .flags = RPC_TASK_ASYNC, |
| 5294 | }; |
| 5295 | int status = -ENOMEM; |
| 5296 | |
| 5297 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5298 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5299 | if (calldata == NULL) |
| 5300 | goto out; |
| 5301 | calldata->clp = clp; |
| 5302 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5303 | |
| 5304 | msg.rpc_argp = &calldata->arg; |
| 5305 | msg.rpc_resp = &calldata->res; |
| 5306 | task_setup_data.callback_data = calldata; |
| 5307 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5308 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5309 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5310 | goto out; |
| 5311 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5312 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5313 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5314 | out: |
| 5315 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5316 | return status; |
| 5317 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5318 | |
| 5319 | static void |
| 5320 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5321 | { |
| 5322 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5323 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5324 | |
| 5325 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5326 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5327 | * right now covering the LAYOUTGET we are about to send. |
| 5328 | * However, that is not so catastrophic, and there seems |
| 5329 | * to be no way to prevent it completely. |
| 5330 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5331 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5332 | &lgp->res.seq_res, 0, task)) |
| 5333 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5334 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5335 | NFS_I(lgp->args.inode)->layout, |
| 5336 | lgp->args.ctx->state)) { |
| 5337 | rpc_exit(task, NFS4_OK); |
| 5338 | return; |
| 5339 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5340 | rpc_call_start(task); |
| 5341 | } |
| 5342 | |
| 5343 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5344 | { |
| 5345 | struct nfs4_layoutget *lgp = calldata; |
| 5346 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5347 | |
| 5348 | dprintk("--> %s\n", __func__); |
| 5349 | |
| 5350 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5351 | return; |
| 5352 | |
| 5353 | switch (task->tk_status) { |
| 5354 | case 0: |
| 5355 | break; |
| 5356 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5357 | case -NFS4ERR_RECALLCONFLICT: |
| 5358 | task->tk_status = -NFS4ERR_DELAY; |
| 5359 | /* Fall through */ |
| 5360 | default: |
| 5361 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5362 | rpc_restart_call_prepare(task); |
| 5363 | return; |
| 5364 | } |
| 5365 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5366 | dprintk("<-- %s\n", __func__); |
| 5367 | } |
| 5368 | |
| 5369 | static void nfs4_layoutget_release(void *calldata) |
| 5370 | { |
| 5371 | struct nfs4_layoutget *lgp = calldata; |
| 5372 | |
| 5373 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5374 | if (lgp->res.layout.buf != NULL) |
| 5375 | free_page((unsigned long) lgp->res.layout.buf); |
| 5376 | put_nfs_open_context(lgp->args.ctx); |
| 5377 | kfree(calldata); |
| 5378 | dprintk("<-- %s\n", __func__); |
| 5379 | } |
| 5380 | |
| 5381 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5382 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5383 | .rpc_call_done = nfs4_layoutget_done, |
| 5384 | .rpc_release = nfs4_layoutget_release, |
| 5385 | }; |
| 5386 | |
| 5387 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5388 | { |
| 5389 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5390 | struct rpc_task *task; |
| 5391 | struct rpc_message msg = { |
| 5392 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5393 | .rpc_argp = &lgp->args, |
| 5394 | .rpc_resp = &lgp->res, |
| 5395 | }; |
| 5396 | struct rpc_task_setup task_setup_data = { |
| 5397 | .rpc_client = server->client, |
| 5398 | .rpc_message = &msg, |
| 5399 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5400 | .callback_data = lgp, |
| 5401 | .flags = RPC_TASK_ASYNC, |
| 5402 | }; |
| 5403 | int status = 0; |
| 5404 | |
| 5405 | dprintk("--> %s\n", __func__); |
| 5406 | |
| 5407 | lgp->res.layout.buf = (void *)__get_free_page(GFP_NOFS); |
| 5408 | if (lgp->res.layout.buf == NULL) { |
| 5409 | nfs4_layoutget_release(lgp); |
| 5410 | return -ENOMEM; |
| 5411 | } |
| 5412 | |
| 5413 | lgp->res.seq_res.sr_slot = NULL; |
| 5414 | task = rpc_run_task(&task_setup_data); |
| 5415 | if (IS_ERR(task)) |
| 5416 | return PTR_ERR(task); |
| 5417 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5418 | if (status == 0) |
| 5419 | status = task->tk_status; |
| 5420 | if (status == 0) |
| 5421 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5422 | rpc_put_task(task); |
| 5423 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5424 | return status; |
| 5425 | } |
| 5426 | |
| 5427 | static int |
| 5428 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5429 | { |
| 5430 | struct nfs4_getdeviceinfo_args args = { |
| 5431 | .pdev = pdev, |
| 5432 | }; |
| 5433 | struct nfs4_getdeviceinfo_res res = { |
| 5434 | .pdev = pdev, |
| 5435 | }; |
| 5436 | struct rpc_message msg = { |
| 5437 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5438 | .rpc_argp = &args, |
| 5439 | .rpc_resp = &res, |
| 5440 | }; |
| 5441 | int status; |
| 5442 | |
| 5443 | dprintk("--> %s\n", __func__); |
| 5444 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
| 5445 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5446 | |
| 5447 | return status; |
| 5448 | } |
| 5449 | |
| 5450 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5451 | { |
| 5452 | struct nfs4_exception exception = { }; |
| 5453 | int err; |
| 5454 | |
| 5455 | do { |
| 5456 | err = nfs4_handle_exception(server, |
| 5457 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5458 | &exception); |
| 5459 | } while (exception.retry); |
| 5460 | return err; |
| 5461 | } |
| 5462 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5463 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5464 | #endif /* CONFIG_NFS_V4_1 */ |
| 5465 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5466 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5467 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5468 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5469 | .recover_open = nfs4_open_reclaim, |
| 5470 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5471 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5472 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5473 | }; |
| 5474 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5475 | #if defined(CONFIG_NFS_V4_1) |
| 5476 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5477 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5478 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5479 | .recover_open = nfs4_open_reclaim, |
| 5480 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5481 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5482 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5483 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5484 | }; |
| 5485 | #endif /* CONFIG_NFS_V4_1 */ |
| 5486 | |
| 5487 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5488 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5489 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5490 | .recover_open = nfs4_open_expired, |
| 5491 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5492 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5493 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | }; |
| 5495 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5496 | #if defined(CONFIG_NFS_V4_1) |
| 5497 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5498 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5499 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5500 | .recover_open = nfs4_open_expired, |
| 5501 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5502 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5503 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5504 | }; |
| 5505 | #endif /* CONFIG_NFS_V4_1 */ |
| 5506 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5507 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5508 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5509 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5510 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5511 | }; |
| 5512 | |
| 5513 | #if defined(CONFIG_NFS_V4_1) |
| 5514 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5515 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5516 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5517 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5518 | }; |
| 5519 | #endif |
| 5520 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5521 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 5522 | .minor_version = 0, |
| 5523 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5524 | .validate_stateid = nfs4_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5525 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 5526 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 5527 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5528 | }; |
| 5529 | |
| 5530 | #if defined(CONFIG_NFS_V4_1) |
| 5531 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 5532 | .minor_version = 1, |
| 5533 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5534 | .validate_stateid = nfs41_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5535 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 5536 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 5537 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5538 | }; |
| 5539 | #endif |
| 5540 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5541 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 5542 | [0] = &nfs_v4_0_minor_ops, |
| 5543 | #if defined(CONFIG_NFS_V4_1) |
| 5544 | [1] = &nfs_v4_1_minor_ops, |
| 5545 | #endif |
| 5546 | }; |
| 5547 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5548 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5549 | .permission = nfs_permission, |
| 5550 | .getattr = nfs_getattr, |
| 5551 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5552 | .getxattr = generic_getxattr, |
| 5553 | .setxattr = generic_setxattr, |
| 5554 | .listxattr = generic_listxattr, |
| 5555 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5556 | }; |
| 5557 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5558 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5559 | .version = 4, /* protocol version */ |
| 5560 | .dentry_ops = &nfs4_dentry_operations, |
| 5561 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5562 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5563 | .getroot = nfs4_proc_get_root, |
| 5564 | .getattr = nfs4_proc_getattr, |
| 5565 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5566 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | .lookup = nfs4_proc_lookup, |
| 5568 | .access = nfs4_proc_access, |
| 5569 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5570 | .create = nfs4_proc_create, |
| 5571 | .remove = nfs4_proc_remove, |
| 5572 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5573 | .unlink_done = nfs4_proc_unlink_done, |
| 5574 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 5575 | .rename_setup = nfs4_proc_rename_setup, |
| 5576 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5577 | .link = nfs4_proc_link, |
| 5578 | .symlink = nfs4_proc_symlink, |
| 5579 | .mkdir = nfs4_proc_mkdir, |
| 5580 | .rmdir = nfs4_proc_remove, |
| 5581 | .readdir = nfs4_proc_readdir, |
| 5582 | .mknod = nfs4_proc_mknod, |
| 5583 | .statfs = nfs4_proc_statfs, |
| 5584 | .fsinfo = nfs4_proc_fsinfo, |
| 5585 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5586 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | .decode_dirent = nfs4_decode_dirent, |
| 5588 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5589 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5591 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5592 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5593 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5594 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5595 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5596 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 5597 | .open_context = nfs4_atomic_open, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | }; |
| 5599 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5600 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 5601 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 5602 | .list = nfs4_xattr_list_nfs4_acl, |
| 5603 | .get = nfs4_xattr_get_nfs4_acl, |
| 5604 | .set = nfs4_xattr_set_nfs4_acl, |
| 5605 | }; |
| 5606 | |
| 5607 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 5608 | &nfs4_xattr_nfs4_acl_handler, |
| 5609 | NULL |
| 5610 | }; |
| 5611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5612 | /* |
| 5613 | * Local variables: |
| 5614 | * c-basic-offset: 8 |
| 5615 | * End: |
| 5616 | */ |