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> |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 54 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 56 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 58 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 59 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 60 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 61 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 64 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 65 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 67 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 68 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 69 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 70 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 71 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 72 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | 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] | 74 | 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] | 75 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
| 76 | 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] | 77 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 78 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 79 | struct nfs4_state *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 82 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 84 | if (err >= -1000) |
| 85 | return err; |
| 86 | switch (err) { |
| 87 | case -NFS4ERR_RESOURCE: |
| 88 | return -EREMOTEIO; |
| 89 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 91 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 92 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 94 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* |
| 98 | * This is our standard bitmap for GETATTR requests. |
| 99 | */ |
| 100 | const u32 nfs4_fattr_bitmap[2] = { |
| 101 | FATTR4_WORD0_TYPE |
| 102 | | FATTR4_WORD0_CHANGE |
| 103 | | FATTR4_WORD0_SIZE |
| 104 | | FATTR4_WORD0_FSID |
| 105 | | FATTR4_WORD0_FILEID, |
| 106 | FATTR4_WORD1_MODE |
| 107 | | FATTR4_WORD1_NUMLINKS |
| 108 | | FATTR4_WORD1_OWNER |
| 109 | | FATTR4_WORD1_OWNER_GROUP |
| 110 | | FATTR4_WORD1_RAWDEV |
| 111 | | FATTR4_WORD1_SPACE_USED |
| 112 | | FATTR4_WORD1_TIME_ACCESS |
| 113 | | FATTR4_WORD1_TIME_METADATA |
| 114 | | FATTR4_WORD1_TIME_MODIFY |
| 115 | }; |
| 116 | |
| 117 | const u32 nfs4_statfs_bitmap[2] = { |
| 118 | FATTR4_WORD0_FILES_AVAIL |
| 119 | | FATTR4_WORD0_FILES_FREE |
| 120 | | FATTR4_WORD0_FILES_TOTAL, |
| 121 | FATTR4_WORD1_SPACE_AVAIL |
| 122 | | FATTR4_WORD1_SPACE_FREE |
| 123 | | FATTR4_WORD1_SPACE_TOTAL |
| 124 | }; |
| 125 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 126 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | FATTR4_WORD0_MAXLINK |
| 128 | | FATTR4_WORD0_MAXNAME, |
| 129 | 0 |
| 130 | }; |
| 131 | |
| 132 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 133 | | FATTR4_WORD0_MAXREAD |
| 134 | | FATTR4_WORD0_MAXWRITE |
| 135 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 136 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 137 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 140 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 141 | FATTR4_WORD0_TYPE |
| 142 | | FATTR4_WORD0_CHANGE |
| 143 | | FATTR4_WORD0_SIZE |
| 144 | | FATTR4_WORD0_FSID |
| 145 | | FATTR4_WORD0_FILEID |
| 146 | | FATTR4_WORD0_FS_LOCATIONS, |
| 147 | FATTR4_WORD1_MODE |
| 148 | | FATTR4_WORD1_NUMLINKS |
| 149 | | FATTR4_WORD1_OWNER |
| 150 | | FATTR4_WORD1_OWNER_GROUP |
| 151 | | FATTR4_WORD1_RAWDEV |
| 152 | | FATTR4_WORD1_SPACE_USED |
| 153 | | FATTR4_WORD1_TIME_ACCESS |
| 154 | | FATTR4_WORD1_TIME_METADATA |
| 155 | | FATTR4_WORD1_TIME_MODIFY |
| 156 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 157 | }; |
| 158 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 159 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | struct nfs4_readdir_arg *readdir) |
| 161 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 162 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | BUG_ON(readdir->count < 80); |
| 165 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 166 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | readdir->cookie = 0; |
| 172 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 173 | if (cookie == 2) |
| 174 | return; |
| 175 | |
| 176 | /* |
| 177 | * NFSv4 servers do not return entries for '.' and '..' |
| 178 | * Therefore, we fake these entries here. We let '.' |
| 179 | * have cookie 0 and '..' have cookie 1. Note that |
| 180 | * when talking to the server, we always send cookie 0 |
| 181 | * instead of 1 or 2. |
| 182 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 183 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | if (cookie == 0) { |
| 186 | *p++ = xdr_one; /* next */ |
| 187 | *p++ = xdr_zero; /* cookie, first word */ |
| 188 | *p++ = xdr_one; /* cookie, second word */ |
| 189 | *p++ = xdr_one; /* entry len */ |
| 190 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 191 | p++; |
| 192 | *p++ = xdr_one; /* bitmap length */ |
| 193 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 194 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 195 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | *p++ = xdr_one; /* next */ |
| 199 | *p++ = xdr_zero; /* cookie, first word */ |
| 200 | *p++ = xdr_two; /* cookie, second word */ |
| 201 | *p++ = xdr_two; /* entry len */ |
| 202 | memcpy(p, "..\0\0", 4); /* entry */ |
| 203 | p++; |
| 204 | *p++ = xdr_one; /* bitmap length */ |
| 205 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 206 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 207 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | readdir->pgbase = (char *)p - (char *)start; |
| 210 | readdir->count -= readdir->pgbase; |
| 211 | kunmap_atomic(start, KM_USER0); |
| 212 | } |
| 213 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 214 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 215 | { |
| 216 | int res; |
| 217 | |
| 218 | might_sleep(); |
| 219 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 220 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 221 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 222 | return res; |
| 223 | } |
| 224 | |
| 225 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 226 | { |
| 227 | int res = 0; |
| 228 | |
| 229 | might_sleep(); |
| 230 | |
| 231 | if (*timeout <= 0) |
| 232 | *timeout = NFS4_POLL_RETRY_MIN; |
| 233 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 234 | *timeout = NFS4_POLL_RETRY_MAX; |
| 235 | schedule_timeout_killable(*timeout); |
| 236 | if (fatal_signal_pending(current)) |
| 237 | res = -ERESTARTSYS; |
| 238 | *timeout <<= 1; |
| 239 | return res; |
| 240 | } |
| 241 | |
| 242 | /* This is the error handling routine for processes that are allowed |
| 243 | * to sleep. |
| 244 | */ |
| 245 | static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
| 246 | { |
| 247 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 248 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 249 | int ret = errorcode; |
| 250 | |
| 251 | exception->retry = 0; |
| 252 | switch(errorcode) { |
| 253 | case 0: |
| 254 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 255 | case -NFS4ERR_ADMIN_REVOKED: |
| 256 | case -NFS4ERR_BAD_STATEID: |
| 257 | case -NFS4ERR_OPENMODE: |
| 258 | if (state == NULL) |
| 259 | break; |
| 260 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 261 | goto do_state_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 262 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 263 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 264 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 265 | goto do_state_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 266 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 267 | case -NFS4ERR_BADSESSION: |
| 268 | case -NFS4ERR_BADSLOT: |
| 269 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 270 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 271 | case -NFS4ERR_DEADSESSION: |
| 272 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 273 | case -NFS4ERR_SEQ_MISORDERED: |
| 274 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 275 | errorcode); |
Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 276 | nfs4_schedule_state_recovery(clp); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 277 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 278 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 279 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 280 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 281 | if (exception->timeout > HZ) { |
| 282 | /* We have retried a decent amount, time to |
| 283 | * fail |
| 284 | */ |
| 285 | ret = -EBUSY; |
| 286 | break; |
| 287 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 288 | case -NFS4ERR_GRACE: |
| 289 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 290 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 291 | ret = nfs4_delay(server->client, &exception->timeout); |
| 292 | if (ret != 0) |
| 293 | break; |
| 294 | case -NFS4ERR_OLD_STATEID: |
| 295 | exception->retry = 1; |
| 296 | } |
| 297 | /* We failed to handle the error */ |
| 298 | return nfs4_map_errors(ret); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 299 | do_state_recovery: |
| 300 | nfs4_schedule_state_recovery(clp); |
| 301 | ret = nfs4_wait_clnt_recover(clp); |
| 302 | if (ret == 0) |
| 303 | exception->retry = 1; |
| 304 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 308 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | spin_lock(&clp->cl_lock); |
| 311 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 312 | clp->cl_last_renewal = timestamp; |
| 313 | spin_unlock(&clp->cl_lock); |
| 314 | } |
| 315 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 316 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 317 | { |
| 318 | do_renew_lease(server->nfs_client, timestamp); |
| 319 | } |
| 320 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 321 | #if defined(CONFIG_NFS_V4_1) |
| 322 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 323 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 324 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 325 | * |
| 326 | * freeing a slot is trivially done by clearing its respective bit |
| 327 | * in the bitmap. |
| 328 | * If the freed slotid equals highest_used_slotid we want to update it |
| 329 | * so that the server would be able to size down the slot table if needed, |
| 330 | * otherwise we know that the highest_used_slotid is still in use. |
| 331 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 332 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 333 | * highest slotid in use. |
| 334 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 335 | * |
| 336 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 337 | */ |
| 338 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 339 | 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] | 340 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 341 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 342 | int slotid = free_slotid; |
| 343 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 344 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 345 | /* clear used bit in bitmap */ |
| 346 | __clear_bit(slotid, tbl->used_slots); |
| 347 | |
| 348 | /* update highest_used_slotid when it is freed */ |
| 349 | if (slotid == tbl->highest_used_slotid) { |
| 350 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 351 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 352 | tbl->highest_used_slotid = slotid; |
| 353 | else |
| 354 | tbl->highest_used_slotid = -1; |
| 355 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 356 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 357 | free_slotid, tbl->highest_used_slotid); |
| 358 | } |
| 359 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 360 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 361 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 362 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 363 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 364 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 365 | struct rpc_task *task; |
| 366 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 367 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 368 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 369 | if (task) |
| 370 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 371 | return; |
| 372 | } |
| 373 | |
| 374 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 375 | return; |
| 376 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 377 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 378 | complete(&ses->fc_slot_table.complete); |
| 379 | } |
| 380 | |
| 381 | /* |
| 382 | * Signal state manager thread if session back channel is drained |
| 383 | */ |
| 384 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 385 | { |
| 386 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 387 | ses->bc_slot_table.highest_used_slotid != -1) |
| 388 | return; |
| 389 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 390 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 391 | } |
| 392 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 393 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 394 | { |
| 395 | struct nfs4_slot_table *tbl; |
| 396 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 397 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 398 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 399 | /* just wake up the next guy waiting since |
| 400 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 401 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 402 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 403 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 404 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 405 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 406 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 407 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 408 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 409 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 410 | } |
| 411 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 412 | 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] | 413 | { |
| 414 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 415 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 416 | |
| 417 | /* |
| 418 | * sr_status remains 1 if an RPC level error occurred. The server |
| 419 | * may or may not have processed the sequence operation.. |
| 420 | * Proceed as if the server received and processed the sequence |
| 421 | * operation. |
| 422 | */ |
| 423 | if (res->sr_status == 1) |
| 424 | res->sr_status = NFS_OK; |
| 425 | |
| 426 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 427 | if (!res->sr_slot) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 428 | goto out; |
| 429 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 430 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 431 | switch (res->sr_status) { |
| 432 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 433 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 434 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 435 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 436 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 437 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 438 | /* Check sequence flags */ |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 439 | if (atomic_read(&clp->cl_count) > 1) |
| 440 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 441 | break; |
| 442 | case -NFS4ERR_DELAY: |
| 443 | /* The server detected a resend of the RPC call and |
| 444 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 445 | * of RFC5661. |
| 446 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 447 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 448 | __func__, |
| 449 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 450 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 451 | goto out_retry; |
| 452 | default: |
| 453 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 454 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 455 | } |
| 456 | out: |
| 457 | /* The session may be reset by one of the error handlers. */ |
| 458 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 459 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 460 | return 1; |
| 461 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 462 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 463 | goto out; |
| 464 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 465 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 466 | } |
| 467 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 468 | static int nfs4_sequence_done(struct rpc_task *task, |
| 469 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 470 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 471 | if (res->sr_session == NULL) |
| 472 | return 1; |
| 473 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 474 | } |
| 475 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 476 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 477 | * nfs4_find_slot - efficiently look for a free slot |
| 478 | * |
| 479 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 480 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 481 | * and respectively set up the sequence operation args. |
| 482 | * 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] | 483 | * |
| 484 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 485 | */ |
| 486 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 487 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 488 | { |
| 489 | int slotid; |
| 490 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 491 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 492 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 493 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 494 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 495 | tbl->max_slots); |
| 496 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 497 | if (slotid >= tbl->max_slots) |
| 498 | goto out; |
| 499 | __set_bit(slotid, tbl->used_slots); |
| 500 | if (slotid > tbl->highest_used_slotid) |
| 501 | tbl->highest_used_slotid = slotid; |
| 502 | ret_id = slotid; |
| 503 | out: |
| 504 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 505 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 506 | return ret_id; |
| 507 | } |
| 508 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 509 | static int nfs41_setup_sequence(struct nfs4_session *session, |
| 510 | struct nfs4_sequence_args *args, |
| 511 | struct nfs4_sequence_res *res, |
| 512 | int cache_reply, |
| 513 | struct rpc_task *task) |
| 514 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 515 | struct nfs4_slot *slot; |
| 516 | struct nfs4_slot_table *tbl; |
| 517 | u8 slotid; |
| 518 | |
| 519 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 520 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 521 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 522 | return 0; |
| 523 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 524 | tbl = &session->fc_slot_table; |
| 525 | |
| 526 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 527 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 528 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 529 | /* |
| 530 | * The state manager will wait until the slot table is empty. |
| 531 | * Schedule the reset thread |
| 532 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 533 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 534 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 535 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 536 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 539 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 540 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 541 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 542 | spin_unlock(&tbl->slot_tbl_lock); |
| 543 | dprintk("%s enforce FIFO order\n", __func__); |
| 544 | return -EAGAIN; |
| 545 | } |
| 546 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 547 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 548 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 549 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 550 | spin_unlock(&tbl->slot_tbl_lock); |
| 551 | dprintk("<-- %s: no free slots\n", __func__); |
| 552 | return -EAGAIN; |
| 553 | } |
| 554 | spin_unlock(&tbl->slot_tbl_lock); |
| 555 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 556 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 557 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 558 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 559 | args->sa_slotid = slotid; |
| 560 | args->sa_cache_this = cache_reply; |
| 561 | |
| 562 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 563 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 564 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 565 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 566 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 567 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 568 | /* |
| 569 | * sr_status is only set in decode_sequence, and so will remain |
| 570 | * set to 1 if an rpc level failure occurs. |
| 571 | */ |
| 572 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 573 | return 0; |
| 574 | } |
| 575 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 576 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 577 | struct nfs4_sequence_args *args, |
| 578 | struct nfs4_sequence_res *res, |
| 579 | int cache_reply, |
| 580 | struct rpc_task *task) |
| 581 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 582 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 583 | int ret = 0; |
| 584 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 585 | if (session == NULL) { |
| 586 | args->sa_session = NULL; |
| 587 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 588 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 589 | } |
| 590 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 591 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 592 | __func__, session->clp, session, res->sr_slot ? |
| 593 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 594 | |
| 595 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 596 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 597 | out: |
| 598 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 599 | return ret; |
| 600 | } |
| 601 | |
| 602 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 603 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 604 | struct nfs4_sequence_args *seq_args; |
| 605 | struct nfs4_sequence_res *seq_res; |
| 606 | int cache_reply; |
| 607 | }; |
| 608 | |
| 609 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 610 | { |
| 611 | struct nfs41_call_sync_data *data = calldata; |
| 612 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 613 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 614 | |
| 615 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 616 | data->seq_res, data->cache_reply, task)) |
| 617 | return; |
| 618 | rpc_call_start(task); |
| 619 | } |
| 620 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 621 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 622 | { |
| 623 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 624 | nfs41_call_sync_prepare(task, calldata); |
| 625 | } |
| 626 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 627 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 628 | { |
| 629 | struct nfs41_call_sync_data *data = calldata; |
| 630 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 631 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 632 | } |
| 633 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 634 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 635 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 636 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 637 | }; |
| 638 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 639 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 640 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 641 | .rpc_call_done = nfs41_call_sync_done, |
| 642 | }; |
| 643 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 644 | static int nfs4_call_sync_sequence(struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 645 | struct rpc_message *msg, |
| 646 | struct nfs4_sequence_args *args, |
| 647 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 648 | int cache_reply, |
| 649 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 650 | { |
| 651 | int ret; |
| 652 | struct rpc_task *task; |
| 653 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 654 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 655 | .seq_args = args, |
| 656 | .seq_res = res, |
| 657 | .cache_reply = cache_reply, |
| 658 | }; |
| 659 | struct rpc_task_setup task_setup = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 660 | .rpc_client = server->client, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | .rpc_message = msg, |
| 662 | .callback_ops = &nfs41_call_sync_ops, |
| 663 | .callback_data = &data |
| 664 | }; |
| 665 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 666 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 667 | if (privileged) |
| 668 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 669 | task = rpc_run_task(&task_setup); |
| 670 | if (IS_ERR(task)) |
| 671 | ret = PTR_ERR(task); |
| 672 | else { |
| 673 | ret = task->tk_status; |
| 674 | rpc_put_task(task); |
| 675 | } |
| 676 | return ret; |
| 677 | } |
| 678 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 679 | int _nfs4_call_sync_session(struct nfs_server *server, |
| 680 | struct rpc_message *msg, |
| 681 | struct nfs4_sequence_args *args, |
| 682 | struct nfs4_sequence_res *res, |
| 683 | int cache_reply) |
| 684 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 685 | return nfs4_call_sync_sequence(server, msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 686 | } |
| 687 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 688 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 689 | static int nfs4_sequence_done(struct rpc_task *task, |
| 690 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 691 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 692 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 693 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 694 | #endif /* CONFIG_NFS_V4_1 */ |
| 695 | |
| 696 | int _nfs4_call_sync(struct nfs_server *server, |
| 697 | struct rpc_message *msg, |
| 698 | struct nfs4_sequence_args *args, |
| 699 | struct nfs4_sequence_res *res, |
| 700 | int cache_reply) |
| 701 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 702 | args->sa_session = res->sr_session = NULL; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 703 | return rpc_call_sync(server->client, msg, 0); |
| 704 | } |
| 705 | |
| 706 | #define nfs4_call_sync(server, msg, args, res, cache_reply) \ |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 707 | (server)->nfs_client->cl_mvops->call_sync((server), (msg), &(args)->seq_args, \ |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 708 | &(res)->seq_res, (cache_reply)) |
| 709 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 710 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 712 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 714 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 715 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 716 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 717 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 718 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 719 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 722 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 723 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 724 | struct nfs_openargs o_arg; |
| 725 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 726 | struct nfs_open_confirmargs c_arg; |
| 727 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 728 | struct nfs_fattr f_attr; |
| 729 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 730 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 731 | struct dentry *dir; |
| 732 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 733 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 734 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 735 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 736 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 737 | int rpc_status; |
| 738 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 739 | }; |
| 740 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 741 | |
| 742 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 743 | { |
| 744 | p->o_res.f_attr = &p->f_attr; |
| 745 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 746 | p->o_res.seqid = p->o_arg.seqid; |
| 747 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 748 | p->o_res.server = p->o_arg.server; |
| 749 | nfs_fattr_init(&p->f_attr); |
| 750 | nfs_fattr_init(&p->dir_attr); |
| 751 | } |
| 752 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 753 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 754 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 755 | const struct iattr *attrs, |
| 756 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 757 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 758 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 759 | struct inode *dir = parent->d_inode; |
| 760 | struct nfs_server *server = NFS_SERVER(dir); |
| 761 | struct nfs4_opendata *p; |
| 762 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 763 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 764 | if (p == NULL) |
| 765 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 766 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 767 | if (p->o_arg.seqid == NULL) |
| 768 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 769 | path_get(path); |
| 770 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 771 | p->dir = parent; |
| 772 | p->owner = sp; |
| 773 | atomic_inc(&sp->so_count); |
| 774 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 775 | p->o_arg.open_flags = flags; |
| 776 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 777 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 778 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 779 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 780 | p->o_arg.server = server; |
| 781 | p->o_arg.bitmask = server->attr_bitmask; |
| 782 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 783 | if (flags & O_CREAT) { |
| 784 | u32 *s; |
| 785 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 786 | p->o_arg.u.attrs = &p->attrs; |
| 787 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 788 | s = (u32 *) p->o_arg.u.verifier.data; |
| 789 | s[0] = jiffies; |
| 790 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 791 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 792 | p->c_arg.fh = &p->o_res.fh; |
| 793 | p->c_arg.stateid = &p->o_res.stateid; |
| 794 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 795 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 796 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 797 | return p; |
| 798 | err_free: |
| 799 | kfree(p); |
| 800 | err: |
| 801 | dput(parent); |
| 802 | return NULL; |
| 803 | } |
| 804 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 805 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 806 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 807 | struct nfs4_opendata *p = container_of(kref, |
| 808 | struct nfs4_opendata, kref); |
| 809 | |
| 810 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 811 | if (p->state != NULL) |
| 812 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 813 | nfs4_put_state_owner(p->owner); |
| 814 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 815 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 816 | kfree(p); |
| 817 | } |
| 818 | |
| 819 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 820 | { |
| 821 | if (p != NULL) |
| 822 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | } |
| 824 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 825 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 826 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 827 | int ret; |
| 828 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 829 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 830 | return ret; |
| 831 | } |
| 832 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 833 | 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] | 834 | { |
| 835 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 836 | |
| 837 | if (open_mode & O_EXCL) |
| 838 | goto out; |
| 839 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 840 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 841 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 842 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 843 | break; |
| 844 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 845 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 846 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 847 | break; |
| 848 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 849 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 850 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 851 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 852 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 853 | return ret; |
| 854 | } |
| 855 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 856 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 857 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 858 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 859 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 860 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 861 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 862 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 863 | return 1; |
| 864 | } |
| 865 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 866 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 867 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 868 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 869 | case FMODE_WRITE: |
| 870 | state->n_wronly++; |
| 871 | break; |
| 872 | case FMODE_READ: |
| 873 | state->n_rdonly++; |
| 874 | break; |
| 875 | case FMODE_READ|FMODE_WRITE: |
| 876 | state->n_rdwr++; |
| 877 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 878 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 879 | } |
| 880 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 881 | 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] | 882 | { |
| 883 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 884 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 885 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 886 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 887 | case FMODE_READ: |
| 888 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 889 | break; |
| 890 | case FMODE_WRITE: |
| 891 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 892 | break; |
| 893 | case FMODE_READ|FMODE_WRITE: |
| 894 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 895 | } |
| 896 | } |
| 897 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 898 | 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] | 899 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 900 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 901 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 902 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 903 | } |
| 904 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 905 | 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] | 906 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 907 | /* |
| 908 | * Protect the call to nfs4_state_set_mode_locked and |
| 909 | * serialise the stateid update |
| 910 | */ |
| 911 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 912 | if (deleg_stateid != NULL) { |
| 913 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 914 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 915 | } |
| 916 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 917 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 918 | write_sequnlock(&state->seqlock); |
| 919 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 921 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 924 | 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] | 925 | { |
| 926 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 927 | struct nfs_delegation *deleg_cur; |
| 928 | int ret = 0; |
| 929 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 930 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 931 | |
| 932 | rcu_read_lock(); |
| 933 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 934 | if (deleg_cur == NULL) |
| 935 | goto no_delegation; |
| 936 | |
| 937 | spin_lock(&deleg_cur->lock); |
| 938 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 939 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 940 | goto no_delegation_unlock; |
| 941 | |
| 942 | if (delegation == NULL) |
| 943 | delegation = &deleg_cur->stateid; |
| 944 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 945 | goto no_delegation_unlock; |
| 946 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 947 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 948 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 949 | ret = 1; |
| 950 | no_delegation_unlock: |
| 951 | spin_unlock(&deleg_cur->lock); |
| 952 | no_delegation: |
| 953 | rcu_read_unlock(); |
| 954 | |
| 955 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 956 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 957 | ret = 1; |
| 958 | } |
| 959 | |
| 960 | return ret; |
| 961 | } |
| 962 | |
| 963 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 964 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 965 | { |
| 966 | struct nfs_delegation *delegation; |
| 967 | |
| 968 | rcu_read_lock(); |
| 969 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 970 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 971 | rcu_read_unlock(); |
| 972 | return; |
| 973 | } |
| 974 | rcu_read_unlock(); |
| 975 | nfs_inode_return_delegation(inode); |
| 976 | } |
| 977 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 978 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 979 | { |
| 980 | struct nfs4_state *state = opendata->state; |
| 981 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 982 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 983 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 984 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 985 | nfs4_stateid stateid; |
| 986 | int ret = -EAGAIN; |
| 987 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 988 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 989 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 990 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 991 | if (can_open_cached(state, fmode, open_mode)) { |
| 992 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 993 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 994 | goto out_return_state; |
| 995 | } |
| 996 | spin_unlock(&state->owner->so_lock); |
| 997 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 998 | rcu_read_lock(); |
| 999 | delegation = rcu_dereference(nfsi->delegation); |
| 1000 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1001 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1002 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1003 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1004 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1005 | /* Save the delegation */ |
| 1006 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1007 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1008 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1009 | if (ret != 0) |
| 1010 | goto out; |
| 1011 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1012 | |
| 1013 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1014 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1015 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1016 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1017 | out: |
| 1018 | return ERR_PTR(ret); |
| 1019 | out_return_state: |
| 1020 | atomic_inc(&state->count); |
| 1021 | return state; |
| 1022 | } |
| 1023 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1024 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1025 | { |
| 1026 | struct inode *inode; |
| 1027 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1028 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1029 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1030 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1031 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1032 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1033 | goto out; |
| 1034 | } |
| 1035 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1036 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1037 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1038 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1039 | 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] | 1040 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1041 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1042 | goto err; |
| 1043 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1044 | state = nfs4_get_open_state(inode, data->owner); |
| 1045 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1046 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1047 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1048 | int delegation_flags = 0; |
| 1049 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1050 | rcu_read_lock(); |
| 1051 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1052 | if (delegation) |
| 1053 | delegation_flags = delegation->flags; |
| 1054 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1055 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1056 | nfs_inode_set_delegation(state->inode, |
| 1057 | data->owner->so_cred, |
| 1058 | &data->o_res); |
| 1059 | else |
| 1060 | nfs_inode_reclaim_delegation(state->inode, |
| 1061 | data->owner->so_cred, |
| 1062 | &data->o_res); |
| 1063 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1064 | |
| 1065 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1066 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1067 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1068 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1069 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1070 | err_put_inode: |
| 1071 | iput(inode); |
| 1072 | err: |
| 1073 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1074 | } |
| 1075 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1076 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1077 | { |
| 1078 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1079 | struct nfs_open_context *ctx; |
| 1080 | |
| 1081 | spin_lock(&state->inode->i_lock); |
| 1082 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1083 | if (ctx->state != state) |
| 1084 | continue; |
| 1085 | get_nfs_open_context(ctx); |
| 1086 | spin_unlock(&state->inode->i_lock); |
| 1087 | return ctx; |
| 1088 | } |
| 1089 | spin_unlock(&state->inode->i_lock); |
| 1090 | return ERR_PTR(-ENOENT); |
| 1091 | } |
| 1092 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1093 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1094 | { |
| 1095 | struct nfs4_opendata *opendata; |
| 1096 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1097 | 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] | 1098 | if (opendata == NULL) |
| 1099 | return ERR_PTR(-ENOMEM); |
| 1100 | opendata->state = state; |
| 1101 | atomic_inc(&state->count); |
| 1102 | return opendata; |
| 1103 | } |
| 1104 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1105 | 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] | 1106 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1107 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1108 | int ret; |
| 1109 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1110 | opendata->o_arg.open_flags = 0; |
| 1111 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1112 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1113 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1114 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1115 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1116 | if (ret != 0) |
| 1117 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1118 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1119 | if (IS_ERR(newstate)) |
| 1120 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1121 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1122 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1127 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1128 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1129 | int ret; |
| 1130 | |
| 1131 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1132 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1133 | smp_rmb(); |
| 1134 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1135 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1136 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1137 | if (ret != 0) |
| 1138 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1139 | if (newstate != state) |
| 1140 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1141 | } |
| 1142 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1143 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1144 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1145 | if (ret != 0) |
| 1146 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1147 | if (newstate != state) |
| 1148 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1149 | } |
| 1150 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1151 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1152 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1153 | if (ret != 0) |
| 1154 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1155 | if (newstate != state) |
| 1156 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1157 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1158 | /* |
| 1159 | * We may have performed cached opens for all three recoveries. |
| 1160 | * Check if we need to update the current stateid. |
| 1161 | */ |
| 1162 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1163 | 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] | 1164 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1165 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1166 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1167 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1168 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1169 | return 0; |
| 1170 | } |
| 1171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | /* |
| 1173 | * OPEN_RECLAIM: |
| 1174 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1176 | 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] | 1177 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1178 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1179 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1180 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | int status; |
| 1182 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1183 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1184 | if (IS_ERR(opendata)) |
| 1185 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1186 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1187 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1188 | rcu_read_lock(); |
| 1189 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1190 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1191 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1192 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1193 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1194 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1195 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | return status; |
| 1197 | } |
| 1198 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1199 | 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] | 1200 | { |
| 1201 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1202 | struct nfs4_exception exception = { }; |
| 1203 | int err; |
| 1204 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1205 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1206 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1207 | break; |
| 1208 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | } while (exception.retry); |
| 1210 | return err; |
| 1211 | } |
| 1212 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1213 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1214 | { |
| 1215 | struct nfs_open_context *ctx; |
| 1216 | int ret; |
| 1217 | |
| 1218 | ctx = nfs4_state_find_open_context(state); |
| 1219 | if (IS_ERR(ctx)) |
| 1220 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1221 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1222 | put_nfs_open_context(ctx); |
| 1223 | return ret; |
| 1224 | } |
| 1225 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1226 | 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] | 1227 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1228 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1229 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1231 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1232 | if (IS_ERR(opendata)) |
| 1233 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1234 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1235 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1236 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1237 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1238 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1239 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1242 | 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] | 1243 | { |
| 1244 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1245 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | int err; |
| 1247 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1248 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | switch (err) { |
| 1250 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1251 | case -ENOENT: |
| 1252 | case -ESTALE: |
| 1253 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1254 | case -NFS4ERR_BADSESSION: |
| 1255 | case -NFS4ERR_BADSLOT: |
| 1256 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1257 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1258 | case -NFS4ERR_DEADSESSION: |
| 1259 | nfs4_schedule_state_recovery( |
| 1260 | server->nfs_client); |
| 1261 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | case -NFS4ERR_STALE_CLIENTID: |
| 1263 | case -NFS4ERR_STALE_STATEID: |
| 1264 | case -NFS4ERR_EXPIRED: |
| 1265 | /* Don't recall a delegation if it was lost */ |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1266 | nfs4_schedule_state_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1267 | goto out; |
| 1268 | case -ERESTARTSYS: |
| 1269 | /* |
| 1270 | * The show must go on: exit, but mark the |
| 1271 | * stateid as needing recovery. |
| 1272 | */ |
| 1273 | case -NFS4ERR_ADMIN_REVOKED: |
| 1274 | case -NFS4ERR_BAD_STATEID: |
| 1275 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1276 | case -EKEYEXPIRED: |
| 1277 | /* |
| 1278 | * User RPCSEC_GSS context has expired. |
| 1279 | * We cannot recover this stateid now, so |
| 1280 | * skip it and allow recovery thread to |
| 1281 | * proceed. |
| 1282 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1283 | case -ENOMEM: |
| 1284 | err = 0; |
| 1285 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | } |
| 1287 | err = nfs4_handle_exception(server, err, &exception); |
| 1288 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1289 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | return err; |
| 1291 | } |
| 1292 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1293 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1294 | { |
| 1295 | struct nfs4_opendata *data = calldata; |
| 1296 | |
| 1297 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1298 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1299 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1300 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1301 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1302 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1303 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1304 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | static void nfs4_open_confirm_release(void *calldata) |
| 1308 | { |
| 1309 | struct nfs4_opendata *data = calldata; |
| 1310 | struct nfs4_state *state = NULL; |
| 1311 | |
| 1312 | /* If this request hasn't been cancelled, do nothing */ |
| 1313 | if (data->cancelled == 0) |
| 1314 | goto out_free; |
| 1315 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1316 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1317 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1318 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1319 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1320 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1321 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1322 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1326 | .rpc_call_done = nfs4_open_confirm_done, |
| 1327 | .rpc_release = nfs4_open_confirm_release, |
| 1328 | }; |
| 1329 | |
| 1330 | /* |
| 1331 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1332 | */ |
| 1333 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1334 | { |
| 1335 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1336 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1337 | struct rpc_message msg = { |
| 1338 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1339 | .rpc_argp = &data->c_arg, |
| 1340 | .rpc_resp = &data->c_res, |
| 1341 | .rpc_cred = data->owner->so_cred, |
| 1342 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1343 | struct rpc_task_setup task_setup_data = { |
| 1344 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1345 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1346 | .callback_ops = &nfs4_open_confirm_ops, |
| 1347 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1348 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1349 | .flags = RPC_TASK_ASYNC, |
| 1350 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | int status; |
| 1352 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1353 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1354 | data->rpc_done = 0; |
| 1355 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1356 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1357 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1358 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1359 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1360 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1361 | if (status != 0) { |
| 1362 | data->cancelled = 1; |
| 1363 | smp_wmb(); |
| 1364 | } else |
| 1365 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1366 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | return status; |
| 1368 | } |
| 1369 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1370 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1372 | struct nfs4_opendata *data = calldata; |
| 1373 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1374 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1375 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1376 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1377 | /* |
| 1378 | * Check if we still need to send an OPEN call, or if we can use |
| 1379 | * a delegation instead. |
| 1380 | */ |
| 1381 | if (data->state != NULL) { |
| 1382 | struct nfs_delegation *delegation; |
| 1383 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1384 | 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] | 1385 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1386 | rcu_read_lock(); |
| 1387 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1388 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1389 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1390 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1391 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1392 | } |
| 1393 | rcu_read_unlock(); |
| 1394 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1395 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1396 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1397 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1398 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1399 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1400 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1401 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1402 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1403 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1404 | &data->o_arg.seq_args, |
| 1405 | &data->o_res.seq_res, 1, task)) |
| 1406 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1407 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1408 | return; |
| 1409 | out_no_action: |
| 1410 | task->tk_action = NULL; |
| 1411 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1414 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1415 | { |
| 1416 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1417 | nfs4_open_prepare(task, calldata); |
| 1418 | } |
| 1419 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1420 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1421 | { |
| 1422 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1424 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1425 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1426 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1427 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1428 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1429 | if (task->tk_status == 0) { |
| 1430 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1431 | case S_IFREG: |
| 1432 | break; |
| 1433 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1434 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1435 | break; |
| 1436 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1437 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1438 | break; |
| 1439 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1440 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1441 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1442 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1443 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1444 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1445 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1446 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1447 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1448 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1449 | static void nfs4_open_release(void *calldata) |
| 1450 | { |
| 1451 | struct nfs4_opendata *data = calldata; |
| 1452 | struct nfs4_state *state = NULL; |
| 1453 | |
| 1454 | /* If this request hasn't been cancelled, do nothing */ |
| 1455 | if (data->cancelled == 0) |
| 1456 | goto out_free; |
| 1457 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1458 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1459 | goto out_free; |
| 1460 | /* In case we need an open_confirm, no cleanup! */ |
| 1461 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1462 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1463 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1464 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1465 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1466 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1467 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1471 | .rpc_call_prepare = nfs4_open_prepare, |
| 1472 | .rpc_call_done = nfs4_open_done, |
| 1473 | .rpc_release = nfs4_open_release, |
| 1474 | }; |
| 1475 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1476 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1477 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1478 | .rpc_call_done = nfs4_open_done, |
| 1479 | .rpc_release = nfs4_open_release, |
| 1480 | }; |
| 1481 | |
| 1482 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1483 | { |
| 1484 | struct inode *dir = data->dir->d_inode; |
| 1485 | struct nfs_server *server = NFS_SERVER(dir); |
| 1486 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1487 | struct nfs_openres *o_res = &data->o_res; |
| 1488 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1489 | struct rpc_message msg = { |
| 1490 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1491 | .rpc_argp = o_arg, |
| 1492 | .rpc_resp = o_res, |
| 1493 | .rpc_cred = data->owner->so_cred, |
| 1494 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1495 | struct rpc_task_setup task_setup_data = { |
| 1496 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1497 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1498 | .callback_ops = &nfs4_open_ops, |
| 1499 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1500 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1501 | .flags = RPC_TASK_ASYNC, |
| 1502 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1503 | int status; |
| 1504 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1505 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1506 | data->rpc_done = 0; |
| 1507 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1508 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1509 | if (isrecover) |
| 1510 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1511 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1512 | if (IS_ERR(task)) |
| 1513 | return PTR_ERR(task); |
| 1514 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1515 | if (status != 0) { |
| 1516 | data->cancelled = 1; |
| 1517 | smp_wmb(); |
| 1518 | } else |
| 1519 | status = data->rpc_status; |
| 1520 | rpc_put_task(task); |
| 1521 | |
| 1522 | return status; |
| 1523 | } |
| 1524 | |
| 1525 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1526 | { |
| 1527 | struct inode *dir = data->dir->d_inode; |
| 1528 | struct nfs_openres *o_res = &data->o_res; |
| 1529 | int status; |
| 1530 | |
| 1531 | status = nfs4_run_open_task(data, 1); |
| 1532 | if (status != 0 || !data->rpc_done) |
| 1533 | return status; |
| 1534 | |
| 1535 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1536 | |
| 1537 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1538 | status = _nfs4_proc_open_confirm(data); |
| 1539 | if (status != 0) |
| 1540 | return status; |
| 1541 | } |
| 1542 | |
| 1543 | return status; |
| 1544 | } |
| 1545 | |
| 1546 | /* |
| 1547 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1548 | */ |
| 1549 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1550 | { |
| 1551 | struct inode *dir = data->dir->d_inode; |
| 1552 | struct nfs_server *server = NFS_SERVER(dir); |
| 1553 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1554 | struct nfs_openres *o_res = &data->o_res; |
| 1555 | int status; |
| 1556 | |
| 1557 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1558 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1559 | return status; |
| 1560 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1561 | if (o_arg->open_flags & O_CREAT) { |
| 1562 | update_changeattr(dir, &o_res->cinfo); |
| 1563 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1564 | } else |
| 1565 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1566 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1567 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1569 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1571 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | } |
| 1573 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1574 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1575 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
Trond Myklebust | 10afec9 | 2007-05-14 17:16:04 -0400 | [diff] [blame] | 1578 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1579 | { |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 1580 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1581 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1582 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1583 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1584 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1585 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1586 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1587 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1588 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1589 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1590 | break; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1591 | nfs4_schedule_state_recovery(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1592 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1593 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1594 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1595 | } |
| 1596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | /* |
| 1598 | * OPEN_EXPIRED: |
| 1599 | * reclaim state on the server after a network partition. |
| 1600 | * Assumes caller holds the appropriate lock |
| 1601 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1602 | 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] | 1603 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1604 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1605 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1607 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1608 | if (IS_ERR(opendata)) |
| 1609 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1610 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1611 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1612 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1613 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1614 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | } |
| 1616 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1617 | 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] | 1618 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1619 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1620 | struct nfs4_exception exception = { }; |
| 1621 | int err; |
| 1622 | |
| 1623 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1624 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1625 | switch (err) { |
| 1626 | default: |
| 1627 | goto out; |
| 1628 | case -NFS4ERR_GRACE: |
| 1629 | case -NFS4ERR_DELAY: |
| 1630 | nfs4_handle_exception(server, err, &exception); |
| 1631 | err = 0; |
| 1632 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1633 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1634 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1635 | return err; |
| 1636 | } |
| 1637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1639 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1641 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1643 | ctx = nfs4_state_find_open_context(state); |
| 1644 | if (IS_ERR(ctx)) |
| 1645 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1646 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1647 | put_nfs_open_context(ctx); |
| 1648 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1652 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1653 | * fields corresponding to attributes that were used to store the verifier. |
| 1654 | * Make sure we clobber those fields in the later setattr call |
| 1655 | */ |
| 1656 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1657 | { |
| 1658 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1659 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1660 | sattr->ia_valid |= ATTR_ATIME; |
| 1661 | |
| 1662 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1663 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1664 | sattr->ia_valid |= ATTR_MTIME; |
| 1665 | } |
| 1666 | |
| 1667 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1668 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1670 | 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] | 1671 | { |
| 1672 | struct nfs4_state_owner *sp; |
| 1673 | struct nfs4_state *state = NULL; |
| 1674 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1675 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1676 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | |
| 1678 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | status = -ENOMEM; |
| 1680 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1681 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1682 | goto out_err; |
| 1683 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1684 | status = nfs4_recover_expired_lease(server); |
| 1685 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1686 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1687 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1688 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1689 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1690 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1691 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1692 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1694 | if (path->dentry->d_inode != NULL) |
| 1695 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1696 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1697 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1699 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1701 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1702 | status = PTR_ERR(state); |
| 1703 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1704 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1705 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1706 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1707 | |
| 1708 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1709 | nfs4_exclusive_attrset(opendata, sattr); |
| 1710 | |
| 1711 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1712 | status = nfs4_do_setattr(state->inode, cred, |
| 1713 | opendata->o_res.f_attr, sattr, |
| 1714 | state); |
| 1715 | if (status == 0) |
| 1716 | nfs_setattr_update_inode(state->inode, sattr); |
| 1717 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1718 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1719 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | *res = state; |
| 1722 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1723 | err_opendata_put: |
| 1724 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1725 | err_put_state_owner: |
| 1726 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | *res = NULL; |
| 1729 | return status; |
| 1730 | } |
| 1731 | |
| 1732 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1733 | 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] | 1734 | { |
| 1735 | struct nfs4_exception exception = { }; |
| 1736 | struct nfs4_state *res; |
| 1737 | int status; |
| 1738 | |
| 1739 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1740 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | if (status == 0) |
| 1742 | break; |
| 1743 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1744 | * book-keeping w.r.t. state-changing operations |
| 1745 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1746 | * It is actually a sign of a bug on the client or on the server. |
| 1747 | * |
| 1748 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1749 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | * have unhashed the old state_owner for us, and that we can |
| 1751 | * therefore safely retry using a new one. We should still warn |
| 1752 | * the user though... |
| 1753 | */ |
| 1754 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1755 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1756 | " returned a bad sequence-id error!\n", |
| 1757 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | exception.retry = 1; |
| 1759 | continue; |
| 1760 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1761 | /* |
| 1762 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1763 | * state before it received the OPEN_CONFIRM. |
| 1764 | * Recover by retrying the request as per the discussion |
| 1765 | * on Page 181 of RFC3530. |
| 1766 | */ |
| 1767 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1768 | exception.retry = 1; |
| 1769 | continue; |
| 1770 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1771 | if (status == -EAGAIN) { |
| 1772 | /* We must have found a delegation */ |
| 1773 | exception.retry = 1; |
| 1774 | continue; |
| 1775 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1777 | status, &exception)); |
| 1778 | } while (exception.retry); |
| 1779 | return res; |
| 1780 | } |
| 1781 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1782 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1783 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1784 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1786 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1788 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | .iap = sattr, |
| 1790 | .server = server, |
| 1791 | .bitmask = server->attr_bitmask, |
| 1792 | }; |
| 1793 | struct nfs_setattrres res = { |
| 1794 | .fattr = fattr, |
| 1795 | .server = server, |
| 1796 | }; |
| 1797 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1798 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1799 | .rpc_argp = &arg, |
| 1800 | .rpc_resp = &res, |
| 1801 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1803 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1804 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1806 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1808 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1809 | /* Use that stateid */ |
| 1810 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1811 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1812 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1814 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 1815 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1816 | if (status == 0 && state != NULL) |
| 1817 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1818 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1821 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1822 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1823 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1825 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | struct nfs4_exception exception = { }; |
| 1827 | int err; |
| 1828 | do { |
| 1829 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1830 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | &exception); |
| 1832 | } while (exception.retry); |
| 1833 | return err; |
| 1834 | } |
| 1835 | |
| 1836 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1837 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | struct inode *inode; |
| 1839 | struct nfs4_state *state; |
| 1840 | struct nfs_closeargs arg; |
| 1841 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1842 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1843 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1844 | bool roc; |
| 1845 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | }; |
| 1847 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1848 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1849 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1850 | struct nfs4_closedata *calldata = data; |
| 1851 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1852 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1853 | if (calldata->roc) |
| 1854 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1855 | nfs4_put_open_state(calldata->state); |
| 1856 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1857 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1858 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1859 | kfree(calldata); |
| 1860 | } |
| 1861 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1862 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1863 | fmode_t fmode) |
| 1864 | { |
| 1865 | spin_lock(&state->owner->so_lock); |
| 1866 | if (!(fmode & FMODE_READ)) |
| 1867 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1868 | if (!(fmode & FMODE_WRITE)) |
| 1869 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1870 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1871 | spin_unlock(&state->owner->so_lock); |
| 1872 | } |
| 1873 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1874 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1876 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1879 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1880 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1881 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | /* hmm. we are done with the inode, and in the process of freeing |
| 1883 | * the state_owner. we keep this around to process errors |
| 1884 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | switch (task->tk_status) { |
| 1886 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1887 | if (calldata->roc) |
| 1888 | pnfs_roc_set_barrier(state->inode, |
| 1889 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1890 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1891 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1892 | nfs4_close_clear_stateid_flags(state, |
| 1893 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | break; |
| 1895 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1896 | case -NFS4ERR_OLD_STATEID: |
| 1897 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1899 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1900 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1902 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1903 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1905 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1906 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | } |
| 1908 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1909 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1911 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1912 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1913 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1914 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1915 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1916 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1917 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1918 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1919 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1920 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1921 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1922 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1923 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1924 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1925 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1926 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1927 | } |
| 1928 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1929 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1930 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1931 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1932 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1933 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1934 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1935 | |
| 1936 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1937 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1938 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1939 | return; |
| 1940 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1941 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1942 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1943 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1944 | if (calldata->roc && |
| 1945 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 1946 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 1947 | task, NULL); |
| 1948 | return; |
| 1949 | } |
| 1950 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1951 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1952 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1953 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1954 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1955 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1956 | 1, task)) |
| 1957 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1958 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1961 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1962 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1963 | .rpc_call_done = nfs4_close_done, |
| 1964 | .rpc_release = nfs4_free_closedata, |
| 1965 | }; |
| 1966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | /* |
| 1968 | * It is possible for data to be read/written from a mem-mapped file |
| 1969 | * after the sys_close call (which hits the vfs layer as a flush). |
| 1970 | * This means that we can't safely call nfsv4 close on a file until |
| 1971 | * the inode is cleared. This in turn means that we are not good |
| 1972 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 1973 | * share state even when we are done with one of the three share |
| 1974 | * stateid's in the inode. |
| 1975 | * |
| 1976 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 1977 | */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1978 | 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] | 1979 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1980 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 1982 | struct nfs4_state_owner *sp = state->owner; |
| 1983 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1984 | struct rpc_message msg = { |
| 1985 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 1986 | .rpc_cred = state->owner->so_cred, |
| 1987 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1988 | struct rpc_task_setup task_setup_data = { |
| 1989 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1990 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1991 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1992 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1993 | .flags = RPC_TASK_ASYNC, |
| 1994 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1995 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1997 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1999 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2000 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2002 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2003 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2005 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2006 | if (calldata->arg.seqid == NULL) |
| 2007 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2008 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2009 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2010 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2011 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2012 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2013 | calldata->roc = roc; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2014 | path_get(path); |
| 2015 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2016 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2017 | msg.rpc_argp = &calldata->arg; |
| 2018 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2019 | task_setup_data.callback_data = calldata; |
| 2020 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2021 | if (IS_ERR(task)) |
| 2022 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2023 | status = 0; |
| 2024 | if (wait) |
| 2025 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2026 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2027 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2028 | out_free_calldata: |
| 2029 | kfree(calldata); |
| 2030 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2031 | if (roc) |
| 2032 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2033 | nfs4_put_open_state(state); |
| 2034 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2035 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2038 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2039 | 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] | 2040 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | struct nfs4_state *state; |
| 2042 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2043 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2044 | 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] | 2045 | if (IS_ERR(state)) |
| 2046 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2047 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2048 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2051 | 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] | 2052 | { |
| 2053 | if (ctx->state == NULL) |
| 2054 | return; |
| 2055 | if (is_sync) |
| 2056 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2057 | else |
| 2058 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2059 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
| 2061 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2062 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2063 | struct nfs4_server_caps_arg args = { |
| 2064 | .fhandle = fhandle, |
| 2065 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | struct nfs4_server_caps_res res = {}; |
| 2067 | struct rpc_message msg = { |
| 2068 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2069 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | .rpc_resp = &res, |
| 2071 | }; |
| 2072 | int status; |
| 2073 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2074 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | if (status == 0) { |
| 2076 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2077 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2078 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2079 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2080 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2081 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2083 | server->caps |= NFS_CAP_ACLS; |
| 2084 | if (res.has_links != 0) |
| 2085 | server->caps |= NFS_CAP_HARDLINKS; |
| 2086 | if (res.has_symlinks != 0) |
| 2087 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2088 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2089 | server->caps |= NFS_CAP_FILEID; |
| 2090 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2091 | server->caps |= NFS_CAP_MODE; |
| 2092 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2093 | server->caps |= NFS_CAP_NLINK; |
| 2094 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2095 | server->caps |= NFS_CAP_OWNER; |
| 2096 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2097 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2098 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2099 | server->caps |= NFS_CAP_ATIME; |
| 2100 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2101 | server->caps |= NFS_CAP_CTIME; |
| 2102 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2103 | server->caps |= NFS_CAP_MTIME; |
| 2104 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2105 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2106 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2107 | 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] | 2108 | server->acl_bitmask = res.acl_bitmask; |
| 2109 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | return status; |
| 2112 | } |
| 2113 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2114 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | { |
| 2116 | struct nfs4_exception exception = { }; |
| 2117 | int err; |
| 2118 | do { |
| 2119 | err = nfs4_handle_exception(server, |
| 2120 | _nfs4_server_capabilities(server, fhandle), |
| 2121 | &exception); |
| 2122 | } while (exception.retry); |
| 2123 | return err; |
| 2124 | } |
| 2125 | |
| 2126 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2127 | struct nfs_fsinfo *info) |
| 2128 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | struct nfs4_lookup_root_arg args = { |
| 2130 | .bitmask = nfs4_fattr_bitmap, |
| 2131 | }; |
| 2132 | struct nfs4_lookup_res res = { |
| 2133 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2134 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | .fh = fhandle, |
| 2136 | }; |
| 2137 | struct rpc_message msg = { |
| 2138 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2139 | .rpc_argp = &args, |
| 2140 | .rpc_resp = &res, |
| 2141 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2142 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2143 | nfs_fattr_init(info->fattr); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 2144 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2148 | struct nfs_fsinfo *info) |
| 2149 | { |
| 2150 | struct nfs4_exception exception = { }; |
| 2151 | int err; |
| 2152 | do { |
| 2153 | err = nfs4_handle_exception(server, |
| 2154 | _nfs4_lookup_root(server, fhandle, info), |
| 2155 | &exception); |
| 2156 | } while (exception.retry); |
| 2157 | return err; |
| 2158 | } |
| 2159 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2160 | /* |
| 2161 | * get the file handle for the "/" directory on the server |
| 2162 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | 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] | 2164 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | int status; |
| 2167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | if (status == 0) |
| 2170 | status = nfs4_server_capabilities(server, fhandle); |
| 2171 | if (status == 0) |
| 2172 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2173 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2176 | /* |
| 2177 | * Get locations and (maybe) other attributes of a referral. |
| 2178 | * Note that we'll actually follow the referral later when |
| 2179 | * we detect fsid mismatch in inode revalidation |
| 2180 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2181 | 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] | 2182 | { |
| 2183 | int status = -ENOMEM; |
| 2184 | struct page *page = NULL; |
| 2185 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2186 | |
| 2187 | page = alloc_page(GFP_KERNEL); |
| 2188 | if (page == NULL) |
| 2189 | goto out; |
| 2190 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2191 | if (locations == NULL) |
| 2192 | goto out; |
| 2193 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2194 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2195 | if (status != 0) |
| 2196 | goto out; |
| 2197 | /* Make sure server returned a different fsid for the referral */ |
| 2198 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2199 | 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] | 2200 | status = -EIO; |
| 2201 | goto out; |
| 2202 | } |
| 2203 | |
| 2204 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2205 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2206 | if (!fattr->mode) |
| 2207 | fattr->mode = S_IFDIR; |
| 2208 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2209 | out: |
| 2210 | if (page) |
| 2211 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2212 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2213 | return status; |
| 2214 | } |
| 2215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2217 | { |
| 2218 | struct nfs4_getattr_arg args = { |
| 2219 | .fh = fhandle, |
| 2220 | .bitmask = server->attr_bitmask, |
| 2221 | }; |
| 2222 | struct nfs4_getattr_res res = { |
| 2223 | .fattr = fattr, |
| 2224 | .server = server, |
| 2225 | }; |
| 2226 | struct rpc_message msg = { |
| 2227 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2228 | .rpc_argp = &args, |
| 2229 | .rpc_resp = &res, |
| 2230 | }; |
| 2231 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2232 | nfs_fattr_init(fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2233 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2237 | { |
| 2238 | struct nfs4_exception exception = { }; |
| 2239 | int err; |
| 2240 | do { |
| 2241 | err = nfs4_handle_exception(server, |
| 2242 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2243 | &exception); |
| 2244 | } while (exception.retry); |
| 2245 | return err; |
| 2246 | } |
| 2247 | |
| 2248 | /* |
| 2249 | * The file is not closed if it is opened due to the a request to change |
| 2250 | * the size of the file. The open call will not be needed once the |
| 2251 | * VFS layer lookup-intents are implemented. |
| 2252 | * |
| 2253 | * Close is called when the inode is destroyed. |
| 2254 | * If we haven't opened the file for O_WRONLY, we |
| 2255 | * need to in the size_change case to obtain a stateid. |
| 2256 | * |
| 2257 | * Got race? |
| 2258 | * Because OPEN is always done by name in nfsv4, it is |
| 2259 | * possible that we opened a different file by the same |
| 2260 | * name. We can recognize this race condition, but we |
| 2261 | * can't do anything about it besides returning an error. |
| 2262 | * |
| 2263 | * This will be fixed with VFS changes (lookup-intent). |
| 2264 | */ |
| 2265 | static int |
| 2266 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2267 | struct iattr *sattr) |
| 2268 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2269 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2270 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2271 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | int status; |
| 2273 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2274 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2276 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2277 | if (sattr->ia_valid & ATTR_FILE) { |
| 2278 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2279 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2280 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2281 | if (ctx) { |
| 2282 | cred = ctx->cred; |
| 2283 | state = ctx->state; |
| 2284 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2288 | if (status == 0) |
| 2289 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | return status; |
| 2291 | } |
| 2292 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2293 | static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh, |
| 2294 | const struct qstr *name, struct nfs_fh *fhandle, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2295 | struct nfs_fattr *fattr) |
| 2296 | { |
| 2297 | int status; |
| 2298 | struct nfs4_lookup_arg args = { |
| 2299 | .bitmask = server->attr_bitmask, |
| 2300 | .dir_fh = dirfh, |
| 2301 | .name = name, |
| 2302 | }; |
| 2303 | struct nfs4_lookup_res res = { |
| 2304 | .server = server, |
| 2305 | .fattr = fattr, |
| 2306 | .fh = fhandle, |
| 2307 | }; |
| 2308 | struct rpc_message msg = { |
| 2309 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2310 | .rpc_argp = &args, |
| 2311 | .rpc_resp = &res, |
| 2312 | }; |
| 2313 | |
| 2314 | nfs_fattr_init(fattr); |
| 2315 | |
| 2316 | dprintk("NFS call lookupfh %s\n", name->name); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2317 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2318 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2319 | return status; |
| 2320 | } |
| 2321 | |
| 2322 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2323 | struct qstr *name, struct nfs_fh *fhandle, |
| 2324 | struct nfs_fattr *fattr) |
| 2325 | { |
| 2326 | struct nfs4_exception exception = { }; |
| 2327 | int err; |
| 2328 | do { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2329 | err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr); |
| 2330 | /* FIXME: !!!! */ |
| 2331 | if (err == -NFS4ERR_MOVED) { |
| 2332 | err = -EREMOTE; |
| 2333 | break; |
| 2334 | } |
| 2335 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2336 | } while (exception.retry); |
| 2337 | return err; |
| 2338 | } |
| 2339 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2340 | static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2342 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2343 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | |
| 2345 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2346 | 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] | 2347 | if (status == -NFS4ERR_MOVED) |
| 2348 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | dprintk("NFS reply lookup: %d\n", status); |
| 2350 | return status; |
| 2351 | } |
| 2352 | |
| 2353 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2354 | { |
| 2355 | struct nfs4_exception exception = { }; |
| 2356 | int err; |
| 2357 | do { |
| 2358 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2359 | _nfs4_proc_lookup(dir, name, fhandle, fattr), |
| 2360 | &exception); |
| 2361 | } while (exception.retry); |
| 2362 | return err; |
| 2363 | } |
| 2364 | |
| 2365 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2366 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2367 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | struct nfs4_accessargs args = { |
| 2369 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2370 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2372 | struct nfs4_accessres res = { |
| 2373 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2374 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | struct rpc_message msg = { |
| 2376 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2377 | .rpc_argp = &args, |
| 2378 | .rpc_resp = &res, |
| 2379 | .rpc_cred = entry->cred, |
| 2380 | }; |
| 2381 | int mode = entry->mask; |
| 2382 | int status; |
| 2383 | |
| 2384 | /* |
| 2385 | * Determine which access bits we want to ask for... |
| 2386 | */ |
| 2387 | if (mode & MAY_READ) |
| 2388 | args.access |= NFS4_ACCESS_READ; |
| 2389 | if (S_ISDIR(inode->i_mode)) { |
| 2390 | if (mode & MAY_WRITE) |
| 2391 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2392 | if (mode & MAY_EXEC) |
| 2393 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2394 | } else { |
| 2395 | if (mode & MAY_WRITE) |
| 2396 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2397 | if (mode & MAY_EXEC) |
| 2398 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2399 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2400 | |
| 2401 | res.fattr = nfs_alloc_fattr(); |
| 2402 | if (res.fattr == NULL) |
| 2403 | return -ENOMEM; |
| 2404 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2405 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | if (!status) { |
| 2407 | entry->mask = 0; |
| 2408 | if (res.access & NFS4_ACCESS_READ) |
| 2409 | entry->mask |= MAY_READ; |
| 2410 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2411 | entry->mask |= MAY_WRITE; |
| 2412 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2413 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2414 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2416 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | return status; |
| 2418 | } |
| 2419 | |
| 2420 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2421 | { |
| 2422 | struct nfs4_exception exception = { }; |
| 2423 | int err; |
| 2424 | do { |
| 2425 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2426 | _nfs4_proc_access(inode, entry), |
| 2427 | &exception); |
| 2428 | } while (exception.retry); |
| 2429 | return err; |
| 2430 | } |
| 2431 | |
| 2432 | /* |
| 2433 | * TODO: For the time being, we don't try to get any attributes |
| 2434 | * along with any of the zero-copy operations READ, READDIR, |
| 2435 | * READLINK, WRITE. |
| 2436 | * |
| 2437 | * In the case of the first three, we want to put the GETATTR |
| 2438 | * after the read-type operation -- this is because it is hard |
| 2439 | * to predict the length of a GETATTR response in v4, and thus |
| 2440 | * align the READ data correctly. This means that the GETATTR |
| 2441 | * may end up partially falling into the page cache, and we should |
| 2442 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2443 | * To do this efficiently, we need to know the total length |
| 2444 | * of data received, which doesn't seem to be available outside |
| 2445 | * of the RPC layer. |
| 2446 | * |
| 2447 | * In the case of WRITE, we also want to put the GETATTR after |
| 2448 | * the operation -- in this case because we want to make sure |
| 2449 | * we get the post-operation mtime and size. This means that |
| 2450 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2451 | * of it which would leave room in the 'tail' iovec. |
| 2452 | * |
| 2453 | * Both of these changes to the XDR layer would in fact be quite |
| 2454 | * minor, but I decided to leave them for a subsequent patch. |
| 2455 | */ |
| 2456 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2457 | unsigned int pgbase, unsigned int pglen) |
| 2458 | { |
| 2459 | struct nfs4_readlink args = { |
| 2460 | .fh = NFS_FH(inode), |
| 2461 | .pgbase = pgbase, |
| 2462 | .pglen = pglen, |
| 2463 | .pages = &page, |
| 2464 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2465 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | struct rpc_message msg = { |
| 2467 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2468 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2469 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | }; |
| 2471 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2472 | return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2476 | unsigned int pgbase, unsigned int pglen) |
| 2477 | { |
| 2478 | struct nfs4_exception exception = { }; |
| 2479 | int err; |
| 2480 | do { |
| 2481 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2482 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2483 | &exception); |
| 2484 | } while (exception.retry); |
| 2485 | return err; |
| 2486 | } |
| 2487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | /* |
| 2489 | * Got race? |
| 2490 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2491 | * Until then, this create/open method is prone to inefficiency and race |
| 2492 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2493 | * placed on the wire. |
| 2494 | * |
| 2495 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2496 | * The file will be opened again in the subsequent VFS open call |
| 2497 | * (nfs4_proc_file_open). |
| 2498 | * |
| 2499 | * The open for read will just hang around to be used by any process that |
| 2500 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2501 | */ |
| 2502 | |
| 2503 | static int |
| 2504 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2505 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2507 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2508 | .dentry = dentry, |
| 2509 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2510 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2512 | struct rpc_cred *cred = NULL; |
| 2513 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | int status = 0; |
| 2515 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2516 | if (ctx != NULL) { |
| 2517 | cred = ctx->cred; |
| 2518 | path = &ctx->path; |
| 2519 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2521 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2522 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2523 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | if (IS_ERR(state)) { |
| 2525 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2526 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2528 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2529 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2530 | if (ctx != NULL) |
| 2531 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2532 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2533 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | out: |
| 2535 | return status; |
| 2536 | } |
| 2537 | |
| 2538 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2539 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2540 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2541 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2543 | .name.len = name->len, |
| 2544 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2545 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2547 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2548 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2549 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2551 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2552 | .rpc_argp = &args, |
| 2553 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2555 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2557 | res.dir_attr = nfs_alloc_fattr(); |
| 2558 | if (res.dir_attr == NULL) |
| 2559 | goto out; |
| 2560 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2561 | status = nfs4_call_sync(server, &msg, &args, &res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2562 | if (status == 0) { |
| 2563 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2564 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2565 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2566 | nfs_free_fattr(res.dir_attr); |
| 2567 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | return status; |
| 2569 | } |
| 2570 | |
| 2571 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2572 | { |
| 2573 | struct nfs4_exception exception = { }; |
| 2574 | int err; |
| 2575 | do { |
| 2576 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2577 | _nfs4_proc_remove(dir, name), |
| 2578 | &exception); |
| 2579 | } while (exception.retry); |
| 2580 | return err; |
| 2581 | } |
| 2582 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2583 | 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] | 2584 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2585 | struct nfs_server *server = NFS_SERVER(dir); |
| 2586 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2587 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2589 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2590 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2591 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2595 | 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] | 2596 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2597 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2598 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2599 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2600 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2601 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2602 | return 0; |
| 2603 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2604 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2605 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | } |
| 2607 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2608 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2609 | { |
| 2610 | struct nfs_server *server = NFS_SERVER(dir); |
| 2611 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2612 | struct nfs_renameres *res = msg->rpc_resp; |
| 2613 | |
| 2614 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2615 | arg->bitmask = server->attr_bitmask; |
| 2616 | res->server = server; |
| 2617 | } |
| 2618 | |
| 2619 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2620 | struct inode *new_dir) |
| 2621 | { |
| 2622 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2623 | |
| 2624 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2625 | return 0; |
| 2626 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2627 | return 0; |
| 2628 | |
| 2629 | update_changeattr(old_dir, &res->old_cinfo); |
| 2630 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2631 | update_changeattr(new_dir, &res->new_cinfo); |
| 2632 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2633 | return 1; |
| 2634 | } |
| 2635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2637 | struct inode *new_dir, struct qstr *new_name) |
| 2638 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2639 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2640 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | .old_dir = NFS_FH(old_dir), |
| 2642 | .new_dir = NFS_FH(new_dir), |
| 2643 | .old_name = old_name, |
| 2644 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2645 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2647 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2648 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2649 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | struct rpc_message msg = { |
| 2651 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2652 | .rpc_argp = &arg, |
| 2653 | .rpc_resp = &res, |
| 2654 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2655 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2657 | res.old_fattr = nfs_alloc_fattr(); |
| 2658 | res.new_fattr = nfs_alloc_fattr(); |
| 2659 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2660 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2662 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | if (!status) { |
| 2664 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2665 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2667 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2669 | out: |
| 2670 | nfs_free_fattr(res.new_fattr); |
| 2671 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | return status; |
| 2673 | } |
| 2674 | |
| 2675 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2676 | struct inode *new_dir, struct qstr *new_name) |
| 2677 | { |
| 2678 | struct nfs4_exception exception = { }; |
| 2679 | int err; |
| 2680 | do { |
| 2681 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2682 | _nfs4_proc_rename(old_dir, old_name, |
| 2683 | new_dir, new_name), |
| 2684 | &exception); |
| 2685 | } while (exception.retry); |
| 2686 | return err; |
| 2687 | } |
| 2688 | |
| 2689 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2690 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2691 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | struct nfs4_link_arg arg = { |
| 2693 | .fh = NFS_FH(inode), |
| 2694 | .dir_fh = NFS_FH(dir), |
| 2695 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2696 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2698 | struct nfs4_link_res res = { |
| 2699 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2700 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | struct rpc_message msg = { |
| 2702 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2703 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2704 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2706 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2708 | res.fattr = nfs_alloc_fattr(); |
| 2709 | res.dir_attr = nfs_alloc_fattr(); |
| 2710 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2711 | goto out; |
| 2712 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2713 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2714 | if (!status) { |
| 2715 | update_changeattr(dir, &res.cinfo); |
| 2716 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2717 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2718 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2719 | out: |
| 2720 | nfs_free_fattr(res.dir_attr); |
| 2721 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | return status; |
| 2723 | } |
| 2724 | |
| 2725 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2726 | { |
| 2727 | struct nfs4_exception exception = { }; |
| 2728 | int err; |
| 2729 | do { |
| 2730 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2731 | _nfs4_proc_link(inode, dir, name), |
| 2732 | &exception); |
| 2733 | } while (exception.retry); |
| 2734 | return err; |
| 2735 | } |
| 2736 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2737 | struct nfs4_createdata { |
| 2738 | struct rpc_message msg; |
| 2739 | struct nfs4_create_arg arg; |
| 2740 | struct nfs4_create_res res; |
| 2741 | struct nfs_fh fh; |
| 2742 | struct nfs_fattr fattr; |
| 2743 | struct nfs_fattr dir_fattr; |
| 2744 | }; |
| 2745 | |
| 2746 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2747 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2748 | { |
| 2749 | struct nfs4_createdata *data; |
| 2750 | |
| 2751 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2752 | if (data != NULL) { |
| 2753 | struct nfs_server *server = NFS_SERVER(dir); |
| 2754 | |
| 2755 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2756 | data->msg.rpc_argp = &data->arg; |
| 2757 | data->msg.rpc_resp = &data->res; |
| 2758 | data->arg.dir_fh = NFS_FH(dir); |
| 2759 | data->arg.server = server; |
| 2760 | data->arg.name = name; |
| 2761 | data->arg.attrs = sattr; |
| 2762 | data->arg.ftype = ftype; |
| 2763 | data->arg.bitmask = server->attr_bitmask; |
| 2764 | data->res.server = server; |
| 2765 | data->res.fh = &data->fh; |
| 2766 | data->res.fattr = &data->fattr; |
| 2767 | data->res.dir_fattr = &data->dir_fattr; |
| 2768 | nfs_fattr_init(data->res.fattr); |
| 2769 | nfs_fattr_init(data->res.dir_fattr); |
| 2770 | } |
| 2771 | return data; |
| 2772 | } |
| 2773 | |
| 2774 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2775 | { |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2776 | int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg, |
| 2777 | &data->arg, &data->res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2778 | if (status == 0) { |
| 2779 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2780 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2781 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2782 | } |
| 2783 | return status; |
| 2784 | } |
| 2785 | |
| 2786 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2787 | { |
| 2788 | kfree(data); |
| 2789 | } |
| 2790 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2791 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2792 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2794 | struct nfs4_createdata *data; |
| 2795 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2797 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2798 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2799 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2800 | status = -ENOMEM; |
| 2801 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2802 | if (data == NULL) |
| 2803 | goto out; |
| 2804 | |
| 2805 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2806 | data->arg.u.symlink.pages = &page; |
| 2807 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2809 | status = nfs4_do_create(dir, dentry, data); |
| 2810 | |
| 2811 | nfs4_free_createdata(data); |
| 2812 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | return status; |
| 2814 | } |
| 2815 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2816 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2817 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | { |
| 2819 | struct nfs4_exception exception = { }; |
| 2820 | int err; |
| 2821 | do { |
| 2822 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2823 | _nfs4_proc_symlink(dir, dentry, page, |
| 2824 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | &exception); |
| 2826 | } while (exception.retry); |
| 2827 | return err; |
| 2828 | } |
| 2829 | |
| 2830 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2831 | struct iattr *sattr) |
| 2832 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2833 | struct nfs4_createdata *data; |
| 2834 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2836 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2837 | if (data == NULL) |
| 2838 | goto out; |
| 2839 | |
| 2840 | status = nfs4_do_create(dir, dentry, data); |
| 2841 | |
| 2842 | nfs4_free_createdata(data); |
| 2843 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | return status; |
| 2845 | } |
| 2846 | |
| 2847 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2848 | struct iattr *sattr) |
| 2849 | { |
| 2850 | struct nfs4_exception exception = { }; |
| 2851 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2852 | |
| 2853 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | do { |
| 2855 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2856 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2857 | &exception); |
| 2858 | } while (exception.retry); |
| 2859 | return err; |
| 2860 | } |
| 2861 | |
| 2862 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2863 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | { |
| 2865 | struct inode *dir = dentry->d_inode; |
| 2866 | struct nfs4_readdir_arg args = { |
| 2867 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2868 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | .pgbase = 0, |
| 2870 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2871 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2872 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 | }; |
| 2874 | struct nfs4_readdir_res res; |
| 2875 | struct rpc_message msg = { |
| 2876 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2877 | .rpc_argp = &args, |
| 2878 | .rpc_resp = &res, |
| 2879 | .rpc_cred = cred, |
| 2880 | }; |
| 2881 | int status; |
| 2882 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2883 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2884 | dentry->d_parent->d_name.name, |
| 2885 | dentry->d_name.name, |
| 2886 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2888 | res.pgbase = args.pgbase; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2889 | status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2890 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2892 | status += args.pgbase; |
| 2893 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2894 | |
| 2895 | nfs_invalidate_atime(dir); |
| 2896 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2897 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | return status; |
| 2899 | } |
| 2900 | |
| 2901 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2902 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | { |
| 2904 | struct nfs4_exception exception = { }; |
| 2905 | int err; |
| 2906 | do { |
| 2907 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2908 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2909 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | &exception); |
| 2911 | } while (exception.retry); |
| 2912 | return err; |
| 2913 | } |
| 2914 | |
| 2915 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2916 | struct iattr *sattr, dev_t rdev) |
| 2917 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2918 | struct nfs4_createdata *data; |
| 2919 | int mode = sattr->ia_mode; |
| 2920 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | |
| 2922 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2923 | 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] | 2924 | |
| 2925 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2926 | if (data == NULL) |
| 2927 | goto out; |
| 2928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2930 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2932 | data->arg.ftype = NF4BLK; |
| 2933 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2934 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | } |
| 2936 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2937 | data->arg.ftype = NF4CHR; |
| 2938 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2939 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2942 | status = nfs4_do_create(dir, dentry, data); |
| 2943 | |
| 2944 | nfs4_free_createdata(data); |
| 2945 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | return status; |
| 2947 | } |
| 2948 | |
| 2949 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2950 | struct iattr *sattr, dev_t rdev) |
| 2951 | { |
| 2952 | struct nfs4_exception exception = { }; |
| 2953 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2954 | |
| 2955 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2956 | do { |
| 2957 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2958 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 2959 | &exception); |
| 2960 | } while (exception.retry); |
| 2961 | return err; |
| 2962 | } |
| 2963 | |
| 2964 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2965 | struct nfs_fsstat *fsstat) |
| 2966 | { |
| 2967 | struct nfs4_statfs_arg args = { |
| 2968 | .fh = fhandle, |
| 2969 | .bitmask = server->attr_bitmask, |
| 2970 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2971 | struct nfs4_statfs_res res = { |
| 2972 | .fsstat = fsstat, |
| 2973 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | struct rpc_message msg = { |
| 2975 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 2976 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 2977 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | }; |
| 2979 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2980 | nfs_fattr_init(fsstat->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2981 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 2985 | { |
| 2986 | struct nfs4_exception exception = { }; |
| 2987 | int err; |
| 2988 | do { |
| 2989 | err = nfs4_handle_exception(server, |
| 2990 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 2991 | &exception); |
| 2992 | } while (exception.retry); |
| 2993 | return err; |
| 2994 | } |
| 2995 | |
| 2996 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2997 | struct nfs_fsinfo *fsinfo) |
| 2998 | { |
| 2999 | struct nfs4_fsinfo_arg args = { |
| 3000 | .fh = fhandle, |
| 3001 | .bitmask = server->attr_bitmask, |
| 3002 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3003 | struct nfs4_fsinfo_res res = { |
| 3004 | .fsinfo = fsinfo, |
| 3005 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | struct rpc_message msg = { |
| 3007 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3008 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3009 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | }; |
| 3011 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3012 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3016 | { |
| 3017 | struct nfs4_exception exception = { }; |
| 3018 | int err; |
| 3019 | |
| 3020 | do { |
| 3021 | err = nfs4_handle_exception(server, |
| 3022 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3023 | &exception); |
| 3024 | } while (exception.retry); |
| 3025 | return err; |
| 3026 | } |
| 3027 | |
| 3028 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3029 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3030 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3032 | } |
| 3033 | |
| 3034 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3035 | struct nfs_pathconf *pathconf) |
| 3036 | { |
| 3037 | struct nfs4_pathconf_arg args = { |
| 3038 | .fh = fhandle, |
| 3039 | .bitmask = server->attr_bitmask, |
| 3040 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3041 | struct nfs4_pathconf_res res = { |
| 3042 | .pathconf = pathconf, |
| 3043 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | struct rpc_message msg = { |
| 3045 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3046 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3047 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | }; |
| 3049 | |
| 3050 | /* None of the pathconf attributes are mandatory to implement */ |
| 3051 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3052 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3053 | return 0; |
| 3054 | } |
| 3055 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3056 | nfs_fattr_init(pathconf->fattr); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3057 | return nfs4_call_sync(server, &msg, &args, &res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3061 | struct nfs_pathconf *pathconf) |
| 3062 | { |
| 3063 | struct nfs4_exception exception = { }; |
| 3064 | int err; |
| 3065 | |
| 3066 | do { |
| 3067 | err = nfs4_handle_exception(server, |
| 3068 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3069 | &exception); |
| 3070 | } while (exception.retry); |
| 3071 | return err; |
| 3072 | } |
| 3073 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3074 | 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] | 3075 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3076 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3078 | dprintk("--> %s\n", __func__); |
| 3079 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3080 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3081 | return -EAGAIN; |
Andy Adamson | f11c88a | 2009-04-01 09:22:25 -0400 | [diff] [blame] | 3082 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3083 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3084 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3085 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3087 | |
| 3088 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3090 | renew_lease(server, data->timestamp); |
| 3091 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3094 | 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] | 3095 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | data->timestamp = jiffies; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3097 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | } |
| 3099 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3100 | 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] | 3101 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | struct inode *inode = data->inode; |
| 3103 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3104 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3105 | return -EAGAIN; |
Andy Adamson | def6ed7 | 2009-04-01 09:22:26 -0400 | [diff] [blame] | 3106 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3107 | 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] | 3108 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3109 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3111 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3113 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3114 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3115 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | } |
| 3117 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3118 | 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] | 3119 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3120 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3121 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3122 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3123 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | data->timestamp = jiffies; |
| 3125 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3126 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3129 | 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] | 3130 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3131 | struct inode *inode = data->inode; |
| 3132 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3133 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3134 | return -EAGAIN; |
| 3135 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3136 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3137 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3138 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3140 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3141 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | } |
| 3143 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3144 | 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] | 3145 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3146 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3148 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3149 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3150 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | } |
| 3152 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3153 | struct nfs4_renewdata { |
| 3154 | struct nfs_client *client; |
| 3155 | unsigned long timestamp; |
| 3156 | }; |
| 3157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | /* |
| 3159 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3160 | * standalone procedure for queueing an asynchronous RENEW. |
| 3161 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3162 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3163 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3164 | struct nfs4_renewdata *data = calldata; |
| 3165 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3166 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3167 | if (atomic_read(&clp->cl_count) > 1) |
| 3168 | nfs4_schedule_state_renewal(clp); |
| 3169 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3170 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3171 | } |
| 3172 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3173 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3175 | struct nfs4_renewdata *data = calldata; |
| 3176 | struct nfs_client *clp = data->client; |
| 3177 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | |
| 3179 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3180 | /* Unless we're shutting down, schedule state recovery! */ |
| 3181 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
| 3182 | nfs4_schedule_state_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | return; |
| 3184 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3185 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | } |
| 3187 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3188 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3189 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3190 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3191 | }; |
| 3192 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3193 | 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] | 3194 | { |
| 3195 | struct rpc_message msg = { |
| 3196 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3197 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3198 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3200 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3202 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3203 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3204 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3205 | if (data == NULL) |
| 3206 | return -ENOMEM; |
| 3207 | data->client = clp; |
| 3208 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3210 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3213 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | { |
| 3215 | struct rpc_message msg = { |
| 3216 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3217 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3218 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | }; |
| 3220 | unsigned long now = jiffies; |
| 3221 | int status; |
| 3222 | |
| 3223 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3224 | if (status < 0) |
| 3225 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3226 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | return 0; |
| 3228 | } |
| 3229 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3230 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3231 | { |
| 3232 | return (server->caps & NFS_CAP_ACLS) |
| 3233 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3234 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3235 | } |
| 3236 | |
| 3237 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3238 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3239 | * the stack. |
| 3240 | */ |
| 3241 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3242 | |
| 3243 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3244 | struct page **pages, unsigned int *pgbase) |
| 3245 | { |
| 3246 | const void *p = buf; |
| 3247 | |
| 3248 | *pgbase = offset_in_page(buf); |
| 3249 | p -= *pgbase; |
| 3250 | while (p < buf + buflen) { |
| 3251 | *(pages++) = virt_to_page(p); |
| 3252 | p += PAGE_CACHE_SIZE; |
| 3253 | } |
| 3254 | } |
| 3255 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3256 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3257 | struct page **pages, unsigned int *pgbase) |
| 3258 | { |
| 3259 | struct page *newpage, **spages; |
| 3260 | int rc = 0; |
| 3261 | size_t len; |
| 3262 | spages = pages; |
| 3263 | |
| 3264 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3265 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3266 | newpage = alloc_page(GFP_KERNEL); |
| 3267 | |
| 3268 | if (newpage == NULL) |
| 3269 | goto unwind; |
| 3270 | memcpy(page_address(newpage), buf, len); |
| 3271 | buf += len; |
| 3272 | buflen -= len; |
| 3273 | *pages++ = newpage; |
| 3274 | rc++; |
| 3275 | } while (buflen != 0); |
| 3276 | |
| 3277 | return rc; |
| 3278 | |
| 3279 | unwind: |
| 3280 | for(; rc > 0; rc--) |
| 3281 | __free_page(spages[rc-1]); |
| 3282 | return -ENOMEM; |
| 3283 | } |
| 3284 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3285 | struct nfs4_cached_acl { |
| 3286 | int cached; |
| 3287 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3288 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3289 | }; |
| 3290 | |
| 3291 | 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] | 3292 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3293 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3294 | |
| 3295 | spin_lock(&inode->i_lock); |
| 3296 | kfree(nfsi->nfs4_acl); |
| 3297 | nfsi->nfs4_acl = acl; |
| 3298 | spin_unlock(&inode->i_lock); |
| 3299 | } |
| 3300 | |
| 3301 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3302 | { |
| 3303 | nfs4_set_cached_acl(inode, NULL); |
| 3304 | } |
| 3305 | |
| 3306 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3307 | { |
| 3308 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3309 | struct nfs4_cached_acl *acl; |
| 3310 | int ret = -ENOENT; |
| 3311 | |
| 3312 | spin_lock(&inode->i_lock); |
| 3313 | acl = nfsi->nfs4_acl; |
| 3314 | if (acl == NULL) |
| 3315 | goto out; |
| 3316 | if (buf == NULL) /* user is just asking for length */ |
| 3317 | goto out_len; |
| 3318 | if (acl->cached == 0) |
| 3319 | goto out; |
| 3320 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3321 | if (acl->len > buflen) |
| 3322 | goto out; |
| 3323 | memcpy(buf, acl->data, acl->len); |
| 3324 | out_len: |
| 3325 | ret = acl->len; |
| 3326 | out: |
| 3327 | spin_unlock(&inode->i_lock); |
| 3328 | return ret; |
| 3329 | } |
| 3330 | |
| 3331 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3332 | { |
| 3333 | struct nfs4_cached_acl *acl; |
| 3334 | |
| 3335 | if (buf && acl_len <= PAGE_SIZE) { |
| 3336 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3337 | if (acl == NULL) |
| 3338 | goto out; |
| 3339 | acl->cached = 1; |
| 3340 | memcpy(acl->data, buf, acl_len); |
| 3341 | } else { |
| 3342 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3343 | if (acl == NULL) |
| 3344 | goto out; |
| 3345 | acl->cached = 0; |
| 3346 | } |
| 3347 | acl->len = acl_len; |
| 3348 | out: |
| 3349 | nfs4_set_cached_acl(inode, acl); |
| 3350 | } |
| 3351 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3352 | 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] | 3353 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3354 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3355 | struct nfs_getaclargs args = { |
| 3356 | .fh = NFS_FH(inode), |
| 3357 | .acl_pages = pages, |
| 3358 | .acl_len = buflen, |
| 3359 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3360 | struct nfs_getaclres res = { |
| 3361 | .acl_len = buflen, |
| 3362 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3363 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3364 | struct rpc_message msg = { |
| 3365 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3366 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3367 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3368 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3369 | struct page *localpage = NULL; |
| 3370 | int ret; |
| 3371 | |
| 3372 | if (buflen < PAGE_SIZE) { |
| 3373 | /* As long as we're doing a round trip to the server anyway, |
| 3374 | * let's be prepared for a page of acl data. */ |
| 3375 | localpage = alloc_page(GFP_KERNEL); |
| 3376 | resp_buf = page_address(localpage); |
| 3377 | if (localpage == NULL) |
| 3378 | return -ENOMEM; |
| 3379 | args.acl_pages[0] = localpage; |
| 3380 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3381 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3382 | } else { |
| 3383 | resp_buf = buf; |
| 3384 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3385 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3386 | ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3387 | if (ret) |
| 3388 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3389 | if (res.acl_len > args.acl_len) |
| 3390 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3391 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3392 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3393 | if (buf) { |
| 3394 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3395 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3396 | goto out_free; |
| 3397 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3398 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3399 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3400 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3401 | out_free: |
| 3402 | if (localpage) |
| 3403 | __free_page(localpage); |
| 3404 | return ret; |
| 3405 | } |
| 3406 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3407 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3408 | { |
| 3409 | struct nfs4_exception exception = { }; |
| 3410 | ssize_t ret; |
| 3411 | do { |
| 3412 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3413 | if (ret >= 0) |
| 3414 | break; |
| 3415 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3416 | } while (exception.retry); |
| 3417 | return ret; |
| 3418 | } |
| 3419 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3420 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3421 | { |
| 3422 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3423 | int ret; |
| 3424 | |
| 3425 | if (!nfs4_server_supports_acls(server)) |
| 3426 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3427 | ret = nfs_revalidate_inode(server, inode); |
| 3428 | if (ret < 0) |
| 3429 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3430 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3431 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3432 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3433 | if (ret != -ENOENT) |
| 3434 | return ret; |
| 3435 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3436 | } |
| 3437 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3438 | 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] | 3439 | { |
| 3440 | struct nfs_server *server = NFS_SERVER(inode); |
| 3441 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3442 | struct nfs_setaclargs arg = { |
| 3443 | .fh = NFS_FH(inode), |
| 3444 | .acl_pages = pages, |
| 3445 | .acl_len = buflen, |
| 3446 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3447 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3448 | struct rpc_message msg = { |
| 3449 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3450 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3451 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3452 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3453 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3454 | |
| 3455 | if (!nfs4_server_supports_acls(server)) |
| 3456 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3457 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3458 | if (i < 0) |
| 3459 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3460 | nfs_inode_return_delegation(inode); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3461 | ret = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3462 | |
| 3463 | /* |
| 3464 | * Free each page after tx, so the only ref left is |
| 3465 | * held by the network stack |
| 3466 | */ |
| 3467 | for (; i > 0; i--) |
| 3468 | put_page(pages[i-1]); |
| 3469 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3470 | /* |
| 3471 | * Acl update can result in inode attribute update. |
| 3472 | * so mark the attribute cache invalid. |
| 3473 | */ |
| 3474 | spin_lock(&inode->i_lock); |
| 3475 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3476 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3477 | nfs_access_zap_cache(inode); |
| 3478 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3479 | return ret; |
| 3480 | } |
| 3481 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3482 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3483 | { |
| 3484 | struct nfs4_exception exception = { }; |
| 3485 | int err; |
| 3486 | do { |
| 3487 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3488 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3489 | &exception); |
| 3490 | } while (exception.retry); |
| 3491 | return err; |
| 3492 | } |
| 3493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3495 | 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] | 3496 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3497 | struct nfs_client *clp = server->nfs_client; |
| 3498 | |
| 3499 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | return 0; |
| 3501 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3502 | case -NFS4ERR_ADMIN_REVOKED: |
| 3503 | case -NFS4ERR_BAD_STATEID: |
| 3504 | case -NFS4ERR_OPENMODE: |
| 3505 | if (state == NULL) |
| 3506 | break; |
| 3507 | nfs4_state_mark_reclaim_nograce(clp, state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3508 | goto do_state_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3509 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3510 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3512 | goto do_state_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3513 | #if defined(CONFIG_NFS_V4_1) |
| 3514 | case -NFS4ERR_BADSESSION: |
| 3515 | case -NFS4ERR_BADSLOT: |
| 3516 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3517 | case -NFS4ERR_DEADSESSION: |
| 3518 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3519 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3520 | case -NFS4ERR_SEQ_MISORDERED: |
| 3521 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3522 | task->tk_status); |
Andy Adamson | 0b9e2d4 | 2009-12-04 16:02:14 -0500 | [diff] [blame] | 3523 | nfs4_schedule_state_recovery(clp); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3524 | task->tk_status = 0; |
| 3525 | return -EAGAIN; |
| 3526 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3528 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3529 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3530 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3532 | task->tk_status = 0; |
| 3533 | return -EAGAIN; |
| 3534 | case -NFS4ERR_OLD_STATEID: |
| 3535 | task->tk_status = 0; |
| 3536 | return -EAGAIN; |
| 3537 | } |
| 3538 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3539 | return 0; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3540 | do_state_recovery: |
| 3541 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
| 3542 | nfs4_schedule_state_recovery(clp); |
| 3543 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3544 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3545 | task->tk_status = 0; |
| 3546 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3549 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3550 | unsigned short port, struct rpc_cred *cred, |
| 3551 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | { |
| 3553 | nfs4_verifier sc_verifier; |
| 3554 | struct nfs4_setclientid setclientid = { |
| 3555 | .sc_verifier = &sc_verifier, |
| 3556 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3557 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | }; |
| 3559 | struct rpc_message msg = { |
| 3560 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3561 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3562 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3563 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3565 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | int loop = 0; |
| 3567 | int status; |
| 3568 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3569 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3571 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3572 | |
| 3573 | for(;;) { |
| 3574 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3575 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3576 | clp->cl_ipaddr, |
| 3577 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3578 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3579 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3580 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3581 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3582 | clp->cl_id_uniquifier); |
| 3583 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3584 | sizeof(setclientid.sc_netid), |
| 3585 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3586 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3588 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3590 | |
| 3591 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3592 | if (status != -NFS4ERR_CLID_INUSE) |
| 3593 | break; |
| 3594 | if (signalled()) |
| 3595 | break; |
| 3596 | if (loop++ & 1) |
J. Bruce Fields | 611c96c | 2010-12-13 19:05:46 -0500 | [diff] [blame] | 3597 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | else |
| 3599 | if (++clp->cl_id_uniquifier == 0) |
| 3600 | break; |
| 3601 | } |
| 3602 | return status; |
| 3603 | } |
| 3604 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3605 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3606 | struct nfs4_setclientid_res *arg, |
| 3607 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | { |
| 3609 | struct nfs_fsinfo fsinfo; |
| 3610 | struct rpc_message msg = { |
| 3611 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3612 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3613 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3614 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | }; |
| 3616 | unsigned long now; |
| 3617 | int status; |
| 3618 | |
| 3619 | now = jiffies; |
| 3620 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3621 | if (status == 0) { |
| 3622 | spin_lock(&clp->cl_lock); |
| 3623 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3624 | clp->cl_last_renewal = now; |
| 3625 | spin_unlock(&clp->cl_lock); |
| 3626 | } |
| 3627 | return status; |
| 3628 | } |
| 3629 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3630 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3631 | struct nfs4_setclientid_res *arg, |
| 3632 | struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3633 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3634 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3635 | int err; |
| 3636 | do { |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3637 | err = _nfs4_proc_setclientid_confirm(clp, arg, cred); |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3638 | switch (err) { |
| 3639 | case 0: |
| 3640 | return err; |
| 3641 | case -NFS4ERR_RESOURCE: |
| 3642 | /* The IBM lawyers misread another document! */ |
| 3643 | case -NFS4ERR_DELAY: |
| 3644 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3645 | } |
| 3646 | } while (err == 0); |
| 3647 | return err; |
| 3648 | } |
| 3649 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3650 | struct nfs4_delegreturndata { |
| 3651 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3652 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3653 | struct nfs_fh fh; |
| 3654 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3655 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3656 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3657 | int rpc_status; |
| 3658 | }; |
| 3659 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3660 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3661 | { |
| 3662 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3663 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3664 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3665 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3666 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3667 | switch (task->tk_status) { |
| 3668 | case -NFS4ERR_STALE_STATEID: |
| 3669 | case -NFS4ERR_EXPIRED: |
| 3670 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3671 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3672 | break; |
| 3673 | default: |
| 3674 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3675 | -EAGAIN) { |
| 3676 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3677 | return; |
| 3678 | } |
| 3679 | } |
| 3680 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | static void nfs4_delegreturn_release(void *calldata) |
| 3684 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3685 | kfree(calldata); |
| 3686 | } |
| 3687 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3688 | #if defined(CONFIG_NFS_V4_1) |
| 3689 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3690 | { |
| 3691 | struct nfs4_delegreturndata *d_data; |
| 3692 | |
| 3693 | d_data = (struct nfs4_delegreturndata *)data; |
| 3694 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3695 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3696 | &d_data->args.seq_args, |
| 3697 | &d_data->res.seq_res, 1, task)) |
| 3698 | return; |
| 3699 | rpc_call_start(task); |
| 3700 | } |
| 3701 | #endif /* CONFIG_NFS_V4_1 */ |
| 3702 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3703 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3704 | #if defined(CONFIG_NFS_V4_1) |
| 3705 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3706 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3707 | .rpc_call_done = nfs4_delegreturn_done, |
| 3708 | .rpc_release = nfs4_delegreturn_release, |
| 3709 | }; |
| 3710 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3711 | 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] | 3712 | { |
| 3713 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3714 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3715 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3716 | struct rpc_message msg = { |
| 3717 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3718 | .rpc_cred = cred, |
| 3719 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3720 | struct rpc_task_setup task_setup_data = { |
| 3721 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3722 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3723 | .callback_ops = &nfs4_delegreturn_ops, |
| 3724 | .flags = RPC_TASK_ASYNC, |
| 3725 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3726 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3727 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3728 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3729 | if (data == NULL) |
| 3730 | return -ENOMEM; |
| 3731 | data->args.fhandle = &data->fh; |
| 3732 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3733 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3734 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3735 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3736 | data->res.fattr = &data->fattr; |
| 3737 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3738 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3739 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3740 | data->rpc_status = 0; |
| 3741 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3742 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3743 | msg.rpc_argp = &data->args; |
| 3744 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3745 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3746 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3747 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3748 | if (!issync) |
| 3749 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3750 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3751 | if (status != 0) |
| 3752 | goto out; |
| 3753 | status = data->rpc_status; |
| 3754 | if (status != 0) |
| 3755 | goto out; |
| 3756 | nfs_refresh_inode(inode, &data->fattr); |
| 3757 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3758 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3759 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | } |
| 3761 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3762 | 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] | 3763 | { |
| 3764 | struct nfs_server *server = NFS_SERVER(inode); |
| 3765 | struct nfs4_exception exception = { }; |
| 3766 | int err; |
| 3767 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3768 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3769 | switch (err) { |
| 3770 | case -NFS4ERR_STALE_STATEID: |
| 3771 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | case 0: |
| 3773 | return 0; |
| 3774 | } |
| 3775 | err = nfs4_handle_exception(server, err, &exception); |
| 3776 | } while (exception.retry); |
| 3777 | return err; |
| 3778 | } |
| 3779 | |
| 3780 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3781 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3782 | |
| 3783 | /* |
| 3784 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3785 | */ |
| 3786 | static unsigned long |
| 3787 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3788 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3789 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | timeout <<= 1; |
| 3791 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3792 | return NFS4_LOCK_MAXTIMEOUT; |
| 3793 | return timeout; |
| 3794 | } |
| 3795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3797 | { |
| 3798 | struct inode *inode = state->inode; |
| 3799 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3800 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3801 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3803 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3805 | struct nfs_lockt_res res = { |
| 3806 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | }; |
| 3808 | struct rpc_message msg = { |
| 3809 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3810 | .rpc_argp = &arg, |
| 3811 | .rpc_resp = &res, |
| 3812 | .rpc_cred = state->owner->so_cred, |
| 3813 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | struct nfs4_lock_state *lsp; |
| 3815 | int status; |
| 3816 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3817 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3818 | status = nfs4_set_lock_state(state, request); |
| 3819 | if (status != 0) |
| 3820 | goto out; |
| 3821 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3822 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3823 | arg.lock_owner.s_dev = server->s_dev; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 3824 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3825 | switch (status) { |
| 3826 | case 0: |
| 3827 | request->fl_type = F_UNLCK; |
| 3828 | break; |
| 3829 | case -NFS4ERR_DENIED: |
| 3830 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3832 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3833 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | return status; |
| 3835 | } |
| 3836 | |
| 3837 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3838 | { |
| 3839 | struct nfs4_exception exception = { }; |
| 3840 | int err; |
| 3841 | |
| 3842 | do { |
| 3843 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3844 | _nfs4_proc_getlk(state, cmd, request), |
| 3845 | &exception); |
| 3846 | } while (exception.retry); |
| 3847 | return err; |
| 3848 | } |
| 3849 | |
| 3850 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3851 | { |
| 3852 | int res = 0; |
| 3853 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3854 | case FL_POSIX: |
| 3855 | res = posix_lock_file_wait(file, fl); |
| 3856 | break; |
| 3857 | case FL_FLOCK: |
| 3858 | res = flock_lock_file_wait(file, fl); |
| 3859 | break; |
| 3860 | default: |
| 3861 | BUG(); |
| 3862 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | return res; |
| 3864 | } |
| 3865 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3866 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3867 | struct nfs_locku_args arg; |
| 3868 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3869 | struct nfs4_lock_state *lsp; |
| 3870 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3871 | struct file_lock fl; |
| 3872 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3873 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3874 | }; |
| 3875 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3876 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 3877 | struct nfs_open_context *ctx, |
| 3878 | struct nfs4_lock_state *lsp, |
| 3879 | struct nfs_seqid *seqid) |
| 3880 | { |
| 3881 | struct nfs4_unlockdata *p; |
| 3882 | struct inode *inode = lsp->ls_state->inode; |
| 3883 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3884 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3885 | if (p == NULL) |
| 3886 | return NULL; |
| 3887 | p->arg.fh = NFS_FH(inode); |
| 3888 | p->arg.fl = &p->fl; |
| 3889 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3890 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3891 | p->arg.stateid = &lsp->ls_stateid; |
| 3892 | p->lsp = lsp; |
| 3893 | atomic_inc(&lsp->ls_count); |
| 3894 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3895 | p->ctx = get_nfs_open_context(ctx); |
| 3896 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3897 | p->server = NFS_SERVER(inode); |
| 3898 | return p; |
| 3899 | } |
| 3900 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3901 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3902 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3903 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3904 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3905 | nfs4_put_lock_state(calldata->lsp); |
| 3906 | put_nfs_open_context(calldata->ctx); |
| 3907 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3910 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3911 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3912 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3913 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3914 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 3915 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3916 | switch (task->tk_status) { |
| 3917 | case 0: |
| 3918 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3919 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3920 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3921 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3922 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3923 | case -NFS4ERR_BAD_STATEID: |
| 3924 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3925 | case -NFS4ERR_STALE_STATEID: |
| 3926 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3927 | break; |
| 3928 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3929 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3930 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 3931 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3932 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3933 | } |
| 3934 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3935 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3936 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3937 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3939 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3940 | return; |
| 3941 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3942 | /* Note: exit _without_ running nfs4_locku_done */ |
| 3943 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3944 | return; |
| 3945 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3946 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3947 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 3948 | &calldata->arg.seq_args, |
| 3949 | &calldata->res.seq_res, 1, task)) |
| 3950 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3951 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | } |
| 3953 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3954 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 3955 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3956 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3957 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3958 | }; |
| 3959 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3960 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 3961 | struct nfs_open_context *ctx, |
| 3962 | struct nfs4_lock_state *lsp, |
| 3963 | struct nfs_seqid *seqid) |
| 3964 | { |
| 3965 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3966 | struct rpc_message msg = { |
| 3967 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 3968 | .rpc_cred = ctx->cred, |
| 3969 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3970 | struct rpc_task_setup task_setup_data = { |
| 3971 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3972 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3973 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 3974 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3975 | .flags = RPC_TASK_ASYNC, |
| 3976 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3977 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 3978 | /* Ensure this is an unlock - when canceling a lock, the |
| 3979 | * canceled lock is passed in, and it won't be an unlock. |
| 3980 | */ |
| 3981 | fl->fl_type = F_UNLCK; |
| 3982 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3983 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 3984 | if (data == NULL) { |
| 3985 | nfs_free_seqid(seqid); |
| 3986 | return ERR_PTR(-ENOMEM); |
| 3987 | } |
| 3988 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3989 | msg.rpc_argp = &data->arg; |
| 3990 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3991 | task_setup_data.callback_data = data; |
| 3992 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 3993 | } |
| 3994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3996 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 3997 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3998 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3999 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4000 | struct rpc_task *task; |
| 4001 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4002 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4004 | status = nfs4_set_lock_state(state, request); |
| 4005 | /* Unlock _before_ we do the RPC call */ |
| 4006 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4007 | down_read(&nfsi->rwsem); |
| 4008 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4009 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4010 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4011 | } |
| 4012 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4013 | if (status != 0) |
| 4014 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4015 | /* Is this a delegated lock? */ |
| 4016 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4017 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4018 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4019 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4020 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4021 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4022 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4023 | 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] | 4024 | status = PTR_ERR(task); |
| 4025 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4026 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4027 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4028 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4029 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4030 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4031 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4034 | struct nfs4_lockdata { |
| 4035 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4036 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4037 | struct nfs4_lock_state *lsp; |
| 4038 | struct nfs_open_context *ctx; |
| 4039 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4040 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4041 | int rpc_status; |
| 4042 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4043 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4044 | }; |
| 4045 | |
| 4046 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4047 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4048 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4049 | { |
| 4050 | struct nfs4_lockdata *p; |
| 4051 | struct inode *inode = lsp->ls_state->inode; |
| 4052 | struct nfs_server *server = NFS_SERVER(inode); |
| 4053 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4054 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4055 | if (p == NULL) |
| 4056 | return NULL; |
| 4057 | |
| 4058 | p->arg.fh = NFS_FH(inode); |
| 4059 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4060 | 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] | 4061 | if (p->arg.open_seqid == NULL) |
| 4062 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4063 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4064 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4065 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4066 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4067 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4068 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4069 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4070 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4071 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4072 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4073 | atomic_inc(&lsp->ls_count); |
| 4074 | p->ctx = get_nfs_open_context(ctx); |
| 4075 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4076 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4077 | out_free_seqid: |
| 4078 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4079 | out_free: |
| 4080 | kfree(p); |
| 4081 | return NULL; |
| 4082 | } |
| 4083 | |
| 4084 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4085 | { |
| 4086 | struct nfs4_lockdata *data = calldata; |
| 4087 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4089 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4090 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4091 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4092 | /* Do we need to do an open_to_lock_owner? */ |
| 4093 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4094 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4095 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4096 | data->arg.open_stateid = &state->stateid; |
| 4097 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4098 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4099 | } else |
| 4100 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4101 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4102 | if (nfs4_setup_sequence(data->server, |
| 4103 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4104 | &data->res.seq_res, 1, task)) |
| 4105 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4106 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4107 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4108 | } |
| 4109 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4110 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4111 | { |
| 4112 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4113 | nfs4_lock_prepare(task, calldata); |
| 4114 | } |
| 4115 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4116 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4117 | { |
| 4118 | struct nfs4_lockdata *data = calldata; |
| 4119 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4120 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4121 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4122 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4123 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4124 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4125 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4126 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4127 | if (data->rpc_status == 0) |
| 4128 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4129 | else |
| 4130 | goto out; |
| 4131 | } |
| 4132 | if (data->rpc_status == 0) { |
| 4133 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4134 | sizeof(data->lsp->ls_stateid.data)); |
| 4135 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4136 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4137 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4138 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4139 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | static void nfs4_lock_release(void *calldata) |
| 4143 | { |
| 4144 | struct nfs4_lockdata *data = calldata; |
| 4145 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4146 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4147 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4148 | if (data->cancelled != 0) { |
| 4149 | struct rpc_task *task; |
| 4150 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4151 | data->arg.lock_seqid); |
| 4152 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4153 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4154 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4155 | } else |
| 4156 | nfs_free_seqid(data->arg.lock_seqid); |
| 4157 | nfs4_put_lock_state(data->lsp); |
| 4158 | put_nfs_open_context(data->ctx); |
| 4159 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4160 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4164 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4165 | .rpc_call_done = nfs4_lock_done, |
| 4166 | .rpc_release = nfs4_lock_release, |
| 4167 | }; |
| 4168 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4169 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4170 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4171 | .rpc_call_done = nfs4_lock_done, |
| 4172 | .rpc_release = nfs4_lock_release, |
| 4173 | }; |
| 4174 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4175 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4176 | { |
| 4177 | struct nfs_client *clp = server->nfs_client; |
| 4178 | struct nfs4_state *state = lsp->ls_state; |
| 4179 | |
| 4180 | switch (error) { |
| 4181 | case -NFS4ERR_ADMIN_REVOKED: |
| 4182 | case -NFS4ERR_BAD_STATEID: |
| 4183 | case -NFS4ERR_EXPIRED: |
| 4184 | if (new_lock_owner != 0 || |
| 4185 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
| 4186 | nfs4_state_mark_reclaim_nograce(clp, state); |
| 4187 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4188 | break; |
| 4189 | case -NFS4ERR_STALE_STATEID: |
| 4190 | if (new_lock_owner != 0 || |
| 4191 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
| 4192 | nfs4_state_mark_reclaim_reboot(clp, state); |
| 4193 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4194 | }; |
| 4195 | } |
| 4196 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4197 | 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] | 4198 | { |
| 4199 | struct nfs4_lockdata *data; |
| 4200 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4201 | struct rpc_message msg = { |
| 4202 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4203 | .rpc_cred = state->owner->so_cred, |
| 4204 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4205 | struct rpc_task_setup task_setup_data = { |
| 4206 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4207 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4208 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4209 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4210 | .flags = RPC_TASK_ASYNC, |
| 4211 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4212 | int ret; |
| 4213 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4214 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4215 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4216 | fl->fl_u.nfs4_fl.owner, |
| 4217 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4218 | if (data == NULL) |
| 4219 | return -ENOMEM; |
| 4220 | if (IS_SETLKW(cmd)) |
| 4221 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4222 | if (recovery_type > NFS_LOCK_NEW) { |
| 4223 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4224 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4225 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4226 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4227 | msg.rpc_argp = &data->arg; |
| 4228 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4229 | task_setup_data.callback_data = data; |
| 4230 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4231 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4232 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4233 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4234 | if (ret == 0) { |
| 4235 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4236 | if (ret) |
| 4237 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4238 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4239 | } else |
| 4240 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4241 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4242 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4243 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4247 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4248 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4249 | struct nfs4_exception exception = { }; |
| 4250 | int err; |
| 4251 | |
| 4252 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4253 | /* Cache the lock if possible... */ |
| 4254 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4255 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4256 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4257 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4258 | break; |
| 4259 | nfs4_handle_exception(server, err, &exception); |
| 4260 | } while (exception.retry); |
| 4261 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4265 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4266 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4267 | struct nfs4_exception exception = { }; |
| 4268 | int err; |
| 4269 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4270 | err = nfs4_set_lock_state(state, request); |
| 4271 | if (err != 0) |
| 4272 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4273 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4274 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4275 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4276 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4277 | switch (err) { |
| 4278 | default: |
| 4279 | goto out; |
| 4280 | case -NFS4ERR_GRACE: |
| 4281 | case -NFS4ERR_DELAY: |
| 4282 | nfs4_handle_exception(server, err, &exception); |
| 4283 | err = 0; |
| 4284 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4285 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4286 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4287 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4291 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4292 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4293 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4294 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4296 | if ((fl_flags & FL_POSIX) && |
| 4297 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4298 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4299 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4300 | status = nfs4_set_lock_state(state, request); |
| 4301 | if (status != 0) |
| 4302 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4303 | request->fl_flags |= FL_ACCESS; |
| 4304 | status = do_vfs_lock(request->fl_file, request); |
| 4305 | if (status < 0) |
| 4306 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4307 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4308 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4309 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4310 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4311 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4312 | status = do_vfs_lock(request->fl_file, request); |
| 4313 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4314 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4315 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4316 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4317 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4318 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4319 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4320 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4321 | 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] | 4322 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4323 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4324 | out: |
| 4325 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | return status; |
| 4327 | } |
| 4328 | |
| 4329 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4330 | { |
| 4331 | struct nfs4_exception exception = { }; |
| 4332 | int err; |
| 4333 | |
| 4334 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4335 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4336 | if (err == -NFS4ERR_DENIED) |
| 4337 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4339 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | } while (exception.retry); |
| 4341 | return err; |
| 4342 | } |
| 4343 | |
| 4344 | static int |
| 4345 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4346 | { |
| 4347 | struct nfs_open_context *ctx; |
| 4348 | struct nfs4_state *state; |
| 4349 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4350 | int status; |
| 4351 | |
| 4352 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4353 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | state = ctx->state; |
| 4355 | |
| 4356 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4357 | return -EINVAL; |
| 4358 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4359 | if (IS_GETLK(cmd)) { |
| 4360 | if (state != NULL) |
| 4361 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4362 | return 0; |
| 4363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | |
| 4365 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4366 | return -EINVAL; |
| 4367 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4368 | if (request->fl_type == F_UNLCK) { |
| 4369 | if (state != NULL) |
| 4370 | return nfs4_proc_unlck(state, cmd, request); |
| 4371 | return 0; |
| 4372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4374 | if (state == NULL) |
| 4375 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | do { |
| 4377 | status = nfs4_proc_setlk(state, cmd, request); |
| 4378 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4379 | break; |
| 4380 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4381 | status = -ERESTARTSYS; |
| 4382 | if (signalled()) |
| 4383 | break; |
| 4384 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | return status; |
| 4386 | } |
| 4387 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4388 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4389 | { |
| 4390 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4391 | struct nfs4_exception exception = { }; |
| 4392 | int err; |
| 4393 | |
| 4394 | err = nfs4_set_lock_state(state, fl); |
| 4395 | if (err != 0) |
| 4396 | goto out; |
| 4397 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4398 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4399 | switch (err) { |
| 4400 | default: |
| 4401 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4402 | __func__, err); |
| 4403 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4404 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4405 | goto out; |
| 4406 | case -NFS4ERR_EXPIRED: |
| 4407 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4408 | case -NFS4ERR_STALE_STATEID: |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4409 | case -NFS4ERR_BADSESSION: |
| 4410 | case -NFS4ERR_BADSLOT: |
| 4411 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4412 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4413 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4414 | nfs4_schedule_state_recovery(server->nfs_client); |
| 4415 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4416 | case -ERESTARTSYS: |
| 4417 | /* |
| 4418 | * The show must go on: exit, but mark the |
| 4419 | * stateid as needing recovery. |
| 4420 | */ |
| 4421 | case -NFS4ERR_ADMIN_REVOKED: |
| 4422 | case -NFS4ERR_BAD_STATEID: |
| 4423 | case -NFS4ERR_OPENMODE: |
| 4424 | nfs4_state_mark_reclaim_nograce(server->nfs_client, state); |
| 4425 | err = 0; |
| 4426 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4427 | case -EKEYEXPIRED: |
| 4428 | /* |
| 4429 | * User RPCSEC_GSS context has expired. |
| 4430 | * We cannot recover this stateid now, so |
| 4431 | * skip it and allow recovery thread to |
| 4432 | * proceed. |
| 4433 | */ |
| 4434 | err = 0; |
| 4435 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4436 | case -ENOMEM: |
| 4437 | case -NFS4ERR_DENIED: |
| 4438 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4439 | err = 0; |
| 4440 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4441 | case -NFS4ERR_DELAY: |
| 4442 | break; |
| 4443 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4444 | err = nfs4_handle_exception(server, err, &exception); |
| 4445 | } while (exception.retry); |
| 4446 | out: |
| 4447 | return err; |
| 4448 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4449 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4450 | static void nfs4_release_lockowner_release(void *calldata) |
| 4451 | { |
| 4452 | kfree(calldata); |
| 4453 | } |
| 4454 | |
| 4455 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4456 | .rpc_release = nfs4_release_lockowner_release, |
| 4457 | }; |
| 4458 | |
| 4459 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4460 | { |
| 4461 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4462 | struct nfs_release_lockowner_args *args; |
| 4463 | struct rpc_message msg = { |
| 4464 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4465 | }; |
| 4466 | |
| 4467 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4468 | return; |
| 4469 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4470 | if (!args) |
| 4471 | return; |
| 4472 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4473 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4474 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4475 | msg.rpc_argp = args; |
| 4476 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4477 | } |
| 4478 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4479 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4480 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4481 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4482 | const void *buf, size_t buflen, |
| 4483 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4484 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4485 | if (strcmp(key, "") != 0) |
| 4486 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4487 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4488 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4489 | } |
| 4490 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4491 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4492 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4493 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4494 | if (strcmp(key, "") != 0) |
| 4495 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4496 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4497 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4498 | } |
| 4499 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4500 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4501 | size_t list_len, const char *name, |
| 4502 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4503 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4504 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4505 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4506 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4507 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4508 | |
| 4509 | if (list && len <= list_len) |
| 4510 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4511 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4512 | } |
| 4513 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4514 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4515 | { |
| 4516 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4517 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4518 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4519 | return; |
| 4520 | |
| 4521 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4522 | NFS_ATTR_FATTR_NLINK; |
| 4523 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4524 | fattr->nlink = 2; |
| 4525 | } |
| 4526 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4527 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4528 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4529 | { |
| 4530 | struct nfs_server *server = NFS_SERVER(dir); |
| 4531 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4532 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4533 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4534 | }; |
| 4535 | struct nfs4_fs_locations_arg args = { |
| 4536 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4537 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4538 | .page = page, |
| 4539 | .bitmask = bitmask, |
| 4540 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4541 | struct nfs4_fs_locations_res res = { |
| 4542 | .fs_locations = fs_locations, |
| 4543 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4544 | struct rpc_message msg = { |
| 4545 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4546 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4547 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4548 | }; |
| 4549 | int status; |
| 4550 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4551 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4552 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4553 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4554 | fs_locations->nlocations = 0; |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 4555 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4556 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4557 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4558 | return status; |
| 4559 | } |
| 4560 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4561 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4562 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4563 | * Check the exchange flags returned by the server for invalid flags, having |
| 4564 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4565 | * DS flags set. |
| 4566 | */ |
| 4567 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4568 | { |
| 4569 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4570 | goto out_inval; |
| 4571 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4572 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4573 | goto out_inval; |
| 4574 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4575 | goto out_inval; |
| 4576 | return NFS_OK; |
| 4577 | out_inval: |
| 4578 | return -NFS4ERR_INVAL; |
| 4579 | } |
| 4580 | |
| 4581 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4582 | * nfs4_proc_exchange_id() |
| 4583 | * |
| 4584 | * Since the clientid has expired, all compounds using sessions |
| 4585 | * associated with the stale clientid will be returning |
| 4586 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4587 | * be in some phase of session reset. |
| 4588 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4589 | 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] | 4590 | { |
| 4591 | nfs4_verifier verifier; |
| 4592 | struct nfs41_exchange_id_args args = { |
| 4593 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4594 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4595 | }; |
| 4596 | struct nfs41_exchange_id_res res = { |
| 4597 | .client = clp, |
| 4598 | }; |
| 4599 | int status; |
| 4600 | struct rpc_message msg = { |
| 4601 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4602 | .rpc_argp = &args, |
| 4603 | .rpc_resp = &res, |
| 4604 | .rpc_cred = cred, |
| 4605 | }; |
| 4606 | __be32 *p; |
| 4607 | |
| 4608 | dprintk("--> %s\n", __func__); |
| 4609 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4610 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4611 | p = (u32 *)verifier.data; |
| 4612 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4613 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4614 | args.verifier = &verifier; |
| 4615 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4616 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4617 | "%s/%s.%s/%u", |
| 4618 | clp->cl_ipaddr, |
| 4619 | init_utsname()->nodename, |
| 4620 | init_utsname()->domainname, |
| 4621 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4622 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4623 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4624 | if (!status) |
| 4625 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4626 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4627 | return status; |
| 4628 | } |
| 4629 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4630 | struct nfs4_get_lease_time_data { |
| 4631 | struct nfs4_get_lease_time_args *args; |
| 4632 | struct nfs4_get_lease_time_res *res; |
| 4633 | struct nfs_client *clp; |
| 4634 | }; |
| 4635 | |
| 4636 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4637 | void *calldata) |
| 4638 | { |
| 4639 | int ret; |
| 4640 | struct nfs4_get_lease_time_data *data = |
| 4641 | (struct nfs4_get_lease_time_data *)calldata; |
| 4642 | |
| 4643 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4644 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4645 | /* just setup sequence, do not trigger session recovery |
| 4646 | since we're invoked within one */ |
| 4647 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4648 | &data->args->la_seq_args, |
| 4649 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4650 | |
| 4651 | BUG_ON(ret == -EAGAIN); |
| 4652 | rpc_call_start(task); |
| 4653 | dprintk("<-- %s\n", __func__); |
| 4654 | } |
| 4655 | |
| 4656 | /* |
| 4657 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4658 | * from sequence operation or clientid errors. |
| 4659 | */ |
| 4660 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4661 | { |
| 4662 | struct nfs4_get_lease_time_data *data = |
| 4663 | (struct nfs4_get_lease_time_data *)calldata; |
| 4664 | |
| 4665 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4666 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4667 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4668 | switch (task->tk_status) { |
| 4669 | case -NFS4ERR_DELAY: |
| 4670 | case -NFS4ERR_GRACE: |
| 4671 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4672 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4673 | task->tk_status = 0; |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4674 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4675 | return; |
| 4676 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4677 | dprintk("<-- %s\n", __func__); |
| 4678 | } |
| 4679 | |
| 4680 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4681 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4682 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4683 | }; |
| 4684 | |
| 4685 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4686 | { |
| 4687 | struct rpc_task *task; |
| 4688 | struct nfs4_get_lease_time_args args; |
| 4689 | struct nfs4_get_lease_time_res res = { |
| 4690 | .lr_fsinfo = fsinfo, |
| 4691 | }; |
| 4692 | struct nfs4_get_lease_time_data data = { |
| 4693 | .args = &args, |
| 4694 | .res = &res, |
| 4695 | .clp = clp, |
| 4696 | }; |
| 4697 | struct rpc_message msg = { |
| 4698 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4699 | .rpc_argp = &args, |
| 4700 | .rpc_resp = &res, |
| 4701 | }; |
| 4702 | struct rpc_task_setup task_setup = { |
| 4703 | .rpc_client = clp->cl_rpcclient, |
| 4704 | .rpc_message = &msg, |
| 4705 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4706 | .callback_data = &data |
| 4707 | }; |
| 4708 | int status; |
| 4709 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4710 | dprintk("--> %s\n", __func__); |
| 4711 | task = rpc_run_task(&task_setup); |
| 4712 | |
| 4713 | if (IS_ERR(task)) |
| 4714 | status = PTR_ERR(task); |
| 4715 | else { |
| 4716 | status = task->tk_status; |
| 4717 | rpc_put_task(task); |
| 4718 | } |
| 4719 | dprintk("<-- %s return %d\n", __func__, status); |
| 4720 | |
| 4721 | return status; |
| 4722 | } |
| 4723 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4724 | /* |
| 4725 | * Reset a slot table |
| 4726 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4727 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4728 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4729 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4730 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4731 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4732 | int ret = 0; |
| 4733 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4734 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4735 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4736 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4737 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4738 | if (max_reqs != tbl->max_slots) { |
| 4739 | ret = -ENOMEM; |
| 4740 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4741 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4742 | if (!new) |
| 4743 | goto out; |
| 4744 | ret = 0; |
| 4745 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4746 | } |
| 4747 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4748 | if (new) { |
| 4749 | tbl->slots = new; |
| 4750 | tbl->max_slots = max_reqs; |
| 4751 | } |
| 4752 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4753 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4754 | spin_unlock(&tbl->slot_tbl_lock); |
| 4755 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4756 | tbl, tbl->slots, tbl->max_slots); |
| 4757 | out: |
| 4758 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4759 | return ret; |
| 4760 | } |
| 4761 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4762 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4763 | * Reset the forechannel and backchannel slot tables |
| 4764 | */ |
| 4765 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4766 | { |
| 4767 | int status; |
| 4768 | |
| 4769 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4770 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4771 | if (status) |
| 4772 | return status; |
| 4773 | |
| 4774 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4775 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4776 | return status; |
| 4777 | } |
| 4778 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4779 | /* Destroy the slot table */ |
| 4780 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4781 | { |
| 4782 | if (session->fc_slot_table.slots != NULL) { |
| 4783 | kfree(session->fc_slot_table.slots); |
| 4784 | session->fc_slot_table.slots = NULL; |
| 4785 | } |
| 4786 | if (session->bc_slot_table.slots != NULL) { |
| 4787 | kfree(session->bc_slot_table.slots); |
| 4788 | session->bc_slot_table.slots = NULL; |
| 4789 | } |
| 4790 | return; |
| 4791 | } |
| 4792 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4793 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4794 | * Initialize slot table |
| 4795 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4796 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4797 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4798 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4799 | struct nfs4_slot *slot; |
| 4800 | int ret = -ENOMEM; |
| 4801 | |
| 4802 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4803 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4804 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4805 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4806 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4807 | if (!slot) |
| 4808 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4809 | ret = 0; |
| 4810 | |
| 4811 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4812 | tbl->max_slots = max_slots; |
| 4813 | tbl->slots = slot; |
| 4814 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4815 | spin_unlock(&tbl->slot_tbl_lock); |
| 4816 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4817 | tbl, tbl->slots, tbl->max_slots); |
| 4818 | out: |
| 4819 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4820 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4821 | } |
| 4822 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4823 | /* |
| 4824 | * Initialize the forechannel and backchannel tables |
| 4825 | */ |
| 4826 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4827 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4828 | struct nfs4_slot_table *tbl; |
| 4829 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4830 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4831 | tbl = &session->fc_slot_table; |
| 4832 | if (tbl->slots == NULL) { |
| 4833 | status = nfs4_init_slot_table(tbl, |
| 4834 | session->fc_attrs.max_reqs, 1); |
| 4835 | if (status) |
| 4836 | return status; |
| 4837 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4838 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4839 | tbl = &session->bc_slot_table; |
| 4840 | if (tbl->slots == NULL) { |
| 4841 | status = nfs4_init_slot_table(tbl, |
| 4842 | session->bc_attrs.max_reqs, 0); |
| 4843 | if (status) |
| 4844 | nfs4_destroy_slot_tables(session); |
| 4845 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4846 | |
| 4847 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 4851 | { |
| 4852 | struct nfs4_session *session; |
| 4853 | struct nfs4_slot_table *tbl; |
| 4854 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4855 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4856 | if (!session) |
| 4857 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4858 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4859 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4860 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4861 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4862 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4863 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4864 | |
| 4865 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4866 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4867 | spin_lock_init(&tbl->slot_tbl_lock); |
| 4868 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4869 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4870 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 4871 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 4872 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4873 | session->clp = clp; |
| 4874 | return session; |
| 4875 | } |
| 4876 | |
| 4877 | void nfs4_destroy_session(struct nfs4_session *session) |
| 4878 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 4879 | nfs4_proc_destroy_session(session); |
| 4880 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 4881 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 4882 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 4883 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4884 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4885 | kfree(session); |
| 4886 | } |
| 4887 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4888 | /* |
| 4889 | * Initialize the values to be used by the client in CREATE_SESSION |
| 4890 | * If nfs4_init_session set the fore channel request and response sizes, |
| 4891 | * use them. |
| 4892 | * |
| 4893 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 4894 | * always set csa_cachethis to FALSE because the current implementation |
| 4895 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 4896 | */ |
| 4897 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 4898 | { |
| 4899 | struct nfs4_session *session = args->client->cl_session; |
| 4900 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 4901 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 4902 | |
| 4903 | if (mxrqst_sz == 0) |
| 4904 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 4905 | if (mxresp_sz == 0) |
| 4906 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 4907 | /* Fore channel attributes */ |
| 4908 | args->fc_attrs.headerpadsz = 0; |
| 4909 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 4910 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4911 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 4912 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 4913 | |
| 4914 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4915 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4916 | __func__, |
| 4917 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 4918 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4919 | |
| 4920 | /* Back channel attributes */ |
| 4921 | args->bc_attrs.headerpadsz = 0; |
| 4922 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 4923 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 4924 | args->bc_attrs.max_resp_sz_cached = 0; |
| 4925 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 4926 | args->bc_attrs.max_reqs = 1; |
| 4927 | |
| 4928 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 4929 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 4930 | __func__, |
| 4931 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 4932 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 4933 | args->bc_attrs.max_reqs); |
| 4934 | } |
| 4935 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4936 | 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] | 4937 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4938 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 4939 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 4940 | |
| 4941 | if (rcvd->headerpadsz > sent->headerpadsz) |
| 4942 | return -EINVAL; |
| 4943 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 4944 | return -EINVAL; |
| 4945 | /* |
| 4946 | * Our requested max_ops is the minimum we need; we're not |
| 4947 | * prepared to break up compounds into smaller pieces than that. |
| 4948 | * So, no point even trying to continue if the server won't |
| 4949 | * cooperate: |
| 4950 | */ |
| 4951 | if (rcvd->max_ops < sent->max_ops) |
| 4952 | return -EINVAL; |
| 4953 | if (rcvd->max_reqs == 0) |
| 4954 | return -EINVAL; |
| 4955 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4956 | } |
| 4957 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4958 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 4959 | { |
| 4960 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 4961 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4962 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4963 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 4964 | return -EINVAL; |
| 4965 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 4966 | return -EINVAL; |
| 4967 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 4968 | return -EINVAL; |
| 4969 | /* These would render the backchannel useless: */ |
| 4970 | if (rcvd->max_ops == 0) |
| 4971 | return -EINVAL; |
| 4972 | if (rcvd->max_reqs == 0) |
| 4973 | return -EINVAL; |
| 4974 | return 0; |
| 4975 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4976 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4977 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 4978 | struct nfs4_session *session) |
| 4979 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4980 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4981 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 4982 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 4983 | if (ret) |
| 4984 | return ret; |
| 4985 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 4986 | } |
| 4987 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4988 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 4989 | { |
| 4990 | struct nfs4_session *session = clp->cl_session; |
| 4991 | struct nfs41_create_session_args args = { |
| 4992 | .client = clp, |
| 4993 | .cb_program = NFS4_CALLBACK, |
| 4994 | }; |
| 4995 | struct nfs41_create_session_res res = { |
| 4996 | .client = clp, |
| 4997 | }; |
| 4998 | struct rpc_message msg = { |
| 4999 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5000 | .rpc_argp = &args, |
| 5001 | .rpc_resp = &res, |
| 5002 | }; |
| 5003 | int status; |
| 5004 | |
| 5005 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5006 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5007 | |
| 5008 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5009 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5010 | if (!status) |
| 5011 | /* Verify the session's negotiated channel_attrs values */ |
| 5012 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5013 | if (!status) { |
| 5014 | /* Increment the clientid slot sequence id */ |
| 5015 | clp->cl_seqid++; |
| 5016 | } |
| 5017 | |
| 5018 | return status; |
| 5019 | } |
| 5020 | |
| 5021 | /* |
| 5022 | * Issues a CREATE_SESSION operation to the server. |
| 5023 | * It is the responsibility of the caller to verify the session is |
| 5024 | * expired before calling this routine. |
| 5025 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5026 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5027 | { |
| 5028 | int status; |
| 5029 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5030 | struct nfs4_session *session = clp->cl_session; |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5031 | long timeout = 0; |
| 5032 | int err; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5033 | |
| 5034 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5035 | |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5036 | do { |
| 5037 | status = _nfs4_proc_create_session(clp); |
| 5038 | if (status == -NFS4ERR_DELAY) { |
| 5039 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 5040 | if (err) |
| 5041 | status = err; |
| 5042 | } |
| 5043 | } while (status == -NFS4ERR_DELAY); |
| 5044 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5045 | if (status) |
| 5046 | goto out; |
| 5047 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5048 | /* Init and reset the fore channel */ |
| 5049 | status = nfs4_init_slot_tables(session); |
| 5050 | dprintk("slot table initialization returned %d\n", status); |
| 5051 | if (status) |
| 5052 | goto out; |
| 5053 | status = nfs4_reset_slot_tables(session); |
| 5054 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5055 | if (status) |
| 5056 | goto out; |
| 5057 | |
| 5058 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5059 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5060 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5061 | out: |
| 5062 | dprintk("<-- %s\n", __func__); |
| 5063 | return status; |
| 5064 | } |
| 5065 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5066 | /* |
| 5067 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5068 | * The caller must serialize access to this routine. |
| 5069 | */ |
| 5070 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5071 | { |
| 5072 | int status = 0; |
| 5073 | struct rpc_message msg; |
| 5074 | |
| 5075 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5076 | |
| 5077 | /* session is still being setup */ |
| 5078 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5079 | return status; |
| 5080 | |
| 5081 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5082 | msg.rpc_argp = session; |
| 5083 | msg.rpc_resp = NULL; |
| 5084 | msg.rpc_cred = NULL; |
| 5085 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5086 | |
| 5087 | if (status) |
| 5088 | printk(KERN_WARNING |
| 5089 | "Got error %d from the server on DESTROY_SESSION. " |
| 5090 | "Session has been destroyed regardless...\n", status); |
| 5091 | |
| 5092 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5093 | return status; |
| 5094 | } |
| 5095 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5096 | int nfs4_init_session(struct nfs_server *server) |
| 5097 | { |
| 5098 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5099 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5100 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5101 | int ret; |
| 5102 | |
| 5103 | if (!nfs4_has_session(clp)) |
| 5104 | return 0; |
| 5105 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5106 | session = clp->cl_session; |
| 5107 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5108 | return 0; |
| 5109 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5110 | rsize = server->rsize; |
| 5111 | if (rsize == 0) |
| 5112 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5113 | wsize = server->wsize; |
| 5114 | if (wsize == 0) |
| 5115 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5116 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5117 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5118 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5119 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5120 | ret = nfs4_recover_expired_lease(server); |
| 5121 | if (!ret) |
| 5122 | ret = nfs4_check_client_ready(clp); |
| 5123 | return ret; |
| 5124 | } |
| 5125 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5126 | /* |
| 5127 | * Renew the cl_session lease. |
| 5128 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5129 | struct nfs4_sequence_data { |
| 5130 | struct nfs_client *clp; |
| 5131 | struct nfs4_sequence_args args; |
| 5132 | struct nfs4_sequence_res res; |
| 5133 | }; |
| 5134 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5135 | static void nfs41_sequence_release(void *data) |
| 5136 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5137 | struct nfs4_sequence_data *calldata = data; |
| 5138 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5139 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5140 | if (atomic_read(&clp->cl_count) > 1) |
| 5141 | nfs4_schedule_state_renewal(clp); |
| 5142 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5143 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5144 | } |
| 5145 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5146 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5147 | { |
| 5148 | switch(task->tk_status) { |
| 5149 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5150 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5151 | return -EAGAIN; |
| 5152 | default: |
| 5153 | nfs4_schedule_state_recovery(clp); |
| 5154 | } |
| 5155 | return 0; |
| 5156 | } |
| 5157 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5158 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5159 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5160 | struct nfs4_sequence_data *calldata = data; |
| 5161 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5162 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5163 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5164 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5165 | |
| 5166 | if (task->tk_status < 0) { |
| 5167 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5168 | if (atomic_read(&clp->cl_count) == 1) |
| 5169 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5170 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5171 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5172 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5173 | return; |
| 5174 | } |
| 5175 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5176 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5177 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5178 | dprintk("<-- %s\n", __func__); |
| 5179 | } |
| 5180 | |
| 5181 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5182 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5183 | struct nfs4_sequence_data *calldata = data; |
| 5184 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5185 | struct nfs4_sequence_args *args; |
| 5186 | struct nfs4_sequence_res *res; |
| 5187 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5188 | args = task->tk_msg.rpc_argp; |
| 5189 | res = task->tk_msg.rpc_resp; |
| 5190 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5191 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5192 | return; |
| 5193 | rpc_call_start(task); |
| 5194 | } |
| 5195 | |
| 5196 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5197 | .rpc_call_done = nfs41_sequence_call_done, |
| 5198 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5199 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5200 | }; |
| 5201 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5202 | 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] | 5203 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5204 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5205 | struct rpc_message msg = { |
| 5206 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5207 | .rpc_cred = cred, |
| 5208 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5209 | struct rpc_task_setup task_setup_data = { |
| 5210 | .rpc_client = clp->cl_rpcclient, |
| 5211 | .rpc_message = &msg, |
| 5212 | .callback_ops = &nfs41_sequence_ops, |
| 5213 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5214 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5215 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5216 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5217 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5218 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5219 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5220 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5221 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5222 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5223 | msg.rpc_argp = &calldata->args; |
| 5224 | msg.rpc_resp = &calldata->res; |
| 5225 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5226 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5227 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5228 | return rpc_run_task(&task_setup_data); |
| 5229 | } |
| 5230 | |
| 5231 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5232 | { |
| 5233 | struct rpc_task *task; |
| 5234 | int ret = 0; |
| 5235 | |
| 5236 | task = _nfs41_proc_sequence(clp, cred); |
| 5237 | if (IS_ERR(task)) |
| 5238 | ret = PTR_ERR(task); |
| 5239 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5240 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5241 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5242 | return ret; |
| 5243 | } |
| 5244 | |
| 5245 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5246 | { |
| 5247 | struct rpc_task *task; |
| 5248 | int ret; |
| 5249 | |
| 5250 | task = _nfs41_proc_sequence(clp, cred); |
| 5251 | if (IS_ERR(task)) { |
| 5252 | ret = PTR_ERR(task); |
| 5253 | goto out; |
| 5254 | } |
| 5255 | ret = rpc_wait_for_completion_task(task); |
| 5256 | if (!ret) |
| 5257 | ret = task->tk_status; |
| 5258 | rpc_put_task(task); |
| 5259 | out: |
| 5260 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5261 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5262 | } |
| 5263 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5264 | struct nfs4_reclaim_complete_data { |
| 5265 | struct nfs_client *clp; |
| 5266 | struct nfs41_reclaim_complete_args arg; |
| 5267 | struct nfs41_reclaim_complete_res res; |
| 5268 | }; |
| 5269 | |
| 5270 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5271 | { |
| 5272 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5273 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5274 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5275 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5276 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5277 | &calldata->res.seq_res, 0, task)) |
| 5278 | return; |
| 5279 | |
| 5280 | rpc_call_start(task); |
| 5281 | } |
| 5282 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5283 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5284 | { |
| 5285 | switch(task->tk_status) { |
| 5286 | case 0: |
| 5287 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5288 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5289 | break; |
| 5290 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5291 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5292 | return -EAGAIN; |
| 5293 | default: |
| 5294 | nfs4_schedule_state_recovery(clp); |
| 5295 | } |
| 5296 | return 0; |
| 5297 | } |
| 5298 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5299 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5300 | { |
| 5301 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5302 | struct nfs_client *clp = calldata->clp; |
| 5303 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5304 | |
| 5305 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5306 | if (!nfs41_sequence_done(task, res)) |
| 5307 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5308 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5309 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5310 | rpc_restart_call_prepare(task); |
| 5311 | return; |
| 5312 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5313 | dprintk("<-- %s\n", __func__); |
| 5314 | } |
| 5315 | |
| 5316 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5317 | { |
| 5318 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5319 | |
| 5320 | kfree(calldata); |
| 5321 | } |
| 5322 | |
| 5323 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5324 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5325 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5326 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5327 | }; |
| 5328 | |
| 5329 | /* |
| 5330 | * Issue a global reclaim complete. |
| 5331 | */ |
| 5332 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5333 | { |
| 5334 | struct nfs4_reclaim_complete_data *calldata; |
| 5335 | struct rpc_task *task; |
| 5336 | struct rpc_message msg = { |
| 5337 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5338 | }; |
| 5339 | struct rpc_task_setup task_setup_data = { |
| 5340 | .rpc_client = clp->cl_rpcclient, |
| 5341 | .rpc_message = &msg, |
| 5342 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5343 | .flags = RPC_TASK_ASYNC, |
| 5344 | }; |
| 5345 | int status = -ENOMEM; |
| 5346 | |
| 5347 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5348 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5349 | if (calldata == NULL) |
| 5350 | goto out; |
| 5351 | calldata->clp = clp; |
| 5352 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5353 | |
| 5354 | msg.rpc_argp = &calldata->arg; |
| 5355 | msg.rpc_resp = &calldata->res; |
| 5356 | task_setup_data.callback_data = calldata; |
| 5357 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5358 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5359 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5360 | goto out; |
| 5361 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame^] | 5362 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5363 | if (status == 0) |
| 5364 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5365 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5366 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5367 | out: |
| 5368 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5369 | return status; |
| 5370 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5371 | |
| 5372 | static void |
| 5373 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5374 | { |
| 5375 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5376 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5377 | |
| 5378 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5379 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5380 | * right now covering the LAYOUTGET we are about to send. |
| 5381 | * However, that is not so catastrophic, and there seems |
| 5382 | * to be no way to prevent it completely. |
| 5383 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5384 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5385 | &lgp->res.seq_res, 0, task)) |
| 5386 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5387 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5388 | NFS_I(lgp->args.inode)->layout, |
| 5389 | lgp->args.ctx->state)) { |
| 5390 | rpc_exit(task, NFS4_OK); |
| 5391 | return; |
| 5392 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5393 | rpc_call_start(task); |
| 5394 | } |
| 5395 | |
| 5396 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5397 | { |
| 5398 | struct nfs4_layoutget *lgp = calldata; |
| 5399 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5400 | |
| 5401 | dprintk("--> %s\n", __func__); |
| 5402 | |
| 5403 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5404 | return; |
| 5405 | |
| 5406 | switch (task->tk_status) { |
| 5407 | case 0: |
| 5408 | break; |
| 5409 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5410 | case -NFS4ERR_RECALLCONFLICT: |
| 5411 | task->tk_status = -NFS4ERR_DELAY; |
| 5412 | /* Fall through */ |
| 5413 | default: |
| 5414 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5415 | rpc_restart_call_prepare(task); |
| 5416 | return; |
| 5417 | } |
| 5418 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5419 | dprintk("<-- %s\n", __func__); |
| 5420 | } |
| 5421 | |
| 5422 | static void nfs4_layoutget_release(void *calldata) |
| 5423 | { |
| 5424 | struct nfs4_layoutget *lgp = calldata; |
| 5425 | |
| 5426 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5427 | if (lgp->res.layout.buf != NULL) |
| 5428 | free_page((unsigned long) lgp->res.layout.buf); |
| 5429 | put_nfs_open_context(lgp->args.ctx); |
| 5430 | kfree(calldata); |
| 5431 | dprintk("<-- %s\n", __func__); |
| 5432 | } |
| 5433 | |
| 5434 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5435 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5436 | .rpc_call_done = nfs4_layoutget_done, |
| 5437 | .rpc_release = nfs4_layoutget_release, |
| 5438 | }; |
| 5439 | |
| 5440 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5441 | { |
| 5442 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5443 | struct rpc_task *task; |
| 5444 | struct rpc_message msg = { |
| 5445 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5446 | .rpc_argp = &lgp->args, |
| 5447 | .rpc_resp = &lgp->res, |
| 5448 | }; |
| 5449 | struct rpc_task_setup task_setup_data = { |
| 5450 | .rpc_client = server->client, |
| 5451 | .rpc_message = &msg, |
| 5452 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5453 | .callback_data = lgp, |
| 5454 | .flags = RPC_TASK_ASYNC, |
| 5455 | }; |
| 5456 | int status = 0; |
| 5457 | |
| 5458 | dprintk("--> %s\n", __func__); |
| 5459 | |
| 5460 | lgp->res.layout.buf = (void *)__get_free_page(GFP_NOFS); |
| 5461 | if (lgp->res.layout.buf == NULL) { |
| 5462 | nfs4_layoutget_release(lgp); |
| 5463 | return -ENOMEM; |
| 5464 | } |
| 5465 | |
| 5466 | lgp->res.seq_res.sr_slot = NULL; |
| 5467 | task = rpc_run_task(&task_setup_data); |
| 5468 | if (IS_ERR(task)) |
| 5469 | return PTR_ERR(task); |
| 5470 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5471 | if (status == 0) |
| 5472 | status = task->tk_status; |
| 5473 | if (status == 0) |
| 5474 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5475 | rpc_put_task(task); |
| 5476 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5477 | return status; |
| 5478 | } |
| 5479 | |
| 5480 | static int |
| 5481 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5482 | { |
| 5483 | struct nfs4_getdeviceinfo_args args = { |
| 5484 | .pdev = pdev, |
| 5485 | }; |
| 5486 | struct nfs4_getdeviceinfo_res res = { |
| 5487 | .pdev = pdev, |
| 5488 | }; |
| 5489 | struct rpc_message msg = { |
| 5490 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5491 | .rpc_argp = &args, |
| 5492 | .rpc_resp = &res, |
| 5493 | }; |
| 5494 | int status; |
| 5495 | |
| 5496 | dprintk("--> %s\n", __func__); |
| 5497 | status = nfs4_call_sync(server, &msg, &args, &res, 0); |
| 5498 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5499 | |
| 5500 | return status; |
| 5501 | } |
| 5502 | |
| 5503 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5504 | { |
| 5505 | struct nfs4_exception exception = { }; |
| 5506 | int err; |
| 5507 | |
| 5508 | do { |
| 5509 | err = nfs4_handle_exception(server, |
| 5510 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5511 | &exception); |
| 5512 | } while (exception.retry); |
| 5513 | return err; |
| 5514 | } |
| 5515 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5516 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5517 | #endif /* CONFIG_NFS_V4_1 */ |
| 5518 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5519 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5520 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5521 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | .recover_open = nfs4_open_reclaim, |
| 5523 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5524 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5525 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | }; |
| 5527 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5528 | #if defined(CONFIG_NFS_V4_1) |
| 5529 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5530 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5531 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5532 | .recover_open = nfs4_open_reclaim, |
| 5533 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5534 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5535 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5536 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5537 | }; |
| 5538 | #endif /* CONFIG_NFS_V4_1 */ |
| 5539 | |
| 5540 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5541 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5542 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | .recover_open = nfs4_open_expired, |
| 5544 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5545 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5546 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5547 | }; |
| 5548 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5549 | #if defined(CONFIG_NFS_V4_1) |
| 5550 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5551 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5552 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5553 | .recover_open = nfs4_open_expired, |
| 5554 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5555 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5556 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5557 | }; |
| 5558 | #endif /* CONFIG_NFS_V4_1 */ |
| 5559 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5560 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5561 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5562 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5563 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5564 | }; |
| 5565 | |
| 5566 | #if defined(CONFIG_NFS_V4_1) |
| 5567 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5568 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5569 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5570 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5571 | }; |
| 5572 | #endif |
| 5573 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5574 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 5575 | .minor_version = 0, |
| 5576 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5577 | .validate_stateid = nfs4_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5578 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 5579 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 5580 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5581 | }; |
| 5582 | |
| 5583 | #if defined(CONFIG_NFS_V4_1) |
| 5584 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 5585 | .minor_version = 1, |
| 5586 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5587 | .validate_stateid = nfs41_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5588 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 5589 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 5590 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5591 | }; |
| 5592 | #endif |
| 5593 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5594 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 5595 | [0] = &nfs_v4_0_minor_ops, |
| 5596 | #if defined(CONFIG_NFS_V4_1) |
| 5597 | [1] = &nfs_v4_1_minor_ops, |
| 5598 | #endif |
| 5599 | }; |
| 5600 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5601 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5602 | .permission = nfs_permission, |
| 5603 | .getattr = nfs_getattr, |
| 5604 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5605 | .getxattr = generic_getxattr, |
| 5606 | .setxattr = generic_setxattr, |
| 5607 | .listxattr = generic_listxattr, |
| 5608 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5609 | }; |
| 5610 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5611 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5612 | .version = 4, /* protocol version */ |
| 5613 | .dentry_ops = &nfs4_dentry_operations, |
| 5614 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5615 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | .getroot = nfs4_proc_get_root, |
| 5617 | .getattr = nfs4_proc_getattr, |
| 5618 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5619 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5620 | .lookup = nfs4_proc_lookup, |
| 5621 | .access = nfs4_proc_access, |
| 5622 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | .create = nfs4_proc_create, |
| 5624 | .remove = nfs4_proc_remove, |
| 5625 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5626 | .unlink_done = nfs4_proc_unlink_done, |
| 5627 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 5628 | .rename_setup = nfs4_proc_rename_setup, |
| 5629 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5630 | .link = nfs4_proc_link, |
| 5631 | .symlink = nfs4_proc_symlink, |
| 5632 | .mkdir = nfs4_proc_mkdir, |
| 5633 | .rmdir = nfs4_proc_remove, |
| 5634 | .readdir = nfs4_proc_readdir, |
| 5635 | .mknod = nfs4_proc_mknod, |
| 5636 | .statfs = nfs4_proc_statfs, |
| 5637 | .fsinfo = nfs4_proc_fsinfo, |
| 5638 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5639 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5640 | .decode_dirent = nfs4_decode_dirent, |
| 5641 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5642 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5644 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5645 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5646 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5647 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5648 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5649 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 5650 | .open_context = nfs4_atomic_open, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 | }; |
| 5652 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5653 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 5654 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 5655 | .list = nfs4_xattr_list_nfs4_acl, |
| 5656 | .get = nfs4_xattr_get_nfs4_acl, |
| 5657 | .set = nfs4_xattr_set_nfs4_acl, |
| 5658 | }; |
| 5659 | |
| 5660 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 5661 | &nfs4_xattr_nfs4_acl_handler, |
| 5662 | NULL |
| 5663 | }; |
| 5664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5665 | /* |
| 5666 | * Local variables: |
| 5667 | * c-basic-offset: 8 |
| 5668 | * End: |
| 5669 | */ |