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> |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 44 | #include <linux/sunrpc/gss_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/nfs.h> |
| 46 | #include <linux/nfs4.h> |
| 47 | #include <linux/nfs_fs.h> |
| 48 | #include <linux/nfs_page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 50 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 51 | #include <linux/module.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 52 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 53 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 54 | #include <linux/utsname.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 *); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 75 | static int _nfs4_proc_lookup(struct rpc_clnt *client, struct inode *dir, |
| 76 | const struct qstr *name, struct nfs_fh *fhandle, |
| 77 | struct nfs_fattr *fattr); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 78 | 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] | 79 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 80 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 81 | struct nfs4_state *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 84 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 86 | if (err >= -1000) |
| 87 | return err; |
| 88 | switch (err) { |
| 89 | case -NFS4ERR_RESOURCE: |
| 90 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 91 | case -NFS4ERR_WRONGSEC: |
| 92 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 93 | case -NFS4ERR_BADOWNER: |
| 94 | case -NFS4ERR_BADNAME: |
| 95 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 96 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 98 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 99 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 101 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /* |
| 105 | * This is our standard bitmap for GETATTR requests. |
| 106 | */ |
| 107 | const u32 nfs4_fattr_bitmap[2] = { |
| 108 | FATTR4_WORD0_TYPE |
| 109 | | FATTR4_WORD0_CHANGE |
| 110 | | FATTR4_WORD0_SIZE |
| 111 | | FATTR4_WORD0_FSID |
| 112 | | FATTR4_WORD0_FILEID, |
| 113 | FATTR4_WORD1_MODE |
| 114 | | FATTR4_WORD1_NUMLINKS |
| 115 | | FATTR4_WORD1_OWNER |
| 116 | | FATTR4_WORD1_OWNER_GROUP |
| 117 | | FATTR4_WORD1_RAWDEV |
| 118 | | FATTR4_WORD1_SPACE_USED |
| 119 | | FATTR4_WORD1_TIME_ACCESS |
| 120 | | FATTR4_WORD1_TIME_METADATA |
| 121 | | FATTR4_WORD1_TIME_MODIFY |
| 122 | }; |
| 123 | |
| 124 | const u32 nfs4_statfs_bitmap[2] = { |
| 125 | FATTR4_WORD0_FILES_AVAIL |
| 126 | | FATTR4_WORD0_FILES_FREE |
| 127 | | FATTR4_WORD0_FILES_TOTAL, |
| 128 | FATTR4_WORD1_SPACE_AVAIL |
| 129 | | FATTR4_WORD1_SPACE_FREE |
| 130 | | FATTR4_WORD1_SPACE_TOTAL |
| 131 | }; |
| 132 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 133 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | FATTR4_WORD0_MAXLINK |
| 135 | | FATTR4_WORD0_MAXNAME, |
| 136 | 0 |
| 137 | }; |
| 138 | |
| 139 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 140 | | FATTR4_WORD0_MAXREAD |
| 141 | | FATTR4_WORD0_MAXWRITE |
| 142 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 143 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 144 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 147 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 148 | FATTR4_WORD0_TYPE |
| 149 | | FATTR4_WORD0_CHANGE |
| 150 | | FATTR4_WORD0_SIZE |
| 151 | | FATTR4_WORD0_FSID |
| 152 | | FATTR4_WORD0_FILEID |
| 153 | | FATTR4_WORD0_FS_LOCATIONS, |
| 154 | FATTR4_WORD1_MODE |
| 155 | | FATTR4_WORD1_NUMLINKS |
| 156 | | FATTR4_WORD1_OWNER |
| 157 | | FATTR4_WORD1_OWNER_GROUP |
| 158 | | FATTR4_WORD1_RAWDEV |
| 159 | | FATTR4_WORD1_SPACE_USED |
| 160 | | FATTR4_WORD1_TIME_ACCESS |
| 161 | | FATTR4_WORD1_TIME_METADATA |
| 162 | | FATTR4_WORD1_TIME_MODIFY |
| 163 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 164 | }; |
| 165 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 166 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | struct nfs4_readdir_arg *readdir) |
| 168 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 169 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | BUG_ON(readdir->count < 80); |
| 172 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 173 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | readdir->cookie = 0; |
| 179 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 180 | if (cookie == 2) |
| 181 | return; |
| 182 | |
| 183 | /* |
| 184 | * NFSv4 servers do not return entries for '.' and '..' |
| 185 | * Therefore, we fake these entries here. We let '.' |
| 186 | * have cookie 0 and '..' have cookie 1. Note that |
| 187 | * when talking to the server, we always send cookie 0 |
| 188 | * instead of 1 or 2. |
| 189 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 190 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | if (cookie == 0) { |
| 193 | *p++ = xdr_one; /* next */ |
| 194 | *p++ = xdr_zero; /* cookie, first word */ |
| 195 | *p++ = xdr_one; /* cookie, second word */ |
| 196 | *p++ = xdr_one; /* entry len */ |
| 197 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 198 | p++; |
| 199 | *p++ = xdr_one; /* bitmap length */ |
| 200 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 201 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 202 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | *p++ = xdr_one; /* next */ |
| 206 | *p++ = xdr_zero; /* cookie, first word */ |
| 207 | *p++ = xdr_two; /* cookie, second word */ |
| 208 | *p++ = xdr_two; /* entry len */ |
| 209 | memcpy(p, "..\0\0", 4); /* entry */ |
| 210 | p++; |
| 211 | *p++ = xdr_one; /* bitmap length */ |
| 212 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 213 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 214 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | readdir->pgbase = (char *)p - (char *)start; |
| 217 | readdir->count -= readdir->pgbase; |
| 218 | kunmap_atomic(start, KM_USER0); |
| 219 | } |
| 220 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 221 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 222 | { |
| 223 | int res; |
| 224 | |
| 225 | might_sleep(); |
| 226 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 227 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 228 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 229 | return res; |
| 230 | } |
| 231 | |
| 232 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 233 | { |
| 234 | int res = 0; |
| 235 | |
| 236 | might_sleep(); |
| 237 | |
| 238 | if (*timeout <= 0) |
| 239 | *timeout = NFS4_POLL_RETRY_MIN; |
| 240 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 241 | *timeout = NFS4_POLL_RETRY_MAX; |
| 242 | schedule_timeout_killable(*timeout); |
| 243 | if (fatal_signal_pending(current)) |
| 244 | res = -ERESTARTSYS; |
| 245 | *timeout <<= 1; |
| 246 | return res; |
| 247 | } |
| 248 | |
| 249 | /* This is the error handling routine for processes that are allowed |
| 250 | * to sleep. |
| 251 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 252 | static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception) |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 253 | { |
| 254 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 255 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 256 | int ret = errorcode; |
| 257 | |
| 258 | exception->retry = 0; |
| 259 | switch(errorcode) { |
| 260 | case 0: |
| 261 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 262 | case -NFS4ERR_ADMIN_REVOKED: |
| 263 | case -NFS4ERR_BAD_STATEID: |
| 264 | case -NFS4ERR_OPENMODE: |
| 265 | if (state == NULL) |
| 266 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 267 | nfs4_schedule_stateid_recovery(server, state); |
| 268 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 269 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 270 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 271 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 272 | nfs4_schedule_lease_recovery(clp); |
| 273 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 274 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 275 | case -NFS4ERR_BADSESSION: |
| 276 | case -NFS4ERR_BADSLOT: |
| 277 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 278 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 279 | case -NFS4ERR_DEADSESSION: |
| 280 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 281 | case -NFS4ERR_SEQ_MISORDERED: |
| 282 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 283 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 284 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 285 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 286 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 287 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 288 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 289 | if (exception->timeout > HZ) { |
| 290 | /* We have retried a decent amount, time to |
| 291 | * fail |
| 292 | */ |
| 293 | ret = -EBUSY; |
| 294 | break; |
| 295 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 296 | case -NFS4ERR_GRACE: |
| 297 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 298 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 299 | ret = nfs4_delay(server->client, &exception->timeout); |
| 300 | if (ret != 0) |
| 301 | break; |
| 302 | case -NFS4ERR_OLD_STATEID: |
| 303 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 304 | break; |
| 305 | case -NFS4ERR_BADOWNER: |
| 306 | /* The following works around a Linux server bug! */ |
| 307 | case -NFS4ERR_BADNAME: |
| 308 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 309 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 310 | exception->retry = 1; |
| 311 | printk(KERN_WARNING "NFS: v4 server %s " |
| 312 | "does not accept raw " |
| 313 | "uid/gids. " |
| 314 | "Reenabling the idmapper.\n", |
| 315 | server->nfs_client->cl_hostname); |
| 316 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 317 | } |
| 318 | /* We failed to handle the error */ |
| 319 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 320 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 321 | ret = nfs4_wait_clnt_recover(clp); |
| 322 | if (ret == 0) |
| 323 | exception->retry = 1; |
| 324 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 328 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | spin_lock(&clp->cl_lock); |
| 331 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 332 | clp->cl_last_renewal = timestamp; |
| 333 | spin_unlock(&clp->cl_lock); |
| 334 | } |
| 335 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 336 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 337 | { |
| 338 | do_renew_lease(server->nfs_client, timestamp); |
| 339 | } |
| 340 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 341 | #if defined(CONFIG_NFS_V4_1) |
| 342 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 343 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 344 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 345 | * |
| 346 | * freeing a slot is trivially done by clearing its respective bit |
| 347 | * in the bitmap. |
| 348 | * If the freed slotid equals highest_used_slotid we want to update it |
| 349 | * so that the server would be able to size down the slot table if needed, |
| 350 | * otherwise we know that the highest_used_slotid is still in use. |
| 351 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 352 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 353 | * highest slotid in use. |
| 354 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 355 | * |
| 356 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 357 | */ |
| 358 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 359 | 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] | 360 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 361 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 362 | int slotid = free_slotid; |
| 363 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 364 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 365 | /* clear used bit in bitmap */ |
| 366 | __clear_bit(slotid, tbl->used_slots); |
| 367 | |
| 368 | /* update highest_used_slotid when it is freed */ |
| 369 | if (slotid == tbl->highest_used_slotid) { |
| 370 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 371 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 372 | tbl->highest_used_slotid = slotid; |
| 373 | else |
| 374 | tbl->highest_used_slotid = -1; |
| 375 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 376 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 377 | free_slotid, tbl->highest_used_slotid); |
| 378 | } |
| 379 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 380 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 381 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 382 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 383 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 384 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 385 | struct rpc_task *task; |
| 386 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 387 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 388 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 389 | if (task) |
| 390 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 391 | return; |
| 392 | } |
| 393 | |
| 394 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 395 | return; |
| 396 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 397 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 398 | complete(&ses->fc_slot_table.complete); |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * Signal state manager thread if session back channel is drained |
| 403 | */ |
| 404 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 405 | { |
| 406 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 407 | ses->bc_slot_table.highest_used_slotid != -1) |
| 408 | return; |
| 409 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 410 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 411 | } |
| 412 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 413 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 414 | { |
| 415 | struct nfs4_slot_table *tbl; |
| 416 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 417 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 418 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 419 | /* just wake up the next guy waiting since |
| 420 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 421 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 422 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 423 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 424 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 425 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 426 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 427 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 428 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 429 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 430 | } |
| 431 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 432 | 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] | 433 | { |
| 434 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 435 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 436 | |
| 437 | /* |
| 438 | * sr_status remains 1 if an RPC level error occurred. The server |
| 439 | * may or may not have processed the sequence operation.. |
| 440 | * Proceed as if the server received and processed the sequence |
| 441 | * operation. |
| 442 | */ |
| 443 | if (res->sr_status == 1) |
| 444 | res->sr_status = NFS_OK; |
| 445 | |
| 446 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 447 | if (!res->sr_slot) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 448 | goto out; |
| 449 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 450 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 451 | switch (res->sr_status) { |
| 452 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 453 | /* Update the slot's sequence and clientid lease timer */ |
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 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 456 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 457 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 458 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 459 | if (res->sr_status_flags != 0) |
| 460 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 461 | break; |
| 462 | case -NFS4ERR_DELAY: |
| 463 | /* The server detected a resend of the RPC call and |
| 464 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 465 | * of RFC5661. |
| 466 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 467 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 468 | __func__, |
| 469 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 470 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 471 | goto out_retry; |
| 472 | default: |
| 473 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 474 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 475 | } |
| 476 | out: |
| 477 | /* The session may be reset by one of the error handlers. */ |
| 478 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 479 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 480 | return 1; |
| 481 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 482 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 483 | goto out; |
| 484 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 485 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 486 | } |
| 487 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 488 | static int nfs4_sequence_done(struct rpc_task *task, |
| 489 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 490 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 491 | if (res->sr_session == NULL) |
| 492 | return 1; |
| 493 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 494 | } |
| 495 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 496 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 497 | * nfs4_find_slot - efficiently look for a free slot |
| 498 | * |
| 499 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 500 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 501 | * and respectively set up the sequence operation args. |
| 502 | * 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] | 503 | * |
| 504 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 505 | */ |
| 506 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 507 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 508 | { |
| 509 | int slotid; |
| 510 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 511 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 512 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 513 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 514 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 515 | tbl->max_slots); |
| 516 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 517 | if (slotid >= tbl->max_slots) |
| 518 | goto out; |
| 519 | __set_bit(slotid, tbl->used_slots); |
| 520 | if (slotid > tbl->highest_used_slotid) |
| 521 | tbl->highest_used_slotid = slotid; |
| 522 | ret_id = slotid; |
| 523 | out: |
| 524 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 525 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 526 | return ret_id; |
| 527 | } |
| 528 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 529 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 530 | struct nfs4_sequence_args *args, |
| 531 | struct nfs4_sequence_res *res, |
| 532 | int cache_reply, |
| 533 | struct rpc_task *task) |
| 534 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 535 | struct nfs4_slot *slot; |
| 536 | struct nfs4_slot_table *tbl; |
| 537 | u8 slotid; |
| 538 | |
| 539 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 540 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 541 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 542 | return 0; |
| 543 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 544 | tbl = &session->fc_slot_table; |
| 545 | |
| 546 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 547 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 548 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 549 | /* |
| 550 | * The state manager will wait until the slot table is empty. |
| 551 | * Schedule the reset thread |
| 552 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 553 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 554 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 555 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 556 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 557 | } |
| 558 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 559 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 560 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 561 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 562 | spin_unlock(&tbl->slot_tbl_lock); |
| 563 | dprintk("%s enforce FIFO order\n", __func__); |
| 564 | return -EAGAIN; |
| 565 | } |
| 566 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 567 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 568 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 569 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 570 | spin_unlock(&tbl->slot_tbl_lock); |
| 571 | dprintk("<-- %s: no free slots\n", __func__); |
| 572 | return -EAGAIN; |
| 573 | } |
| 574 | spin_unlock(&tbl->slot_tbl_lock); |
| 575 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 576 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 577 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 578 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 579 | args->sa_slotid = slotid; |
| 580 | args->sa_cache_this = cache_reply; |
| 581 | |
| 582 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 583 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 584 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 585 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 586 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 587 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 588 | /* |
| 589 | * sr_status is only set in decode_sequence, and so will remain |
| 590 | * set to 1 if an rpc level failure occurs. |
| 591 | */ |
| 592 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 593 | return 0; |
| 594 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 595 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 596 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 597 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 598 | struct nfs4_sequence_args *args, |
| 599 | struct nfs4_sequence_res *res, |
| 600 | int cache_reply, |
| 601 | struct rpc_task *task) |
| 602 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 603 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 604 | int ret = 0; |
| 605 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 606 | if (session == NULL) { |
| 607 | args->sa_session = NULL; |
| 608 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 609 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 610 | } |
| 611 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 612 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 613 | __func__, session->clp, session, res->sr_slot ? |
| 614 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 615 | |
| 616 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 618 | out: |
| 619 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 620 | return ret; |
| 621 | } |
| 622 | |
| 623 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 624 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 625 | struct nfs4_sequence_args *seq_args; |
| 626 | struct nfs4_sequence_res *seq_res; |
| 627 | int cache_reply; |
| 628 | }; |
| 629 | |
| 630 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 631 | { |
| 632 | struct nfs41_call_sync_data *data = calldata; |
| 633 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 634 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 635 | |
| 636 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 637 | data->seq_res, data->cache_reply, task)) |
| 638 | return; |
| 639 | rpc_call_start(task); |
| 640 | } |
| 641 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 642 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 643 | { |
| 644 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 645 | nfs41_call_sync_prepare(task, calldata); |
| 646 | } |
| 647 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 648 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 649 | { |
| 650 | struct nfs41_call_sync_data *data = calldata; |
| 651 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 652 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 653 | } |
| 654 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 655 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 656 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 657 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 658 | }; |
| 659 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 660 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 661 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 662 | .rpc_call_done = nfs41_call_sync_done, |
| 663 | }; |
| 664 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 665 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 666 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 667 | struct rpc_message *msg, |
| 668 | struct nfs4_sequence_args *args, |
| 669 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 670 | int cache_reply, |
| 671 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 672 | { |
| 673 | int ret; |
| 674 | struct rpc_task *task; |
| 675 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 676 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | .seq_args = args, |
| 678 | .seq_res = res, |
| 679 | .cache_reply = cache_reply, |
| 680 | }; |
| 681 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 682 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 683 | .rpc_message = msg, |
| 684 | .callback_ops = &nfs41_call_sync_ops, |
| 685 | .callback_data = &data |
| 686 | }; |
| 687 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 688 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 689 | if (privileged) |
| 690 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 691 | task = rpc_run_task(&task_setup); |
| 692 | if (IS_ERR(task)) |
| 693 | ret = PTR_ERR(task); |
| 694 | else { |
| 695 | ret = task->tk_status; |
| 696 | rpc_put_task(task); |
| 697 | } |
| 698 | return ret; |
| 699 | } |
| 700 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 701 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 702 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 703 | struct rpc_message *msg, |
| 704 | struct nfs4_sequence_args *args, |
| 705 | struct nfs4_sequence_res *res, |
| 706 | int cache_reply) |
| 707 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 708 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, cache_reply, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 709 | } |
| 710 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 711 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 712 | static int nfs4_sequence_done(struct rpc_task *task, |
| 713 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 714 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 715 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 716 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 717 | #endif /* CONFIG_NFS_V4_1 */ |
| 718 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 719 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 720 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 721 | struct rpc_message *msg, |
| 722 | struct nfs4_sequence_args *args, |
| 723 | struct nfs4_sequence_res *res, |
| 724 | int cache_reply) |
| 725 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 726 | args->sa_session = res->sr_session = NULL; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 727 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 730 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 731 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 732 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 733 | struct rpc_message *msg, |
| 734 | struct nfs4_sequence_args *args, |
| 735 | struct nfs4_sequence_res *res, |
| 736 | int cache_reply) |
| 737 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 738 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 739 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 740 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 741 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 742 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 744 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 746 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 747 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 748 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 749 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 750 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 751 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 754 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 755 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 756 | struct nfs_openargs o_arg; |
| 757 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 758 | struct nfs_open_confirmargs c_arg; |
| 759 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 760 | struct nfs_fattr f_attr; |
| 761 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 762 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 763 | struct dentry *dir; |
| 764 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 765 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 766 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 767 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 768 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 769 | int rpc_status; |
| 770 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 771 | }; |
| 772 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 773 | |
| 774 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 775 | { |
| 776 | p->o_res.f_attr = &p->f_attr; |
| 777 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 778 | p->o_res.seqid = p->o_arg.seqid; |
| 779 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 780 | p->o_res.server = p->o_arg.server; |
| 781 | nfs_fattr_init(&p->f_attr); |
| 782 | nfs_fattr_init(&p->dir_attr); |
| 783 | } |
| 784 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 785 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 786 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 787 | const struct iattr *attrs, |
| 788 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 789 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 790 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 791 | struct inode *dir = parent->d_inode; |
| 792 | struct nfs_server *server = NFS_SERVER(dir); |
| 793 | struct nfs4_opendata *p; |
| 794 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 795 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 796 | if (p == NULL) |
| 797 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 798 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 799 | if (p->o_arg.seqid == NULL) |
| 800 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 801 | path_get(path); |
| 802 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 803 | p->dir = parent; |
| 804 | p->owner = sp; |
| 805 | atomic_inc(&sp->so_count); |
| 806 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 807 | p->o_arg.open_flags = flags; |
| 808 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 809 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 810 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 811 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 812 | p->o_arg.server = server; |
| 813 | p->o_arg.bitmask = server->attr_bitmask; |
| 814 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 815 | if (flags & O_CREAT) { |
| 816 | u32 *s; |
| 817 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | p->o_arg.u.attrs = &p->attrs; |
| 819 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 820 | s = (u32 *) p->o_arg.u.verifier.data; |
| 821 | s[0] = jiffies; |
| 822 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 824 | p->c_arg.fh = &p->o_res.fh; |
| 825 | p->c_arg.stateid = &p->o_res.stateid; |
| 826 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 827 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 828 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 829 | return p; |
| 830 | err_free: |
| 831 | kfree(p); |
| 832 | err: |
| 833 | dput(parent); |
| 834 | return NULL; |
| 835 | } |
| 836 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 837 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 838 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 839 | struct nfs4_opendata *p = container_of(kref, |
| 840 | struct nfs4_opendata, kref); |
| 841 | |
| 842 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 843 | if (p->state != NULL) |
| 844 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 845 | nfs4_put_state_owner(p->owner); |
| 846 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 847 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 848 | kfree(p); |
| 849 | } |
| 850 | |
| 851 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 852 | { |
| 853 | if (p != NULL) |
| 854 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 855 | } |
| 856 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 857 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 858 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 859 | int ret; |
| 860 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 861 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 862 | return ret; |
| 863 | } |
| 864 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 865 | 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] | 866 | { |
| 867 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 868 | |
| 869 | if (open_mode & O_EXCL) |
| 870 | goto out; |
| 871 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 872 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 873 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 874 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 875 | break; |
| 876 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 877 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 878 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 879 | break; |
| 880 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 881 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 882 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 883 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 884 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 885 | return ret; |
| 886 | } |
| 887 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 888 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 889 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 890 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 891 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 892 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 893 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 894 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 895 | return 1; |
| 896 | } |
| 897 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 898 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 899 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 900 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 901 | case FMODE_WRITE: |
| 902 | state->n_wronly++; |
| 903 | break; |
| 904 | case FMODE_READ: |
| 905 | state->n_rdonly++; |
| 906 | break; |
| 907 | case FMODE_READ|FMODE_WRITE: |
| 908 | state->n_rdwr++; |
| 909 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 910 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 911 | } |
| 912 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 913 | 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] | 914 | { |
| 915 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 916 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 917 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 918 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 919 | case FMODE_READ: |
| 920 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 921 | break; |
| 922 | case FMODE_WRITE: |
| 923 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 924 | break; |
| 925 | case FMODE_READ|FMODE_WRITE: |
| 926 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 927 | } |
| 928 | } |
| 929 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 930 | 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] | 931 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 932 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 933 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 934 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 935 | } |
| 936 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 937 | 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] | 938 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 939 | /* |
| 940 | * Protect the call to nfs4_state_set_mode_locked and |
| 941 | * serialise the stateid update |
| 942 | */ |
| 943 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 944 | if (deleg_stateid != NULL) { |
| 945 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 946 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 947 | } |
| 948 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 949 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 950 | write_sequnlock(&state->seqlock); |
| 951 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 952 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 953 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 956 | 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] | 957 | { |
| 958 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 959 | struct nfs_delegation *deleg_cur; |
| 960 | int ret = 0; |
| 961 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 962 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 963 | |
| 964 | rcu_read_lock(); |
| 965 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 966 | if (deleg_cur == NULL) |
| 967 | goto no_delegation; |
| 968 | |
| 969 | spin_lock(&deleg_cur->lock); |
| 970 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 971 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 972 | goto no_delegation_unlock; |
| 973 | |
| 974 | if (delegation == NULL) |
| 975 | delegation = &deleg_cur->stateid; |
| 976 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 977 | goto no_delegation_unlock; |
| 978 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 979 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 980 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 981 | ret = 1; |
| 982 | no_delegation_unlock: |
| 983 | spin_unlock(&deleg_cur->lock); |
| 984 | no_delegation: |
| 985 | rcu_read_unlock(); |
| 986 | |
| 987 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 988 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 989 | ret = 1; |
| 990 | } |
| 991 | |
| 992 | return ret; |
| 993 | } |
| 994 | |
| 995 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 996 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 997 | { |
| 998 | struct nfs_delegation *delegation; |
| 999 | |
| 1000 | rcu_read_lock(); |
| 1001 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1002 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1003 | rcu_read_unlock(); |
| 1004 | return; |
| 1005 | } |
| 1006 | rcu_read_unlock(); |
| 1007 | nfs_inode_return_delegation(inode); |
| 1008 | } |
| 1009 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1010 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1011 | { |
| 1012 | struct nfs4_state *state = opendata->state; |
| 1013 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1014 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1015 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 1016 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1017 | nfs4_stateid stateid; |
| 1018 | int ret = -EAGAIN; |
| 1019 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1020 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1021 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1022 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1023 | if (can_open_cached(state, fmode, open_mode)) { |
| 1024 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1025 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1026 | goto out_return_state; |
| 1027 | } |
| 1028 | spin_unlock(&state->owner->so_lock); |
| 1029 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1030 | rcu_read_lock(); |
| 1031 | delegation = rcu_dereference(nfsi->delegation); |
| 1032 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1033 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1034 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1035 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1036 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1037 | /* Save the delegation */ |
| 1038 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1039 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1040 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1041 | if (ret != 0) |
| 1042 | goto out; |
| 1043 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1044 | |
| 1045 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1046 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1047 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1048 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1049 | out: |
| 1050 | return ERR_PTR(ret); |
| 1051 | out_return_state: |
| 1052 | atomic_inc(&state->count); |
| 1053 | return state; |
| 1054 | } |
| 1055 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1056 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1057 | { |
| 1058 | struct inode *inode; |
| 1059 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1060 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1061 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1062 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1063 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1064 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1065 | goto out; |
| 1066 | } |
| 1067 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1068 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1069 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1070 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1071 | 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] | 1072 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1073 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1074 | goto err; |
| 1075 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1076 | state = nfs4_get_open_state(inode, data->owner); |
| 1077 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1078 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1079 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1080 | int delegation_flags = 0; |
| 1081 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1082 | rcu_read_lock(); |
| 1083 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1084 | if (delegation) |
| 1085 | delegation_flags = delegation->flags; |
| 1086 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1087 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1088 | nfs_inode_set_delegation(state->inode, |
| 1089 | data->owner->so_cred, |
| 1090 | &data->o_res); |
| 1091 | else |
| 1092 | nfs_inode_reclaim_delegation(state->inode, |
| 1093 | data->owner->so_cred, |
| 1094 | &data->o_res); |
| 1095 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1096 | |
| 1097 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1098 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1099 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1100 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1101 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1102 | err_put_inode: |
| 1103 | iput(inode); |
| 1104 | err: |
| 1105 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1106 | } |
| 1107 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1108 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1109 | { |
| 1110 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1111 | struct nfs_open_context *ctx; |
| 1112 | |
| 1113 | spin_lock(&state->inode->i_lock); |
| 1114 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1115 | if (ctx->state != state) |
| 1116 | continue; |
| 1117 | get_nfs_open_context(ctx); |
| 1118 | spin_unlock(&state->inode->i_lock); |
| 1119 | return ctx; |
| 1120 | } |
| 1121 | spin_unlock(&state->inode->i_lock); |
| 1122 | return ERR_PTR(-ENOENT); |
| 1123 | } |
| 1124 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1125 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1126 | { |
| 1127 | struct nfs4_opendata *opendata; |
| 1128 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1129 | 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] | 1130 | if (opendata == NULL) |
| 1131 | return ERR_PTR(-ENOMEM); |
| 1132 | opendata->state = state; |
| 1133 | atomic_inc(&state->count); |
| 1134 | return opendata; |
| 1135 | } |
| 1136 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1137 | 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] | 1138 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1139 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1140 | int ret; |
| 1141 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1142 | opendata->o_arg.open_flags = 0; |
| 1143 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1144 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1145 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1146 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1147 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1148 | if (ret != 0) |
| 1149 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1150 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1151 | if (IS_ERR(newstate)) |
| 1152 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1153 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1154 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1159 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1160 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1161 | int ret; |
| 1162 | |
| 1163 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1164 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1165 | smp_rmb(); |
| 1166 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1167 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1168 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1169 | if (ret != 0) |
| 1170 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1171 | if (newstate != state) |
| 1172 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1173 | } |
| 1174 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1175 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1176 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1177 | if (ret != 0) |
| 1178 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1179 | if (newstate != state) |
| 1180 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1181 | } |
| 1182 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1183 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1184 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1185 | if (ret != 0) |
| 1186 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1187 | if (newstate != state) |
| 1188 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1189 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1190 | /* |
| 1191 | * We may have performed cached opens for all three recoveries. |
| 1192 | * Check if we need to update the current stateid. |
| 1193 | */ |
| 1194 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1195 | 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] | 1196 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1197 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1198 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1199 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1200 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1201 | return 0; |
| 1202 | } |
| 1203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | /* |
| 1205 | * OPEN_RECLAIM: |
| 1206 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1208 | 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] | 1209 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1210 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1211 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1212 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | int status; |
| 1214 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1215 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1216 | if (IS_ERR(opendata)) |
| 1217 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1218 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1219 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1220 | rcu_read_lock(); |
| 1221 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1222 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1223 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1224 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1225 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1226 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1227 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | return status; |
| 1229 | } |
| 1230 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1231 | 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] | 1232 | { |
| 1233 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1234 | struct nfs4_exception exception = { }; |
| 1235 | int err; |
| 1236 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1237 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1238 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1239 | break; |
| 1240 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | } while (exception.retry); |
| 1242 | return err; |
| 1243 | } |
| 1244 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1245 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1246 | { |
| 1247 | struct nfs_open_context *ctx; |
| 1248 | int ret; |
| 1249 | |
| 1250 | ctx = nfs4_state_find_open_context(state); |
| 1251 | if (IS_ERR(ctx)) |
| 1252 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1253 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1254 | put_nfs_open_context(ctx); |
| 1255 | return ret; |
| 1256 | } |
| 1257 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1258 | 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] | 1259 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1260 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1261 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1263 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1264 | if (IS_ERR(opendata)) |
| 1265 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1266 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1267 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1268 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1269 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1270 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1271 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1274 | 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] | 1275 | { |
| 1276 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1277 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | int err; |
| 1279 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1280 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | switch (err) { |
| 1282 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1283 | case -ENOENT: |
| 1284 | case -ESTALE: |
| 1285 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1286 | case -NFS4ERR_BADSESSION: |
| 1287 | case -NFS4ERR_BADSLOT: |
| 1288 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1289 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1290 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1291 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1292 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | case -NFS4ERR_STALE_CLIENTID: |
| 1294 | case -NFS4ERR_STALE_STATEID: |
| 1295 | case -NFS4ERR_EXPIRED: |
| 1296 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1297 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1298 | goto out; |
| 1299 | case -ERESTARTSYS: |
| 1300 | /* |
| 1301 | * The show must go on: exit, but mark the |
| 1302 | * stateid as needing recovery. |
| 1303 | */ |
| 1304 | case -NFS4ERR_ADMIN_REVOKED: |
| 1305 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1306 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1307 | case -EKEYEXPIRED: |
| 1308 | /* |
| 1309 | * User RPCSEC_GSS context has expired. |
| 1310 | * We cannot recover this stateid now, so |
| 1311 | * skip it and allow recovery thread to |
| 1312 | * proceed. |
| 1313 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1314 | case -ENOMEM: |
| 1315 | err = 0; |
| 1316 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | } |
| 1318 | err = nfs4_handle_exception(server, err, &exception); |
| 1319 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1320 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | return err; |
| 1322 | } |
| 1323 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1324 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1325 | { |
| 1326 | struct nfs4_opendata *data = calldata; |
| 1327 | |
| 1328 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1329 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1330 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1331 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1332 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1333 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1334 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1335 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | static void nfs4_open_confirm_release(void *calldata) |
| 1339 | { |
| 1340 | struct nfs4_opendata *data = calldata; |
| 1341 | struct nfs4_state *state = NULL; |
| 1342 | |
| 1343 | /* If this request hasn't been cancelled, do nothing */ |
| 1344 | if (data->cancelled == 0) |
| 1345 | goto out_free; |
| 1346 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1347 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1348 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1349 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1350 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1351 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1352 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1353 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1357 | .rpc_call_done = nfs4_open_confirm_done, |
| 1358 | .rpc_release = nfs4_open_confirm_release, |
| 1359 | }; |
| 1360 | |
| 1361 | /* |
| 1362 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1363 | */ |
| 1364 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1365 | { |
| 1366 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1367 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1368 | struct rpc_message msg = { |
| 1369 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1370 | .rpc_argp = &data->c_arg, |
| 1371 | .rpc_resp = &data->c_res, |
| 1372 | .rpc_cred = data->owner->so_cred, |
| 1373 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1374 | struct rpc_task_setup task_setup_data = { |
| 1375 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1376 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1377 | .callback_ops = &nfs4_open_confirm_ops, |
| 1378 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1379 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1380 | .flags = RPC_TASK_ASYNC, |
| 1381 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | int status; |
| 1383 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1384 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1385 | data->rpc_done = 0; |
| 1386 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1387 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1388 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1389 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1390 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1391 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1392 | if (status != 0) { |
| 1393 | data->cancelled = 1; |
| 1394 | smp_wmb(); |
| 1395 | } else |
| 1396 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1397 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | return status; |
| 1399 | } |
| 1400 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1401 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1403 | struct nfs4_opendata *data = calldata; |
| 1404 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1405 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1406 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1407 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1408 | /* |
| 1409 | * Check if we still need to send an OPEN call, or if we can use |
| 1410 | * a delegation instead. |
| 1411 | */ |
| 1412 | if (data->state != NULL) { |
| 1413 | struct nfs_delegation *delegation; |
| 1414 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1415 | 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] | 1416 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1417 | rcu_read_lock(); |
| 1418 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1419 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1420 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1421 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1422 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1423 | } |
| 1424 | rcu_read_unlock(); |
| 1425 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1426 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1427 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1428 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1429 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1430 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1431 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1432 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1433 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1434 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1435 | &data->o_arg.seq_args, |
| 1436 | &data->o_res.seq_res, 1, task)) |
| 1437 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1438 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1439 | return; |
| 1440 | out_no_action: |
| 1441 | task->tk_action = NULL; |
| 1442 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1445 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1446 | { |
| 1447 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1448 | nfs4_open_prepare(task, calldata); |
| 1449 | } |
| 1450 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1451 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1452 | { |
| 1453 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1455 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1456 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1457 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1458 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1459 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1460 | if (task->tk_status == 0) { |
| 1461 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1462 | case S_IFREG: |
| 1463 | break; |
| 1464 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1465 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1466 | break; |
| 1467 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1468 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1469 | break; |
| 1470 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1471 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1472 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1473 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1474 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1475 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1476 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1477 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1478 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1479 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1480 | static void nfs4_open_release(void *calldata) |
| 1481 | { |
| 1482 | struct nfs4_opendata *data = calldata; |
| 1483 | struct nfs4_state *state = NULL; |
| 1484 | |
| 1485 | /* If this request hasn't been cancelled, do nothing */ |
| 1486 | if (data->cancelled == 0) |
| 1487 | goto out_free; |
| 1488 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1489 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1490 | goto out_free; |
| 1491 | /* In case we need an open_confirm, no cleanup! */ |
| 1492 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1493 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1494 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1495 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1496 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1497 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1498 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1502 | .rpc_call_prepare = nfs4_open_prepare, |
| 1503 | .rpc_call_done = nfs4_open_done, |
| 1504 | .rpc_release = nfs4_open_release, |
| 1505 | }; |
| 1506 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1507 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1508 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1509 | .rpc_call_done = nfs4_open_done, |
| 1510 | .rpc_release = nfs4_open_release, |
| 1511 | }; |
| 1512 | |
| 1513 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1514 | { |
| 1515 | struct inode *dir = data->dir->d_inode; |
| 1516 | struct nfs_server *server = NFS_SERVER(dir); |
| 1517 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1518 | struct nfs_openres *o_res = &data->o_res; |
| 1519 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1520 | struct rpc_message msg = { |
| 1521 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1522 | .rpc_argp = o_arg, |
| 1523 | .rpc_resp = o_res, |
| 1524 | .rpc_cred = data->owner->so_cred, |
| 1525 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1526 | struct rpc_task_setup task_setup_data = { |
| 1527 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1528 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1529 | .callback_ops = &nfs4_open_ops, |
| 1530 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1531 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1532 | .flags = RPC_TASK_ASYNC, |
| 1533 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1534 | int status; |
| 1535 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1536 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1537 | data->rpc_done = 0; |
| 1538 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1539 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1540 | if (isrecover) |
| 1541 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1542 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1543 | if (IS_ERR(task)) |
| 1544 | return PTR_ERR(task); |
| 1545 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1546 | if (status != 0) { |
| 1547 | data->cancelled = 1; |
| 1548 | smp_wmb(); |
| 1549 | } else |
| 1550 | status = data->rpc_status; |
| 1551 | rpc_put_task(task); |
| 1552 | |
| 1553 | return status; |
| 1554 | } |
| 1555 | |
| 1556 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1557 | { |
| 1558 | struct inode *dir = data->dir->d_inode; |
| 1559 | struct nfs_openres *o_res = &data->o_res; |
| 1560 | int status; |
| 1561 | |
| 1562 | status = nfs4_run_open_task(data, 1); |
| 1563 | if (status != 0 || !data->rpc_done) |
| 1564 | return status; |
| 1565 | |
| 1566 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1567 | |
| 1568 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1569 | status = _nfs4_proc_open_confirm(data); |
| 1570 | if (status != 0) |
| 1571 | return status; |
| 1572 | } |
| 1573 | |
| 1574 | return status; |
| 1575 | } |
| 1576 | |
| 1577 | /* |
| 1578 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1579 | */ |
| 1580 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1581 | { |
| 1582 | struct inode *dir = data->dir->d_inode; |
| 1583 | struct nfs_server *server = NFS_SERVER(dir); |
| 1584 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1585 | struct nfs_openres *o_res = &data->o_res; |
| 1586 | int status; |
| 1587 | |
| 1588 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1589 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1590 | return status; |
| 1591 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1592 | if (o_arg->open_flags & O_CREAT) { |
| 1593 | update_changeattr(dir, &o_res->cinfo); |
| 1594 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1595 | } else |
| 1596 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1597 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1598 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1600 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1602 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | } |
| 1604 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1605 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1606 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1609 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1610 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1611 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1612 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1613 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1614 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1615 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1616 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1617 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1618 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1619 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1620 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1621 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1622 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1623 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1624 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1625 | } |
| 1626 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1627 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1628 | { |
| 1629 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1630 | } |
| 1631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | /* |
| 1633 | * OPEN_EXPIRED: |
| 1634 | * reclaim state on the server after a network partition. |
| 1635 | * Assumes caller holds the appropriate lock |
| 1636 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1637 | 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] | 1638 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1639 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1640 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1642 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1643 | if (IS_ERR(opendata)) |
| 1644 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1645 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1646 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1647 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1648 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1649 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1652 | 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] | 1653 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1654 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1655 | struct nfs4_exception exception = { }; |
| 1656 | int err; |
| 1657 | |
| 1658 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1659 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1660 | switch (err) { |
| 1661 | default: |
| 1662 | goto out; |
| 1663 | case -NFS4ERR_GRACE: |
| 1664 | case -NFS4ERR_DELAY: |
| 1665 | nfs4_handle_exception(server, err, &exception); |
| 1666 | err = 0; |
| 1667 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1668 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1669 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1670 | return err; |
| 1671 | } |
| 1672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1674 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1676 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1678 | ctx = nfs4_state_find_open_context(state); |
| 1679 | if (IS_ERR(ctx)) |
| 1680 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1681 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1682 | put_nfs_open_context(ctx); |
| 1683 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1687 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1688 | * fields corresponding to attributes that were used to store the verifier. |
| 1689 | * Make sure we clobber those fields in the later setattr call |
| 1690 | */ |
| 1691 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1692 | { |
| 1693 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1694 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1695 | sattr->ia_valid |= ATTR_ATIME; |
| 1696 | |
| 1697 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1698 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1699 | sattr->ia_valid |= ATTR_MTIME; |
| 1700 | } |
| 1701 | |
| 1702 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1703 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1705 | 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] | 1706 | { |
| 1707 | struct nfs4_state_owner *sp; |
| 1708 | struct nfs4_state *state = NULL; |
| 1709 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1710 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1711 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | |
| 1713 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | status = -ENOMEM; |
| 1715 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1716 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1717 | goto out_err; |
| 1718 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1719 | status = nfs4_recover_expired_lease(server); |
| 1720 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1721 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1722 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1723 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1724 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1725 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1726 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1727 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1729 | if (path->dentry->d_inode != NULL) |
| 1730 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1731 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1732 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1734 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1736 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1737 | status = PTR_ERR(state); |
| 1738 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1739 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1740 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1741 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1742 | |
| 1743 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1744 | nfs4_exclusive_attrset(opendata, sattr); |
| 1745 | |
| 1746 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1747 | status = nfs4_do_setattr(state->inode, cred, |
| 1748 | opendata->o_res.f_attr, sattr, |
| 1749 | state); |
| 1750 | if (status == 0) |
| 1751 | nfs_setattr_update_inode(state->inode, sattr); |
| 1752 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1753 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1754 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | *res = state; |
| 1757 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1758 | err_opendata_put: |
| 1759 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1760 | err_put_state_owner: |
| 1761 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | *res = NULL; |
| 1764 | return status; |
| 1765 | } |
| 1766 | |
| 1767 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1768 | 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] | 1769 | { |
| 1770 | struct nfs4_exception exception = { }; |
| 1771 | struct nfs4_state *res; |
| 1772 | int status; |
| 1773 | |
| 1774 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1775 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | if (status == 0) |
| 1777 | break; |
| 1778 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1779 | * book-keeping w.r.t. state-changing operations |
| 1780 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1781 | * It is actually a sign of a bug on the client or on the server. |
| 1782 | * |
| 1783 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1784 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | * have unhashed the old state_owner for us, and that we can |
| 1786 | * therefore safely retry using a new one. We should still warn |
| 1787 | * the user though... |
| 1788 | */ |
| 1789 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1790 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1791 | " returned a bad sequence-id error!\n", |
| 1792 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | exception.retry = 1; |
| 1794 | continue; |
| 1795 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1796 | /* |
| 1797 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1798 | * state before it received the OPEN_CONFIRM. |
| 1799 | * Recover by retrying the request as per the discussion |
| 1800 | * on Page 181 of RFC3530. |
| 1801 | */ |
| 1802 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1803 | exception.retry = 1; |
| 1804 | continue; |
| 1805 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1806 | if (status == -EAGAIN) { |
| 1807 | /* We must have found a delegation */ |
| 1808 | exception.retry = 1; |
| 1809 | continue; |
| 1810 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1812 | status, &exception)); |
| 1813 | } while (exception.retry); |
| 1814 | return res; |
| 1815 | } |
| 1816 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1817 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1818 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1819 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1821 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1823 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | .iap = sattr, |
| 1825 | .server = server, |
| 1826 | .bitmask = server->attr_bitmask, |
| 1827 | }; |
| 1828 | struct nfs_setattrres res = { |
| 1829 | .fattr = fattr, |
| 1830 | .server = server, |
| 1831 | }; |
| 1832 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1833 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1834 | .rpc_argp = &arg, |
| 1835 | .rpc_resp = &res, |
| 1836 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1838 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1839 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1841 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1843 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1844 | /* Use that stateid */ |
| 1845 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1846 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1847 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1849 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1850 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1851 | if (status == 0 && state != NULL) |
| 1852 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1853 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1856 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1857 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1858 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1860 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | struct nfs4_exception exception = { }; |
| 1862 | int err; |
| 1863 | do { |
| 1864 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1865 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | &exception); |
| 1867 | } while (exception.retry); |
| 1868 | return err; |
| 1869 | } |
| 1870 | |
| 1871 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1872 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | struct inode *inode; |
| 1874 | struct nfs4_state *state; |
| 1875 | struct nfs_closeargs arg; |
| 1876 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1877 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1878 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1879 | bool roc; |
| 1880 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | }; |
| 1882 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1883 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1884 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1885 | struct nfs4_closedata *calldata = data; |
| 1886 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1887 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1888 | if (calldata->roc) |
| 1889 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1890 | nfs4_put_open_state(calldata->state); |
| 1891 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1892 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1893 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1894 | kfree(calldata); |
| 1895 | } |
| 1896 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1897 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1898 | fmode_t fmode) |
| 1899 | { |
| 1900 | spin_lock(&state->owner->so_lock); |
| 1901 | if (!(fmode & FMODE_READ)) |
| 1902 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1903 | if (!(fmode & FMODE_WRITE)) |
| 1904 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1905 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1906 | spin_unlock(&state->owner->so_lock); |
| 1907 | } |
| 1908 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1909 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1911 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1914 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1915 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1916 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | /* hmm. we are done with the inode, and in the process of freeing |
| 1918 | * the state_owner. we keep this around to process errors |
| 1919 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | switch (task->tk_status) { |
| 1921 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1922 | if (calldata->roc) |
| 1923 | pnfs_roc_set_barrier(state->inode, |
| 1924 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1925 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1926 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1927 | nfs4_close_clear_stateid_flags(state, |
| 1928 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | break; |
| 1930 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1931 | case -NFS4ERR_OLD_STATEID: |
| 1932 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1934 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1935 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1937 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1938 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1940 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1941 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1944 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1946 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1947 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1948 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1949 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1950 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1951 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1952 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1953 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1954 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1955 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1956 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1957 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1958 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1959 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1960 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1961 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1962 | } |
| 1963 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1964 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1965 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1966 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1967 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1968 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1969 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1970 | |
| 1971 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1972 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1973 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1974 | return; |
| 1975 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1976 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1977 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1978 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1979 | if (calldata->roc && |
| 1980 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 1981 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 1982 | task, NULL); |
| 1983 | return; |
| 1984 | } |
| 1985 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1986 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1987 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1988 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1989 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1990 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1991 | 1, task)) |
| 1992 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1993 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1996 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1997 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1998 | .rpc_call_done = nfs4_close_done, |
| 1999 | .rpc_release = nfs4_free_closedata, |
| 2000 | }; |
| 2001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | /* |
| 2003 | * It is possible for data to be read/written from a mem-mapped file |
| 2004 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2005 | * This means that we can't safely call nfsv4 close on a file until |
| 2006 | * the inode is cleared. This in turn means that we are not good |
| 2007 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2008 | * share state even when we are done with one of the three share |
| 2009 | * stateid's in the inode. |
| 2010 | * |
| 2011 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2012 | */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2013 | 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] | 2014 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2015 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2017 | struct nfs4_state_owner *sp = state->owner; |
| 2018 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2019 | struct rpc_message msg = { |
| 2020 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2021 | .rpc_cred = state->owner->so_cred, |
| 2022 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2023 | struct rpc_task_setup task_setup_data = { |
| 2024 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2025 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2026 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2027 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2028 | .flags = RPC_TASK_ASYNC, |
| 2029 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2030 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2032 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2034 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2035 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2037 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2038 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2040 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2041 | if (calldata->arg.seqid == NULL) |
| 2042 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2043 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2044 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2045 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2046 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2047 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2048 | calldata->roc = roc; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2049 | path_get(path); |
| 2050 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2051 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2052 | msg.rpc_argp = &calldata->arg; |
| 2053 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2054 | task_setup_data.callback_data = calldata; |
| 2055 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2056 | if (IS_ERR(task)) |
| 2057 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2058 | status = 0; |
| 2059 | if (wait) |
| 2060 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2061 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2062 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2063 | out_free_calldata: |
| 2064 | kfree(calldata); |
| 2065 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2066 | if (roc) |
| 2067 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2068 | nfs4_put_open_state(state); |
| 2069 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2070 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2073 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2074 | 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] | 2075 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | struct nfs4_state *state; |
| 2077 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2078 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2079 | 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] | 2080 | if (IS_ERR(state)) |
| 2081 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2082 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2083 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2086 | 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] | 2087 | { |
| 2088 | if (ctx->state == NULL) |
| 2089 | return; |
| 2090 | if (is_sync) |
| 2091 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2092 | else |
| 2093 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2094 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | |
| 2096 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2097 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2098 | struct nfs4_server_caps_arg args = { |
| 2099 | .fhandle = fhandle, |
| 2100 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | struct nfs4_server_caps_res res = {}; |
| 2102 | struct rpc_message msg = { |
| 2103 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2104 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | .rpc_resp = &res, |
| 2106 | }; |
| 2107 | int status; |
| 2108 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2109 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | if (status == 0) { |
| 2111 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2112 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2113 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2114 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2115 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2116 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2118 | server->caps |= NFS_CAP_ACLS; |
| 2119 | if (res.has_links != 0) |
| 2120 | server->caps |= NFS_CAP_HARDLINKS; |
| 2121 | if (res.has_symlinks != 0) |
| 2122 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2123 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2124 | server->caps |= NFS_CAP_FILEID; |
| 2125 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2126 | server->caps |= NFS_CAP_MODE; |
| 2127 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2128 | server->caps |= NFS_CAP_NLINK; |
| 2129 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2130 | server->caps |= NFS_CAP_OWNER; |
| 2131 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2132 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2133 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2134 | server->caps |= NFS_CAP_ATIME; |
| 2135 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2136 | server->caps |= NFS_CAP_CTIME; |
| 2137 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2138 | server->caps |= NFS_CAP_MTIME; |
| 2139 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2140 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2141 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2142 | 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] | 2143 | server->acl_bitmask = res.acl_bitmask; |
| 2144 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | return status; |
| 2147 | } |
| 2148 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2149 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | { |
| 2151 | struct nfs4_exception exception = { }; |
| 2152 | int err; |
| 2153 | do { |
| 2154 | err = nfs4_handle_exception(server, |
| 2155 | _nfs4_server_capabilities(server, fhandle), |
| 2156 | &exception); |
| 2157 | } while (exception.retry); |
| 2158 | return err; |
| 2159 | } |
| 2160 | |
| 2161 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2162 | struct nfs_fsinfo *info) |
| 2163 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | struct nfs4_lookup_root_arg args = { |
| 2165 | .bitmask = nfs4_fattr_bitmap, |
| 2166 | }; |
| 2167 | struct nfs4_lookup_res res = { |
| 2168 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2169 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | .fh = fhandle, |
| 2171 | }; |
| 2172 | struct rpc_message msg = { |
| 2173 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2174 | .rpc_argp = &args, |
| 2175 | .rpc_resp = &res, |
| 2176 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2177 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2178 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2179 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2183 | struct nfs_fsinfo *info) |
| 2184 | { |
| 2185 | struct nfs4_exception exception = { }; |
| 2186 | int err; |
| 2187 | do { |
| 2188 | err = nfs4_handle_exception(server, |
| 2189 | _nfs4_lookup_root(server, fhandle, info), |
| 2190 | &exception); |
| 2191 | } while (exception.retry); |
| 2192 | return err; |
| 2193 | } |
| 2194 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2195 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2196 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2197 | { |
| 2198 | struct rpc_auth *auth; |
| 2199 | int ret; |
| 2200 | |
| 2201 | auth = rpcauth_create(flavor, server->client); |
| 2202 | if (!auth) { |
| 2203 | ret = -EIO; |
| 2204 | goto out; |
| 2205 | } |
| 2206 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2207 | out: |
| 2208 | return ret; |
| 2209 | } |
| 2210 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2211 | /* |
| 2212 | * get the file handle for the "/" directory on the server |
| 2213 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | 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] | 2215 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2217 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame^] | 2218 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2220 | flav_array[0] = RPC_AUTH_UNIX; |
| 2221 | len = gss_mech_list_pseudoflavors(&flav_array[1]); |
| 2222 | flav_array[1+len] = RPC_AUTH_NULL; |
| 2223 | len += 2; |
| 2224 | |
| 2225 | for (i = 0; i < len; i++) { |
| 2226 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2227 | if (status == -EPERM || status == -EACCES) |
| 2228 | continue; |
| 2229 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2230 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | if (status == 0) |
| 2232 | status = nfs4_server_capabilities(server, fhandle); |
| 2233 | if (status == 0) |
| 2234 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2235 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2238 | /* |
| 2239 | * Get locations and (maybe) other attributes of a referral. |
| 2240 | * Note that we'll actually follow the referral later when |
| 2241 | * we detect fsid mismatch in inode revalidation |
| 2242 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2243 | 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] | 2244 | { |
| 2245 | int status = -ENOMEM; |
| 2246 | struct page *page = NULL; |
| 2247 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2248 | |
| 2249 | page = alloc_page(GFP_KERNEL); |
| 2250 | if (page == NULL) |
| 2251 | goto out; |
| 2252 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2253 | if (locations == NULL) |
| 2254 | goto out; |
| 2255 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2256 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2257 | if (status != 0) |
| 2258 | goto out; |
| 2259 | /* Make sure server returned a different fsid for the referral */ |
| 2260 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2261 | 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] | 2262 | status = -EIO; |
| 2263 | goto out; |
| 2264 | } |
| 2265 | |
| 2266 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2267 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2268 | if (!fattr->mode) |
| 2269 | fattr->mode = S_IFDIR; |
| 2270 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2271 | out: |
| 2272 | if (page) |
| 2273 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2274 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2275 | return status; |
| 2276 | } |
| 2277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2279 | { |
| 2280 | struct nfs4_getattr_arg args = { |
| 2281 | .fh = fhandle, |
| 2282 | .bitmask = server->attr_bitmask, |
| 2283 | }; |
| 2284 | struct nfs4_getattr_res res = { |
| 2285 | .fattr = fattr, |
| 2286 | .server = server, |
| 2287 | }; |
| 2288 | struct rpc_message msg = { |
| 2289 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2290 | .rpc_argp = &args, |
| 2291 | .rpc_resp = &res, |
| 2292 | }; |
| 2293 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2294 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2295 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2299 | { |
| 2300 | struct nfs4_exception exception = { }; |
| 2301 | int err; |
| 2302 | do { |
| 2303 | err = nfs4_handle_exception(server, |
| 2304 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2305 | &exception); |
| 2306 | } while (exception.retry); |
| 2307 | return err; |
| 2308 | } |
| 2309 | |
| 2310 | /* |
| 2311 | * The file is not closed if it is opened due to the a request to change |
| 2312 | * the size of the file. The open call will not be needed once the |
| 2313 | * VFS layer lookup-intents are implemented. |
| 2314 | * |
| 2315 | * Close is called when the inode is destroyed. |
| 2316 | * If we haven't opened the file for O_WRONLY, we |
| 2317 | * need to in the size_change case to obtain a stateid. |
| 2318 | * |
| 2319 | * Got race? |
| 2320 | * Because OPEN is always done by name in nfsv4, it is |
| 2321 | * possible that we opened a different file by the same |
| 2322 | * name. We can recognize this race condition, but we |
| 2323 | * can't do anything about it besides returning an error. |
| 2324 | * |
| 2325 | * This will be fixed with VFS changes (lookup-intent). |
| 2326 | */ |
| 2327 | static int |
| 2328 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2329 | struct iattr *sattr) |
| 2330 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2331 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2332 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2333 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | int status; |
| 2335 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2336 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2338 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2339 | if (sattr->ia_valid & ATTR_FILE) { |
| 2340 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2341 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2342 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2343 | if (ctx) { |
| 2344 | cred = ctx->cred; |
| 2345 | state = ctx->state; |
| 2346 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2350 | if (status == 0) |
| 2351 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | return status; |
| 2353 | } |
| 2354 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2355 | static int _nfs4_proc_lookupfh(struct rpc_clnt *clnt, struct nfs_server *server, |
| 2356 | const struct nfs_fh *dirfh, const struct qstr *name, |
| 2357 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2358 | { |
| 2359 | int status; |
| 2360 | struct nfs4_lookup_arg args = { |
| 2361 | .bitmask = server->attr_bitmask, |
| 2362 | .dir_fh = dirfh, |
| 2363 | .name = name, |
| 2364 | }; |
| 2365 | struct nfs4_lookup_res res = { |
| 2366 | .server = server, |
| 2367 | .fattr = fattr, |
| 2368 | .fh = fhandle, |
| 2369 | }; |
| 2370 | struct rpc_message msg = { |
| 2371 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2372 | .rpc_argp = &args, |
| 2373 | .rpc_resp = &res, |
| 2374 | }; |
| 2375 | |
| 2376 | nfs_fattr_init(fattr); |
| 2377 | |
| 2378 | dprintk("NFS call lookupfh %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2379 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2380 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2381 | return status; |
| 2382 | } |
| 2383 | |
| 2384 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2385 | struct qstr *name, struct nfs_fh *fhandle, |
| 2386 | struct nfs_fattr *fattr) |
| 2387 | { |
| 2388 | struct nfs4_exception exception = { }; |
| 2389 | int err; |
| 2390 | do { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2391 | err = _nfs4_proc_lookupfh(server->client, server, dirfh, name, fhandle, fattr); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2392 | /* FIXME: !!!! */ |
| 2393 | if (err == -NFS4ERR_MOVED) { |
| 2394 | err = -EREMOTE; |
| 2395 | break; |
| 2396 | } |
| 2397 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2398 | } while (exception.retry); |
| 2399 | return err; |
| 2400 | } |
| 2401 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2402 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2403 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2404 | struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2406 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | |
| 2408 | dprintk("NFS call lookup %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2409 | status = _nfs4_proc_lookupfh(clnt, NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2410 | if (status == -NFS4ERR_MOVED) |
| 2411 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | dprintk("NFS reply lookup: %d\n", status); |
| 2413 | return status; |
| 2414 | } |
| 2415 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2416 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2417 | { |
| 2418 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2419 | fattr->fsid.major = 1; |
| 2420 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2421 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2422 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2423 | fattr->nlink = 2; |
| 2424 | } |
| 2425 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2426 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2427 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | { |
| 2429 | struct nfs4_exception exception = { }; |
| 2430 | int err; |
| 2431 | do { |
| 2432 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2433 | _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | &exception); |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2435 | if (err == -EPERM) |
| 2436 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | } while (exception.retry); |
| 2438 | return err; |
| 2439 | } |
| 2440 | |
| 2441 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2442 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2443 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | struct nfs4_accessargs args = { |
| 2445 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2446 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2448 | struct nfs4_accessres res = { |
| 2449 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2450 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | struct rpc_message msg = { |
| 2452 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2453 | .rpc_argp = &args, |
| 2454 | .rpc_resp = &res, |
| 2455 | .rpc_cred = entry->cred, |
| 2456 | }; |
| 2457 | int mode = entry->mask; |
| 2458 | int status; |
| 2459 | |
| 2460 | /* |
| 2461 | * Determine which access bits we want to ask for... |
| 2462 | */ |
| 2463 | if (mode & MAY_READ) |
| 2464 | args.access |= NFS4_ACCESS_READ; |
| 2465 | if (S_ISDIR(inode->i_mode)) { |
| 2466 | if (mode & MAY_WRITE) |
| 2467 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2468 | if (mode & MAY_EXEC) |
| 2469 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2470 | } else { |
| 2471 | if (mode & MAY_WRITE) |
| 2472 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2473 | if (mode & MAY_EXEC) |
| 2474 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2475 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2476 | |
| 2477 | res.fattr = nfs_alloc_fattr(); |
| 2478 | if (res.fattr == NULL) |
| 2479 | return -ENOMEM; |
| 2480 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2481 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | if (!status) { |
| 2483 | entry->mask = 0; |
| 2484 | if (res.access & NFS4_ACCESS_READ) |
| 2485 | entry->mask |= MAY_READ; |
| 2486 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2487 | entry->mask |= MAY_WRITE; |
| 2488 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2489 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2490 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2492 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | return status; |
| 2494 | } |
| 2495 | |
| 2496 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2497 | { |
| 2498 | struct nfs4_exception exception = { }; |
| 2499 | int err; |
| 2500 | do { |
| 2501 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2502 | _nfs4_proc_access(inode, entry), |
| 2503 | &exception); |
| 2504 | } while (exception.retry); |
| 2505 | return err; |
| 2506 | } |
| 2507 | |
| 2508 | /* |
| 2509 | * TODO: For the time being, we don't try to get any attributes |
| 2510 | * along with any of the zero-copy operations READ, READDIR, |
| 2511 | * READLINK, WRITE. |
| 2512 | * |
| 2513 | * In the case of the first three, we want to put the GETATTR |
| 2514 | * after the read-type operation -- this is because it is hard |
| 2515 | * to predict the length of a GETATTR response in v4, and thus |
| 2516 | * align the READ data correctly. This means that the GETATTR |
| 2517 | * may end up partially falling into the page cache, and we should |
| 2518 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2519 | * To do this efficiently, we need to know the total length |
| 2520 | * of data received, which doesn't seem to be available outside |
| 2521 | * of the RPC layer. |
| 2522 | * |
| 2523 | * In the case of WRITE, we also want to put the GETATTR after |
| 2524 | * the operation -- in this case because we want to make sure |
| 2525 | * we get the post-operation mtime and size. This means that |
| 2526 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2527 | * of it which would leave room in the 'tail' iovec. |
| 2528 | * |
| 2529 | * Both of these changes to the XDR layer would in fact be quite |
| 2530 | * minor, but I decided to leave them for a subsequent patch. |
| 2531 | */ |
| 2532 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2533 | unsigned int pgbase, unsigned int pglen) |
| 2534 | { |
| 2535 | struct nfs4_readlink args = { |
| 2536 | .fh = NFS_FH(inode), |
| 2537 | .pgbase = pgbase, |
| 2538 | .pglen = pglen, |
| 2539 | .pages = &page, |
| 2540 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2541 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | struct rpc_message msg = { |
| 2543 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2544 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2545 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | }; |
| 2547 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2548 | return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2552 | unsigned int pgbase, unsigned int pglen) |
| 2553 | { |
| 2554 | struct nfs4_exception exception = { }; |
| 2555 | int err; |
| 2556 | do { |
| 2557 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2558 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2559 | &exception); |
| 2560 | } while (exception.retry); |
| 2561 | return err; |
| 2562 | } |
| 2563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | /* |
| 2565 | * Got race? |
| 2566 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2567 | * Until then, this create/open method is prone to inefficiency and race |
| 2568 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2569 | * placed on the wire. |
| 2570 | * |
| 2571 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2572 | * The file will be opened again in the subsequent VFS open call |
| 2573 | * (nfs4_proc_file_open). |
| 2574 | * |
| 2575 | * The open for read will just hang around to be used by any process that |
| 2576 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2577 | */ |
| 2578 | |
| 2579 | static int |
| 2580 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2581 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2583 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2584 | .dentry = dentry, |
| 2585 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2586 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2588 | struct rpc_cred *cred = NULL; |
| 2589 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | int status = 0; |
| 2591 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2592 | if (ctx != NULL) { |
| 2593 | cred = ctx->cred; |
| 2594 | path = &ctx->path; |
| 2595 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2597 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2598 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2599 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | if (IS_ERR(state)) { |
| 2601 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2602 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2604 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2605 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2606 | if (ctx != NULL) |
| 2607 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2608 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2609 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2610 | out: |
| 2611 | return status; |
| 2612 | } |
| 2613 | |
| 2614 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2615 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2616 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2617 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2619 | .name.len = name->len, |
| 2620 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2621 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2623 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2624 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2625 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2627 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2628 | .rpc_argp = &args, |
| 2629 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2631 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2633 | res.dir_attr = nfs_alloc_fattr(); |
| 2634 | if (res.dir_attr == NULL) |
| 2635 | goto out; |
| 2636 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2637 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2638 | if (status == 0) { |
| 2639 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2640 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2641 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2642 | nfs_free_fattr(res.dir_attr); |
| 2643 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | return status; |
| 2645 | } |
| 2646 | |
| 2647 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2648 | { |
| 2649 | struct nfs4_exception exception = { }; |
| 2650 | int err; |
| 2651 | do { |
| 2652 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2653 | _nfs4_proc_remove(dir, name), |
| 2654 | &exception); |
| 2655 | } while (exception.retry); |
| 2656 | return err; |
| 2657 | } |
| 2658 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2659 | 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] | 2660 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2661 | struct nfs_server *server = NFS_SERVER(dir); |
| 2662 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2663 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2665 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2666 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2667 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2671 | 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] | 2672 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2673 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2674 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2675 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2676 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2677 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2678 | return 0; |
| 2679 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2680 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2681 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2684 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2685 | { |
| 2686 | struct nfs_server *server = NFS_SERVER(dir); |
| 2687 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2688 | struct nfs_renameres *res = msg->rpc_resp; |
| 2689 | |
| 2690 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2691 | arg->bitmask = server->attr_bitmask; |
| 2692 | res->server = server; |
| 2693 | } |
| 2694 | |
| 2695 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2696 | struct inode *new_dir) |
| 2697 | { |
| 2698 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2699 | |
| 2700 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2701 | return 0; |
| 2702 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2703 | return 0; |
| 2704 | |
| 2705 | update_changeattr(old_dir, &res->old_cinfo); |
| 2706 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2707 | update_changeattr(new_dir, &res->new_cinfo); |
| 2708 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2709 | return 1; |
| 2710 | } |
| 2711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2713 | struct inode *new_dir, struct qstr *new_name) |
| 2714 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2715 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2716 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | .old_dir = NFS_FH(old_dir), |
| 2718 | .new_dir = NFS_FH(new_dir), |
| 2719 | .old_name = old_name, |
| 2720 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2721 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2723 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2724 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2725 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | struct rpc_message msg = { |
| 2727 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2728 | .rpc_argp = &arg, |
| 2729 | .rpc_resp = &res, |
| 2730 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2731 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2733 | res.old_fattr = nfs_alloc_fattr(); |
| 2734 | res.new_fattr = nfs_alloc_fattr(); |
| 2735 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2736 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2738 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | if (!status) { |
| 2740 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2741 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2743 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2745 | out: |
| 2746 | nfs_free_fattr(res.new_fattr); |
| 2747 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | return status; |
| 2749 | } |
| 2750 | |
| 2751 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2752 | struct inode *new_dir, struct qstr *new_name) |
| 2753 | { |
| 2754 | struct nfs4_exception exception = { }; |
| 2755 | int err; |
| 2756 | do { |
| 2757 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2758 | _nfs4_proc_rename(old_dir, old_name, |
| 2759 | new_dir, new_name), |
| 2760 | &exception); |
| 2761 | } while (exception.retry); |
| 2762 | return err; |
| 2763 | } |
| 2764 | |
| 2765 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2766 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2767 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | struct nfs4_link_arg arg = { |
| 2769 | .fh = NFS_FH(inode), |
| 2770 | .dir_fh = NFS_FH(dir), |
| 2771 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2772 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2774 | struct nfs4_link_res res = { |
| 2775 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2776 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | struct rpc_message msg = { |
| 2778 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2779 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2780 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2782 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2784 | res.fattr = nfs_alloc_fattr(); |
| 2785 | res.dir_attr = nfs_alloc_fattr(); |
| 2786 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2787 | goto out; |
| 2788 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2789 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2790 | if (!status) { |
| 2791 | update_changeattr(dir, &res.cinfo); |
| 2792 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2793 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2794 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2795 | out: |
| 2796 | nfs_free_fattr(res.dir_attr); |
| 2797 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | return status; |
| 2799 | } |
| 2800 | |
| 2801 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2802 | { |
| 2803 | struct nfs4_exception exception = { }; |
| 2804 | int err; |
| 2805 | do { |
| 2806 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2807 | _nfs4_proc_link(inode, dir, name), |
| 2808 | &exception); |
| 2809 | } while (exception.retry); |
| 2810 | return err; |
| 2811 | } |
| 2812 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2813 | struct nfs4_createdata { |
| 2814 | struct rpc_message msg; |
| 2815 | struct nfs4_create_arg arg; |
| 2816 | struct nfs4_create_res res; |
| 2817 | struct nfs_fh fh; |
| 2818 | struct nfs_fattr fattr; |
| 2819 | struct nfs_fattr dir_fattr; |
| 2820 | }; |
| 2821 | |
| 2822 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2823 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2824 | { |
| 2825 | struct nfs4_createdata *data; |
| 2826 | |
| 2827 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2828 | if (data != NULL) { |
| 2829 | struct nfs_server *server = NFS_SERVER(dir); |
| 2830 | |
| 2831 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2832 | data->msg.rpc_argp = &data->arg; |
| 2833 | data->msg.rpc_resp = &data->res; |
| 2834 | data->arg.dir_fh = NFS_FH(dir); |
| 2835 | data->arg.server = server; |
| 2836 | data->arg.name = name; |
| 2837 | data->arg.attrs = sattr; |
| 2838 | data->arg.ftype = ftype; |
| 2839 | data->arg.bitmask = server->attr_bitmask; |
| 2840 | data->res.server = server; |
| 2841 | data->res.fh = &data->fh; |
| 2842 | data->res.fattr = &data->fattr; |
| 2843 | data->res.dir_fattr = &data->dir_fattr; |
| 2844 | nfs_fattr_init(data->res.fattr); |
| 2845 | nfs_fattr_init(data->res.dir_fattr); |
| 2846 | } |
| 2847 | return data; |
| 2848 | } |
| 2849 | |
| 2850 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2851 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2852 | int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 2853 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2854 | if (status == 0) { |
| 2855 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2856 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2857 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2858 | } |
| 2859 | return status; |
| 2860 | } |
| 2861 | |
| 2862 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2863 | { |
| 2864 | kfree(data); |
| 2865 | } |
| 2866 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2867 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2868 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2870 | struct nfs4_createdata *data; |
| 2871 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2873 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2874 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2875 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2876 | status = -ENOMEM; |
| 2877 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2878 | if (data == NULL) |
| 2879 | goto out; |
| 2880 | |
| 2881 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2882 | data->arg.u.symlink.pages = &page; |
| 2883 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2885 | status = nfs4_do_create(dir, dentry, data); |
| 2886 | |
| 2887 | nfs4_free_createdata(data); |
| 2888 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | return status; |
| 2890 | } |
| 2891 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2892 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2893 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | { |
| 2895 | struct nfs4_exception exception = { }; |
| 2896 | int err; |
| 2897 | do { |
| 2898 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2899 | _nfs4_proc_symlink(dir, dentry, page, |
| 2900 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | &exception); |
| 2902 | } while (exception.retry); |
| 2903 | return err; |
| 2904 | } |
| 2905 | |
| 2906 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2907 | struct iattr *sattr) |
| 2908 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2909 | struct nfs4_createdata *data; |
| 2910 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2912 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2913 | if (data == NULL) |
| 2914 | goto out; |
| 2915 | |
| 2916 | status = nfs4_do_create(dir, dentry, data); |
| 2917 | |
| 2918 | nfs4_free_createdata(data); |
| 2919 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | return status; |
| 2921 | } |
| 2922 | |
| 2923 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2924 | struct iattr *sattr) |
| 2925 | { |
| 2926 | struct nfs4_exception exception = { }; |
| 2927 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2928 | |
| 2929 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | do { |
| 2931 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2932 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2933 | &exception); |
| 2934 | } while (exception.retry); |
| 2935 | return err; |
| 2936 | } |
| 2937 | |
| 2938 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2939 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | { |
| 2941 | struct inode *dir = dentry->d_inode; |
| 2942 | struct nfs4_readdir_arg args = { |
| 2943 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2944 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | .pgbase = 0, |
| 2946 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2947 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2948 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | }; |
| 2950 | struct nfs4_readdir_res res; |
| 2951 | struct rpc_message msg = { |
| 2952 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2953 | .rpc_argp = &args, |
| 2954 | .rpc_resp = &res, |
| 2955 | .rpc_cred = cred, |
| 2956 | }; |
| 2957 | int status; |
| 2958 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2959 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2960 | dentry->d_parent->d_name.name, |
| 2961 | dentry->d_name.name, |
| 2962 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2964 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2965 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2966 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2968 | status += args.pgbase; |
| 2969 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2970 | |
| 2971 | nfs_invalidate_atime(dir); |
| 2972 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2973 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | return status; |
| 2975 | } |
| 2976 | |
| 2977 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2978 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | { |
| 2980 | struct nfs4_exception exception = { }; |
| 2981 | int err; |
| 2982 | do { |
| 2983 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2984 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2985 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | &exception); |
| 2987 | } while (exception.retry); |
| 2988 | return err; |
| 2989 | } |
| 2990 | |
| 2991 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2992 | struct iattr *sattr, dev_t rdev) |
| 2993 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2994 | struct nfs4_createdata *data; |
| 2995 | int mode = sattr->ia_mode; |
| 2996 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | |
| 2998 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2999 | 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] | 3000 | |
| 3001 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3002 | if (data == NULL) |
| 3003 | goto out; |
| 3004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3006 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3008 | data->arg.ftype = NF4BLK; |
| 3009 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3010 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | } |
| 3012 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3013 | data->arg.ftype = NF4CHR; |
| 3014 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3015 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3018 | status = nfs4_do_create(dir, dentry, data); |
| 3019 | |
| 3020 | nfs4_free_createdata(data); |
| 3021 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | return status; |
| 3023 | } |
| 3024 | |
| 3025 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3026 | struct iattr *sattr, dev_t rdev) |
| 3027 | { |
| 3028 | struct nfs4_exception exception = { }; |
| 3029 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3030 | |
| 3031 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | do { |
| 3033 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3034 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3035 | &exception); |
| 3036 | } while (exception.retry); |
| 3037 | return err; |
| 3038 | } |
| 3039 | |
| 3040 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3041 | struct nfs_fsstat *fsstat) |
| 3042 | { |
| 3043 | struct nfs4_statfs_arg args = { |
| 3044 | .fh = fhandle, |
| 3045 | .bitmask = server->attr_bitmask, |
| 3046 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3047 | struct nfs4_statfs_res res = { |
| 3048 | .fsstat = fsstat, |
| 3049 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | struct rpc_message msg = { |
| 3051 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3052 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3053 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | }; |
| 3055 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3056 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3057 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3061 | { |
| 3062 | struct nfs4_exception exception = { }; |
| 3063 | int err; |
| 3064 | do { |
| 3065 | err = nfs4_handle_exception(server, |
| 3066 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3067 | &exception); |
| 3068 | } while (exception.retry); |
| 3069 | return err; |
| 3070 | } |
| 3071 | |
| 3072 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3073 | struct nfs_fsinfo *fsinfo) |
| 3074 | { |
| 3075 | struct nfs4_fsinfo_arg args = { |
| 3076 | .fh = fhandle, |
| 3077 | .bitmask = server->attr_bitmask, |
| 3078 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3079 | struct nfs4_fsinfo_res res = { |
| 3080 | .fsinfo = fsinfo, |
| 3081 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | struct rpc_message msg = { |
| 3083 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3084 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3085 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | }; |
| 3087 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3088 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3092 | { |
| 3093 | struct nfs4_exception exception = { }; |
| 3094 | int err; |
| 3095 | |
| 3096 | do { |
| 3097 | err = nfs4_handle_exception(server, |
| 3098 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3099 | &exception); |
| 3100 | } while (exception.retry); |
| 3101 | return err; |
| 3102 | } |
| 3103 | |
| 3104 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3105 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3106 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3108 | } |
| 3109 | |
| 3110 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3111 | struct nfs_pathconf *pathconf) |
| 3112 | { |
| 3113 | struct nfs4_pathconf_arg args = { |
| 3114 | .fh = fhandle, |
| 3115 | .bitmask = server->attr_bitmask, |
| 3116 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3117 | struct nfs4_pathconf_res res = { |
| 3118 | .pathconf = pathconf, |
| 3119 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | struct rpc_message msg = { |
| 3121 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3122 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3123 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | }; |
| 3125 | |
| 3126 | /* None of the pathconf attributes are mandatory to implement */ |
| 3127 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3128 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3129 | return 0; |
| 3130 | } |
| 3131 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3132 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3133 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3137 | struct nfs_pathconf *pathconf) |
| 3138 | { |
| 3139 | struct nfs4_exception exception = { }; |
| 3140 | int err; |
| 3141 | |
| 3142 | do { |
| 3143 | err = nfs4_handle_exception(server, |
| 3144 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3145 | &exception); |
| 3146 | } while (exception.retry); |
| 3147 | return err; |
| 3148 | } |
| 3149 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3150 | static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3152 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3154 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3155 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3156 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3158 | |
| 3159 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3161 | renew_lease(server, data->timestamp); |
| 3162 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3165 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3166 | { |
| 3167 | |
| 3168 | dprintk("--> %s\n", __func__); |
| 3169 | |
| 3170 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3171 | return -EAGAIN; |
| 3172 | |
| 3173 | return data->read_done_cb(task, data); |
| 3174 | } |
| 3175 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3176 | 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] | 3177 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3179 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3180 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | } |
| 3182 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3183 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3184 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3185 | { |
| 3186 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3187 | put_lseg(data->lseg); |
| 3188 | data->lseg = NULL; |
| 3189 | /* offsets will differ in the dense stripe case */ |
| 3190 | data->args.offset = data->mds_offset; |
| 3191 | data->ds_clp = NULL; |
| 3192 | data->args.fh = NFS_FH(data->inode); |
| 3193 | data->read_done_cb = nfs4_read_done_cb; |
| 3194 | task->tk_ops = data->mds_ops; |
| 3195 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3196 | } |
| 3197 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3198 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3199 | static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | struct inode *inode = data->inode; |
| 3202 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3203 | 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] | 3204 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3205 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3207 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3209 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3210 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3211 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | } |
| 3213 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3214 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3215 | { |
| 3216 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3217 | return -EAGAIN; |
| 3218 | return data->write_done_cb(task, data); |
| 3219 | } |
| 3220 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3221 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3222 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3223 | { |
| 3224 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3225 | put_lseg(data->lseg); |
| 3226 | data->lseg = NULL; |
| 3227 | data->ds_clp = NULL; |
| 3228 | data->write_done_cb = nfs4_write_done_cb; |
| 3229 | data->args.fh = NFS_FH(data->inode); |
| 3230 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3231 | data->args.offset = data->mds_offset; |
| 3232 | data->res.fattr = &data->fattr; |
| 3233 | task->tk_ops = data->mds_ops; |
| 3234 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3235 | } |
| 3236 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3237 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3238 | 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] | 3239 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3240 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3241 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3242 | if (data->lseg) { |
| 3243 | data->args.bitmask = NULL; |
| 3244 | data->res.fattr = NULL; |
| 3245 | } else |
| 3246 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3247 | if (!data->write_done_cb) |
| 3248 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3249 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | data->timestamp = jiffies; |
| 3251 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3252 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | } |
| 3254 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3255 | static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3258 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3259 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3260 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3261 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3263 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3264 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3267 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3268 | { |
| 3269 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3270 | return -EAGAIN; |
| 3271 | return data->write_done_cb(task, data); |
| 3272 | } |
| 3273 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3274 | 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] | 3275 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3276 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3277 | |
| 3278 | if (data->lseg) { |
| 3279 | data->args.bitmask = NULL; |
| 3280 | data->res.fattr = NULL; |
| 3281 | } else |
| 3282 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3283 | if (!data->write_done_cb) |
| 3284 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3285 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3286 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3287 | } |
| 3288 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3289 | struct nfs4_renewdata { |
| 3290 | struct nfs_client *client; |
| 3291 | unsigned long timestamp; |
| 3292 | }; |
| 3293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | /* |
| 3295 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3296 | * standalone procedure for queueing an asynchronous RENEW. |
| 3297 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3298 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3299 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3300 | struct nfs4_renewdata *data = calldata; |
| 3301 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3302 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3303 | if (atomic_read(&clp->cl_count) > 1) |
| 3304 | nfs4_schedule_state_renewal(clp); |
| 3305 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3306 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3307 | } |
| 3308 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3309 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3311 | struct nfs4_renewdata *data = calldata; |
| 3312 | struct nfs_client *clp = data->client; |
| 3313 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | |
| 3315 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3316 | /* Unless we're shutting down, schedule state recovery! */ |
| 3317 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3318 | nfs4_schedule_lease_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3319 | return; |
| 3320 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3321 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | } |
| 3323 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3324 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3325 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3326 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3327 | }; |
| 3328 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3329 | 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] | 3330 | { |
| 3331 | struct rpc_message msg = { |
| 3332 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3333 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3334 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3336 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3338 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3339 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3340 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3341 | if (data == NULL) |
| 3342 | return -ENOMEM; |
| 3343 | data->client = clp; |
| 3344 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3346 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | } |
| 3348 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3349 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | { |
| 3351 | struct rpc_message msg = { |
| 3352 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3353 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3354 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | }; |
| 3356 | unsigned long now = jiffies; |
| 3357 | int status; |
| 3358 | |
| 3359 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3360 | if (status < 0) |
| 3361 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3362 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | return 0; |
| 3364 | } |
| 3365 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3366 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3367 | { |
| 3368 | return (server->caps & NFS_CAP_ACLS) |
| 3369 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3370 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3371 | } |
| 3372 | |
| 3373 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3374 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3375 | * the stack. |
| 3376 | */ |
| 3377 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3378 | |
| 3379 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3380 | struct page **pages, unsigned int *pgbase) |
| 3381 | { |
| 3382 | const void *p = buf; |
| 3383 | |
| 3384 | *pgbase = offset_in_page(buf); |
| 3385 | p -= *pgbase; |
| 3386 | while (p < buf + buflen) { |
| 3387 | *(pages++) = virt_to_page(p); |
| 3388 | p += PAGE_CACHE_SIZE; |
| 3389 | } |
| 3390 | } |
| 3391 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3392 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3393 | struct page **pages, unsigned int *pgbase) |
| 3394 | { |
| 3395 | struct page *newpage, **spages; |
| 3396 | int rc = 0; |
| 3397 | size_t len; |
| 3398 | spages = pages; |
| 3399 | |
| 3400 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3401 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3402 | newpage = alloc_page(GFP_KERNEL); |
| 3403 | |
| 3404 | if (newpage == NULL) |
| 3405 | goto unwind; |
| 3406 | memcpy(page_address(newpage), buf, len); |
| 3407 | buf += len; |
| 3408 | buflen -= len; |
| 3409 | *pages++ = newpage; |
| 3410 | rc++; |
| 3411 | } while (buflen != 0); |
| 3412 | |
| 3413 | return rc; |
| 3414 | |
| 3415 | unwind: |
| 3416 | for(; rc > 0; rc--) |
| 3417 | __free_page(spages[rc-1]); |
| 3418 | return -ENOMEM; |
| 3419 | } |
| 3420 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3421 | struct nfs4_cached_acl { |
| 3422 | int cached; |
| 3423 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3424 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3425 | }; |
| 3426 | |
| 3427 | 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] | 3428 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3429 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3430 | |
| 3431 | spin_lock(&inode->i_lock); |
| 3432 | kfree(nfsi->nfs4_acl); |
| 3433 | nfsi->nfs4_acl = acl; |
| 3434 | spin_unlock(&inode->i_lock); |
| 3435 | } |
| 3436 | |
| 3437 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3438 | { |
| 3439 | nfs4_set_cached_acl(inode, NULL); |
| 3440 | } |
| 3441 | |
| 3442 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3443 | { |
| 3444 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3445 | struct nfs4_cached_acl *acl; |
| 3446 | int ret = -ENOENT; |
| 3447 | |
| 3448 | spin_lock(&inode->i_lock); |
| 3449 | acl = nfsi->nfs4_acl; |
| 3450 | if (acl == NULL) |
| 3451 | goto out; |
| 3452 | if (buf == NULL) /* user is just asking for length */ |
| 3453 | goto out_len; |
| 3454 | if (acl->cached == 0) |
| 3455 | goto out; |
| 3456 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3457 | if (acl->len > buflen) |
| 3458 | goto out; |
| 3459 | memcpy(buf, acl->data, acl->len); |
| 3460 | out_len: |
| 3461 | ret = acl->len; |
| 3462 | out: |
| 3463 | spin_unlock(&inode->i_lock); |
| 3464 | return ret; |
| 3465 | } |
| 3466 | |
| 3467 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3468 | { |
| 3469 | struct nfs4_cached_acl *acl; |
| 3470 | |
| 3471 | if (buf && acl_len <= PAGE_SIZE) { |
| 3472 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3473 | if (acl == NULL) |
| 3474 | goto out; |
| 3475 | acl->cached = 1; |
| 3476 | memcpy(acl->data, buf, acl_len); |
| 3477 | } else { |
| 3478 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3479 | if (acl == NULL) |
| 3480 | goto out; |
| 3481 | acl->cached = 0; |
| 3482 | } |
| 3483 | acl->len = acl_len; |
| 3484 | out: |
| 3485 | nfs4_set_cached_acl(inode, acl); |
| 3486 | } |
| 3487 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3488 | 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] | 3489 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3490 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3491 | struct nfs_getaclargs args = { |
| 3492 | .fh = NFS_FH(inode), |
| 3493 | .acl_pages = pages, |
| 3494 | .acl_len = buflen, |
| 3495 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3496 | struct nfs_getaclres res = { |
| 3497 | .acl_len = buflen, |
| 3498 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3499 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3500 | struct rpc_message msg = { |
| 3501 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3502 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3503 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3504 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3505 | struct page *localpage = NULL; |
| 3506 | int ret; |
| 3507 | |
| 3508 | if (buflen < PAGE_SIZE) { |
| 3509 | /* As long as we're doing a round trip to the server anyway, |
| 3510 | * let's be prepared for a page of acl data. */ |
| 3511 | localpage = alloc_page(GFP_KERNEL); |
| 3512 | resp_buf = page_address(localpage); |
| 3513 | if (localpage == NULL) |
| 3514 | return -ENOMEM; |
| 3515 | args.acl_pages[0] = localpage; |
| 3516 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3517 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3518 | } else { |
| 3519 | resp_buf = buf; |
| 3520 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3521 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3522 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3523 | if (ret) |
| 3524 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3525 | if (res.acl_len > args.acl_len) |
| 3526 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3527 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3528 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3529 | if (buf) { |
| 3530 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3531 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3532 | goto out_free; |
| 3533 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3534 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3535 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3536 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3537 | out_free: |
| 3538 | if (localpage) |
| 3539 | __free_page(localpage); |
| 3540 | return ret; |
| 3541 | } |
| 3542 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3543 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3544 | { |
| 3545 | struct nfs4_exception exception = { }; |
| 3546 | ssize_t ret; |
| 3547 | do { |
| 3548 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3549 | if (ret >= 0) |
| 3550 | break; |
| 3551 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3552 | } while (exception.retry); |
| 3553 | return ret; |
| 3554 | } |
| 3555 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3556 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3557 | { |
| 3558 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3559 | int ret; |
| 3560 | |
| 3561 | if (!nfs4_server_supports_acls(server)) |
| 3562 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3563 | ret = nfs_revalidate_inode(server, inode); |
| 3564 | if (ret < 0) |
| 3565 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3566 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3567 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3568 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3569 | if (ret != -ENOENT) |
| 3570 | return ret; |
| 3571 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3572 | } |
| 3573 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3574 | 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] | 3575 | { |
| 3576 | struct nfs_server *server = NFS_SERVER(inode); |
| 3577 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3578 | struct nfs_setaclargs arg = { |
| 3579 | .fh = NFS_FH(inode), |
| 3580 | .acl_pages = pages, |
| 3581 | .acl_len = buflen, |
| 3582 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3583 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3584 | struct rpc_message msg = { |
| 3585 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3586 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3587 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3588 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3589 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3590 | |
| 3591 | if (!nfs4_server_supports_acls(server)) |
| 3592 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3593 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3594 | if (i < 0) |
| 3595 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3596 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3597 | ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3598 | |
| 3599 | /* |
| 3600 | * Free each page after tx, so the only ref left is |
| 3601 | * held by the network stack |
| 3602 | */ |
| 3603 | for (; i > 0; i--) |
| 3604 | put_page(pages[i-1]); |
| 3605 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3606 | /* |
| 3607 | * Acl update can result in inode attribute update. |
| 3608 | * so mark the attribute cache invalid. |
| 3609 | */ |
| 3610 | spin_lock(&inode->i_lock); |
| 3611 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3612 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3613 | nfs_access_zap_cache(inode); |
| 3614 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3615 | return ret; |
| 3616 | } |
| 3617 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3618 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3619 | { |
| 3620 | struct nfs4_exception exception = { }; |
| 3621 | int err; |
| 3622 | do { |
| 3623 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3624 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3625 | &exception); |
| 3626 | } while (exception.retry); |
| 3627 | return err; |
| 3628 | } |
| 3629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3631 | 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] | 3632 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3633 | struct nfs_client *clp = server->nfs_client; |
| 3634 | |
| 3635 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | return 0; |
| 3637 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3638 | case -NFS4ERR_ADMIN_REVOKED: |
| 3639 | case -NFS4ERR_BAD_STATEID: |
| 3640 | case -NFS4ERR_OPENMODE: |
| 3641 | if (state == NULL) |
| 3642 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3643 | nfs4_schedule_stateid_recovery(server, state); |
| 3644 | goto wait_on_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3646 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3648 | nfs4_schedule_lease_recovery(clp); |
| 3649 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3650 | #if defined(CONFIG_NFS_V4_1) |
| 3651 | case -NFS4ERR_BADSESSION: |
| 3652 | case -NFS4ERR_BADSLOT: |
| 3653 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3654 | case -NFS4ERR_DEADSESSION: |
| 3655 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3656 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3657 | case -NFS4ERR_SEQ_MISORDERED: |
| 3658 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3659 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3660 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3661 | task->tk_status = 0; |
| 3662 | return -EAGAIN; |
| 3663 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3665 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3666 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3667 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3669 | task->tk_status = 0; |
| 3670 | return -EAGAIN; |
| 3671 | case -NFS4ERR_OLD_STATEID: |
| 3672 | task->tk_status = 0; |
| 3673 | return -EAGAIN; |
| 3674 | } |
| 3675 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3676 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3677 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3678 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3679 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3680 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3681 | task->tk_status = 0; |
| 3682 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | } |
| 3684 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3685 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3686 | unsigned short port, struct rpc_cred *cred, |
| 3687 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | { |
| 3689 | nfs4_verifier sc_verifier; |
| 3690 | struct nfs4_setclientid setclientid = { |
| 3691 | .sc_verifier = &sc_verifier, |
| 3692 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3693 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | }; |
| 3695 | struct rpc_message msg = { |
| 3696 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3697 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3698 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3699 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3701 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | int loop = 0; |
| 3703 | int status; |
| 3704 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3705 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3707 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3708 | |
| 3709 | for(;;) { |
| 3710 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3711 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3712 | clp->cl_ipaddr, |
| 3713 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3714 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3715 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3716 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3717 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | clp->cl_id_uniquifier); |
| 3719 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3720 | sizeof(setclientid.sc_netid), |
| 3721 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3722 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3723 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3724 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3726 | |
| 3727 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3728 | if (status != -NFS4ERR_CLID_INUSE) |
| 3729 | break; |
| 3730 | if (signalled()) |
| 3731 | break; |
| 3732 | if (loop++ & 1) |
J. Bruce Fields | 611c96c | 2010-12-13 19:05:46 -0500 | [diff] [blame] | 3733 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | else |
| 3735 | if (++clp->cl_id_uniquifier == 0) |
| 3736 | break; |
| 3737 | } |
| 3738 | return status; |
| 3739 | } |
| 3740 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3741 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3742 | struct nfs4_setclientid_res *arg, |
| 3743 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3744 | { |
| 3745 | struct nfs_fsinfo fsinfo; |
| 3746 | struct rpc_message msg = { |
| 3747 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3748 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3750 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | }; |
| 3752 | unsigned long now; |
| 3753 | int status; |
| 3754 | |
| 3755 | now = jiffies; |
| 3756 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3757 | if (status == 0) { |
| 3758 | spin_lock(&clp->cl_lock); |
| 3759 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3760 | clp->cl_last_renewal = now; |
| 3761 | spin_unlock(&clp->cl_lock); |
| 3762 | } |
| 3763 | return status; |
| 3764 | } |
| 3765 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3766 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3767 | struct nfs4_setclientid_res *arg, |
| 3768 | struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3769 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3770 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3771 | int err; |
| 3772 | do { |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3773 | err = _nfs4_proc_setclientid_confirm(clp, arg, cred); |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3774 | switch (err) { |
| 3775 | case 0: |
| 3776 | return err; |
| 3777 | case -NFS4ERR_RESOURCE: |
| 3778 | /* The IBM lawyers misread another document! */ |
| 3779 | case -NFS4ERR_DELAY: |
| 3780 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3781 | } |
| 3782 | } while (err == 0); |
| 3783 | return err; |
| 3784 | } |
| 3785 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3786 | struct nfs4_delegreturndata { |
| 3787 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3788 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3789 | struct nfs_fh fh; |
| 3790 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3791 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3792 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3793 | int rpc_status; |
| 3794 | }; |
| 3795 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3796 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3797 | { |
| 3798 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3799 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3800 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3801 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3802 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3803 | switch (task->tk_status) { |
| 3804 | case -NFS4ERR_STALE_STATEID: |
| 3805 | case -NFS4ERR_EXPIRED: |
| 3806 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3807 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3808 | break; |
| 3809 | default: |
| 3810 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3811 | -EAGAIN) { |
| 3812 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3813 | return; |
| 3814 | } |
| 3815 | } |
| 3816 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | static void nfs4_delegreturn_release(void *calldata) |
| 3820 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3821 | kfree(calldata); |
| 3822 | } |
| 3823 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3824 | #if defined(CONFIG_NFS_V4_1) |
| 3825 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3826 | { |
| 3827 | struct nfs4_delegreturndata *d_data; |
| 3828 | |
| 3829 | d_data = (struct nfs4_delegreturndata *)data; |
| 3830 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3831 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3832 | &d_data->args.seq_args, |
| 3833 | &d_data->res.seq_res, 1, task)) |
| 3834 | return; |
| 3835 | rpc_call_start(task); |
| 3836 | } |
| 3837 | #endif /* CONFIG_NFS_V4_1 */ |
| 3838 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3839 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3840 | #if defined(CONFIG_NFS_V4_1) |
| 3841 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3842 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3843 | .rpc_call_done = nfs4_delegreturn_done, |
| 3844 | .rpc_release = nfs4_delegreturn_release, |
| 3845 | }; |
| 3846 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3847 | 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] | 3848 | { |
| 3849 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3850 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3851 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3852 | struct rpc_message msg = { |
| 3853 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3854 | .rpc_cred = cred, |
| 3855 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3856 | struct rpc_task_setup task_setup_data = { |
| 3857 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3858 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3859 | .callback_ops = &nfs4_delegreturn_ops, |
| 3860 | .flags = RPC_TASK_ASYNC, |
| 3861 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3862 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3863 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3864 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3865 | if (data == NULL) |
| 3866 | return -ENOMEM; |
| 3867 | data->args.fhandle = &data->fh; |
| 3868 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3869 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3870 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3871 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3872 | data->res.fattr = &data->fattr; |
| 3873 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3874 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3875 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3876 | data->rpc_status = 0; |
| 3877 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3878 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3879 | msg.rpc_argp = &data->args; |
| 3880 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3881 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3882 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3883 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3884 | if (!issync) |
| 3885 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3886 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3887 | if (status != 0) |
| 3888 | goto out; |
| 3889 | status = data->rpc_status; |
| 3890 | if (status != 0) |
| 3891 | goto out; |
| 3892 | nfs_refresh_inode(inode, &data->fattr); |
| 3893 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3894 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3895 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3896 | } |
| 3897 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3898 | 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] | 3899 | { |
| 3900 | struct nfs_server *server = NFS_SERVER(inode); |
| 3901 | struct nfs4_exception exception = { }; |
| 3902 | int err; |
| 3903 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3904 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | switch (err) { |
| 3906 | case -NFS4ERR_STALE_STATEID: |
| 3907 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3908 | case 0: |
| 3909 | return 0; |
| 3910 | } |
| 3911 | err = nfs4_handle_exception(server, err, &exception); |
| 3912 | } while (exception.retry); |
| 3913 | return err; |
| 3914 | } |
| 3915 | |
| 3916 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3917 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3918 | |
| 3919 | /* |
| 3920 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3921 | */ |
| 3922 | static unsigned long |
| 3923 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3924 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3925 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | timeout <<= 1; |
| 3927 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3928 | return NFS4_LOCK_MAXTIMEOUT; |
| 3929 | return timeout; |
| 3930 | } |
| 3931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3933 | { |
| 3934 | struct inode *inode = state->inode; |
| 3935 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3936 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3937 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3939 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3941 | struct nfs_lockt_res res = { |
| 3942 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | }; |
| 3944 | struct rpc_message msg = { |
| 3945 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3946 | .rpc_argp = &arg, |
| 3947 | .rpc_resp = &res, |
| 3948 | .rpc_cred = state->owner->so_cred, |
| 3949 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | struct nfs4_lock_state *lsp; |
| 3951 | int status; |
| 3952 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3953 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3954 | status = nfs4_set_lock_state(state, request); |
| 3955 | if (status != 0) |
| 3956 | goto out; |
| 3957 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3958 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3959 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3960 | status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3961 | switch (status) { |
| 3962 | case 0: |
| 3963 | request->fl_type = F_UNLCK; |
| 3964 | break; |
| 3965 | case -NFS4ERR_DENIED: |
| 3966 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3968 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3969 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | return status; |
| 3971 | } |
| 3972 | |
| 3973 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3974 | { |
| 3975 | struct nfs4_exception exception = { }; |
| 3976 | int err; |
| 3977 | |
| 3978 | do { |
| 3979 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3980 | _nfs4_proc_getlk(state, cmd, request), |
| 3981 | &exception); |
| 3982 | } while (exception.retry); |
| 3983 | return err; |
| 3984 | } |
| 3985 | |
| 3986 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3987 | { |
| 3988 | int res = 0; |
| 3989 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3990 | case FL_POSIX: |
| 3991 | res = posix_lock_file_wait(file, fl); |
| 3992 | break; |
| 3993 | case FL_FLOCK: |
| 3994 | res = flock_lock_file_wait(file, fl); |
| 3995 | break; |
| 3996 | default: |
| 3997 | BUG(); |
| 3998 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3999 | return res; |
| 4000 | } |
| 4001 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4002 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4003 | struct nfs_locku_args arg; |
| 4004 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4005 | struct nfs4_lock_state *lsp; |
| 4006 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4007 | struct file_lock fl; |
| 4008 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4009 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4010 | }; |
| 4011 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4012 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4013 | struct nfs_open_context *ctx, |
| 4014 | struct nfs4_lock_state *lsp, |
| 4015 | struct nfs_seqid *seqid) |
| 4016 | { |
| 4017 | struct nfs4_unlockdata *p; |
| 4018 | struct inode *inode = lsp->ls_state->inode; |
| 4019 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4020 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4021 | if (p == NULL) |
| 4022 | return NULL; |
| 4023 | p->arg.fh = NFS_FH(inode); |
| 4024 | p->arg.fl = &p->fl; |
| 4025 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4026 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4027 | p->arg.stateid = &lsp->ls_stateid; |
| 4028 | p->lsp = lsp; |
| 4029 | atomic_inc(&lsp->ls_count); |
| 4030 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4031 | p->ctx = get_nfs_open_context(ctx); |
| 4032 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4033 | p->server = NFS_SERVER(inode); |
| 4034 | return p; |
| 4035 | } |
| 4036 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4037 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4038 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4039 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4040 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4041 | nfs4_put_lock_state(calldata->lsp); |
| 4042 | put_nfs_open_context(calldata->ctx); |
| 4043 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4044 | } |
| 4045 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4046 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4047 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4048 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4049 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4050 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4051 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4052 | switch (task->tk_status) { |
| 4053 | case 0: |
| 4054 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4055 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4056 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4057 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4058 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4059 | case -NFS4ERR_BAD_STATEID: |
| 4060 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4061 | case -NFS4ERR_STALE_STATEID: |
| 4062 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4063 | break; |
| 4064 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4065 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4066 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 4067 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4068 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4069 | } |
| 4070 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4071 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4072 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4073 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4075 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4076 | return; |
| 4077 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4078 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4079 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4080 | return; |
| 4081 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4082 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4083 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4084 | &calldata->arg.seq_args, |
| 4085 | &calldata->res.seq_res, 1, task)) |
| 4086 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4087 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4090 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4091 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4092 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4093 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4094 | }; |
| 4095 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4096 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4097 | struct nfs_open_context *ctx, |
| 4098 | struct nfs4_lock_state *lsp, |
| 4099 | struct nfs_seqid *seqid) |
| 4100 | { |
| 4101 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4102 | struct rpc_message msg = { |
| 4103 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4104 | .rpc_cred = ctx->cred, |
| 4105 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4106 | struct rpc_task_setup task_setup_data = { |
| 4107 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4108 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4109 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4110 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4111 | .flags = RPC_TASK_ASYNC, |
| 4112 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4113 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4114 | /* Ensure this is an unlock - when canceling a lock, the |
| 4115 | * canceled lock is passed in, and it won't be an unlock. |
| 4116 | */ |
| 4117 | fl->fl_type = F_UNLCK; |
| 4118 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4119 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4120 | if (data == NULL) { |
| 4121 | nfs_free_seqid(seqid); |
| 4122 | return ERR_PTR(-ENOMEM); |
| 4123 | } |
| 4124 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4125 | msg.rpc_argp = &data->arg; |
| 4126 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4127 | task_setup_data.callback_data = data; |
| 4128 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4129 | } |
| 4130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4132 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4133 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4134 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4135 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4136 | struct rpc_task *task; |
| 4137 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4138 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4140 | status = nfs4_set_lock_state(state, request); |
| 4141 | /* Unlock _before_ we do the RPC call */ |
| 4142 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4143 | down_read(&nfsi->rwsem); |
| 4144 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4145 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4146 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4147 | } |
| 4148 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4149 | if (status != 0) |
| 4150 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4151 | /* Is this a delegated lock? */ |
| 4152 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4153 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4154 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4155 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4156 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4157 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4158 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4159 | 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] | 4160 | status = PTR_ERR(task); |
| 4161 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4162 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4163 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4164 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4165 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4166 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4167 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | } |
| 4169 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4170 | struct nfs4_lockdata { |
| 4171 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4172 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4173 | struct nfs4_lock_state *lsp; |
| 4174 | struct nfs_open_context *ctx; |
| 4175 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4176 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4177 | int rpc_status; |
| 4178 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4179 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4180 | }; |
| 4181 | |
| 4182 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4183 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4184 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4185 | { |
| 4186 | struct nfs4_lockdata *p; |
| 4187 | struct inode *inode = lsp->ls_state->inode; |
| 4188 | struct nfs_server *server = NFS_SERVER(inode); |
| 4189 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4190 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4191 | if (p == NULL) |
| 4192 | return NULL; |
| 4193 | |
| 4194 | p->arg.fh = NFS_FH(inode); |
| 4195 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4196 | 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] | 4197 | if (p->arg.open_seqid == NULL) |
| 4198 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4199 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4200 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4201 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4202 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4203 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4204 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4205 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4206 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4207 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4208 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4209 | atomic_inc(&lsp->ls_count); |
| 4210 | p->ctx = get_nfs_open_context(ctx); |
| 4211 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4212 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4213 | out_free_seqid: |
| 4214 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4215 | out_free: |
| 4216 | kfree(p); |
| 4217 | return NULL; |
| 4218 | } |
| 4219 | |
| 4220 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4221 | { |
| 4222 | struct nfs4_lockdata *data = calldata; |
| 4223 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4225 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4226 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4227 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4228 | /* Do we need to do an open_to_lock_owner? */ |
| 4229 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4230 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4231 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4232 | data->arg.open_stateid = &state->stateid; |
| 4233 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4234 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4235 | } else |
| 4236 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4237 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4238 | if (nfs4_setup_sequence(data->server, |
| 4239 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4240 | &data->res.seq_res, 1, task)) |
| 4241 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4242 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4243 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4244 | } |
| 4245 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4246 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4247 | { |
| 4248 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4249 | nfs4_lock_prepare(task, calldata); |
| 4250 | } |
| 4251 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4252 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4253 | { |
| 4254 | struct nfs4_lockdata *data = calldata; |
| 4255 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4256 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4257 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4258 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4259 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4260 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4261 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4262 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4263 | if (data->rpc_status == 0) |
| 4264 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4265 | else |
| 4266 | goto out; |
| 4267 | } |
| 4268 | if (data->rpc_status == 0) { |
| 4269 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4270 | sizeof(data->lsp->ls_stateid.data)); |
| 4271 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4272 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4273 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4274 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4275 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4276 | } |
| 4277 | |
| 4278 | static void nfs4_lock_release(void *calldata) |
| 4279 | { |
| 4280 | struct nfs4_lockdata *data = calldata; |
| 4281 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4282 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4283 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4284 | if (data->cancelled != 0) { |
| 4285 | struct rpc_task *task; |
| 4286 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4287 | data->arg.lock_seqid); |
| 4288 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4289 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4290 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4291 | } else |
| 4292 | nfs_free_seqid(data->arg.lock_seqid); |
| 4293 | nfs4_put_lock_state(data->lsp); |
| 4294 | put_nfs_open_context(data->ctx); |
| 4295 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4296 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4300 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4301 | .rpc_call_done = nfs4_lock_done, |
| 4302 | .rpc_release = nfs4_lock_release, |
| 4303 | }; |
| 4304 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4305 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4306 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4307 | .rpc_call_done = nfs4_lock_done, |
| 4308 | .rpc_release = nfs4_lock_release, |
| 4309 | }; |
| 4310 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4311 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4312 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4313 | switch (error) { |
| 4314 | case -NFS4ERR_ADMIN_REVOKED: |
| 4315 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4316 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4317 | if (new_lock_owner != 0 || |
| 4318 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4319 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4320 | break; |
| 4321 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4322 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4323 | case -NFS4ERR_EXPIRED: |
| 4324 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4325 | }; |
| 4326 | } |
| 4327 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4328 | 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] | 4329 | { |
| 4330 | struct nfs4_lockdata *data; |
| 4331 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4332 | struct rpc_message msg = { |
| 4333 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4334 | .rpc_cred = state->owner->so_cred, |
| 4335 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4336 | struct rpc_task_setup task_setup_data = { |
| 4337 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4338 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4339 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4340 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4341 | .flags = RPC_TASK_ASYNC, |
| 4342 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4343 | int ret; |
| 4344 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4345 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4346 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4347 | fl->fl_u.nfs4_fl.owner, |
| 4348 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4349 | if (data == NULL) |
| 4350 | return -ENOMEM; |
| 4351 | if (IS_SETLKW(cmd)) |
| 4352 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4353 | if (recovery_type > NFS_LOCK_NEW) { |
| 4354 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4355 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4356 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4357 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4358 | msg.rpc_argp = &data->arg; |
| 4359 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4360 | task_setup_data.callback_data = data; |
| 4361 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4362 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4363 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4364 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4365 | if (ret == 0) { |
| 4366 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4367 | if (ret) |
| 4368 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4369 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4370 | } else |
| 4371 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4372 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4373 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4374 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4378 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4379 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4380 | struct nfs4_exception exception = { }; |
| 4381 | int err; |
| 4382 | |
| 4383 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4384 | /* Cache the lock if possible... */ |
| 4385 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4386 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4387 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4388 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4389 | break; |
| 4390 | nfs4_handle_exception(server, err, &exception); |
| 4391 | } while (exception.retry); |
| 4392 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4396 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4397 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4398 | struct nfs4_exception exception = { }; |
| 4399 | int err; |
| 4400 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4401 | err = nfs4_set_lock_state(state, request); |
| 4402 | if (err != 0) |
| 4403 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4404 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4405 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4406 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4407 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4408 | switch (err) { |
| 4409 | default: |
| 4410 | goto out; |
| 4411 | case -NFS4ERR_GRACE: |
| 4412 | case -NFS4ERR_DELAY: |
| 4413 | nfs4_handle_exception(server, err, &exception); |
| 4414 | err = 0; |
| 4415 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4416 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4417 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4418 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4422 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4423 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4424 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4425 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4427 | if ((fl_flags & FL_POSIX) && |
| 4428 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4429 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4430 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4431 | status = nfs4_set_lock_state(state, request); |
| 4432 | if (status != 0) |
| 4433 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4434 | request->fl_flags |= FL_ACCESS; |
| 4435 | status = do_vfs_lock(request->fl_file, request); |
| 4436 | if (status < 0) |
| 4437 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4438 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4439 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4440 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4441 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4442 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4443 | status = do_vfs_lock(request->fl_file, request); |
| 4444 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4445 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4446 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4447 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4448 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4449 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4450 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4451 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4452 | 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] | 4453 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4454 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4455 | out: |
| 4456 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | return status; |
| 4458 | } |
| 4459 | |
| 4460 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4461 | { |
| 4462 | struct nfs4_exception exception = { }; |
| 4463 | int err; |
| 4464 | |
| 4465 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4466 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4467 | if (err == -NFS4ERR_DENIED) |
| 4468 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4470 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | } while (exception.retry); |
| 4472 | return err; |
| 4473 | } |
| 4474 | |
| 4475 | static int |
| 4476 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4477 | { |
| 4478 | struct nfs_open_context *ctx; |
| 4479 | struct nfs4_state *state; |
| 4480 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4481 | int status; |
| 4482 | |
| 4483 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4484 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | state = ctx->state; |
| 4486 | |
| 4487 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4488 | return -EINVAL; |
| 4489 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4490 | if (IS_GETLK(cmd)) { |
| 4491 | if (state != NULL) |
| 4492 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4493 | return 0; |
| 4494 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | |
| 4496 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4497 | return -EINVAL; |
| 4498 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4499 | if (request->fl_type == F_UNLCK) { |
| 4500 | if (state != NULL) |
| 4501 | return nfs4_proc_unlck(state, cmd, request); |
| 4502 | return 0; |
| 4503 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4504 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4505 | if (state == NULL) |
| 4506 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | do { |
| 4508 | status = nfs4_proc_setlk(state, cmd, request); |
| 4509 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4510 | break; |
| 4511 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4512 | status = -ERESTARTSYS; |
| 4513 | if (signalled()) |
| 4514 | break; |
| 4515 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | return status; |
| 4517 | } |
| 4518 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4519 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4520 | { |
| 4521 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4522 | struct nfs4_exception exception = { }; |
| 4523 | int err; |
| 4524 | |
| 4525 | err = nfs4_set_lock_state(state, fl); |
| 4526 | if (err != 0) |
| 4527 | goto out; |
| 4528 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4529 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4530 | switch (err) { |
| 4531 | default: |
| 4532 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4533 | __func__, err); |
| 4534 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4535 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4536 | goto out; |
| 4537 | case -NFS4ERR_EXPIRED: |
| 4538 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4539 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4540 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4541 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4542 | case -NFS4ERR_BADSESSION: |
| 4543 | case -NFS4ERR_BADSLOT: |
| 4544 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4545 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4546 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4547 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4548 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4549 | case -ERESTARTSYS: |
| 4550 | /* |
| 4551 | * The show must go on: exit, but mark the |
| 4552 | * stateid as needing recovery. |
| 4553 | */ |
| 4554 | case -NFS4ERR_ADMIN_REVOKED: |
| 4555 | case -NFS4ERR_BAD_STATEID: |
| 4556 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4557 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4558 | err = 0; |
| 4559 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4560 | case -EKEYEXPIRED: |
| 4561 | /* |
| 4562 | * User RPCSEC_GSS context has expired. |
| 4563 | * We cannot recover this stateid now, so |
| 4564 | * skip it and allow recovery thread to |
| 4565 | * proceed. |
| 4566 | */ |
| 4567 | err = 0; |
| 4568 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4569 | case -ENOMEM: |
| 4570 | case -NFS4ERR_DENIED: |
| 4571 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4572 | err = 0; |
| 4573 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4574 | case -NFS4ERR_DELAY: |
| 4575 | break; |
| 4576 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4577 | err = nfs4_handle_exception(server, err, &exception); |
| 4578 | } while (exception.retry); |
| 4579 | out: |
| 4580 | return err; |
| 4581 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4582 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4583 | static void nfs4_release_lockowner_release(void *calldata) |
| 4584 | { |
| 4585 | kfree(calldata); |
| 4586 | } |
| 4587 | |
| 4588 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4589 | .rpc_release = nfs4_release_lockowner_release, |
| 4590 | }; |
| 4591 | |
| 4592 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4593 | { |
| 4594 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4595 | struct nfs_release_lockowner_args *args; |
| 4596 | struct rpc_message msg = { |
| 4597 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4598 | }; |
| 4599 | |
| 4600 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4601 | return; |
| 4602 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4603 | if (!args) |
| 4604 | return; |
| 4605 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4606 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4607 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4608 | msg.rpc_argp = args; |
| 4609 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4610 | } |
| 4611 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4612 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4613 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4614 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4615 | const void *buf, size_t buflen, |
| 4616 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4617 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4618 | if (strcmp(key, "") != 0) |
| 4619 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4620 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4621 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4622 | } |
| 4623 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4624 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4625 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4626 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4627 | if (strcmp(key, "") != 0) |
| 4628 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4629 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4630 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4631 | } |
| 4632 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4633 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4634 | size_t list_len, const char *name, |
| 4635 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4636 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4637 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4638 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4639 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4640 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4641 | |
| 4642 | if (list && len <= list_len) |
| 4643 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4644 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4645 | } |
| 4646 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4647 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4648 | { |
| 4649 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4650 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4651 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4652 | return; |
| 4653 | |
| 4654 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4655 | NFS_ATTR_FATTR_NLINK; |
| 4656 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4657 | fattr->nlink = 2; |
| 4658 | } |
| 4659 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4660 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4661 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4662 | { |
| 4663 | struct nfs_server *server = NFS_SERVER(dir); |
| 4664 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4665 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4666 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4667 | }; |
| 4668 | struct nfs4_fs_locations_arg args = { |
| 4669 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4670 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4671 | .page = page, |
| 4672 | .bitmask = bitmask, |
| 4673 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4674 | struct nfs4_fs_locations_res res = { |
| 4675 | .fs_locations = fs_locations, |
| 4676 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4677 | struct rpc_message msg = { |
| 4678 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4679 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4680 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4681 | }; |
| 4682 | int status; |
| 4683 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4684 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4685 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4686 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4687 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4688 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4689 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4690 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4691 | return status; |
| 4692 | } |
| 4693 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4694 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4695 | { |
| 4696 | int status; |
| 4697 | struct nfs4_secinfo_arg args = { |
| 4698 | .dir_fh = NFS_FH(dir), |
| 4699 | .name = name, |
| 4700 | }; |
| 4701 | struct nfs4_secinfo_res res = { |
| 4702 | .flavors = flavors, |
| 4703 | }; |
| 4704 | struct rpc_message msg = { |
| 4705 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4706 | .rpc_argp = &args, |
| 4707 | .rpc_resp = &res, |
| 4708 | }; |
| 4709 | |
| 4710 | dprintk("NFS call secinfo %s\n", name->name); |
| 4711 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4712 | dprintk("NFS reply secinfo: %d\n", status); |
| 4713 | return status; |
| 4714 | } |
| 4715 | |
| 4716 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4717 | { |
| 4718 | struct nfs4_exception exception = { }; |
| 4719 | int err; |
| 4720 | do { |
| 4721 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4722 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4723 | &exception); |
| 4724 | } while (exception.retry); |
| 4725 | return err; |
| 4726 | } |
| 4727 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4728 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4729 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4730 | * Check the exchange flags returned by the server for invalid flags, having |
| 4731 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4732 | * DS flags set. |
| 4733 | */ |
| 4734 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4735 | { |
| 4736 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4737 | goto out_inval; |
| 4738 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4739 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4740 | goto out_inval; |
| 4741 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4742 | goto out_inval; |
| 4743 | return NFS_OK; |
| 4744 | out_inval: |
| 4745 | return -NFS4ERR_INVAL; |
| 4746 | } |
| 4747 | |
| 4748 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4749 | * nfs4_proc_exchange_id() |
| 4750 | * |
| 4751 | * Since the clientid has expired, all compounds using sessions |
| 4752 | * associated with the stale clientid will be returning |
| 4753 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4754 | * be in some phase of session reset. |
| 4755 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4756 | 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] | 4757 | { |
| 4758 | nfs4_verifier verifier; |
| 4759 | struct nfs41_exchange_id_args args = { |
| 4760 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4761 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4762 | }; |
| 4763 | struct nfs41_exchange_id_res res = { |
| 4764 | .client = clp, |
| 4765 | }; |
| 4766 | int status; |
| 4767 | struct rpc_message msg = { |
| 4768 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4769 | .rpc_argp = &args, |
| 4770 | .rpc_resp = &res, |
| 4771 | .rpc_cred = cred, |
| 4772 | }; |
| 4773 | __be32 *p; |
| 4774 | |
| 4775 | dprintk("--> %s\n", __func__); |
| 4776 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4777 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4778 | p = (u32 *)verifier.data; |
| 4779 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4780 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4781 | args.verifier = &verifier; |
| 4782 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4783 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4784 | "%s/%s.%s/%u", |
| 4785 | clp->cl_ipaddr, |
| 4786 | init_utsname()->nodename, |
| 4787 | init_utsname()->domainname, |
| 4788 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4789 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4790 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4791 | if (!status) |
| 4792 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4793 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4794 | return status; |
| 4795 | } |
| 4796 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4797 | struct nfs4_get_lease_time_data { |
| 4798 | struct nfs4_get_lease_time_args *args; |
| 4799 | struct nfs4_get_lease_time_res *res; |
| 4800 | struct nfs_client *clp; |
| 4801 | }; |
| 4802 | |
| 4803 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4804 | void *calldata) |
| 4805 | { |
| 4806 | int ret; |
| 4807 | struct nfs4_get_lease_time_data *data = |
| 4808 | (struct nfs4_get_lease_time_data *)calldata; |
| 4809 | |
| 4810 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4811 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4812 | /* just setup sequence, do not trigger session recovery |
| 4813 | since we're invoked within one */ |
| 4814 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4815 | &data->args->la_seq_args, |
| 4816 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4817 | |
| 4818 | BUG_ON(ret == -EAGAIN); |
| 4819 | rpc_call_start(task); |
| 4820 | dprintk("<-- %s\n", __func__); |
| 4821 | } |
| 4822 | |
| 4823 | /* |
| 4824 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4825 | * from sequence operation or clientid errors. |
| 4826 | */ |
| 4827 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4828 | { |
| 4829 | struct nfs4_get_lease_time_data *data = |
| 4830 | (struct nfs4_get_lease_time_data *)calldata; |
| 4831 | |
| 4832 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4833 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4834 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4835 | switch (task->tk_status) { |
| 4836 | case -NFS4ERR_DELAY: |
| 4837 | case -NFS4ERR_GRACE: |
| 4838 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4839 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4840 | task->tk_status = 0; |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4841 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4842 | return; |
| 4843 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4844 | dprintk("<-- %s\n", __func__); |
| 4845 | } |
| 4846 | |
| 4847 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4848 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4849 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4850 | }; |
| 4851 | |
| 4852 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4853 | { |
| 4854 | struct rpc_task *task; |
| 4855 | struct nfs4_get_lease_time_args args; |
| 4856 | struct nfs4_get_lease_time_res res = { |
| 4857 | .lr_fsinfo = fsinfo, |
| 4858 | }; |
| 4859 | struct nfs4_get_lease_time_data data = { |
| 4860 | .args = &args, |
| 4861 | .res = &res, |
| 4862 | .clp = clp, |
| 4863 | }; |
| 4864 | struct rpc_message msg = { |
| 4865 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4866 | .rpc_argp = &args, |
| 4867 | .rpc_resp = &res, |
| 4868 | }; |
| 4869 | struct rpc_task_setup task_setup = { |
| 4870 | .rpc_client = clp->cl_rpcclient, |
| 4871 | .rpc_message = &msg, |
| 4872 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4873 | .callback_data = &data |
| 4874 | }; |
| 4875 | int status; |
| 4876 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4877 | dprintk("--> %s\n", __func__); |
| 4878 | task = rpc_run_task(&task_setup); |
| 4879 | |
| 4880 | if (IS_ERR(task)) |
| 4881 | status = PTR_ERR(task); |
| 4882 | else { |
| 4883 | status = task->tk_status; |
| 4884 | rpc_put_task(task); |
| 4885 | } |
| 4886 | dprintk("<-- %s return %d\n", __func__, status); |
| 4887 | |
| 4888 | return status; |
| 4889 | } |
| 4890 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4891 | /* |
| 4892 | * Reset a slot table |
| 4893 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4894 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4895 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4896 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4897 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4898 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4899 | int ret = 0; |
| 4900 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4901 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4902 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4903 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4904 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4905 | if (max_reqs != tbl->max_slots) { |
| 4906 | ret = -ENOMEM; |
| 4907 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4908 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4909 | if (!new) |
| 4910 | goto out; |
| 4911 | ret = 0; |
| 4912 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4913 | } |
| 4914 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4915 | if (new) { |
| 4916 | tbl->slots = new; |
| 4917 | tbl->max_slots = max_reqs; |
| 4918 | } |
| 4919 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4920 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4921 | spin_unlock(&tbl->slot_tbl_lock); |
| 4922 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4923 | tbl, tbl->slots, tbl->max_slots); |
| 4924 | out: |
| 4925 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4926 | return ret; |
| 4927 | } |
| 4928 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4929 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4930 | * Reset the forechannel and backchannel slot tables |
| 4931 | */ |
| 4932 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4933 | { |
| 4934 | int status; |
| 4935 | |
| 4936 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4937 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4938 | if (status) |
| 4939 | return status; |
| 4940 | |
| 4941 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4942 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4943 | return status; |
| 4944 | } |
| 4945 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4946 | /* Destroy the slot table */ |
| 4947 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4948 | { |
| 4949 | if (session->fc_slot_table.slots != NULL) { |
| 4950 | kfree(session->fc_slot_table.slots); |
| 4951 | session->fc_slot_table.slots = NULL; |
| 4952 | } |
| 4953 | if (session->bc_slot_table.slots != NULL) { |
| 4954 | kfree(session->bc_slot_table.slots); |
| 4955 | session->bc_slot_table.slots = NULL; |
| 4956 | } |
| 4957 | return; |
| 4958 | } |
| 4959 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4960 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4961 | * Initialize slot table |
| 4962 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4963 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4964 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4965 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4966 | struct nfs4_slot *slot; |
| 4967 | int ret = -ENOMEM; |
| 4968 | |
| 4969 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4970 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4971 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4972 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4973 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4974 | if (!slot) |
| 4975 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4976 | ret = 0; |
| 4977 | |
| 4978 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4979 | tbl->max_slots = max_slots; |
| 4980 | tbl->slots = slot; |
| 4981 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4982 | spin_unlock(&tbl->slot_tbl_lock); |
| 4983 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4984 | tbl, tbl->slots, tbl->max_slots); |
| 4985 | out: |
| 4986 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4987 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4988 | } |
| 4989 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4990 | /* |
| 4991 | * Initialize the forechannel and backchannel tables |
| 4992 | */ |
| 4993 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4994 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4995 | struct nfs4_slot_table *tbl; |
| 4996 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4997 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4998 | tbl = &session->fc_slot_table; |
| 4999 | if (tbl->slots == NULL) { |
| 5000 | status = nfs4_init_slot_table(tbl, |
| 5001 | session->fc_attrs.max_reqs, 1); |
| 5002 | if (status) |
| 5003 | return status; |
| 5004 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5005 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5006 | tbl = &session->bc_slot_table; |
| 5007 | if (tbl->slots == NULL) { |
| 5008 | status = nfs4_init_slot_table(tbl, |
| 5009 | session->bc_attrs.max_reqs, 0); |
| 5010 | if (status) |
| 5011 | nfs4_destroy_slot_tables(session); |
| 5012 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5013 | |
| 5014 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5018 | { |
| 5019 | struct nfs4_session *session; |
| 5020 | struct nfs4_slot_table *tbl; |
| 5021 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5022 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5023 | if (!session) |
| 5024 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5025 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5026 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5027 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5028 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5029 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5030 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5031 | |
| 5032 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5033 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5034 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5035 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5036 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5037 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5038 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5039 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5040 | session->clp = clp; |
| 5041 | return session; |
| 5042 | } |
| 5043 | |
| 5044 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5045 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5046 | nfs4_proc_destroy_session(session); |
| 5047 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 5048 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 5049 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 5050 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5051 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5052 | kfree(session); |
| 5053 | } |
| 5054 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5055 | /* |
| 5056 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5057 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5058 | * use them. |
| 5059 | * |
| 5060 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5061 | * always set csa_cachethis to FALSE because the current implementation |
| 5062 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5063 | */ |
| 5064 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5065 | { |
| 5066 | struct nfs4_session *session = args->client->cl_session; |
| 5067 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5068 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5069 | |
| 5070 | if (mxrqst_sz == 0) |
| 5071 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5072 | if (mxresp_sz == 0) |
| 5073 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5074 | /* Fore channel attributes */ |
| 5075 | args->fc_attrs.headerpadsz = 0; |
| 5076 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5077 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5078 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 5079 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 5080 | |
| 5081 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5082 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5083 | __func__, |
| 5084 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5085 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5086 | |
| 5087 | /* Back channel attributes */ |
| 5088 | args->bc_attrs.headerpadsz = 0; |
| 5089 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5090 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5091 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5092 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5093 | args->bc_attrs.max_reqs = 1; |
| 5094 | |
| 5095 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5096 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5097 | __func__, |
| 5098 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5099 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5100 | args->bc_attrs.max_reqs); |
| 5101 | } |
| 5102 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5103 | 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] | 5104 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5105 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5106 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5107 | |
| 5108 | if (rcvd->headerpadsz > sent->headerpadsz) |
| 5109 | return -EINVAL; |
| 5110 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5111 | return -EINVAL; |
| 5112 | /* |
| 5113 | * Our requested max_ops is the minimum we need; we're not |
| 5114 | * prepared to break up compounds into smaller pieces than that. |
| 5115 | * So, no point even trying to continue if the server won't |
| 5116 | * cooperate: |
| 5117 | */ |
| 5118 | if (rcvd->max_ops < sent->max_ops) |
| 5119 | return -EINVAL; |
| 5120 | if (rcvd->max_reqs == 0) |
| 5121 | return -EINVAL; |
| 5122 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5123 | } |
| 5124 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5125 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5126 | { |
| 5127 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5128 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5129 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5130 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5131 | return -EINVAL; |
| 5132 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5133 | return -EINVAL; |
| 5134 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5135 | return -EINVAL; |
| 5136 | /* These would render the backchannel useless: */ |
| 5137 | if (rcvd->max_ops == 0) |
| 5138 | return -EINVAL; |
| 5139 | if (rcvd->max_reqs == 0) |
| 5140 | return -EINVAL; |
| 5141 | return 0; |
| 5142 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5143 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5144 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5145 | struct nfs4_session *session) |
| 5146 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5147 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5148 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5149 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5150 | if (ret) |
| 5151 | return ret; |
| 5152 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5153 | } |
| 5154 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5155 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5156 | { |
| 5157 | struct nfs4_session *session = clp->cl_session; |
| 5158 | struct nfs41_create_session_args args = { |
| 5159 | .client = clp, |
| 5160 | .cb_program = NFS4_CALLBACK, |
| 5161 | }; |
| 5162 | struct nfs41_create_session_res res = { |
| 5163 | .client = clp, |
| 5164 | }; |
| 5165 | struct rpc_message msg = { |
| 5166 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5167 | .rpc_argp = &args, |
| 5168 | .rpc_resp = &res, |
| 5169 | }; |
| 5170 | int status; |
| 5171 | |
| 5172 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5173 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5174 | |
| 5175 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5176 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5177 | if (!status) |
| 5178 | /* Verify the session's negotiated channel_attrs values */ |
| 5179 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5180 | if (!status) { |
| 5181 | /* Increment the clientid slot sequence id */ |
| 5182 | clp->cl_seqid++; |
| 5183 | } |
| 5184 | |
| 5185 | return status; |
| 5186 | } |
| 5187 | |
| 5188 | /* |
| 5189 | * Issues a CREATE_SESSION operation to the server. |
| 5190 | * It is the responsibility of the caller to verify the session is |
| 5191 | * expired before calling this routine. |
| 5192 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5193 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5194 | { |
| 5195 | int status; |
| 5196 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5197 | struct nfs4_session *session = clp->cl_session; |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5198 | long timeout = 0; |
| 5199 | int err; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5200 | |
| 5201 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5202 | |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5203 | do { |
| 5204 | status = _nfs4_proc_create_session(clp); |
| 5205 | if (status == -NFS4ERR_DELAY) { |
| 5206 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 5207 | if (err) |
| 5208 | status = err; |
| 5209 | } |
| 5210 | } while (status == -NFS4ERR_DELAY); |
| 5211 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5212 | if (status) |
| 5213 | goto out; |
| 5214 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5215 | /* Init and reset the fore channel */ |
| 5216 | status = nfs4_init_slot_tables(session); |
| 5217 | dprintk("slot table initialization returned %d\n", status); |
| 5218 | if (status) |
| 5219 | goto out; |
| 5220 | status = nfs4_reset_slot_tables(session); |
| 5221 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5222 | if (status) |
| 5223 | goto out; |
| 5224 | |
| 5225 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5226 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5227 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5228 | out: |
| 5229 | dprintk("<-- %s\n", __func__); |
| 5230 | return status; |
| 5231 | } |
| 5232 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5233 | /* |
| 5234 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5235 | * The caller must serialize access to this routine. |
| 5236 | */ |
| 5237 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5238 | { |
| 5239 | int status = 0; |
| 5240 | struct rpc_message msg; |
| 5241 | |
| 5242 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5243 | |
| 5244 | /* session is still being setup */ |
| 5245 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5246 | return status; |
| 5247 | |
| 5248 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5249 | msg.rpc_argp = session; |
| 5250 | msg.rpc_resp = NULL; |
| 5251 | msg.rpc_cred = NULL; |
| 5252 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5253 | |
| 5254 | if (status) |
| 5255 | printk(KERN_WARNING |
| 5256 | "Got error %d from the server on DESTROY_SESSION. " |
| 5257 | "Session has been destroyed regardless...\n", status); |
| 5258 | |
| 5259 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5260 | return status; |
| 5261 | } |
| 5262 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5263 | int nfs4_init_session(struct nfs_server *server) |
| 5264 | { |
| 5265 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5266 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5267 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5268 | int ret; |
| 5269 | |
| 5270 | if (!nfs4_has_session(clp)) |
| 5271 | return 0; |
| 5272 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5273 | session = clp->cl_session; |
| 5274 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5275 | return 0; |
| 5276 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5277 | rsize = server->rsize; |
| 5278 | if (rsize == 0) |
| 5279 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5280 | wsize = server->wsize; |
| 5281 | if (wsize == 0) |
| 5282 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5283 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5284 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5285 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5286 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5287 | ret = nfs4_recover_expired_lease(server); |
| 5288 | if (!ret) |
| 5289 | ret = nfs4_check_client_ready(clp); |
| 5290 | return ret; |
| 5291 | } |
| 5292 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5293 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5294 | { |
| 5295 | struct nfs4_session *session = clp->cl_session; |
| 5296 | int ret; |
| 5297 | |
| 5298 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5299 | return 0; |
| 5300 | |
| 5301 | ret = nfs4_client_recover_expired_lease(clp); |
| 5302 | if (!ret) |
| 5303 | /* Test for the DS role */ |
| 5304 | if (!is_ds_client(clp)) |
| 5305 | ret = -ENODEV; |
| 5306 | if (!ret) |
| 5307 | ret = nfs4_check_client_ready(clp); |
| 5308 | return ret; |
| 5309 | |
| 5310 | } |
| 5311 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5312 | |
| 5313 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5314 | /* |
| 5315 | * Renew the cl_session lease. |
| 5316 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5317 | struct nfs4_sequence_data { |
| 5318 | struct nfs_client *clp; |
| 5319 | struct nfs4_sequence_args args; |
| 5320 | struct nfs4_sequence_res res; |
| 5321 | }; |
| 5322 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5323 | static void nfs41_sequence_release(void *data) |
| 5324 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5325 | struct nfs4_sequence_data *calldata = data; |
| 5326 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5327 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5328 | if (atomic_read(&clp->cl_count) > 1) |
| 5329 | nfs4_schedule_state_renewal(clp); |
| 5330 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5331 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5332 | } |
| 5333 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5334 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5335 | { |
| 5336 | switch(task->tk_status) { |
| 5337 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5338 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5339 | return -EAGAIN; |
| 5340 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5341 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5342 | } |
| 5343 | return 0; |
| 5344 | } |
| 5345 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5346 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5347 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5348 | struct nfs4_sequence_data *calldata = data; |
| 5349 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5350 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5351 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5352 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5353 | |
| 5354 | if (task->tk_status < 0) { |
| 5355 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5356 | if (atomic_read(&clp->cl_count) == 1) |
| 5357 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5358 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5359 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5360 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5361 | return; |
| 5362 | } |
| 5363 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5364 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5365 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5366 | dprintk("<-- %s\n", __func__); |
| 5367 | } |
| 5368 | |
| 5369 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5370 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5371 | struct nfs4_sequence_data *calldata = data; |
| 5372 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5373 | struct nfs4_sequence_args *args; |
| 5374 | struct nfs4_sequence_res *res; |
| 5375 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5376 | args = task->tk_msg.rpc_argp; |
| 5377 | res = task->tk_msg.rpc_resp; |
| 5378 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5379 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5380 | return; |
| 5381 | rpc_call_start(task); |
| 5382 | } |
| 5383 | |
| 5384 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5385 | .rpc_call_done = nfs41_sequence_call_done, |
| 5386 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5387 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5388 | }; |
| 5389 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5390 | 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] | 5391 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5392 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5393 | struct rpc_message msg = { |
| 5394 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5395 | .rpc_cred = cred, |
| 5396 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5397 | struct rpc_task_setup task_setup_data = { |
| 5398 | .rpc_client = clp->cl_rpcclient, |
| 5399 | .rpc_message = &msg, |
| 5400 | .callback_ops = &nfs41_sequence_ops, |
| 5401 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5402 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5403 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5404 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5405 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5406 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5407 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5408 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5409 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5410 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5411 | msg.rpc_argp = &calldata->args; |
| 5412 | msg.rpc_resp = &calldata->res; |
| 5413 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5414 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5415 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5416 | return rpc_run_task(&task_setup_data); |
| 5417 | } |
| 5418 | |
| 5419 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5420 | { |
| 5421 | struct rpc_task *task; |
| 5422 | int ret = 0; |
| 5423 | |
| 5424 | task = _nfs41_proc_sequence(clp, cred); |
| 5425 | if (IS_ERR(task)) |
| 5426 | ret = PTR_ERR(task); |
| 5427 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5428 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5429 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5430 | return ret; |
| 5431 | } |
| 5432 | |
| 5433 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5434 | { |
| 5435 | struct rpc_task *task; |
| 5436 | int ret; |
| 5437 | |
| 5438 | task = _nfs41_proc_sequence(clp, cred); |
| 5439 | if (IS_ERR(task)) { |
| 5440 | ret = PTR_ERR(task); |
| 5441 | goto out; |
| 5442 | } |
| 5443 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5444 | if (!ret) { |
| 5445 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5446 | |
| 5447 | if (task->tk_status == 0) |
| 5448 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5449 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5450 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5451 | rpc_put_task(task); |
| 5452 | out: |
| 5453 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5454 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5455 | } |
| 5456 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5457 | struct nfs4_reclaim_complete_data { |
| 5458 | struct nfs_client *clp; |
| 5459 | struct nfs41_reclaim_complete_args arg; |
| 5460 | struct nfs41_reclaim_complete_res res; |
| 5461 | }; |
| 5462 | |
| 5463 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5464 | { |
| 5465 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5466 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5467 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5468 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5469 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5470 | &calldata->res.seq_res, 0, task)) |
| 5471 | return; |
| 5472 | |
| 5473 | rpc_call_start(task); |
| 5474 | } |
| 5475 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5476 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5477 | { |
| 5478 | switch(task->tk_status) { |
| 5479 | case 0: |
| 5480 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5481 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5482 | break; |
| 5483 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5484 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5485 | return -EAGAIN; |
| 5486 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5487 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5488 | } |
| 5489 | return 0; |
| 5490 | } |
| 5491 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5492 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5493 | { |
| 5494 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5495 | struct nfs_client *clp = calldata->clp; |
| 5496 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5497 | |
| 5498 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5499 | if (!nfs41_sequence_done(task, res)) |
| 5500 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5501 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5502 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5503 | rpc_restart_call_prepare(task); |
| 5504 | return; |
| 5505 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5506 | dprintk("<-- %s\n", __func__); |
| 5507 | } |
| 5508 | |
| 5509 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5510 | { |
| 5511 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5512 | |
| 5513 | kfree(calldata); |
| 5514 | } |
| 5515 | |
| 5516 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5517 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5518 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5519 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5520 | }; |
| 5521 | |
| 5522 | /* |
| 5523 | * Issue a global reclaim complete. |
| 5524 | */ |
| 5525 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5526 | { |
| 5527 | struct nfs4_reclaim_complete_data *calldata; |
| 5528 | struct rpc_task *task; |
| 5529 | struct rpc_message msg = { |
| 5530 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5531 | }; |
| 5532 | struct rpc_task_setup task_setup_data = { |
| 5533 | .rpc_client = clp->cl_rpcclient, |
| 5534 | .rpc_message = &msg, |
| 5535 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5536 | .flags = RPC_TASK_ASYNC, |
| 5537 | }; |
| 5538 | int status = -ENOMEM; |
| 5539 | |
| 5540 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5541 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5542 | if (calldata == NULL) |
| 5543 | goto out; |
| 5544 | calldata->clp = clp; |
| 5545 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5546 | |
| 5547 | msg.rpc_argp = &calldata->arg; |
| 5548 | msg.rpc_resp = &calldata->res; |
| 5549 | task_setup_data.callback_data = calldata; |
| 5550 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5551 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5552 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5553 | goto out; |
| 5554 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5555 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5556 | if (status == 0) |
| 5557 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5558 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5559 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5560 | out: |
| 5561 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5562 | return status; |
| 5563 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5564 | |
| 5565 | static void |
| 5566 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5567 | { |
| 5568 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5569 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5570 | |
| 5571 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5572 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5573 | * right now covering the LAYOUTGET we are about to send. |
| 5574 | * However, that is not so catastrophic, and there seems |
| 5575 | * to be no way to prevent it completely. |
| 5576 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5577 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5578 | &lgp->res.seq_res, 0, task)) |
| 5579 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5580 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5581 | NFS_I(lgp->args.inode)->layout, |
| 5582 | lgp->args.ctx->state)) { |
| 5583 | rpc_exit(task, NFS4_OK); |
| 5584 | return; |
| 5585 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5586 | rpc_call_start(task); |
| 5587 | } |
| 5588 | |
| 5589 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5590 | { |
| 5591 | struct nfs4_layoutget *lgp = calldata; |
| 5592 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5593 | |
| 5594 | dprintk("--> %s\n", __func__); |
| 5595 | |
| 5596 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5597 | return; |
| 5598 | |
| 5599 | switch (task->tk_status) { |
| 5600 | case 0: |
| 5601 | break; |
| 5602 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5603 | case -NFS4ERR_RECALLCONFLICT: |
| 5604 | task->tk_status = -NFS4ERR_DELAY; |
| 5605 | /* Fall through */ |
| 5606 | default: |
| 5607 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5608 | rpc_restart_call_prepare(task); |
| 5609 | return; |
| 5610 | } |
| 5611 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5612 | dprintk("<-- %s\n", __func__); |
| 5613 | } |
| 5614 | |
| 5615 | static void nfs4_layoutget_release(void *calldata) |
| 5616 | { |
| 5617 | struct nfs4_layoutget *lgp = calldata; |
| 5618 | |
| 5619 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5620 | put_nfs_open_context(lgp->args.ctx); |
| 5621 | kfree(calldata); |
| 5622 | dprintk("<-- %s\n", __func__); |
| 5623 | } |
| 5624 | |
| 5625 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5626 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5627 | .rpc_call_done = nfs4_layoutget_done, |
| 5628 | .rpc_release = nfs4_layoutget_release, |
| 5629 | }; |
| 5630 | |
| 5631 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5632 | { |
| 5633 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5634 | struct rpc_task *task; |
| 5635 | struct rpc_message msg = { |
| 5636 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5637 | .rpc_argp = &lgp->args, |
| 5638 | .rpc_resp = &lgp->res, |
| 5639 | }; |
| 5640 | struct rpc_task_setup task_setup_data = { |
| 5641 | .rpc_client = server->client, |
| 5642 | .rpc_message = &msg, |
| 5643 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5644 | .callback_data = lgp, |
| 5645 | .flags = RPC_TASK_ASYNC, |
| 5646 | }; |
| 5647 | int status = 0; |
| 5648 | |
| 5649 | dprintk("--> %s\n", __func__); |
| 5650 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5651 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5652 | lgp->res.seq_res.sr_slot = NULL; |
| 5653 | task = rpc_run_task(&task_setup_data); |
| 5654 | if (IS_ERR(task)) |
| 5655 | return PTR_ERR(task); |
| 5656 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5657 | if (status == 0) |
| 5658 | status = task->tk_status; |
| 5659 | if (status == 0) |
| 5660 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5661 | rpc_put_task(task); |
| 5662 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5663 | return status; |
| 5664 | } |
| 5665 | |
| 5666 | static int |
| 5667 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5668 | { |
| 5669 | struct nfs4_getdeviceinfo_args args = { |
| 5670 | .pdev = pdev, |
| 5671 | }; |
| 5672 | struct nfs4_getdeviceinfo_res res = { |
| 5673 | .pdev = pdev, |
| 5674 | }; |
| 5675 | struct rpc_message msg = { |
| 5676 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5677 | .rpc_argp = &args, |
| 5678 | .rpc_resp = &res, |
| 5679 | }; |
| 5680 | int status; |
| 5681 | |
| 5682 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5683 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5684 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5685 | |
| 5686 | return status; |
| 5687 | } |
| 5688 | |
| 5689 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5690 | { |
| 5691 | struct nfs4_exception exception = { }; |
| 5692 | int err; |
| 5693 | |
| 5694 | do { |
| 5695 | err = nfs4_handle_exception(server, |
| 5696 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5697 | &exception); |
| 5698 | } while (exception.retry); |
| 5699 | return err; |
| 5700 | } |
| 5701 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5702 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5703 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 5704 | { |
| 5705 | struct nfs4_layoutcommit_data *data = calldata; |
| 5706 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5707 | |
| 5708 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
| 5709 | &data->res.seq_res, 1, task)) |
| 5710 | return; |
| 5711 | rpc_call_start(task); |
| 5712 | } |
| 5713 | |
| 5714 | static void |
| 5715 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 5716 | { |
| 5717 | struct nfs4_layoutcommit_data *data = calldata; |
| 5718 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5719 | |
| 5720 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5721 | return; |
| 5722 | |
| 5723 | switch (task->tk_status) { /* Just ignore these failures */ |
| 5724 | case NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 5725 | case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 5726 | case NFS4ERR_BADLAYOUT: /* no layout */ |
| 5727 | case NFS4ERR_GRACE: /* loca_recalim always false */ |
| 5728 | task->tk_status = 0; |
| 5729 | } |
| 5730 | |
| 5731 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5732 | nfs_restart_rpc(task, server->nfs_client); |
| 5733 | return; |
| 5734 | } |
| 5735 | |
| 5736 | if (task->tk_status == 0) |
| 5737 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 5738 | data->res.fattr); |
| 5739 | } |
| 5740 | |
| 5741 | static void nfs4_layoutcommit_release(void *calldata) |
| 5742 | { |
| 5743 | struct nfs4_layoutcommit_data *data = calldata; |
| 5744 | |
| 5745 | /* Matched by references in pnfs_set_layoutcommit */ |
| 5746 | put_lseg(data->lseg); |
| 5747 | put_rpccred(data->cred); |
| 5748 | kfree(data); |
| 5749 | } |
| 5750 | |
| 5751 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 5752 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 5753 | .rpc_call_done = nfs4_layoutcommit_done, |
| 5754 | .rpc_release = nfs4_layoutcommit_release, |
| 5755 | }; |
| 5756 | |
| 5757 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5758 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5759 | { |
| 5760 | struct rpc_message msg = { |
| 5761 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 5762 | .rpc_argp = &data->args, |
| 5763 | .rpc_resp = &data->res, |
| 5764 | .rpc_cred = data->cred, |
| 5765 | }; |
| 5766 | struct rpc_task_setup task_setup_data = { |
| 5767 | .task = &data->task, |
| 5768 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 5769 | .rpc_message = &msg, |
| 5770 | .callback_ops = &nfs4_layoutcommit_ops, |
| 5771 | .callback_data = data, |
| 5772 | .flags = RPC_TASK_ASYNC, |
| 5773 | }; |
| 5774 | struct rpc_task *task; |
| 5775 | int status = 0; |
| 5776 | |
| 5777 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 5778 | "lbw: %llu inode %lu\n", |
| 5779 | data->task.tk_pid, sync, |
| 5780 | data->args.lastbytewritten, |
| 5781 | data->args.inode->i_ino); |
| 5782 | |
| 5783 | task = rpc_run_task(&task_setup_data); |
| 5784 | if (IS_ERR(task)) |
| 5785 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5786 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5787 | goto out; |
| 5788 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5789 | if (status != 0) |
| 5790 | goto out; |
| 5791 | status = task->tk_status; |
| 5792 | out: |
| 5793 | dprintk("%s: status %d\n", __func__, status); |
| 5794 | rpc_put_task(task); |
| 5795 | return status; |
| 5796 | } |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5797 | #endif /* CONFIG_NFS_V4_1 */ |
| 5798 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5799 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5800 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5801 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5802 | .recover_open = nfs4_open_reclaim, |
| 5803 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5804 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5805 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | }; |
| 5807 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5808 | #if defined(CONFIG_NFS_V4_1) |
| 5809 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5810 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5811 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5812 | .recover_open = nfs4_open_reclaim, |
| 5813 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5814 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5815 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5816 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5817 | }; |
| 5818 | #endif /* CONFIG_NFS_V4_1 */ |
| 5819 | |
| 5820 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5821 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5822 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5823 | .recover_open = nfs4_open_expired, |
| 5824 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5825 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5826 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5827 | }; |
| 5828 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5829 | #if defined(CONFIG_NFS_V4_1) |
| 5830 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5831 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5832 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5833 | .recover_open = nfs4_open_expired, |
| 5834 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5835 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5836 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5837 | }; |
| 5838 | #endif /* CONFIG_NFS_V4_1 */ |
| 5839 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5840 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5841 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5842 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5843 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5844 | }; |
| 5845 | |
| 5846 | #if defined(CONFIG_NFS_V4_1) |
| 5847 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5848 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5849 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5850 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5851 | }; |
| 5852 | #endif |
| 5853 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5854 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 5855 | .minor_version = 0, |
| 5856 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5857 | .validate_stateid = nfs4_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5858 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 5859 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 5860 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5861 | }; |
| 5862 | |
| 5863 | #if defined(CONFIG_NFS_V4_1) |
| 5864 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 5865 | .minor_version = 1, |
| 5866 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5867 | .validate_stateid = nfs41_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5868 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 5869 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 5870 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5871 | }; |
| 5872 | #endif |
| 5873 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5874 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 5875 | [0] = &nfs_v4_0_minor_ops, |
| 5876 | #if defined(CONFIG_NFS_V4_1) |
| 5877 | [1] = &nfs_v4_1_minor_ops, |
| 5878 | #endif |
| 5879 | }; |
| 5880 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5881 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5882 | .permission = nfs_permission, |
| 5883 | .getattr = nfs_getattr, |
| 5884 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5885 | .getxattr = generic_getxattr, |
| 5886 | .setxattr = generic_setxattr, |
| 5887 | .listxattr = generic_listxattr, |
| 5888 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5889 | }; |
| 5890 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5891 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5892 | .version = 4, /* protocol version */ |
| 5893 | .dentry_ops = &nfs4_dentry_operations, |
| 5894 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5895 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5896 | .getroot = nfs4_proc_get_root, |
| 5897 | .getattr = nfs4_proc_getattr, |
| 5898 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5899 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5900 | .lookup = nfs4_proc_lookup, |
| 5901 | .access = nfs4_proc_access, |
| 5902 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5903 | .create = nfs4_proc_create, |
| 5904 | .remove = nfs4_proc_remove, |
| 5905 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5906 | .unlink_done = nfs4_proc_unlink_done, |
| 5907 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 5908 | .rename_setup = nfs4_proc_rename_setup, |
| 5909 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5910 | .link = nfs4_proc_link, |
| 5911 | .symlink = nfs4_proc_symlink, |
| 5912 | .mkdir = nfs4_proc_mkdir, |
| 5913 | .rmdir = nfs4_proc_remove, |
| 5914 | .readdir = nfs4_proc_readdir, |
| 5915 | .mknod = nfs4_proc_mknod, |
| 5916 | .statfs = nfs4_proc_statfs, |
| 5917 | .fsinfo = nfs4_proc_fsinfo, |
| 5918 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5919 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5920 | .decode_dirent = nfs4_decode_dirent, |
| 5921 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5922 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5923 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5924 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5925 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5926 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5927 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5928 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5929 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 5930 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 5931 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5932 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5933 | }; |
| 5934 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5935 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 5936 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 5937 | .list = nfs4_xattr_list_nfs4_acl, |
| 5938 | .get = nfs4_xattr_get_nfs4_acl, |
| 5939 | .set = nfs4_xattr_set_nfs4_acl, |
| 5940 | }; |
| 5941 | |
| 5942 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 5943 | &nfs4_xattr_nfs4_acl_handler, |
| 5944 | NULL |
| 5945 | }; |
| 5946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5947 | /* |
| 5948 | * Local variables: |
| 5949 | * c-basic-offset: 8 |
| 5950 | * End: |
| 5951 | */ |