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> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 49 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 51 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 52 | #include <linux/module.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 53 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 54 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 55 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 57 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 59 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 60 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 61 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 62 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 65 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 66 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 68 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 69 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 70 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 71 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 72 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 73 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | 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] | 75 | 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] | 76 | static int _nfs4_proc_lookup(struct rpc_clnt *client, struct inode *dir, |
| 77 | const struct qstr *name, struct nfs_fh *fhandle, |
| 78 | struct nfs_fattr *fattr); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 79 | 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] | 80 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 81 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 82 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 83 | #ifdef CONFIG_NFS_V4_1 |
| 84 | static int nfs41_test_stateid(struct nfs_server *, struct nfs4_state *); |
| 85 | static int nfs41_free_stateid(struct nfs_server *, struct nfs4_state *); |
| 86 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 88 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 90 | if (err >= -1000) |
| 91 | return err; |
| 92 | switch (err) { |
| 93 | case -NFS4ERR_RESOURCE: |
| 94 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 95 | case -NFS4ERR_WRONGSEC: |
| 96 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 97 | case -NFS4ERR_BADOWNER: |
| 98 | case -NFS4ERR_BADNAME: |
| 99 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 100 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 102 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 103 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 105 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* |
| 109 | * This is our standard bitmap for GETATTR requests. |
| 110 | */ |
| 111 | const u32 nfs4_fattr_bitmap[2] = { |
| 112 | FATTR4_WORD0_TYPE |
| 113 | | FATTR4_WORD0_CHANGE |
| 114 | | FATTR4_WORD0_SIZE |
| 115 | | FATTR4_WORD0_FSID |
| 116 | | FATTR4_WORD0_FILEID, |
| 117 | FATTR4_WORD1_MODE |
| 118 | | FATTR4_WORD1_NUMLINKS |
| 119 | | FATTR4_WORD1_OWNER |
| 120 | | FATTR4_WORD1_OWNER_GROUP |
| 121 | | FATTR4_WORD1_RAWDEV |
| 122 | | FATTR4_WORD1_SPACE_USED |
| 123 | | FATTR4_WORD1_TIME_ACCESS |
| 124 | | FATTR4_WORD1_TIME_METADATA |
| 125 | | FATTR4_WORD1_TIME_MODIFY |
| 126 | }; |
| 127 | |
| 128 | const u32 nfs4_statfs_bitmap[2] = { |
| 129 | FATTR4_WORD0_FILES_AVAIL |
| 130 | | FATTR4_WORD0_FILES_FREE |
| 131 | | FATTR4_WORD0_FILES_TOTAL, |
| 132 | FATTR4_WORD1_SPACE_AVAIL |
| 133 | | FATTR4_WORD1_SPACE_FREE |
| 134 | | FATTR4_WORD1_SPACE_TOTAL |
| 135 | }; |
| 136 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 137 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | FATTR4_WORD0_MAXLINK |
| 139 | | FATTR4_WORD0_MAXNAME, |
| 140 | 0 |
| 141 | }; |
| 142 | |
| 143 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 144 | | FATTR4_WORD0_MAXREAD |
| 145 | | FATTR4_WORD0_MAXWRITE |
| 146 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 147 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 148 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 151 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 152 | FATTR4_WORD0_TYPE |
| 153 | | FATTR4_WORD0_CHANGE |
| 154 | | FATTR4_WORD0_SIZE |
| 155 | | FATTR4_WORD0_FSID |
| 156 | | FATTR4_WORD0_FILEID |
| 157 | | FATTR4_WORD0_FS_LOCATIONS, |
| 158 | FATTR4_WORD1_MODE |
| 159 | | FATTR4_WORD1_NUMLINKS |
| 160 | | FATTR4_WORD1_OWNER |
| 161 | | FATTR4_WORD1_OWNER_GROUP |
| 162 | | FATTR4_WORD1_RAWDEV |
| 163 | | FATTR4_WORD1_SPACE_USED |
| 164 | | FATTR4_WORD1_TIME_ACCESS |
| 165 | | FATTR4_WORD1_TIME_METADATA |
| 166 | | FATTR4_WORD1_TIME_MODIFY |
| 167 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 168 | }; |
| 169 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 170 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | struct nfs4_readdir_arg *readdir) |
| 172 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 173 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | BUG_ON(readdir->count < 80); |
| 176 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 177 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | readdir->cookie = 0; |
| 183 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 184 | if (cookie == 2) |
| 185 | return; |
| 186 | |
| 187 | /* |
| 188 | * NFSv4 servers do not return entries for '.' and '..' |
| 189 | * Therefore, we fake these entries here. We let '.' |
| 190 | * have cookie 0 and '..' have cookie 1. Note that |
| 191 | * when talking to the server, we always send cookie 0 |
| 192 | * instead of 1 or 2. |
| 193 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 194 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | if (cookie == 0) { |
| 197 | *p++ = xdr_one; /* next */ |
| 198 | *p++ = xdr_zero; /* cookie, first word */ |
| 199 | *p++ = xdr_one; /* cookie, second word */ |
| 200 | *p++ = xdr_one; /* entry len */ |
| 201 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 202 | p++; |
| 203 | *p++ = xdr_one; /* bitmap length */ |
| 204 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 205 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 206 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | *p++ = xdr_one; /* next */ |
| 210 | *p++ = xdr_zero; /* cookie, first word */ |
| 211 | *p++ = xdr_two; /* cookie, second word */ |
| 212 | *p++ = xdr_two; /* entry len */ |
| 213 | memcpy(p, "..\0\0", 4); /* entry */ |
| 214 | p++; |
| 215 | *p++ = xdr_one; /* bitmap length */ |
| 216 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 217 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 218 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | readdir->pgbase = (char *)p - (char *)start; |
| 221 | readdir->count -= readdir->pgbase; |
| 222 | kunmap_atomic(start, KM_USER0); |
| 223 | } |
| 224 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 225 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 226 | { |
| 227 | int res; |
| 228 | |
| 229 | might_sleep(); |
| 230 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 231 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 232 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 233 | return res; |
| 234 | } |
| 235 | |
| 236 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 237 | { |
| 238 | int res = 0; |
| 239 | |
| 240 | might_sleep(); |
| 241 | |
| 242 | if (*timeout <= 0) |
| 243 | *timeout = NFS4_POLL_RETRY_MIN; |
| 244 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 245 | *timeout = NFS4_POLL_RETRY_MAX; |
| 246 | schedule_timeout_killable(*timeout); |
| 247 | if (fatal_signal_pending(current)) |
| 248 | res = -ERESTARTSYS; |
| 249 | *timeout <<= 1; |
| 250 | return res; |
| 251 | } |
| 252 | |
| 253 | /* This is the error handling routine for processes that are allowed |
| 254 | * to sleep. |
| 255 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 256 | 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] | 257 | { |
| 258 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 259 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 260 | int ret = errorcode; |
| 261 | |
| 262 | exception->retry = 0; |
| 263 | switch(errorcode) { |
| 264 | case 0: |
| 265 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 266 | case -NFS4ERR_ADMIN_REVOKED: |
| 267 | case -NFS4ERR_BAD_STATEID: |
| 268 | case -NFS4ERR_OPENMODE: |
| 269 | if (state == NULL) |
| 270 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 271 | nfs4_schedule_stateid_recovery(server, state); |
| 272 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 273 | case -NFS4ERR_EXPIRED: |
| 274 | if (state != NULL) |
| 275 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 276 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 277 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 278 | nfs4_schedule_lease_recovery(clp); |
| 279 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 280 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 281 | case -NFS4ERR_BADSESSION: |
| 282 | case -NFS4ERR_BADSLOT: |
| 283 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 284 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 285 | case -NFS4ERR_DEADSESSION: |
| 286 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 287 | case -NFS4ERR_SEQ_MISORDERED: |
| 288 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 289 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 290 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 291 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 292 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 293 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 294 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 295 | if (exception->timeout > HZ) { |
| 296 | /* We have retried a decent amount, time to |
| 297 | * fail |
| 298 | */ |
| 299 | ret = -EBUSY; |
| 300 | break; |
| 301 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 302 | case -NFS4ERR_GRACE: |
| 303 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 304 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 305 | ret = nfs4_delay(server->client, &exception->timeout); |
| 306 | if (ret != 0) |
| 307 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 308 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 309 | case -NFS4ERR_OLD_STATEID: |
| 310 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 311 | break; |
| 312 | case -NFS4ERR_BADOWNER: |
| 313 | /* The following works around a Linux server bug! */ |
| 314 | case -NFS4ERR_BADNAME: |
| 315 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 316 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 317 | exception->retry = 1; |
| 318 | printk(KERN_WARNING "NFS: v4 server %s " |
| 319 | "does not accept raw " |
| 320 | "uid/gids. " |
| 321 | "Reenabling the idmapper.\n", |
| 322 | server->nfs_client->cl_hostname); |
| 323 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 324 | } |
| 325 | /* We failed to handle the error */ |
| 326 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 327 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 328 | ret = nfs4_wait_clnt_recover(clp); |
| 329 | if (ret == 0) |
| 330 | exception->retry = 1; |
| 331 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 335 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | spin_lock(&clp->cl_lock); |
| 338 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 339 | clp->cl_last_renewal = timestamp; |
| 340 | spin_unlock(&clp->cl_lock); |
| 341 | } |
| 342 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 343 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 344 | { |
| 345 | do_renew_lease(server->nfs_client, timestamp); |
| 346 | } |
| 347 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 348 | #if defined(CONFIG_NFS_V4_1) |
| 349 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 350 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 351 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 352 | * |
| 353 | * freeing a slot is trivially done by clearing its respective bit |
| 354 | * in the bitmap. |
| 355 | * If the freed slotid equals highest_used_slotid we want to update it |
| 356 | * so that the server would be able to size down the slot table if needed, |
| 357 | * otherwise we know that the highest_used_slotid is still in use. |
| 358 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 359 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 360 | * highest slotid in use. |
| 361 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 362 | * |
| 363 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 364 | */ |
| 365 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 366 | 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] | 367 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 368 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 369 | int slotid = free_slotid; |
| 370 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 371 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 372 | /* clear used bit in bitmap */ |
| 373 | __clear_bit(slotid, tbl->used_slots); |
| 374 | |
| 375 | /* update highest_used_slotid when it is freed */ |
| 376 | if (slotid == tbl->highest_used_slotid) { |
| 377 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 378 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 379 | tbl->highest_used_slotid = slotid; |
| 380 | else |
| 381 | tbl->highest_used_slotid = -1; |
| 382 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 383 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 384 | free_slotid, tbl->highest_used_slotid); |
| 385 | } |
| 386 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 387 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 388 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 389 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 390 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 391 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 392 | struct rpc_task *task; |
| 393 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 394 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 395 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 396 | if (task) |
| 397 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 398 | return; |
| 399 | } |
| 400 | |
| 401 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 402 | return; |
| 403 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 404 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 405 | complete(&ses->fc_slot_table.complete); |
| 406 | } |
| 407 | |
| 408 | /* |
| 409 | * Signal state manager thread if session back channel is drained |
| 410 | */ |
| 411 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 412 | { |
| 413 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 414 | ses->bc_slot_table.highest_used_slotid != -1) |
| 415 | return; |
| 416 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 417 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 420 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 421 | { |
| 422 | struct nfs4_slot_table *tbl; |
| 423 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 424 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 425 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 426 | /* just wake up the next guy waiting since |
| 427 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 428 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 429 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 430 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 431 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 432 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 433 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 434 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 435 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 436 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 437 | } |
| 438 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 439 | 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] | 440 | { |
| 441 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 442 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 443 | |
| 444 | /* |
| 445 | * sr_status remains 1 if an RPC level error occurred. The server |
| 446 | * may or may not have processed the sequence operation.. |
| 447 | * Proceed as if the server received and processed the sequence |
| 448 | * operation. |
| 449 | */ |
| 450 | if (res->sr_status == 1) |
| 451 | res->sr_status = NFS_OK; |
| 452 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 453 | /* don't increment the sequence number if the task wasn't sent */ |
| 454 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 455 | goto out; |
| 456 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 457 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 458 | switch (res->sr_status) { |
| 459 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 460 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 461 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 462 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 463 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 464 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 465 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 466 | if (res->sr_status_flags != 0) |
| 467 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 468 | break; |
| 469 | case -NFS4ERR_DELAY: |
| 470 | /* The server detected a resend of the RPC call and |
| 471 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 472 | * of RFC5661. |
| 473 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 474 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 475 | __func__, |
| 476 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 477 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 478 | goto out_retry; |
| 479 | default: |
| 480 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 481 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 482 | } |
| 483 | out: |
| 484 | /* The session may be reset by one of the error handlers. */ |
| 485 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 486 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 487 | return 1; |
| 488 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 489 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 490 | goto out; |
| 491 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 492 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 493 | } |
| 494 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 495 | static int nfs4_sequence_done(struct rpc_task *task, |
| 496 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 497 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 498 | if (res->sr_session == NULL) |
| 499 | return 1; |
| 500 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 501 | } |
| 502 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 503 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 504 | * nfs4_find_slot - efficiently look for a free slot |
| 505 | * |
| 506 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 507 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 508 | * and respectively set up the sequence operation args. |
| 509 | * 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] | 510 | * |
| 511 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 512 | */ |
| 513 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 514 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 515 | { |
| 516 | int slotid; |
| 517 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 518 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 519 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 520 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 521 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 522 | tbl->max_slots); |
| 523 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 524 | if (slotid >= tbl->max_slots) |
| 525 | goto out; |
| 526 | __set_bit(slotid, tbl->used_slots); |
| 527 | if (slotid > tbl->highest_used_slotid) |
| 528 | tbl->highest_used_slotid = slotid; |
| 529 | ret_id = slotid; |
| 530 | out: |
| 531 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 532 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 533 | return ret_id; |
| 534 | } |
| 535 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 536 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 537 | struct nfs4_sequence_args *args, |
| 538 | struct nfs4_sequence_res *res, |
| 539 | int cache_reply, |
| 540 | struct rpc_task *task) |
| 541 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 542 | struct nfs4_slot *slot; |
| 543 | struct nfs4_slot_table *tbl; |
| 544 | u8 slotid; |
| 545 | |
| 546 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 547 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 548 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 549 | return 0; |
| 550 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 551 | tbl = &session->fc_slot_table; |
| 552 | |
| 553 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 554 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 555 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 556 | /* |
| 557 | * The state manager will wait until the slot table is empty. |
| 558 | * Schedule the reset thread |
| 559 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 560 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 561 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 562 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 563 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 564 | } |
| 565 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 566 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 567 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 568 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 569 | spin_unlock(&tbl->slot_tbl_lock); |
| 570 | dprintk("%s enforce FIFO order\n", __func__); |
| 571 | return -EAGAIN; |
| 572 | } |
| 573 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 574 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 575 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 576 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 577 | spin_unlock(&tbl->slot_tbl_lock); |
| 578 | dprintk("<-- %s: no free slots\n", __func__); |
| 579 | return -EAGAIN; |
| 580 | } |
| 581 | spin_unlock(&tbl->slot_tbl_lock); |
| 582 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 583 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 584 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 585 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 586 | args->sa_slotid = slotid; |
| 587 | args->sa_cache_this = cache_reply; |
| 588 | |
| 589 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 590 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 591 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 592 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 593 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 594 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 595 | /* |
| 596 | * sr_status is only set in decode_sequence, and so will remain |
| 597 | * set to 1 if an rpc level failure occurs. |
| 598 | */ |
| 599 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 600 | return 0; |
| 601 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 602 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 603 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 604 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 605 | struct nfs4_sequence_args *args, |
| 606 | struct nfs4_sequence_res *res, |
| 607 | int cache_reply, |
| 608 | struct rpc_task *task) |
| 609 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 610 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 611 | int ret = 0; |
| 612 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 613 | if (session == NULL) { |
| 614 | args->sa_session = NULL; |
| 615 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 616 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 617 | } |
| 618 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 619 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 620 | __func__, session->clp, session, res->sr_slot ? |
| 621 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 622 | |
| 623 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 624 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 625 | out: |
| 626 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 627 | return ret; |
| 628 | } |
| 629 | |
| 630 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 631 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 632 | struct nfs4_sequence_args *seq_args; |
| 633 | struct nfs4_sequence_res *seq_res; |
| 634 | int cache_reply; |
| 635 | }; |
| 636 | |
| 637 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 638 | { |
| 639 | struct nfs41_call_sync_data *data = calldata; |
| 640 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 641 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 642 | |
| 643 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 644 | data->seq_res, data->cache_reply, task)) |
| 645 | return; |
| 646 | rpc_call_start(task); |
| 647 | } |
| 648 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 649 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 650 | { |
| 651 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 652 | nfs41_call_sync_prepare(task, calldata); |
| 653 | } |
| 654 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 655 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 656 | { |
| 657 | struct nfs41_call_sync_data *data = calldata; |
| 658 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 659 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 660 | } |
| 661 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 662 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 663 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 664 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 665 | }; |
| 666 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 667 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 668 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 669 | .rpc_call_done = nfs41_call_sync_done, |
| 670 | }; |
| 671 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 672 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 673 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 674 | struct rpc_message *msg, |
| 675 | struct nfs4_sequence_args *args, |
| 676 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 677 | int cache_reply, |
| 678 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 679 | { |
| 680 | int ret; |
| 681 | struct rpc_task *task; |
| 682 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 683 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 684 | .seq_args = args, |
| 685 | .seq_res = res, |
| 686 | .cache_reply = cache_reply, |
| 687 | }; |
| 688 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 689 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 690 | .rpc_message = msg, |
| 691 | .callback_ops = &nfs41_call_sync_ops, |
| 692 | .callback_data = &data |
| 693 | }; |
| 694 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 695 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 696 | if (privileged) |
| 697 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 698 | task = rpc_run_task(&task_setup); |
| 699 | if (IS_ERR(task)) |
| 700 | ret = PTR_ERR(task); |
| 701 | else { |
| 702 | ret = task->tk_status; |
| 703 | rpc_put_task(task); |
| 704 | } |
| 705 | return ret; |
| 706 | } |
| 707 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 708 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 709 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 710 | struct rpc_message *msg, |
| 711 | struct nfs4_sequence_args *args, |
| 712 | struct nfs4_sequence_res *res, |
| 713 | int cache_reply) |
| 714 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 715 | 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] | 716 | } |
| 717 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 718 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 719 | static int nfs4_sequence_done(struct rpc_task *task, |
| 720 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 721 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 722 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 723 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 724 | #endif /* CONFIG_NFS_V4_1 */ |
| 725 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 726 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 727 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 728 | struct rpc_message *msg, |
| 729 | struct nfs4_sequence_args *args, |
| 730 | struct nfs4_sequence_res *res, |
| 731 | int cache_reply) |
| 732 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 733 | args->sa_session = res->sr_session = NULL; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 734 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 735 | } |
| 736 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 737 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 738 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 739 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 740 | struct rpc_message *msg, |
| 741 | struct nfs4_sequence_args *args, |
| 742 | struct nfs4_sequence_res *res, |
| 743 | int cache_reply) |
| 744 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 745 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 746 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 747 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 748 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 749 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 751 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 753 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 754 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 755 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 756 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 757 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 758 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 761 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 762 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 763 | struct nfs_openargs o_arg; |
| 764 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 765 | struct nfs_open_confirmargs c_arg; |
| 766 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 767 | struct nfs_fattr f_attr; |
| 768 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 769 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 770 | struct dentry *dir; |
| 771 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 772 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 773 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 774 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 775 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 776 | int rpc_status; |
| 777 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 778 | }; |
| 779 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 780 | |
| 781 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 782 | { |
| 783 | p->o_res.f_attr = &p->f_attr; |
| 784 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 785 | p->o_res.seqid = p->o_arg.seqid; |
| 786 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 787 | p->o_res.server = p->o_arg.server; |
| 788 | nfs_fattr_init(&p->f_attr); |
| 789 | nfs_fattr_init(&p->dir_attr); |
| 790 | } |
| 791 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 792 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 793 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 794 | const struct iattr *attrs, |
| 795 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 796 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 797 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 798 | struct inode *dir = parent->d_inode; |
| 799 | struct nfs_server *server = NFS_SERVER(dir); |
| 800 | struct nfs4_opendata *p; |
| 801 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 802 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 803 | if (p == NULL) |
| 804 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 805 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 806 | if (p->o_arg.seqid == NULL) |
| 807 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 808 | path_get(path); |
| 809 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 810 | p->dir = parent; |
| 811 | p->owner = sp; |
| 812 | atomic_inc(&sp->so_count); |
| 813 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 814 | p->o_arg.open_flags = flags; |
| 815 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 816 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 817 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 818 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 819 | p->o_arg.server = server; |
| 820 | p->o_arg.bitmask = server->attr_bitmask; |
| 821 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 822 | if (flags & O_CREAT) { |
| 823 | u32 *s; |
| 824 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 825 | p->o_arg.u.attrs = &p->attrs; |
| 826 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 827 | s = (u32 *) p->o_arg.u.verifier.data; |
| 828 | s[0] = jiffies; |
| 829 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 830 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 831 | p->c_arg.fh = &p->o_res.fh; |
| 832 | p->c_arg.stateid = &p->o_res.stateid; |
| 833 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 834 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 835 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 836 | return p; |
| 837 | err_free: |
| 838 | kfree(p); |
| 839 | err: |
| 840 | dput(parent); |
| 841 | return NULL; |
| 842 | } |
| 843 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 844 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 845 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 846 | struct nfs4_opendata *p = container_of(kref, |
| 847 | struct nfs4_opendata, kref); |
| 848 | |
| 849 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 850 | if (p->state != NULL) |
| 851 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 852 | nfs4_put_state_owner(p->owner); |
| 853 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 854 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 855 | kfree(p); |
| 856 | } |
| 857 | |
| 858 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 859 | { |
| 860 | if (p != NULL) |
| 861 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 862 | } |
| 863 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 864 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 865 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 866 | int ret; |
| 867 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 868 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 869 | return ret; |
| 870 | } |
| 871 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 872 | 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] | 873 | { |
| 874 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 875 | |
| 876 | if (open_mode & O_EXCL) |
| 877 | goto out; |
| 878 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 879 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 880 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 881 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 882 | break; |
| 883 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 884 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 885 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 886 | break; |
| 887 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 888 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 889 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 890 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 891 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 892 | return ret; |
| 893 | } |
| 894 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 895 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 896 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 897 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 898 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 899 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 900 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 901 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 902 | return 1; |
| 903 | } |
| 904 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 905 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 906 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 907 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 908 | case FMODE_WRITE: |
| 909 | state->n_wronly++; |
| 910 | break; |
| 911 | case FMODE_READ: |
| 912 | state->n_rdonly++; |
| 913 | break; |
| 914 | case FMODE_READ|FMODE_WRITE: |
| 915 | state->n_rdwr++; |
| 916 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 917 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | 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] | 921 | { |
| 922 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 923 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 924 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 925 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 926 | case FMODE_READ: |
| 927 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 928 | break; |
| 929 | case FMODE_WRITE: |
| 930 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 931 | break; |
| 932 | case FMODE_READ|FMODE_WRITE: |
| 933 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 934 | } |
| 935 | } |
| 936 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 937 | 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] | 938 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 939 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 940 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 941 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 942 | } |
| 943 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 944 | 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] | 945 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 946 | /* |
| 947 | * Protect the call to nfs4_state_set_mode_locked and |
| 948 | * serialise the stateid update |
| 949 | */ |
| 950 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 951 | if (deleg_stateid != NULL) { |
| 952 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 953 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 954 | } |
| 955 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 956 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 957 | write_sequnlock(&state->seqlock); |
| 958 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 959 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 960 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | 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] | 964 | { |
| 965 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 966 | struct nfs_delegation *deleg_cur; |
| 967 | int ret = 0; |
| 968 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 969 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 970 | |
| 971 | rcu_read_lock(); |
| 972 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 973 | if (deleg_cur == NULL) |
| 974 | goto no_delegation; |
| 975 | |
| 976 | spin_lock(&deleg_cur->lock); |
| 977 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 978 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 979 | goto no_delegation_unlock; |
| 980 | |
| 981 | if (delegation == NULL) |
| 982 | delegation = &deleg_cur->stateid; |
| 983 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 984 | goto no_delegation_unlock; |
| 985 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 986 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 987 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 988 | ret = 1; |
| 989 | no_delegation_unlock: |
| 990 | spin_unlock(&deleg_cur->lock); |
| 991 | no_delegation: |
| 992 | rcu_read_unlock(); |
| 993 | |
| 994 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 995 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 996 | ret = 1; |
| 997 | } |
| 998 | |
| 999 | return ret; |
| 1000 | } |
| 1001 | |
| 1002 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1003 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1004 | { |
| 1005 | struct nfs_delegation *delegation; |
| 1006 | |
| 1007 | rcu_read_lock(); |
| 1008 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1009 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1010 | rcu_read_unlock(); |
| 1011 | return; |
| 1012 | } |
| 1013 | rcu_read_unlock(); |
| 1014 | nfs_inode_return_delegation(inode); |
| 1015 | } |
| 1016 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1017 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1018 | { |
| 1019 | struct nfs4_state *state = opendata->state; |
| 1020 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1021 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1022 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 1023 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1024 | nfs4_stateid stateid; |
| 1025 | int ret = -EAGAIN; |
| 1026 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1027 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1028 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1029 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1030 | if (can_open_cached(state, fmode, open_mode)) { |
| 1031 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1032 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1033 | goto out_return_state; |
| 1034 | } |
| 1035 | spin_unlock(&state->owner->so_lock); |
| 1036 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1037 | rcu_read_lock(); |
| 1038 | delegation = rcu_dereference(nfsi->delegation); |
| 1039 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1040 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1041 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1042 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1043 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1044 | /* Save the delegation */ |
| 1045 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1046 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1047 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1048 | if (ret != 0) |
| 1049 | goto out; |
| 1050 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1051 | |
| 1052 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1053 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1054 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1055 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1056 | out: |
| 1057 | return ERR_PTR(ret); |
| 1058 | out_return_state: |
| 1059 | atomic_inc(&state->count); |
| 1060 | return state; |
| 1061 | } |
| 1062 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1063 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1064 | { |
| 1065 | struct inode *inode; |
| 1066 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1067 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1068 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1069 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1070 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1071 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1072 | goto out; |
| 1073 | } |
| 1074 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1075 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1076 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1077 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1078 | 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] | 1079 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1080 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1081 | goto err; |
| 1082 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1083 | state = nfs4_get_open_state(inode, data->owner); |
| 1084 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1085 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1086 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1087 | int delegation_flags = 0; |
| 1088 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1089 | rcu_read_lock(); |
| 1090 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1091 | if (delegation) |
| 1092 | delegation_flags = delegation->flags; |
| 1093 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1094 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1095 | nfs_inode_set_delegation(state->inode, |
| 1096 | data->owner->so_cred, |
| 1097 | &data->o_res); |
| 1098 | else |
| 1099 | nfs_inode_reclaim_delegation(state->inode, |
| 1100 | data->owner->so_cred, |
| 1101 | &data->o_res); |
| 1102 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1103 | |
| 1104 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1105 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1106 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1107 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1108 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1109 | err_put_inode: |
| 1110 | iput(inode); |
| 1111 | err: |
| 1112 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1115 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1116 | { |
| 1117 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1118 | struct nfs_open_context *ctx; |
| 1119 | |
| 1120 | spin_lock(&state->inode->i_lock); |
| 1121 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1122 | if (ctx->state != state) |
| 1123 | continue; |
| 1124 | get_nfs_open_context(ctx); |
| 1125 | spin_unlock(&state->inode->i_lock); |
| 1126 | return ctx; |
| 1127 | } |
| 1128 | spin_unlock(&state->inode->i_lock); |
| 1129 | return ERR_PTR(-ENOENT); |
| 1130 | } |
| 1131 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1132 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1133 | { |
| 1134 | struct nfs4_opendata *opendata; |
| 1135 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1136 | 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] | 1137 | if (opendata == NULL) |
| 1138 | return ERR_PTR(-ENOMEM); |
| 1139 | opendata->state = state; |
| 1140 | atomic_inc(&state->count); |
| 1141 | return opendata; |
| 1142 | } |
| 1143 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1144 | 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] | 1145 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1146 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1147 | int ret; |
| 1148 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1149 | opendata->o_arg.open_flags = 0; |
| 1150 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1151 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1152 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1153 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1154 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1155 | if (ret != 0) |
| 1156 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1157 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1158 | if (IS_ERR(newstate)) |
| 1159 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1160 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1161 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1162 | return 0; |
| 1163 | } |
| 1164 | |
| 1165 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1166 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1167 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1168 | int ret; |
| 1169 | |
| 1170 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1171 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1172 | smp_rmb(); |
| 1173 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1174 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1175 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1176 | if (ret != 0) |
| 1177 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1178 | if (newstate != state) |
| 1179 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1180 | } |
| 1181 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1182 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1183 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1184 | if (ret != 0) |
| 1185 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1186 | if (newstate != state) |
| 1187 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1188 | } |
| 1189 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1190 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1191 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1192 | if (ret != 0) |
| 1193 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1194 | if (newstate != state) |
| 1195 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1196 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1197 | /* |
| 1198 | * We may have performed cached opens for all three recoveries. |
| 1199 | * Check if we need to update the current stateid. |
| 1200 | */ |
| 1201 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1202 | 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] | 1203 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1204 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1205 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1206 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1207 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1208 | return 0; |
| 1209 | } |
| 1210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | /* |
| 1212 | * OPEN_RECLAIM: |
| 1213 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1215 | 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] | 1216 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1217 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1218 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1219 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | int status; |
| 1221 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1222 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1223 | if (IS_ERR(opendata)) |
| 1224 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1225 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1226 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1227 | rcu_read_lock(); |
| 1228 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1229 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1230 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1231 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1232 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1233 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1234 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | return status; |
| 1236 | } |
| 1237 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1238 | 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] | 1239 | { |
| 1240 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1241 | struct nfs4_exception exception = { }; |
| 1242 | int err; |
| 1243 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1244 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1245 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1246 | break; |
| 1247 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | } while (exception.retry); |
| 1249 | return err; |
| 1250 | } |
| 1251 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1252 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1253 | { |
| 1254 | struct nfs_open_context *ctx; |
| 1255 | int ret; |
| 1256 | |
| 1257 | ctx = nfs4_state_find_open_context(state); |
| 1258 | if (IS_ERR(ctx)) |
| 1259 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1260 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1261 | put_nfs_open_context(ctx); |
| 1262 | return ret; |
| 1263 | } |
| 1264 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1265 | 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] | 1266 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1267 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1268 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1270 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1271 | if (IS_ERR(opendata)) |
| 1272 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1273 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1274 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1275 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1276 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1277 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1278 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1281 | 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] | 1282 | { |
| 1283 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1284 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | int err; |
| 1286 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1287 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | switch (err) { |
| 1289 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1290 | case -ENOENT: |
| 1291 | case -ESTALE: |
| 1292 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1293 | case -NFS4ERR_BADSESSION: |
| 1294 | case -NFS4ERR_BADSLOT: |
| 1295 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1296 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1297 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1298 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1299 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | case -NFS4ERR_STALE_CLIENTID: |
| 1301 | case -NFS4ERR_STALE_STATEID: |
| 1302 | case -NFS4ERR_EXPIRED: |
| 1303 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1304 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1305 | goto out; |
| 1306 | case -ERESTARTSYS: |
| 1307 | /* |
| 1308 | * The show must go on: exit, but mark the |
| 1309 | * stateid as needing recovery. |
| 1310 | */ |
| 1311 | case -NFS4ERR_ADMIN_REVOKED: |
| 1312 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1313 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1314 | case -EKEYEXPIRED: |
| 1315 | /* |
| 1316 | * User RPCSEC_GSS context has expired. |
| 1317 | * We cannot recover this stateid now, so |
| 1318 | * skip it and allow recovery thread to |
| 1319 | * proceed. |
| 1320 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1321 | case -ENOMEM: |
| 1322 | err = 0; |
| 1323 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | } |
| 1325 | err = nfs4_handle_exception(server, err, &exception); |
| 1326 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1327 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | return err; |
| 1329 | } |
| 1330 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1331 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1332 | { |
| 1333 | struct nfs4_opendata *data = calldata; |
| 1334 | |
| 1335 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1336 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1337 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1338 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1339 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1340 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1341 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1342 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static void nfs4_open_confirm_release(void *calldata) |
| 1346 | { |
| 1347 | struct nfs4_opendata *data = calldata; |
| 1348 | struct nfs4_state *state = NULL; |
| 1349 | |
| 1350 | /* If this request hasn't been cancelled, do nothing */ |
| 1351 | if (data->cancelled == 0) |
| 1352 | goto out_free; |
| 1353 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1354 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1355 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1356 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1357 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1358 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1359 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1360 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1364 | .rpc_call_done = nfs4_open_confirm_done, |
| 1365 | .rpc_release = nfs4_open_confirm_release, |
| 1366 | }; |
| 1367 | |
| 1368 | /* |
| 1369 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1370 | */ |
| 1371 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1372 | { |
| 1373 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1374 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1375 | struct rpc_message msg = { |
| 1376 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1377 | .rpc_argp = &data->c_arg, |
| 1378 | .rpc_resp = &data->c_res, |
| 1379 | .rpc_cred = data->owner->so_cred, |
| 1380 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1381 | struct rpc_task_setup task_setup_data = { |
| 1382 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1383 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1384 | .callback_ops = &nfs4_open_confirm_ops, |
| 1385 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1386 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1387 | .flags = RPC_TASK_ASYNC, |
| 1388 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | int status; |
| 1390 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1391 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1392 | data->rpc_done = 0; |
| 1393 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1394 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1395 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1396 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1397 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1398 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1399 | if (status != 0) { |
| 1400 | data->cancelled = 1; |
| 1401 | smp_wmb(); |
| 1402 | } else |
| 1403 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1404 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | return status; |
| 1406 | } |
| 1407 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1408 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1410 | struct nfs4_opendata *data = calldata; |
| 1411 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1412 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1413 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1414 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1415 | /* |
| 1416 | * Check if we still need to send an OPEN call, or if we can use |
| 1417 | * a delegation instead. |
| 1418 | */ |
| 1419 | if (data->state != NULL) { |
| 1420 | struct nfs_delegation *delegation; |
| 1421 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1422 | 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] | 1423 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1424 | rcu_read_lock(); |
| 1425 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1426 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1427 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1428 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1429 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1430 | } |
| 1431 | rcu_read_unlock(); |
| 1432 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1433 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1434 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1435 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1436 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1437 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1438 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1439 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1440 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1441 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1442 | &data->o_arg.seq_args, |
| 1443 | &data->o_res.seq_res, 1, task)) |
| 1444 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1445 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1446 | return; |
| 1447 | out_no_action: |
| 1448 | task->tk_action = NULL; |
| 1449 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1452 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1453 | { |
| 1454 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1455 | nfs4_open_prepare(task, calldata); |
| 1456 | } |
| 1457 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1458 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1459 | { |
| 1460 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1462 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1463 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1464 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1465 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1466 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1467 | if (task->tk_status == 0) { |
| 1468 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1469 | case S_IFREG: |
| 1470 | break; |
| 1471 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1472 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1473 | break; |
| 1474 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1475 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1476 | break; |
| 1477 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1478 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1479 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1480 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1481 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1482 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1483 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1484 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1485 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1486 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1487 | static void nfs4_open_release(void *calldata) |
| 1488 | { |
| 1489 | struct nfs4_opendata *data = calldata; |
| 1490 | struct nfs4_state *state = NULL; |
| 1491 | |
| 1492 | /* If this request hasn't been cancelled, do nothing */ |
| 1493 | if (data->cancelled == 0) |
| 1494 | goto out_free; |
| 1495 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1496 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1497 | goto out_free; |
| 1498 | /* In case we need an open_confirm, no cleanup! */ |
| 1499 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1500 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1501 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1502 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1503 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1504 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1505 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1509 | .rpc_call_prepare = nfs4_open_prepare, |
| 1510 | .rpc_call_done = nfs4_open_done, |
| 1511 | .rpc_release = nfs4_open_release, |
| 1512 | }; |
| 1513 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1514 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1515 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1516 | .rpc_call_done = nfs4_open_done, |
| 1517 | .rpc_release = nfs4_open_release, |
| 1518 | }; |
| 1519 | |
| 1520 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1521 | { |
| 1522 | struct inode *dir = data->dir->d_inode; |
| 1523 | struct nfs_server *server = NFS_SERVER(dir); |
| 1524 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1525 | struct nfs_openres *o_res = &data->o_res; |
| 1526 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1527 | struct rpc_message msg = { |
| 1528 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1529 | .rpc_argp = o_arg, |
| 1530 | .rpc_resp = o_res, |
| 1531 | .rpc_cred = data->owner->so_cred, |
| 1532 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1533 | struct rpc_task_setup task_setup_data = { |
| 1534 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1535 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1536 | .callback_ops = &nfs4_open_ops, |
| 1537 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1538 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1539 | .flags = RPC_TASK_ASYNC, |
| 1540 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1541 | int status; |
| 1542 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1543 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1544 | data->rpc_done = 0; |
| 1545 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1546 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1547 | if (isrecover) |
| 1548 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1549 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1550 | if (IS_ERR(task)) |
| 1551 | return PTR_ERR(task); |
| 1552 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1553 | if (status != 0) { |
| 1554 | data->cancelled = 1; |
| 1555 | smp_wmb(); |
| 1556 | } else |
| 1557 | status = data->rpc_status; |
| 1558 | rpc_put_task(task); |
| 1559 | |
| 1560 | return status; |
| 1561 | } |
| 1562 | |
| 1563 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1564 | { |
| 1565 | struct inode *dir = data->dir->d_inode; |
| 1566 | struct nfs_openres *o_res = &data->o_res; |
| 1567 | int status; |
| 1568 | |
| 1569 | status = nfs4_run_open_task(data, 1); |
| 1570 | if (status != 0 || !data->rpc_done) |
| 1571 | return status; |
| 1572 | |
| 1573 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1574 | |
| 1575 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1576 | status = _nfs4_proc_open_confirm(data); |
| 1577 | if (status != 0) |
| 1578 | return status; |
| 1579 | } |
| 1580 | |
| 1581 | return status; |
| 1582 | } |
| 1583 | |
| 1584 | /* |
| 1585 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1586 | */ |
| 1587 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1588 | { |
| 1589 | struct inode *dir = data->dir->d_inode; |
| 1590 | struct nfs_server *server = NFS_SERVER(dir); |
| 1591 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1592 | struct nfs_openres *o_res = &data->o_res; |
| 1593 | int status; |
| 1594 | |
| 1595 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1596 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1597 | return status; |
| 1598 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1599 | if (o_arg->open_flags & O_CREAT) { |
| 1600 | update_changeattr(dir, &o_res->cinfo); |
| 1601 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1602 | } else |
| 1603 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1604 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1605 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1607 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1609 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | } |
| 1611 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1612 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1613 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1616 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1617 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1618 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1619 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1620 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1621 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1622 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1623 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1624 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1625 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1626 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1627 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1628 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1629 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1630 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1631 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1632 | } |
| 1633 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1634 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1635 | { |
| 1636 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1637 | } |
| 1638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | /* |
| 1640 | * OPEN_EXPIRED: |
| 1641 | * reclaim state on the server after a network partition. |
| 1642 | * Assumes caller holds the appropriate lock |
| 1643 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1644 | 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] | 1645 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1646 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1647 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1649 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1650 | if (IS_ERR(opendata)) |
| 1651 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1652 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1653 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1654 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1655 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1656 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1659 | 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] | 1660 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1661 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1662 | struct nfs4_exception exception = { }; |
| 1663 | int err; |
| 1664 | |
| 1665 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1666 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1667 | switch (err) { |
| 1668 | default: |
| 1669 | goto out; |
| 1670 | case -NFS4ERR_GRACE: |
| 1671 | case -NFS4ERR_DELAY: |
| 1672 | nfs4_handle_exception(server, err, &exception); |
| 1673 | err = 0; |
| 1674 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1675 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1676 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1677 | return err; |
| 1678 | } |
| 1679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1681 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1683 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1685 | ctx = nfs4_state_find_open_context(state); |
| 1686 | if (IS_ERR(ctx)) |
| 1687 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1688 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1689 | put_nfs_open_context(ctx); |
| 1690 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1693 | #if defined(CONFIG_NFS_V4_1) |
| 1694 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1695 | { |
| 1696 | int status; |
| 1697 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1698 | |
| 1699 | status = nfs41_test_stateid(server, state); |
| 1700 | if (status == NFS_OK) |
| 1701 | return 0; |
| 1702 | nfs41_free_stateid(server, state); |
| 1703 | return nfs4_open_expired(sp, state); |
| 1704 | } |
| 1705 | #endif |
| 1706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1708 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1709 | * fields corresponding to attributes that were used to store the verifier. |
| 1710 | * Make sure we clobber those fields in the later setattr call |
| 1711 | */ |
| 1712 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1713 | { |
| 1714 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1715 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1716 | sattr->ia_valid |= ATTR_ATIME; |
| 1717 | |
| 1718 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1719 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1720 | sattr->ia_valid |= ATTR_MTIME; |
| 1721 | } |
| 1722 | |
| 1723 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1724 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1726 | 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] | 1727 | { |
| 1728 | struct nfs4_state_owner *sp; |
| 1729 | struct nfs4_state *state = NULL; |
| 1730 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1731 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1732 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | |
| 1734 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | status = -ENOMEM; |
| 1736 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1737 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1738 | goto out_err; |
| 1739 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1740 | status = nfs4_recover_expired_lease(server); |
| 1741 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1742 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1743 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1744 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1745 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1746 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1747 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1748 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1750 | if (path->dentry->d_inode != NULL) |
| 1751 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1752 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1753 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1755 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1757 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1758 | status = PTR_ERR(state); |
| 1759 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1760 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1761 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1762 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1763 | |
| 1764 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1765 | nfs4_exclusive_attrset(opendata, sattr); |
| 1766 | |
| 1767 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1768 | status = nfs4_do_setattr(state->inode, cred, |
| 1769 | opendata->o_res.f_attr, sattr, |
| 1770 | state); |
| 1771 | if (status == 0) |
| 1772 | nfs_setattr_update_inode(state->inode, sattr); |
| 1773 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1774 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1775 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | *res = state; |
| 1778 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1779 | err_opendata_put: |
| 1780 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1781 | err_put_state_owner: |
| 1782 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | *res = NULL; |
| 1785 | return status; |
| 1786 | } |
| 1787 | |
| 1788 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1789 | 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] | 1790 | { |
| 1791 | struct nfs4_exception exception = { }; |
| 1792 | struct nfs4_state *res; |
| 1793 | int status; |
| 1794 | |
| 1795 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1796 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | if (status == 0) |
| 1798 | break; |
| 1799 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1800 | * book-keeping w.r.t. state-changing operations |
| 1801 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1802 | * It is actually a sign of a bug on the client or on the server. |
| 1803 | * |
| 1804 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1805 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | * have unhashed the old state_owner for us, and that we can |
| 1807 | * therefore safely retry using a new one. We should still warn |
| 1808 | * the user though... |
| 1809 | */ |
| 1810 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1811 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1812 | " returned a bad sequence-id error!\n", |
| 1813 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | exception.retry = 1; |
| 1815 | continue; |
| 1816 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1817 | /* |
| 1818 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1819 | * state before it received the OPEN_CONFIRM. |
| 1820 | * Recover by retrying the request as per the discussion |
| 1821 | * on Page 181 of RFC3530. |
| 1822 | */ |
| 1823 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1824 | exception.retry = 1; |
| 1825 | continue; |
| 1826 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1827 | if (status == -EAGAIN) { |
| 1828 | /* We must have found a delegation */ |
| 1829 | exception.retry = 1; |
| 1830 | continue; |
| 1831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1833 | status, &exception)); |
| 1834 | } while (exception.retry); |
| 1835 | return res; |
| 1836 | } |
| 1837 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1838 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1839 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1840 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1842 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1844 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | .iap = sattr, |
| 1846 | .server = server, |
| 1847 | .bitmask = server->attr_bitmask, |
| 1848 | }; |
| 1849 | struct nfs_setattrres res = { |
| 1850 | .fattr = fattr, |
| 1851 | .server = server, |
| 1852 | }; |
| 1853 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1854 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1855 | .rpc_argp = &arg, |
| 1856 | .rpc_resp = &res, |
| 1857 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1859 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1860 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1862 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1864 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1865 | /* Use that stateid */ |
| 1866 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1867 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1868 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1870 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1871 | 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] | 1872 | if (status == 0 && state != NULL) |
| 1873 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1874 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1877 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1878 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1879 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1881 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | struct nfs4_exception exception = { }; |
| 1883 | int err; |
| 1884 | do { |
| 1885 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1886 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | &exception); |
| 1888 | } while (exception.retry); |
| 1889 | return err; |
| 1890 | } |
| 1891 | |
| 1892 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1893 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | struct inode *inode; |
| 1895 | struct nfs4_state *state; |
| 1896 | struct nfs_closeargs arg; |
| 1897 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1898 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1899 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1900 | bool roc; |
| 1901 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | }; |
| 1903 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1904 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1905 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1906 | struct nfs4_closedata *calldata = data; |
| 1907 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1908 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1909 | if (calldata->roc) |
| 1910 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1911 | nfs4_put_open_state(calldata->state); |
| 1912 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1913 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1914 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1915 | kfree(calldata); |
| 1916 | } |
| 1917 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1918 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1919 | fmode_t fmode) |
| 1920 | { |
| 1921 | spin_lock(&state->owner->so_lock); |
| 1922 | if (!(fmode & FMODE_READ)) |
| 1923 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1924 | if (!(fmode & FMODE_WRITE)) |
| 1925 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1926 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1927 | spin_unlock(&state->owner->so_lock); |
| 1928 | } |
| 1929 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1930 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1932 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1935 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1936 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1937 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | /* hmm. we are done with the inode, and in the process of freeing |
| 1939 | * the state_owner. we keep this around to process errors |
| 1940 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | switch (task->tk_status) { |
| 1942 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1943 | if (calldata->roc) |
| 1944 | pnfs_roc_set_barrier(state->inode, |
| 1945 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1946 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1947 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1948 | nfs4_close_clear_stateid_flags(state, |
| 1949 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | break; |
| 1951 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1952 | case -NFS4ERR_OLD_STATEID: |
| 1953 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1955 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1956 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1958 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1959 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1961 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1962 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1965 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1967 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1968 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1969 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1970 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1971 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1972 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1973 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1974 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1975 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1976 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1977 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1978 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1979 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1980 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1981 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1982 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1983 | } |
| 1984 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1985 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1986 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1987 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1988 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1989 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1990 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1991 | |
| 1992 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1993 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1994 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1995 | return; |
| 1996 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1997 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1998 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1999 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2000 | if (calldata->roc && |
| 2001 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2002 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2003 | task, NULL); |
| 2004 | return; |
| 2005 | } |
| 2006 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2007 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2008 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2009 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2010 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 2011 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 2012 | 1, task)) |
| 2013 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2014 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2017 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2018 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2019 | .rpc_call_done = nfs4_close_done, |
| 2020 | .rpc_release = nfs4_free_closedata, |
| 2021 | }; |
| 2022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | /* |
| 2024 | * It is possible for data to be read/written from a mem-mapped file |
| 2025 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2026 | * This means that we can't safely call nfsv4 close on a file until |
| 2027 | * the inode is cleared. This in turn means that we are not good |
| 2028 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2029 | * share state even when we are done with one of the three share |
| 2030 | * stateid's in the inode. |
| 2031 | * |
| 2032 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2033 | */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2034 | 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] | 2035 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2036 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2038 | struct nfs4_state_owner *sp = state->owner; |
| 2039 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2040 | struct rpc_message msg = { |
| 2041 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2042 | .rpc_cred = state->owner->so_cred, |
| 2043 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2044 | struct rpc_task_setup task_setup_data = { |
| 2045 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2046 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2047 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2048 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2049 | .flags = RPC_TASK_ASYNC, |
| 2050 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2051 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2053 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2055 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2056 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2058 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2059 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2061 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2062 | if (calldata->arg.seqid == NULL) |
| 2063 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2064 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2065 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2066 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2067 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2068 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2069 | calldata->roc = roc; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2070 | path_get(path); |
| 2071 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2072 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2073 | msg.rpc_argp = &calldata->arg; |
| 2074 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2075 | task_setup_data.callback_data = calldata; |
| 2076 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2077 | if (IS_ERR(task)) |
| 2078 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2079 | status = 0; |
| 2080 | if (wait) |
| 2081 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2082 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2083 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2084 | out_free_calldata: |
| 2085 | kfree(calldata); |
| 2086 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2087 | if (roc) |
| 2088 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2089 | nfs4_put_open_state(state); |
| 2090 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2091 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2094 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2095 | 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] | 2096 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | struct nfs4_state *state; |
| 2098 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2099 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2100 | 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] | 2101 | if (IS_ERR(state)) |
| 2102 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2103 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2104 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2107 | 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] | 2108 | { |
| 2109 | if (ctx->state == NULL) |
| 2110 | return; |
| 2111 | if (is_sync) |
| 2112 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2113 | else |
| 2114 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2115 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | |
| 2117 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2118 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2119 | struct nfs4_server_caps_arg args = { |
| 2120 | .fhandle = fhandle, |
| 2121 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | struct nfs4_server_caps_res res = {}; |
| 2123 | struct rpc_message msg = { |
| 2124 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2125 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | .rpc_resp = &res, |
| 2127 | }; |
| 2128 | int status; |
| 2129 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2130 | 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] | 2131 | if (status == 0) { |
| 2132 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2133 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2134 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2135 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2136 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2137 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2139 | server->caps |= NFS_CAP_ACLS; |
| 2140 | if (res.has_links != 0) |
| 2141 | server->caps |= NFS_CAP_HARDLINKS; |
| 2142 | if (res.has_symlinks != 0) |
| 2143 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2144 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2145 | server->caps |= NFS_CAP_FILEID; |
| 2146 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2147 | server->caps |= NFS_CAP_MODE; |
| 2148 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2149 | server->caps |= NFS_CAP_NLINK; |
| 2150 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2151 | server->caps |= NFS_CAP_OWNER; |
| 2152 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2153 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2154 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2155 | server->caps |= NFS_CAP_ATIME; |
| 2156 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2157 | server->caps |= NFS_CAP_CTIME; |
| 2158 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2159 | server->caps |= NFS_CAP_MTIME; |
| 2160 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2161 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2162 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2163 | 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] | 2164 | server->acl_bitmask = res.acl_bitmask; |
| 2165 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | return status; |
| 2168 | } |
| 2169 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2170 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | { |
| 2172 | struct nfs4_exception exception = { }; |
| 2173 | int err; |
| 2174 | do { |
| 2175 | err = nfs4_handle_exception(server, |
| 2176 | _nfs4_server_capabilities(server, fhandle), |
| 2177 | &exception); |
| 2178 | } while (exception.retry); |
| 2179 | return err; |
| 2180 | } |
| 2181 | |
| 2182 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2183 | struct nfs_fsinfo *info) |
| 2184 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | struct nfs4_lookup_root_arg args = { |
| 2186 | .bitmask = nfs4_fattr_bitmap, |
| 2187 | }; |
| 2188 | struct nfs4_lookup_res res = { |
| 2189 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2190 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | .fh = fhandle, |
| 2192 | }; |
| 2193 | struct rpc_message msg = { |
| 2194 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2195 | .rpc_argp = &args, |
| 2196 | .rpc_resp = &res, |
| 2197 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2198 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2199 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2200 | 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] | 2201 | } |
| 2202 | |
| 2203 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2204 | struct nfs_fsinfo *info) |
| 2205 | { |
| 2206 | struct nfs4_exception exception = { }; |
| 2207 | int err; |
| 2208 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2209 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2210 | switch (err) { |
| 2211 | case 0: |
| 2212 | case -NFS4ERR_WRONGSEC: |
| 2213 | break; |
| 2214 | default: |
| 2215 | err = nfs4_handle_exception(server, err, &exception); |
| 2216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | } while (exception.retry); |
| 2218 | return err; |
| 2219 | } |
| 2220 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2221 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2222 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2223 | { |
| 2224 | struct rpc_auth *auth; |
| 2225 | int ret; |
| 2226 | |
| 2227 | auth = rpcauth_create(flavor, server->client); |
| 2228 | if (!auth) { |
| 2229 | ret = -EIO; |
| 2230 | goto out; |
| 2231 | } |
| 2232 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2233 | out: |
| 2234 | return ret; |
| 2235 | } |
| 2236 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2237 | static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2238 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2240 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2241 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2243 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2244 | flav_array[len] = RPC_AUTH_NULL; |
| 2245 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2246 | |
| 2247 | for (i = 0; i < len; i++) { |
| 2248 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2249 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2250 | continue; |
| 2251 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2252 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2253 | /* |
| 2254 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2255 | * to access the mount. It could also mean that we tried to mount |
| 2256 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2257 | * existing mount programs don't handle -EACCES very well so it should |
| 2258 | * be mapped to -EPERM instead. |
| 2259 | */ |
| 2260 | if (status == -EACCES) |
| 2261 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2262 | return status; |
| 2263 | } |
| 2264 | |
| 2265 | /* |
| 2266 | * get the file handle for the "/" directory on the server |
| 2267 | */ |
| 2268 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2269 | struct nfs_fsinfo *info) |
| 2270 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2271 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2272 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2273 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2274 | /* |
| 2275 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2276 | * by nfs4_map_errors() as this function exits. |
| 2277 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2278 | status = nfs_v4_minor_ops[minor_version]->find_root_sec(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | if (status == 0) |
| 2280 | status = nfs4_server_capabilities(server, fhandle); |
| 2281 | if (status == 0) |
| 2282 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2283 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2286 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2287 | /* |
| 2288 | * Get locations and (maybe) other attributes of a referral. |
| 2289 | * Note that we'll actually follow the referral later when |
| 2290 | * we detect fsid mismatch in inode revalidation |
| 2291 | */ |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2292 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, |
| 2293 | struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2294 | { |
| 2295 | int status = -ENOMEM; |
| 2296 | struct page *page = NULL; |
| 2297 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2298 | |
| 2299 | page = alloc_page(GFP_KERNEL); |
| 2300 | if (page == NULL) |
| 2301 | goto out; |
| 2302 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2303 | if (locations == NULL) |
| 2304 | goto out; |
| 2305 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2306 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2307 | if (status != 0) |
| 2308 | goto out; |
| 2309 | /* Make sure server returned a different fsid for the referral */ |
| 2310 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2311 | dprintk("%s: server did not return a different fsid for" |
| 2312 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2313 | status = -EIO; |
| 2314 | goto out; |
| 2315 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2316 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2317 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2318 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2319 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2320 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2321 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2322 | out: |
| 2323 | if (page) |
| 2324 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2325 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2326 | return status; |
| 2327 | } |
| 2328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2330 | { |
| 2331 | struct nfs4_getattr_arg args = { |
| 2332 | .fh = fhandle, |
| 2333 | .bitmask = server->attr_bitmask, |
| 2334 | }; |
| 2335 | struct nfs4_getattr_res res = { |
| 2336 | .fattr = fattr, |
| 2337 | .server = server, |
| 2338 | }; |
| 2339 | struct rpc_message msg = { |
| 2340 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2341 | .rpc_argp = &args, |
| 2342 | .rpc_resp = &res, |
| 2343 | }; |
| 2344 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2345 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2346 | 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] | 2347 | } |
| 2348 | |
| 2349 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2350 | { |
| 2351 | struct nfs4_exception exception = { }; |
| 2352 | int err; |
| 2353 | do { |
| 2354 | err = nfs4_handle_exception(server, |
| 2355 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2356 | &exception); |
| 2357 | } while (exception.retry); |
| 2358 | return err; |
| 2359 | } |
| 2360 | |
| 2361 | /* |
| 2362 | * The file is not closed if it is opened due to the a request to change |
| 2363 | * the size of the file. The open call will not be needed once the |
| 2364 | * VFS layer lookup-intents are implemented. |
| 2365 | * |
| 2366 | * Close is called when the inode is destroyed. |
| 2367 | * If we haven't opened the file for O_WRONLY, we |
| 2368 | * need to in the size_change case to obtain a stateid. |
| 2369 | * |
| 2370 | * Got race? |
| 2371 | * Because OPEN is always done by name in nfsv4, it is |
| 2372 | * possible that we opened a different file by the same |
| 2373 | * name. We can recognize this race condition, but we |
| 2374 | * can't do anything about it besides returning an error. |
| 2375 | * |
| 2376 | * This will be fixed with VFS changes (lookup-intent). |
| 2377 | */ |
| 2378 | static int |
| 2379 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2380 | struct iattr *sattr) |
| 2381 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2382 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2383 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2384 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | int status; |
| 2386 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2387 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2388 | pnfs_return_layout(inode); |
| 2389 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2390 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2392 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2393 | if (sattr->ia_valid & ATTR_FILE) { |
| 2394 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2395 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2396 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2397 | if (ctx) { |
| 2398 | cred = ctx->cred; |
| 2399 | state = ctx->state; |
| 2400 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2404 | if (status == 0) |
| 2405 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | return status; |
| 2407 | } |
| 2408 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2409 | static int _nfs4_proc_lookupfh(struct rpc_clnt *clnt, struct nfs_server *server, |
| 2410 | const struct nfs_fh *dirfh, const struct qstr *name, |
| 2411 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2412 | { |
| 2413 | int status; |
| 2414 | struct nfs4_lookup_arg args = { |
| 2415 | .bitmask = server->attr_bitmask, |
| 2416 | .dir_fh = dirfh, |
| 2417 | .name = name, |
| 2418 | }; |
| 2419 | struct nfs4_lookup_res res = { |
| 2420 | .server = server, |
| 2421 | .fattr = fattr, |
| 2422 | .fh = fhandle, |
| 2423 | }; |
| 2424 | struct rpc_message msg = { |
| 2425 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2426 | .rpc_argp = &args, |
| 2427 | .rpc_resp = &res, |
| 2428 | }; |
| 2429 | |
| 2430 | nfs_fattr_init(fattr); |
| 2431 | |
| 2432 | dprintk("NFS call lookupfh %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2433 | 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] | 2434 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2435 | return status; |
| 2436 | } |
| 2437 | |
| 2438 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2439 | struct qstr *name, struct nfs_fh *fhandle, |
| 2440 | struct nfs_fattr *fattr) |
| 2441 | { |
| 2442 | struct nfs4_exception exception = { }; |
| 2443 | int err; |
| 2444 | do { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2445 | err = _nfs4_proc_lookupfh(server->client, server, dirfh, name, fhandle, fattr); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2446 | /* FIXME: !!!! */ |
| 2447 | if (err == -NFS4ERR_MOVED) { |
| 2448 | err = -EREMOTE; |
| 2449 | break; |
| 2450 | } |
| 2451 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2452 | } while (exception.retry); |
| 2453 | return err; |
| 2454 | } |
| 2455 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2456 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2457 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2458 | struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2460 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | |
| 2462 | dprintk("NFS call lookup %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2463 | 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] | 2464 | if (status == -NFS4ERR_MOVED) |
| 2465 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | dprintk("NFS reply lookup: %d\n", status); |
| 2467 | return status; |
| 2468 | } |
| 2469 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2470 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2471 | { |
| 2472 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2473 | fattr->fsid.major = 1; |
| 2474 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2475 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2476 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2477 | fattr->nlink = 2; |
| 2478 | } |
| 2479 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2480 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2481 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | { |
| 2483 | struct nfs4_exception exception = { }; |
| 2484 | int err; |
| 2485 | do { |
| 2486 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2487 | _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | &exception); |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2489 | if (err == -EPERM) |
| 2490 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | } while (exception.retry); |
| 2492 | return err; |
| 2493 | } |
| 2494 | |
| 2495 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2496 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2497 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | struct nfs4_accessargs args = { |
| 2499 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2500 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2502 | struct nfs4_accessres res = { |
| 2503 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2504 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | struct rpc_message msg = { |
| 2506 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2507 | .rpc_argp = &args, |
| 2508 | .rpc_resp = &res, |
| 2509 | .rpc_cred = entry->cred, |
| 2510 | }; |
| 2511 | int mode = entry->mask; |
| 2512 | int status; |
| 2513 | |
| 2514 | /* |
| 2515 | * Determine which access bits we want to ask for... |
| 2516 | */ |
| 2517 | if (mode & MAY_READ) |
| 2518 | args.access |= NFS4_ACCESS_READ; |
| 2519 | if (S_ISDIR(inode->i_mode)) { |
| 2520 | if (mode & MAY_WRITE) |
| 2521 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2522 | if (mode & MAY_EXEC) |
| 2523 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2524 | } else { |
| 2525 | if (mode & MAY_WRITE) |
| 2526 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2527 | if (mode & MAY_EXEC) |
| 2528 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2529 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2530 | |
| 2531 | res.fattr = nfs_alloc_fattr(); |
| 2532 | if (res.fattr == NULL) |
| 2533 | return -ENOMEM; |
| 2534 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2535 | 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] | 2536 | if (!status) { |
| 2537 | entry->mask = 0; |
| 2538 | if (res.access & NFS4_ACCESS_READ) |
| 2539 | entry->mask |= MAY_READ; |
| 2540 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2541 | entry->mask |= MAY_WRITE; |
| 2542 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2543 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2544 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2546 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | return status; |
| 2548 | } |
| 2549 | |
| 2550 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2551 | { |
| 2552 | struct nfs4_exception exception = { }; |
| 2553 | int err; |
| 2554 | do { |
| 2555 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2556 | _nfs4_proc_access(inode, entry), |
| 2557 | &exception); |
| 2558 | } while (exception.retry); |
| 2559 | return err; |
| 2560 | } |
| 2561 | |
| 2562 | /* |
| 2563 | * TODO: For the time being, we don't try to get any attributes |
| 2564 | * along with any of the zero-copy operations READ, READDIR, |
| 2565 | * READLINK, WRITE. |
| 2566 | * |
| 2567 | * In the case of the first three, we want to put the GETATTR |
| 2568 | * after the read-type operation -- this is because it is hard |
| 2569 | * to predict the length of a GETATTR response in v4, and thus |
| 2570 | * align the READ data correctly. This means that the GETATTR |
| 2571 | * may end up partially falling into the page cache, and we should |
| 2572 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2573 | * To do this efficiently, we need to know the total length |
| 2574 | * of data received, which doesn't seem to be available outside |
| 2575 | * of the RPC layer. |
| 2576 | * |
| 2577 | * In the case of WRITE, we also want to put the GETATTR after |
| 2578 | * the operation -- in this case because we want to make sure |
| 2579 | * we get the post-operation mtime and size. This means that |
| 2580 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2581 | * of it which would leave room in the 'tail' iovec. |
| 2582 | * |
| 2583 | * Both of these changes to the XDR layer would in fact be quite |
| 2584 | * minor, but I decided to leave them for a subsequent patch. |
| 2585 | */ |
| 2586 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2587 | unsigned int pgbase, unsigned int pglen) |
| 2588 | { |
| 2589 | struct nfs4_readlink args = { |
| 2590 | .fh = NFS_FH(inode), |
| 2591 | .pgbase = pgbase, |
| 2592 | .pglen = pglen, |
| 2593 | .pages = &page, |
| 2594 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2595 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | struct rpc_message msg = { |
| 2597 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2598 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2599 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | }; |
| 2601 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2602 | 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] | 2603 | } |
| 2604 | |
| 2605 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2606 | unsigned int pgbase, unsigned int pglen) |
| 2607 | { |
| 2608 | struct nfs4_exception exception = { }; |
| 2609 | int err; |
| 2610 | do { |
| 2611 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2612 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2613 | &exception); |
| 2614 | } while (exception.retry); |
| 2615 | return err; |
| 2616 | } |
| 2617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | /* |
| 2619 | * Got race? |
| 2620 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2621 | * Until then, this create/open method is prone to inefficiency and race |
| 2622 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2623 | * placed on the wire. |
| 2624 | * |
| 2625 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2626 | * The file will be opened again in the subsequent VFS open call |
| 2627 | * (nfs4_proc_file_open). |
| 2628 | * |
| 2629 | * The open for read will just hang around to be used by any process that |
| 2630 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2631 | */ |
| 2632 | |
| 2633 | static int |
| 2634 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2635 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2637 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2638 | .dentry = dentry, |
| 2639 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2640 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2642 | struct rpc_cred *cred = NULL; |
| 2643 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | int status = 0; |
| 2645 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2646 | if (ctx != NULL) { |
| 2647 | cred = ctx->cred; |
| 2648 | path = &ctx->path; |
| 2649 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2651 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2652 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2653 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | if (IS_ERR(state)) { |
| 2655 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2656 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2658 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2659 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2660 | if (ctx != NULL) |
| 2661 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2662 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2663 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | out: |
| 2665 | return status; |
| 2666 | } |
| 2667 | |
| 2668 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2669 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2670 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2671 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2673 | .name.len = name->len, |
| 2674 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2675 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2677 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2678 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2679 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2680 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2681 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2682 | .rpc_argp = &args, |
| 2683 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2685 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2687 | res.dir_attr = nfs_alloc_fattr(); |
| 2688 | if (res.dir_attr == NULL) |
| 2689 | goto out; |
| 2690 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2691 | 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] | 2692 | if (status == 0) { |
| 2693 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2694 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2695 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2696 | nfs_free_fattr(res.dir_attr); |
| 2697 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | return status; |
| 2699 | } |
| 2700 | |
| 2701 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2702 | { |
| 2703 | struct nfs4_exception exception = { }; |
| 2704 | int err; |
| 2705 | do { |
| 2706 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2707 | _nfs4_proc_remove(dir, name), |
| 2708 | &exception); |
| 2709 | } while (exception.retry); |
| 2710 | return err; |
| 2711 | } |
| 2712 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2713 | 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] | 2714 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2715 | struct nfs_server *server = NFS_SERVER(dir); |
| 2716 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2717 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2719 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2720 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2721 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2725 | 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] | 2726 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2727 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2728 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2729 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2730 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2731 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2732 | return 0; |
| 2733 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2734 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2735 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | } |
| 2737 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2738 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2739 | { |
| 2740 | struct nfs_server *server = NFS_SERVER(dir); |
| 2741 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2742 | struct nfs_renameres *res = msg->rpc_resp; |
| 2743 | |
| 2744 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2745 | arg->bitmask = server->attr_bitmask; |
| 2746 | res->server = server; |
| 2747 | } |
| 2748 | |
| 2749 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2750 | struct inode *new_dir) |
| 2751 | { |
| 2752 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2753 | |
| 2754 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2755 | return 0; |
| 2756 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2757 | return 0; |
| 2758 | |
| 2759 | update_changeattr(old_dir, &res->old_cinfo); |
| 2760 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2761 | update_changeattr(new_dir, &res->new_cinfo); |
| 2762 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2763 | return 1; |
| 2764 | } |
| 2765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2767 | struct inode *new_dir, struct qstr *new_name) |
| 2768 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2769 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2770 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | .old_dir = NFS_FH(old_dir), |
| 2772 | .new_dir = NFS_FH(new_dir), |
| 2773 | .old_name = old_name, |
| 2774 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2775 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2776 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2777 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2778 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2779 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | struct rpc_message msg = { |
| 2781 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2782 | .rpc_argp = &arg, |
| 2783 | .rpc_resp = &res, |
| 2784 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2785 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2787 | res.old_fattr = nfs_alloc_fattr(); |
| 2788 | res.new_fattr = nfs_alloc_fattr(); |
| 2789 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2790 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2792 | 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] | 2793 | if (!status) { |
| 2794 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2795 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2797 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2799 | out: |
| 2800 | nfs_free_fattr(res.new_fattr); |
| 2801 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | return status; |
| 2803 | } |
| 2804 | |
| 2805 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2806 | struct inode *new_dir, struct qstr *new_name) |
| 2807 | { |
| 2808 | struct nfs4_exception exception = { }; |
| 2809 | int err; |
| 2810 | do { |
| 2811 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2812 | _nfs4_proc_rename(old_dir, old_name, |
| 2813 | new_dir, new_name), |
| 2814 | &exception); |
| 2815 | } while (exception.retry); |
| 2816 | return err; |
| 2817 | } |
| 2818 | |
| 2819 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2820 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2821 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | struct nfs4_link_arg arg = { |
| 2823 | .fh = NFS_FH(inode), |
| 2824 | .dir_fh = NFS_FH(dir), |
| 2825 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2826 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2828 | struct nfs4_link_res res = { |
| 2829 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2830 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | struct rpc_message msg = { |
| 2832 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2833 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2834 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2836 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2838 | res.fattr = nfs_alloc_fattr(); |
| 2839 | res.dir_attr = nfs_alloc_fattr(); |
| 2840 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2841 | goto out; |
| 2842 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2843 | 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] | 2844 | if (!status) { |
| 2845 | update_changeattr(dir, &res.cinfo); |
| 2846 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2847 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2848 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2849 | out: |
| 2850 | nfs_free_fattr(res.dir_attr); |
| 2851 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | return status; |
| 2853 | } |
| 2854 | |
| 2855 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2856 | { |
| 2857 | struct nfs4_exception exception = { }; |
| 2858 | int err; |
| 2859 | do { |
| 2860 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2861 | _nfs4_proc_link(inode, dir, name), |
| 2862 | &exception); |
| 2863 | } while (exception.retry); |
| 2864 | return err; |
| 2865 | } |
| 2866 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2867 | struct nfs4_createdata { |
| 2868 | struct rpc_message msg; |
| 2869 | struct nfs4_create_arg arg; |
| 2870 | struct nfs4_create_res res; |
| 2871 | struct nfs_fh fh; |
| 2872 | struct nfs_fattr fattr; |
| 2873 | struct nfs_fattr dir_fattr; |
| 2874 | }; |
| 2875 | |
| 2876 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2877 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2878 | { |
| 2879 | struct nfs4_createdata *data; |
| 2880 | |
| 2881 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2882 | if (data != NULL) { |
| 2883 | struct nfs_server *server = NFS_SERVER(dir); |
| 2884 | |
| 2885 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2886 | data->msg.rpc_argp = &data->arg; |
| 2887 | data->msg.rpc_resp = &data->res; |
| 2888 | data->arg.dir_fh = NFS_FH(dir); |
| 2889 | data->arg.server = server; |
| 2890 | data->arg.name = name; |
| 2891 | data->arg.attrs = sattr; |
| 2892 | data->arg.ftype = ftype; |
| 2893 | data->arg.bitmask = server->attr_bitmask; |
| 2894 | data->res.server = server; |
| 2895 | data->res.fh = &data->fh; |
| 2896 | data->res.fattr = &data->fattr; |
| 2897 | data->res.dir_fattr = &data->dir_fattr; |
| 2898 | nfs_fattr_init(data->res.fattr); |
| 2899 | nfs_fattr_init(data->res.dir_fattr); |
| 2900 | } |
| 2901 | return data; |
| 2902 | } |
| 2903 | |
| 2904 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2905 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2906 | 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] | 2907 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2908 | if (status == 0) { |
| 2909 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2910 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2911 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2912 | } |
| 2913 | return status; |
| 2914 | } |
| 2915 | |
| 2916 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2917 | { |
| 2918 | kfree(data); |
| 2919 | } |
| 2920 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2921 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2922 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2924 | struct nfs4_createdata *data; |
| 2925 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2927 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2928 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2929 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2930 | status = -ENOMEM; |
| 2931 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2932 | if (data == NULL) |
| 2933 | goto out; |
| 2934 | |
| 2935 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2936 | data->arg.u.symlink.pages = &page; |
| 2937 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2939 | status = nfs4_do_create(dir, dentry, data); |
| 2940 | |
| 2941 | nfs4_free_createdata(data); |
| 2942 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | return status; |
| 2944 | } |
| 2945 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2946 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2947 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | { |
| 2949 | struct nfs4_exception exception = { }; |
| 2950 | int err; |
| 2951 | do { |
| 2952 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2953 | _nfs4_proc_symlink(dir, dentry, page, |
| 2954 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | &exception); |
| 2956 | } while (exception.retry); |
| 2957 | return err; |
| 2958 | } |
| 2959 | |
| 2960 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2961 | struct iattr *sattr) |
| 2962 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2963 | struct nfs4_createdata *data; |
| 2964 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2966 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2967 | if (data == NULL) |
| 2968 | goto out; |
| 2969 | |
| 2970 | status = nfs4_do_create(dir, dentry, data); |
| 2971 | |
| 2972 | nfs4_free_createdata(data); |
| 2973 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | return status; |
| 2975 | } |
| 2976 | |
| 2977 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2978 | struct iattr *sattr) |
| 2979 | { |
| 2980 | struct nfs4_exception exception = { }; |
| 2981 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2982 | |
| 2983 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | do { |
| 2985 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2986 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2987 | &exception); |
| 2988 | } while (exception.retry); |
| 2989 | return err; |
| 2990 | } |
| 2991 | |
| 2992 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2993 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | { |
| 2995 | struct inode *dir = dentry->d_inode; |
| 2996 | struct nfs4_readdir_arg args = { |
| 2997 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2998 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | .pgbase = 0, |
| 3000 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3001 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3002 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | }; |
| 3004 | struct nfs4_readdir_res res; |
| 3005 | struct rpc_message msg = { |
| 3006 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3007 | .rpc_argp = &args, |
| 3008 | .rpc_resp = &res, |
| 3009 | .rpc_cred = cred, |
| 3010 | }; |
| 3011 | int status; |
| 3012 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3013 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3014 | dentry->d_parent->d_name.name, |
| 3015 | dentry->d_name.name, |
| 3016 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3018 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3019 | 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] | 3020 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3022 | status += args.pgbase; |
| 3023 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3024 | |
| 3025 | nfs_invalidate_atime(dir); |
| 3026 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3027 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | return status; |
| 3029 | } |
| 3030 | |
| 3031 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3032 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | { |
| 3034 | struct nfs4_exception exception = { }; |
| 3035 | int err; |
| 3036 | do { |
| 3037 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3038 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3039 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | &exception); |
| 3041 | } while (exception.retry); |
| 3042 | return err; |
| 3043 | } |
| 3044 | |
| 3045 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3046 | struct iattr *sattr, dev_t rdev) |
| 3047 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3048 | struct nfs4_createdata *data; |
| 3049 | int mode = sattr->ia_mode; |
| 3050 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3051 | |
| 3052 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3053 | 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] | 3054 | |
| 3055 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3056 | if (data == NULL) |
| 3057 | goto out; |
| 3058 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3060 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3062 | data->arg.ftype = NF4BLK; |
| 3063 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3064 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | } |
| 3066 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3067 | data->arg.ftype = NF4CHR; |
| 3068 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3069 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3072 | status = nfs4_do_create(dir, dentry, data); |
| 3073 | |
| 3074 | nfs4_free_createdata(data); |
| 3075 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | return status; |
| 3077 | } |
| 3078 | |
| 3079 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3080 | struct iattr *sattr, dev_t rdev) |
| 3081 | { |
| 3082 | struct nfs4_exception exception = { }; |
| 3083 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3084 | |
| 3085 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | do { |
| 3087 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3088 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3089 | &exception); |
| 3090 | } while (exception.retry); |
| 3091 | return err; |
| 3092 | } |
| 3093 | |
| 3094 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3095 | struct nfs_fsstat *fsstat) |
| 3096 | { |
| 3097 | struct nfs4_statfs_arg args = { |
| 3098 | .fh = fhandle, |
| 3099 | .bitmask = server->attr_bitmask, |
| 3100 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3101 | struct nfs4_statfs_res res = { |
| 3102 | .fsstat = fsstat, |
| 3103 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3104 | struct rpc_message msg = { |
| 3105 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3106 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3107 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | }; |
| 3109 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3110 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3111 | 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] | 3112 | } |
| 3113 | |
| 3114 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3115 | { |
| 3116 | struct nfs4_exception exception = { }; |
| 3117 | int err; |
| 3118 | do { |
| 3119 | err = nfs4_handle_exception(server, |
| 3120 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3121 | &exception); |
| 3122 | } while (exception.retry); |
| 3123 | return err; |
| 3124 | } |
| 3125 | |
| 3126 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3127 | struct nfs_fsinfo *fsinfo) |
| 3128 | { |
| 3129 | struct nfs4_fsinfo_arg args = { |
| 3130 | .fh = fhandle, |
| 3131 | .bitmask = server->attr_bitmask, |
| 3132 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3133 | struct nfs4_fsinfo_res res = { |
| 3134 | .fsinfo = fsinfo, |
| 3135 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | struct rpc_message msg = { |
| 3137 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3138 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3139 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | }; |
| 3141 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3142 | 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] | 3143 | } |
| 3144 | |
| 3145 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3146 | { |
| 3147 | struct nfs4_exception exception = { }; |
| 3148 | int err; |
| 3149 | |
| 3150 | do { |
| 3151 | err = nfs4_handle_exception(server, |
| 3152 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3153 | &exception); |
| 3154 | } while (exception.retry); |
| 3155 | return err; |
| 3156 | } |
| 3157 | |
| 3158 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3159 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3160 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3162 | } |
| 3163 | |
| 3164 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3165 | struct nfs_pathconf *pathconf) |
| 3166 | { |
| 3167 | struct nfs4_pathconf_arg args = { |
| 3168 | .fh = fhandle, |
| 3169 | .bitmask = server->attr_bitmask, |
| 3170 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3171 | struct nfs4_pathconf_res res = { |
| 3172 | .pathconf = pathconf, |
| 3173 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | struct rpc_message msg = { |
| 3175 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3176 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3177 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | }; |
| 3179 | |
| 3180 | /* None of the pathconf attributes are mandatory to implement */ |
| 3181 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3182 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3183 | return 0; |
| 3184 | } |
| 3185 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3186 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3187 | 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] | 3188 | } |
| 3189 | |
| 3190 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3191 | struct nfs_pathconf *pathconf) |
| 3192 | { |
| 3193 | struct nfs4_exception exception = { }; |
| 3194 | int err; |
| 3195 | |
| 3196 | do { |
| 3197 | err = nfs4_handle_exception(server, |
| 3198 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3199 | &exception); |
| 3200 | } while (exception.retry); |
| 3201 | return err; |
| 3202 | } |
| 3203 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3204 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3205 | { |
| 3206 | nfs_invalidate_atime(data->inode); |
| 3207 | } |
| 3208 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3209 | 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] | 3210 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3211 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3213 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3214 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3215 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3217 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3218 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3220 | renew_lease(server, data->timestamp); |
| 3221 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3224 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3225 | { |
| 3226 | |
| 3227 | dprintk("--> %s\n", __func__); |
| 3228 | |
| 3229 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3230 | return -EAGAIN; |
| 3231 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3232 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3233 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3234 | } |
| 3235 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3236 | 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] | 3237 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3238 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3239 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3240 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3243 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3244 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3245 | { |
| 3246 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3247 | put_lseg(data->lseg); |
| 3248 | data->lseg = NULL; |
| 3249 | /* offsets will differ in the dense stripe case */ |
| 3250 | data->args.offset = data->mds_offset; |
| 3251 | data->ds_clp = NULL; |
| 3252 | data->args.fh = NFS_FH(data->inode); |
| 3253 | data->read_done_cb = nfs4_read_done_cb; |
| 3254 | task->tk_ops = data->mds_ops; |
| 3255 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3256 | } |
| 3257 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3258 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3259 | 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] | 3260 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | struct inode *inode = data->inode; |
| 3262 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3263 | 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] | 3264 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3265 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3267 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3268 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3269 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3270 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3271 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3274 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3275 | { |
| 3276 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3277 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3278 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3279 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3282 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3283 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3284 | { |
| 3285 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3286 | put_lseg(data->lseg); |
| 3287 | data->lseg = NULL; |
| 3288 | data->ds_clp = NULL; |
| 3289 | data->write_done_cb = nfs4_write_done_cb; |
| 3290 | data->args.fh = NFS_FH(data->inode); |
| 3291 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3292 | data->args.offset = data->mds_offset; |
| 3293 | data->res.fattr = &data->fattr; |
| 3294 | task->tk_ops = data->mds_ops; |
| 3295 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3296 | } |
| 3297 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3298 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3299 | 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] | 3300 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3301 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3302 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3303 | if (data->lseg) { |
| 3304 | data->args.bitmask = NULL; |
| 3305 | data->res.fattr = NULL; |
| 3306 | } else |
| 3307 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3308 | if (!data->write_done_cb) |
| 3309 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3310 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | data->timestamp = jiffies; |
| 3312 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3313 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3316 | 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] | 3317 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3319 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3320 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3321 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3322 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3324 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3325 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | } |
| 3327 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3328 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3329 | { |
| 3330 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3331 | return -EAGAIN; |
| 3332 | return data->write_done_cb(task, data); |
| 3333 | } |
| 3334 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3335 | 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] | 3336 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3337 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3338 | |
| 3339 | if (data->lseg) { |
| 3340 | data->args.bitmask = NULL; |
| 3341 | data->res.fattr = NULL; |
| 3342 | } else |
| 3343 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3344 | if (!data->write_done_cb) |
| 3345 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3346 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3347 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | } |
| 3349 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3350 | struct nfs4_renewdata { |
| 3351 | struct nfs_client *client; |
| 3352 | unsigned long timestamp; |
| 3353 | }; |
| 3354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | /* |
| 3356 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3357 | * standalone procedure for queueing an asynchronous RENEW. |
| 3358 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3359 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3360 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3361 | struct nfs4_renewdata *data = calldata; |
| 3362 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3363 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3364 | if (atomic_read(&clp->cl_count) > 1) |
| 3365 | nfs4_schedule_state_renewal(clp); |
| 3366 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3367 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3368 | } |
| 3369 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3370 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3372 | struct nfs4_renewdata *data = calldata; |
| 3373 | struct nfs_client *clp = data->client; |
| 3374 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | |
| 3376 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3377 | /* Unless we're shutting down, schedule state recovery! */ |
| 3378 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3379 | nfs4_schedule_lease_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | return; |
| 3381 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3382 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3385 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3386 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3387 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3388 | }; |
| 3389 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3390 | 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] | 3391 | { |
| 3392 | struct rpc_message msg = { |
| 3393 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3394 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3395 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3397 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3399 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3400 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3401 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3402 | if (data == NULL) |
| 3403 | return -ENOMEM; |
| 3404 | data->client = clp; |
| 3405 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3407 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | } |
| 3409 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3410 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | { |
| 3412 | struct rpc_message msg = { |
| 3413 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3414 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3415 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | }; |
| 3417 | unsigned long now = jiffies; |
| 3418 | int status; |
| 3419 | |
| 3420 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3421 | if (status < 0) |
| 3422 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3423 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | return 0; |
| 3425 | } |
| 3426 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3427 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3428 | { |
| 3429 | return (server->caps & NFS_CAP_ACLS) |
| 3430 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3431 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3432 | } |
| 3433 | |
| 3434 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3435 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3436 | * the stack. |
| 3437 | */ |
| 3438 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3439 | |
| 3440 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3441 | struct page **pages, unsigned int *pgbase) |
| 3442 | { |
| 3443 | const void *p = buf; |
| 3444 | |
| 3445 | *pgbase = offset_in_page(buf); |
| 3446 | p -= *pgbase; |
| 3447 | while (p < buf + buflen) { |
| 3448 | *(pages++) = virt_to_page(p); |
| 3449 | p += PAGE_CACHE_SIZE; |
| 3450 | } |
| 3451 | } |
| 3452 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3453 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3454 | struct page **pages, unsigned int *pgbase) |
| 3455 | { |
| 3456 | struct page *newpage, **spages; |
| 3457 | int rc = 0; |
| 3458 | size_t len; |
| 3459 | spages = pages; |
| 3460 | |
| 3461 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3462 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3463 | newpage = alloc_page(GFP_KERNEL); |
| 3464 | |
| 3465 | if (newpage == NULL) |
| 3466 | goto unwind; |
| 3467 | memcpy(page_address(newpage), buf, len); |
| 3468 | buf += len; |
| 3469 | buflen -= len; |
| 3470 | *pages++ = newpage; |
| 3471 | rc++; |
| 3472 | } while (buflen != 0); |
| 3473 | |
| 3474 | return rc; |
| 3475 | |
| 3476 | unwind: |
| 3477 | for(; rc > 0; rc--) |
| 3478 | __free_page(spages[rc-1]); |
| 3479 | return -ENOMEM; |
| 3480 | } |
| 3481 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3482 | struct nfs4_cached_acl { |
| 3483 | int cached; |
| 3484 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3485 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3486 | }; |
| 3487 | |
| 3488 | 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] | 3489 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3490 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3491 | |
| 3492 | spin_lock(&inode->i_lock); |
| 3493 | kfree(nfsi->nfs4_acl); |
| 3494 | nfsi->nfs4_acl = acl; |
| 3495 | spin_unlock(&inode->i_lock); |
| 3496 | } |
| 3497 | |
| 3498 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3499 | { |
| 3500 | nfs4_set_cached_acl(inode, NULL); |
| 3501 | } |
| 3502 | |
| 3503 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3504 | { |
| 3505 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3506 | struct nfs4_cached_acl *acl; |
| 3507 | int ret = -ENOENT; |
| 3508 | |
| 3509 | spin_lock(&inode->i_lock); |
| 3510 | acl = nfsi->nfs4_acl; |
| 3511 | if (acl == NULL) |
| 3512 | goto out; |
| 3513 | if (buf == NULL) /* user is just asking for length */ |
| 3514 | goto out_len; |
| 3515 | if (acl->cached == 0) |
| 3516 | goto out; |
| 3517 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3518 | if (acl->len > buflen) |
| 3519 | goto out; |
| 3520 | memcpy(buf, acl->data, acl->len); |
| 3521 | out_len: |
| 3522 | ret = acl->len; |
| 3523 | out: |
| 3524 | spin_unlock(&inode->i_lock); |
| 3525 | return ret; |
| 3526 | } |
| 3527 | |
| 3528 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3529 | { |
| 3530 | struct nfs4_cached_acl *acl; |
| 3531 | |
| 3532 | if (buf && acl_len <= PAGE_SIZE) { |
| 3533 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3534 | if (acl == NULL) |
| 3535 | goto out; |
| 3536 | acl->cached = 1; |
| 3537 | memcpy(acl->data, buf, acl_len); |
| 3538 | } else { |
| 3539 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3540 | if (acl == NULL) |
| 3541 | goto out; |
| 3542 | acl->cached = 0; |
| 3543 | } |
| 3544 | acl->len = acl_len; |
| 3545 | out: |
| 3546 | nfs4_set_cached_acl(inode, acl); |
| 3547 | } |
| 3548 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3549 | 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] | 3550 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3551 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3552 | struct nfs_getaclargs args = { |
| 3553 | .fh = NFS_FH(inode), |
| 3554 | .acl_pages = pages, |
| 3555 | .acl_len = buflen, |
| 3556 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3557 | struct nfs_getaclres res = { |
| 3558 | .acl_len = buflen, |
| 3559 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3560 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3561 | struct rpc_message msg = { |
| 3562 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3563 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3564 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3565 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3566 | struct page *localpage = NULL; |
| 3567 | int ret; |
| 3568 | |
| 3569 | if (buflen < PAGE_SIZE) { |
| 3570 | /* As long as we're doing a round trip to the server anyway, |
| 3571 | * let's be prepared for a page of acl data. */ |
| 3572 | localpage = alloc_page(GFP_KERNEL); |
| 3573 | resp_buf = page_address(localpage); |
| 3574 | if (localpage == NULL) |
| 3575 | return -ENOMEM; |
| 3576 | args.acl_pages[0] = localpage; |
| 3577 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3578 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3579 | } else { |
| 3580 | resp_buf = buf; |
| 3581 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3582 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3583 | 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] | 3584 | if (ret) |
| 3585 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3586 | if (res.acl_len > args.acl_len) |
| 3587 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3588 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3589 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3590 | if (buf) { |
| 3591 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3592 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3593 | goto out_free; |
| 3594 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3595 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3596 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3597 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3598 | out_free: |
| 3599 | if (localpage) |
| 3600 | __free_page(localpage); |
| 3601 | return ret; |
| 3602 | } |
| 3603 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3604 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3605 | { |
| 3606 | struct nfs4_exception exception = { }; |
| 3607 | ssize_t ret; |
| 3608 | do { |
| 3609 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3610 | if (ret >= 0) |
| 3611 | break; |
| 3612 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3613 | } while (exception.retry); |
| 3614 | return ret; |
| 3615 | } |
| 3616 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3617 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3618 | { |
| 3619 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3620 | int ret; |
| 3621 | |
| 3622 | if (!nfs4_server_supports_acls(server)) |
| 3623 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3624 | ret = nfs_revalidate_inode(server, inode); |
| 3625 | if (ret < 0) |
| 3626 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3627 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3628 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3629 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3630 | if (ret != -ENOENT) |
| 3631 | return ret; |
| 3632 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3633 | } |
| 3634 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3635 | 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] | 3636 | { |
| 3637 | struct nfs_server *server = NFS_SERVER(inode); |
| 3638 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3639 | struct nfs_setaclargs arg = { |
| 3640 | .fh = NFS_FH(inode), |
| 3641 | .acl_pages = pages, |
| 3642 | .acl_len = buflen, |
| 3643 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3644 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3645 | struct rpc_message msg = { |
| 3646 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3647 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3648 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3649 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3650 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3651 | |
| 3652 | if (!nfs4_server_supports_acls(server)) |
| 3653 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3654 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3655 | if (i < 0) |
| 3656 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3657 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3658 | 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] | 3659 | |
| 3660 | /* |
| 3661 | * Free each page after tx, so the only ref left is |
| 3662 | * held by the network stack |
| 3663 | */ |
| 3664 | for (; i > 0; i--) |
| 3665 | put_page(pages[i-1]); |
| 3666 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3667 | /* |
| 3668 | * Acl update can result in inode attribute update. |
| 3669 | * so mark the attribute cache invalid. |
| 3670 | */ |
| 3671 | spin_lock(&inode->i_lock); |
| 3672 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3673 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3674 | nfs_access_zap_cache(inode); |
| 3675 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3676 | return ret; |
| 3677 | } |
| 3678 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3679 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3680 | { |
| 3681 | struct nfs4_exception exception = { }; |
| 3682 | int err; |
| 3683 | do { |
| 3684 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3685 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3686 | &exception); |
| 3687 | } while (exception.retry); |
| 3688 | return err; |
| 3689 | } |
| 3690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3692 | 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] | 3693 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3694 | struct nfs_client *clp = server->nfs_client; |
| 3695 | |
| 3696 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | return 0; |
| 3698 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3699 | case -NFS4ERR_ADMIN_REVOKED: |
| 3700 | case -NFS4ERR_BAD_STATEID: |
| 3701 | case -NFS4ERR_OPENMODE: |
| 3702 | if (state == NULL) |
| 3703 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3704 | nfs4_schedule_stateid_recovery(server, state); |
| 3705 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3706 | case -NFS4ERR_EXPIRED: |
| 3707 | if (state != NULL) |
| 3708 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3710 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3711 | nfs4_schedule_lease_recovery(clp); |
| 3712 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3713 | #if defined(CONFIG_NFS_V4_1) |
| 3714 | case -NFS4ERR_BADSESSION: |
| 3715 | case -NFS4ERR_BADSLOT: |
| 3716 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3717 | case -NFS4ERR_DEADSESSION: |
| 3718 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3719 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3720 | case -NFS4ERR_SEQ_MISORDERED: |
| 3721 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3722 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3723 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3724 | task->tk_status = 0; |
| 3725 | return -EAGAIN; |
| 3726 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3728 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3729 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3730 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3732 | task->tk_status = 0; |
| 3733 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3734 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | case -NFS4ERR_OLD_STATEID: |
| 3736 | task->tk_status = 0; |
| 3737 | return -EAGAIN; |
| 3738 | } |
| 3739 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3740 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3741 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3742 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3743 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3744 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3745 | task->tk_status = 0; |
| 3746 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3749 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3750 | unsigned short port, struct rpc_cred *cred, |
| 3751 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | { |
| 3753 | nfs4_verifier sc_verifier; |
| 3754 | struct nfs4_setclientid setclientid = { |
| 3755 | .sc_verifier = &sc_verifier, |
| 3756 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3757 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | }; |
| 3759 | struct rpc_message msg = { |
| 3760 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3761 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3762 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3763 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3765 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | int loop = 0; |
| 3767 | int status; |
| 3768 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3769 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3771 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3772 | |
| 3773 | for(;;) { |
| 3774 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3775 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3776 | clp->cl_ipaddr, |
| 3777 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3778 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3779 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3780 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3781 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | clp->cl_id_uniquifier); |
| 3783 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3784 | sizeof(setclientid.sc_netid), |
| 3785 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3786 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3788 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3790 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3791 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | if (status != -NFS4ERR_CLID_INUSE) |
| 3793 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3794 | if (loop != 0) { |
| 3795 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3797 | } |
| 3798 | ++loop; |
| 3799 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | } |
| 3801 | return status; |
| 3802 | } |
| 3803 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3804 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3805 | struct nfs4_setclientid_res *arg, |
| 3806 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | { |
| 3808 | struct nfs_fsinfo fsinfo; |
| 3809 | struct rpc_message msg = { |
| 3810 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3811 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3813 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | }; |
| 3815 | unsigned long now; |
| 3816 | int status; |
| 3817 | |
| 3818 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3819 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | if (status == 0) { |
| 3821 | spin_lock(&clp->cl_lock); |
| 3822 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3823 | clp->cl_last_renewal = now; |
| 3824 | spin_unlock(&clp->cl_lock); |
| 3825 | } |
| 3826 | return status; |
| 3827 | } |
| 3828 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3829 | struct nfs4_delegreturndata { |
| 3830 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3831 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3832 | struct nfs_fh fh; |
| 3833 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3834 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3835 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3836 | int rpc_status; |
| 3837 | }; |
| 3838 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3839 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3840 | { |
| 3841 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3842 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3843 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3844 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3845 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3846 | switch (task->tk_status) { |
| 3847 | case -NFS4ERR_STALE_STATEID: |
| 3848 | case -NFS4ERR_EXPIRED: |
| 3849 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3850 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3851 | break; |
| 3852 | default: |
| 3853 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3854 | -EAGAIN) { |
| 3855 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3856 | return; |
| 3857 | } |
| 3858 | } |
| 3859 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | static void nfs4_delegreturn_release(void *calldata) |
| 3863 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3864 | kfree(calldata); |
| 3865 | } |
| 3866 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3867 | #if defined(CONFIG_NFS_V4_1) |
| 3868 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3869 | { |
| 3870 | struct nfs4_delegreturndata *d_data; |
| 3871 | |
| 3872 | d_data = (struct nfs4_delegreturndata *)data; |
| 3873 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3874 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3875 | &d_data->args.seq_args, |
| 3876 | &d_data->res.seq_res, 1, task)) |
| 3877 | return; |
| 3878 | rpc_call_start(task); |
| 3879 | } |
| 3880 | #endif /* CONFIG_NFS_V4_1 */ |
| 3881 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3882 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3883 | #if defined(CONFIG_NFS_V4_1) |
| 3884 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3885 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3886 | .rpc_call_done = nfs4_delegreturn_done, |
| 3887 | .rpc_release = nfs4_delegreturn_release, |
| 3888 | }; |
| 3889 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3890 | 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] | 3891 | { |
| 3892 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3893 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3894 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3895 | struct rpc_message msg = { |
| 3896 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3897 | .rpc_cred = cred, |
| 3898 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3899 | struct rpc_task_setup task_setup_data = { |
| 3900 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3901 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3902 | .callback_ops = &nfs4_delegreturn_ops, |
| 3903 | .flags = RPC_TASK_ASYNC, |
| 3904 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3905 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3906 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3907 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3908 | if (data == NULL) |
| 3909 | return -ENOMEM; |
| 3910 | data->args.fhandle = &data->fh; |
| 3911 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3912 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3913 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3914 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3915 | data->res.fattr = &data->fattr; |
| 3916 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3917 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3918 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3919 | data->rpc_status = 0; |
| 3920 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3921 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3922 | msg.rpc_argp = &data->args; |
| 3923 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3924 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3925 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3926 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3927 | if (!issync) |
| 3928 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3929 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3930 | if (status != 0) |
| 3931 | goto out; |
| 3932 | status = data->rpc_status; |
| 3933 | if (status != 0) |
| 3934 | goto out; |
| 3935 | nfs_refresh_inode(inode, &data->fattr); |
| 3936 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3937 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3938 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3939 | } |
| 3940 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3941 | 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] | 3942 | { |
| 3943 | struct nfs_server *server = NFS_SERVER(inode); |
| 3944 | struct nfs4_exception exception = { }; |
| 3945 | int err; |
| 3946 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3947 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | switch (err) { |
| 3949 | case -NFS4ERR_STALE_STATEID: |
| 3950 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | case 0: |
| 3952 | return 0; |
| 3953 | } |
| 3954 | err = nfs4_handle_exception(server, err, &exception); |
| 3955 | } while (exception.retry); |
| 3956 | return err; |
| 3957 | } |
| 3958 | |
| 3959 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3960 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3961 | |
| 3962 | /* |
| 3963 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3964 | */ |
| 3965 | static unsigned long |
| 3966 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3967 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3968 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | timeout <<= 1; |
| 3970 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3971 | return NFS4_LOCK_MAXTIMEOUT; |
| 3972 | return timeout; |
| 3973 | } |
| 3974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3976 | { |
| 3977 | struct inode *inode = state->inode; |
| 3978 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3979 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3980 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3982 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3984 | struct nfs_lockt_res res = { |
| 3985 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | }; |
| 3987 | struct rpc_message msg = { |
| 3988 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3989 | .rpc_argp = &arg, |
| 3990 | .rpc_resp = &res, |
| 3991 | .rpc_cred = state->owner->so_cred, |
| 3992 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | struct nfs4_lock_state *lsp; |
| 3994 | int status; |
| 3995 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3996 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3997 | status = nfs4_set_lock_state(state, request); |
| 3998 | if (status != 0) |
| 3999 | goto out; |
| 4000 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4001 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4002 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4003 | 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] | 4004 | switch (status) { |
| 4005 | case 0: |
| 4006 | request->fl_type = F_UNLCK; |
| 4007 | break; |
| 4008 | case -NFS4ERR_DENIED: |
| 4009 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4011 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4012 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | return status; |
| 4014 | } |
| 4015 | |
| 4016 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4017 | { |
| 4018 | struct nfs4_exception exception = { }; |
| 4019 | int err; |
| 4020 | |
| 4021 | do { |
| 4022 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4023 | _nfs4_proc_getlk(state, cmd, request), |
| 4024 | &exception); |
| 4025 | } while (exception.retry); |
| 4026 | return err; |
| 4027 | } |
| 4028 | |
| 4029 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4030 | { |
| 4031 | int res = 0; |
| 4032 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4033 | case FL_POSIX: |
| 4034 | res = posix_lock_file_wait(file, fl); |
| 4035 | break; |
| 4036 | case FL_FLOCK: |
| 4037 | res = flock_lock_file_wait(file, fl); |
| 4038 | break; |
| 4039 | default: |
| 4040 | BUG(); |
| 4041 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | return res; |
| 4043 | } |
| 4044 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4045 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4046 | struct nfs_locku_args arg; |
| 4047 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4048 | struct nfs4_lock_state *lsp; |
| 4049 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4050 | struct file_lock fl; |
| 4051 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4052 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4053 | }; |
| 4054 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4055 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4056 | struct nfs_open_context *ctx, |
| 4057 | struct nfs4_lock_state *lsp, |
| 4058 | struct nfs_seqid *seqid) |
| 4059 | { |
| 4060 | struct nfs4_unlockdata *p; |
| 4061 | struct inode *inode = lsp->ls_state->inode; |
| 4062 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4063 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4064 | if (p == NULL) |
| 4065 | return NULL; |
| 4066 | p->arg.fh = NFS_FH(inode); |
| 4067 | p->arg.fl = &p->fl; |
| 4068 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4069 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4070 | p->arg.stateid = &lsp->ls_stateid; |
| 4071 | p->lsp = lsp; |
| 4072 | atomic_inc(&lsp->ls_count); |
| 4073 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4074 | p->ctx = get_nfs_open_context(ctx); |
| 4075 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4076 | p->server = NFS_SERVER(inode); |
| 4077 | return p; |
| 4078 | } |
| 4079 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4080 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4081 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4082 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4083 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4084 | nfs4_put_lock_state(calldata->lsp); |
| 4085 | put_nfs_open_context(calldata->ctx); |
| 4086 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4087 | } |
| 4088 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4089 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4090 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4091 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4092 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4093 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4094 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4095 | switch (task->tk_status) { |
| 4096 | case 0: |
| 4097 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4098 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4099 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4100 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4101 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4102 | case -NFS4ERR_BAD_STATEID: |
| 4103 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4104 | case -NFS4ERR_STALE_STATEID: |
| 4105 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4106 | break; |
| 4107 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4108 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4109 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 4110 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4111 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4112 | } |
| 4113 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4114 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4115 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4116 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4118 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4119 | return; |
| 4120 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4121 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4122 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4123 | return; |
| 4124 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4125 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4126 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4127 | &calldata->arg.seq_args, |
| 4128 | &calldata->res.seq_res, 1, task)) |
| 4129 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4130 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | } |
| 4132 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4133 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4134 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4135 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4136 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4137 | }; |
| 4138 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4139 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4140 | struct nfs_open_context *ctx, |
| 4141 | struct nfs4_lock_state *lsp, |
| 4142 | struct nfs_seqid *seqid) |
| 4143 | { |
| 4144 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4145 | struct rpc_message msg = { |
| 4146 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4147 | .rpc_cred = ctx->cred, |
| 4148 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4149 | struct rpc_task_setup task_setup_data = { |
| 4150 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4151 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4152 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4153 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4154 | .flags = RPC_TASK_ASYNC, |
| 4155 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4156 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4157 | /* Ensure this is an unlock - when canceling a lock, the |
| 4158 | * canceled lock is passed in, and it won't be an unlock. |
| 4159 | */ |
| 4160 | fl->fl_type = F_UNLCK; |
| 4161 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4162 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4163 | if (data == NULL) { |
| 4164 | nfs_free_seqid(seqid); |
| 4165 | return ERR_PTR(-ENOMEM); |
| 4166 | } |
| 4167 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4168 | msg.rpc_argp = &data->arg; |
| 4169 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4170 | task_setup_data.callback_data = data; |
| 4171 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4172 | } |
| 4173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4175 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4176 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4177 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4178 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4179 | struct rpc_task *task; |
| 4180 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4181 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4183 | status = nfs4_set_lock_state(state, request); |
| 4184 | /* Unlock _before_ we do the RPC call */ |
| 4185 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4186 | down_read(&nfsi->rwsem); |
| 4187 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4188 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4189 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4190 | } |
| 4191 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4192 | if (status != 0) |
| 4193 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4194 | /* Is this a delegated lock? */ |
| 4195 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4196 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4197 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4198 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4199 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4200 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4201 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4202 | 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] | 4203 | status = PTR_ERR(task); |
| 4204 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4205 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4206 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4207 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4208 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4209 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4210 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | } |
| 4212 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4213 | struct nfs4_lockdata { |
| 4214 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4215 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4216 | struct nfs4_lock_state *lsp; |
| 4217 | struct nfs_open_context *ctx; |
| 4218 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4219 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4220 | int rpc_status; |
| 4221 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4222 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4223 | }; |
| 4224 | |
| 4225 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4226 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4227 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4228 | { |
| 4229 | struct nfs4_lockdata *p; |
| 4230 | struct inode *inode = lsp->ls_state->inode; |
| 4231 | struct nfs_server *server = NFS_SERVER(inode); |
| 4232 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4233 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4234 | if (p == NULL) |
| 4235 | return NULL; |
| 4236 | |
| 4237 | p->arg.fh = NFS_FH(inode); |
| 4238 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4239 | 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] | 4240 | if (p->arg.open_seqid == NULL) |
| 4241 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4242 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4243 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4244 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4245 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4246 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4247 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4248 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4249 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4250 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4251 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4252 | atomic_inc(&lsp->ls_count); |
| 4253 | p->ctx = get_nfs_open_context(ctx); |
| 4254 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4255 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4256 | out_free_seqid: |
| 4257 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4258 | out_free: |
| 4259 | kfree(p); |
| 4260 | return NULL; |
| 4261 | } |
| 4262 | |
| 4263 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4264 | { |
| 4265 | struct nfs4_lockdata *data = calldata; |
| 4266 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4268 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4269 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4270 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4271 | /* Do we need to do an open_to_lock_owner? */ |
| 4272 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4273 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4274 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4275 | data->arg.open_stateid = &state->stateid; |
| 4276 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4277 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4278 | } else |
| 4279 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4280 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4281 | if (nfs4_setup_sequence(data->server, |
| 4282 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4283 | &data->res.seq_res, 1, task)) |
| 4284 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4285 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4286 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4287 | } |
| 4288 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4289 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4290 | { |
| 4291 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4292 | nfs4_lock_prepare(task, calldata); |
| 4293 | } |
| 4294 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4295 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4296 | { |
| 4297 | struct nfs4_lockdata *data = calldata; |
| 4298 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4299 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4300 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4301 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4302 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4303 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4304 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4305 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4306 | if (data->rpc_status == 0) |
| 4307 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4308 | else |
| 4309 | goto out; |
| 4310 | } |
| 4311 | if (data->rpc_status == 0) { |
| 4312 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4313 | sizeof(data->lsp->ls_stateid.data)); |
| 4314 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4315 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4316 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4317 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4318 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | static void nfs4_lock_release(void *calldata) |
| 4322 | { |
| 4323 | struct nfs4_lockdata *data = calldata; |
| 4324 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4325 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4326 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4327 | if (data->cancelled != 0) { |
| 4328 | struct rpc_task *task; |
| 4329 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4330 | data->arg.lock_seqid); |
| 4331 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4332 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4333 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4334 | } else |
| 4335 | nfs_free_seqid(data->arg.lock_seqid); |
| 4336 | nfs4_put_lock_state(data->lsp); |
| 4337 | put_nfs_open_context(data->ctx); |
| 4338 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4339 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4340 | } |
| 4341 | |
| 4342 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4343 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4344 | .rpc_call_done = nfs4_lock_done, |
| 4345 | .rpc_release = nfs4_lock_release, |
| 4346 | }; |
| 4347 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4348 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4349 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4350 | .rpc_call_done = nfs4_lock_done, |
| 4351 | .rpc_release = nfs4_lock_release, |
| 4352 | }; |
| 4353 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4354 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4355 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4356 | switch (error) { |
| 4357 | case -NFS4ERR_ADMIN_REVOKED: |
| 4358 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4359 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4360 | if (new_lock_owner != 0 || |
| 4361 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4362 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4363 | break; |
| 4364 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4365 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4366 | case -NFS4ERR_EXPIRED: |
| 4367 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4368 | }; |
| 4369 | } |
| 4370 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4371 | 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] | 4372 | { |
| 4373 | struct nfs4_lockdata *data; |
| 4374 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4375 | struct rpc_message msg = { |
| 4376 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4377 | .rpc_cred = state->owner->so_cred, |
| 4378 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4379 | struct rpc_task_setup task_setup_data = { |
| 4380 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4381 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4382 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4383 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4384 | .flags = RPC_TASK_ASYNC, |
| 4385 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4386 | int ret; |
| 4387 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4388 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4389 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4390 | fl->fl_u.nfs4_fl.owner, |
| 4391 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4392 | if (data == NULL) |
| 4393 | return -ENOMEM; |
| 4394 | if (IS_SETLKW(cmd)) |
| 4395 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4396 | if (recovery_type > NFS_LOCK_NEW) { |
| 4397 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4398 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4399 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4400 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4401 | msg.rpc_argp = &data->arg; |
| 4402 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4403 | task_setup_data.callback_data = data; |
| 4404 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4405 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4406 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4407 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4408 | if (ret == 0) { |
| 4409 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4410 | if (ret) |
| 4411 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4412 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4413 | } else |
| 4414 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4415 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4416 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4417 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4421 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4422 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4423 | struct nfs4_exception exception = { }; |
| 4424 | int err; |
| 4425 | |
| 4426 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4427 | /* Cache the lock if possible... */ |
| 4428 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4429 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4430 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4431 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4432 | break; |
| 4433 | nfs4_handle_exception(server, err, &exception); |
| 4434 | } while (exception.retry); |
| 4435 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | } |
| 4437 | |
| 4438 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4439 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4440 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4441 | struct nfs4_exception exception = { }; |
| 4442 | int err; |
| 4443 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4444 | err = nfs4_set_lock_state(state, request); |
| 4445 | if (err != 0) |
| 4446 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4447 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4448 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4449 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4450 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4451 | switch (err) { |
| 4452 | default: |
| 4453 | goto out; |
| 4454 | case -NFS4ERR_GRACE: |
| 4455 | case -NFS4ERR_DELAY: |
| 4456 | nfs4_handle_exception(server, err, &exception); |
| 4457 | err = 0; |
| 4458 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4459 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4460 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4461 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | } |
| 4463 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4464 | #if defined(CONFIG_NFS_V4_1) |
| 4465 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4466 | { |
| 4467 | int status; |
| 4468 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4469 | |
| 4470 | status = nfs41_test_stateid(server, state); |
| 4471 | if (status == NFS_OK) |
| 4472 | return 0; |
| 4473 | nfs41_free_stateid(server, state); |
| 4474 | return nfs4_lock_expired(state, request); |
| 4475 | } |
| 4476 | #endif |
| 4477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4479 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4480 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4481 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4482 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4484 | if ((fl_flags & FL_POSIX) && |
| 4485 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4486 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4487 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4488 | status = nfs4_set_lock_state(state, request); |
| 4489 | if (status != 0) |
| 4490 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4491 | request->fl_flags |= FL_ACCESS; |
| 4492 | status = do_vfs_lock(request->fl_file, request); |
| 4493 | if (status < 0) |
| 4494 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4495 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4496 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4497 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4498 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4499 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4500 | status = do_vfs_lock(request->fl_file, request); |
| 4501 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4502 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4503 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4504 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4505 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4506 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4507 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4508 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4509 | 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] | 4510 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4511 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4512 | out: |
| 4513 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4514 | return status; |
| 4515 | } |
| 4516 | |
| 4517 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4518 | { |
| 4519 | struct nfs4_exception exception = { }; |
| 4520 | int err; |
| 4521 | |
| 4522 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4523 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4524 | if (err == -NFS4ERR_DENIED) |
| 4525 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4527 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4528 | } while (exception.retry); |
| 4529 | return err; |
| 4530 | } |
| 4531 | |
| 4532 | static int |
| 4533 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4534 | { |
| 4535 | struct nfs_open_context *ctx; |
| 4536 | struct nfs4_state *state; |
| 4537 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4538 | int status; |
| 4539 | |
| 4540 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4541 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | state = ctx->state; |
| 4543 | |
| 4544 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4545 | return -EINVAL; |
| 4546 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4547 | if (IS_GETLK(cmd)) { |
| 4548 | if (state != NULL) |
| 4549 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4550 | return 0; |
| 4551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | |
| 4553 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4554 | return -EINVAL; |
| 4555 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4556 | if (request->fl_type == F_UNLCK) { |
| 4557 | if (state != NULL) |
| 4558 | return nfs4_proc_unlck(state, cmd, request); |
| 4559 | return 0; |
| 4560 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4562 | if (state == NULL) |
| 4563 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | do { |
| 4565 | status = nfs4_proc_setlk(state, cmd, request); |
| 4566 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4567 | break; |
| 4568 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4569 | status = -ERESTARTSYS; |
| 4570 | if (signalled()) |
| 4571 | break; |
| 4572 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | return status; |
| 4574 | } |
| 4575 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4576 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4577 | { |
| 4578 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4579 | struct nfs4_exception exception = { }; |
| 4580 | int err; |
| 4581 | |
| 4582 | err = nfs4_set_lock_state(state, fl); |
| 4583 | if (err != 0) |
| 4584 | goto out; |
| 4585 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4586 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4587 | switch (err) { |
| 4588 | default: |
| 4589 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4590 | __func__, err); |
| 4591 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4592 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4593 | goto out; |
| 4594 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4595 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4596 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4597 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4598 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4599 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4600 | case -NFS4ERR_BADSESSION: |
| 4601 | case -NFS4ERR_BADSLOT: |
| 4602 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4603 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4604 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4605 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4606 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4607 | case -ERESTARTSYS: |
| 4608 | /* |
| 4609 | * The show must go on: exit, but mark the |
| 4610 | * stateid as needing recovery. |
| 4611 | */ |
| 4612 | case -NFS4ERR_ADMIN_REVOKED: |
| 4613 | case -NFS4ERR_BAD_STATEID: |
| 4614 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4615 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4616 | err = 0; |
| 4617 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4618 | case -EKEYEXPIRED: |
| 4619 | /* |
| 4620 | * User RPCSEC_GSS context has expired. |
| 4621 | * We cannot recover this stateid now, so |
| 4622 | * skip it and allow recovery thread to |
| 4623 | * proceed. |
| 4624 | */ |
| 4625 | err = 0; |
| 4626 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4627 | case -ENOMEM: |
| 4628 | case -NFS4ERR_DENIED: |
| 4629 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4630 | err = 0; |
| 4631 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4632 | case -NFS4ERR_DELAY: |
| 4633 | break; |
| 4634 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4635 | err = nfs4_handle_exception(server, err, &exception); |
| 4636 | } while (exception.retry); |
| 4637 | out: |
| 4638 | return err; |
| 4639 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4640 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4641 | static void nfs4_release_lockowner_release(void *calldata) |
| 4642 | { |
| 4643 | kfree(calldata); |
| 4644 | } |
| 4645 | |
| 4646 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4647 | .rpc_release = nfs4_release_lockowner_release, |
| 4648 | }; |
| 4649 | |
| 4650 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4651 | { |
| 4652 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4653 | struct nfs_release_lockowner_args *args; |
| 4654 | struct rpc_message msg = { |
| 4655 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4656 | }; |
| 4657 | |
| 4658 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4659 | return; |
| 4660 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4661 | if (!args) |
| 4662 | return; |
| 4663 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4664 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4665 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4666 | msg.rpc_argp = args; |
| 4667 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4668 | } |
| 4669 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4670 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4671 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4672 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4673 | const void *buf, size_t buflen, |
| 4674 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4675 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4676 | if (strcmp(key, "") != 0) |
| 4677 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4678 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4679 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4680 | } |
| 4681 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4682 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4683 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4684 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4685 | if (strcmp(key, "") != 0) |
| 4686 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4687 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4688 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4691 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4692 | size_t list_len, const char *name, |
| 4693 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4694 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4695 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4696 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4697 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4698 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4699 | |
| 4700 | if (list && len <= list_len) |
| 4701 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4702 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4703 | } |
| 4704 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4705 | /* |
| 4706 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4707 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4708 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4709 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4710 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4711 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4712 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4713 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4714 | return; |
| 4715 | |
| 4716 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4717 | NFS_ATTR_FATTR_NLINK; |
| 4718 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4719 | fattr->nlink = 2; |
| 4720 | } |
| 4721 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4722 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4723 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4724 | { |
| 4725 | struct nfs_server *server = NFS_SERVER(dir); |
| 4726 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4727 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4728 | }; |
| 4729 | struct nfs4_fs_locations_arg args = { |
| 4730 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4731 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4732 | .page = page, |
| 4733 | .bitmask = bitmask, |
| 4734 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4735 | struct nfs4_fs_locations_res res = { |
| 4736 | .fs_locations = fs_locations, |
| 4737 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4738 | struct rpc_message msg = { |
| 4739 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4740 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4741 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4742 | }; |
| 4743 | int status; |
| 4744 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4745 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4746 | |
| 4747 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 4748 | * is not supported */ |
| 4749 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 4750 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 4751 | else |
| 4752 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 4753 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4754 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4755 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4756 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4757 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4758 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4759 | return status; |
| 4760 | } |
| 4761 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4762 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4763 | { |
| 4764 | int status; |
| 4765 | struct nfs4_secinfo_arg args = { |
| 4766 | .dir_fh = NFS_FH(dir), |
| 4767 | .name = name, |
| 4768 | }; |
| 4769 | struct nfs4_secinfo_res res = { |
| 4770 | .flavors = flavors, |
| 4771 | }; |
| 4772 | struct rpc_message msg = { |
| 4773 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4774 | .rpc_argp = &args, |
| 4775 | .rpc_resp = &res, |
| 4776 | }; |
| 4777 | |
| 4778 | dprintk("NFS call secinfo %s\n", name->name); |
| 4779 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4780 | dprintk("NFS reply secinfo: %d\n", status); |
| 4781 | return status; |
| 4782 | } |
| 4783 | |
| 4784 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4785 | { |
| 4786 | struct nfs4_exception exception = { }; |
| 4787 | int err; |
| 4788 | do { |
| 4789 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4790 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4791 | &exception); |
| 4792 | } while (exception.retry); |
| 4793 | return err; |
| 4794 | } |
| 4795 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4796 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4797 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4798 | * Check the exchange flags returned by the server for invalid flags, having |
| 4799 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4800 | * DS flags set. |
| 4801 | */ |
| 4802 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4803 | { |
| 4804 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4805 | goto out_inval; |
| 4806 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4807 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4808 | goto out_inval; |
| 4809 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4810 | goto out_inval; |
| 4811 | return NFS_OK; |
| 4812 | out_inval: |
| 4813 | return -NFS4ERR_INVAL; |
| 4814 | } |
| 4815 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4816 | static bool |
| 4817 | nfs41_same_server_scope(struct server_scope *a, struct server_scope *b) |
| 4818 | { |
| 4819 | if (a->server_scope_sz == b->server_scope_sz && |
| 4820 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 4821 | return true; |
| 4822 | |
| 4823 | return false; |
| 4824 | } |
| 4825 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4826 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4827 | * nfs4_proc_exchange_id() |
| 4828 | * |
| 4829 | * Since the clientid has expired, all compounds using sessions |
| 4830 | * associated with the stale clientid will be returning |
| 4831 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4832 | * be in some phase of session reset. |
| 4833 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4834 | 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] | 4835 | { |
| 4836 | nfs4_verifier verifier; |
| 4837 | struct nfs41_exchange_id_args args = { |
| 4838 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4839 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4840 | }; |
| 4841 | struct nfs41_exchange_id_res res = { |
| 4842 | .client = clp, |
| 4843 | }; |
| 4844 | int status; |
| 4845 | struct rpc_message msg = { |
| 4846 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4847 | .rpc_argp = &args, |
| 4848 | .rpc_resp = &res, |
| 4849 | .rpc_cred = cred, |
| 4850 | }; |
| 4851 | __be32 *p; |
| 4852 | |
| 4853 | dprintk("--> %s\n", __func__); |
| 4854 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4855 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4856 | p = (u32 *)verifier.data; |
| 4857 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4858 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4859 | args.verifier = &verifier; |
| 4860 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4861 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4862 | "%s/%s.%s/%u", |
| 4863 | clp->cl_ipaddr, |
| 4864 | init_utsname()->nodename, |
| 4865 | init_utsname()->domainname, |
| 4866 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4867 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4868 | res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); |
| 4869 | if (unlikely(!res.server_scope)) |
| 4870 | return -ENOMEM; |
| 4871 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4872 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4873 | if (!status) |
| 4874 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4875 | |
| 4876 | if (!status) { |
| 4877 | if (clp->server_scope && |
| 4878 | !nfs41_same_server_scope(clp->server_scope, |
| 4879 | res.server_scope)) { |
| 4880 | dprintk("%s: server_scope mismatch detected\n", |
| 4881 | __func__); |
| 4882 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 4883 | kfree(clp->server_scope); |
| 4884 | clp->server_scope = NULL; |
| 4885 | } |
| 4886 | |
| 4887 | if (!clp->server_scope) |
| 4888 | clp->server_scope = res.server_scope; |
| 4889 | else |
| 4890 | kfree(res.server_scope); |
| 4891 | } |
| 4892 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4893 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4894 | return status; |
| 4895 | } |
| 4896 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4897 | struct nfs4_get_lease_time_data { |
| 4898 | struct nfs4_get_lease_time_args *args; |
| 4899 | struct nfs4_get_lease_time_res *res; |
| 4900 | struct nfs_client *clp; |
| 4901 | }; |
| 4902 | |
| 4903 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4904 | void *calldata) |
| 4905 | { |
| 4906 | int ret; |
| 4907 | struct nfs4_get_lease_time_data *data = |
| 4908 | (struct nfs4_get_lease_time_data *)calldata; |
| 4909 | |
| 4910 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4911 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4912 | /* just setup sequence, do not trigger session recovery |
| 4913 | since we're invoked within one */ |
| 4914 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4915 | &data->args->la_seq_args, |
| 4916 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4917 | |
| 4918 | BUG_ON(ret == -EAGAIN); |
| 4919 | rpc_call_start(task); |
| 4920 | dprintk("<-- %s\n", __func__); |
| 4921 | } |
| 4922 | |
| 4923 | /* |
| 4924 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4925 | * from sequence operation or clientid errors. |
| 4926 | */ |
| 4927 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4928 | { |
| 4929 | struct nfs4_get_lease_time_data *data = |
| 4930 | (struct nfs4_get_lease_time_data *)calldata; |
| 4931 | |
| 4932 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4933 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4934 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4935 | switch (task->tk_status) { |
| 4936 | case -NFS4ERR_DELAY: |
| 4937 | case -NFS4ERR_GRACE: |
| 4938 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4939 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4940 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4941 | /* fall through */ |
| 4942 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4943 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4944 | return; |
| 4945 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4946 | dprintk("<-- %s\n", __func__); |
| 4947 | } |
| 4948 | |
| 4949 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4950 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4951 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4952 | }; |
| 4953 | |
| 4954 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4955 | { |
| 4956 | struct rpc_task *task; |
| 4957 | struct nfs4_get_lease_time_args args; |
| 4958 | struct nfs4_get_lease_time_res res = { |
| 4959 | .lr_fsinfo = fsinfo, |
| 4960 | }; |
| 4961 | struct nfs4_get_lease_time_data data = { |
| 4962 | .args = &args, |
| 4963 | .res = &res, |
| 4964 | .clp = clp, |
| 4965 | }; |
| 4966 | struct rpc_message msg = { |
| 4967 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4968 | .rpc_argp = &args, |
| 4969 | .rpc_resp = &res, |
| 4970 | }; |
| 4971 | struct rpc_task_setup task_setup = { |
| 4972 | .rpc_client = clp->cl_rpcclient, |
| 4973 | .rpc_message = &msg, |
| 4974 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4975 | .callback_data = &data, |
| 4976 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4977 | }; |
| 4978 | int status; |
| 4979 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4980 | dprintk("--> %s\n", __func__); |
| 4981 | task = rpc_run_task(&task_setup); |
| 4982 | |
| 4983 | if (IS_ERR(task)) |
| 4984 | status = PTR_ERR(task); |
| 4985 | else { |
| 4986 | status = task->tk_status; |
| 4987 | rpc_put_task(task); |
| 4988 | } |
| 4989 | dprintk("<-- %s return %d\n", __func__, status); |
| 4990 | |
| 4991 | return status; |
| 4992 | } |
| 4993 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4994 | /* |
| 4995 | * Reset a slot table |
| 4996 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4997 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4998 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4999 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5000 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5001 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5002 | int ret = 0; |
| 5003 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5004 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5005 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5006 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5007 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5008 | if (max_reqs != tbl->max_slots) { |
| 5009 | ret = -ENOMEM; |
| 5010 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5011 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5012 | if (!new) |
| 5013 | goto out; |
| 5014 | ret = 0; |
| 5015 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5016 | } |
| 5017 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5018 | if (new) { |
| 5019 | tbl->slots = new; |
| 5020 | tbl->max_slots = max_reqs; |
| 5021 | } |
| 5022 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5023 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5024 | spin_unlock(&tbl->slot_tbl_lock); |
| 5025 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5026 | tbl, tbl->slots, tbl->max_slots); |
| 5027 | out: |
| 5028 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5029 | return ret; |
| 5030 | } |
| 5031 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5032 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5033 | * Reset the forechannel and backchannel slot tables |
| 5034 | */ |
| 5035 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 5036 | { |
| 5037 | int status; |
| 5038 | |
| 5039 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5040 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5041 | if (status) |
| 5042 | return status; |
| 5043 | |
| 5044 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5045 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5046 | return status; |
| 5047 | } |
| 5048 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5049 | /* Destroy the slot table */ |
| 5050 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5051 | { |
| 5052 | if (session->fc_slot_table.slots != NULL) { |
| 5053 | kfree(session->fc_slot_table.slots); |
| 5054 | session->fc_slot_table.slots = NULL; |
| 5055 | } |
| 5056 | if (session->bc_slot_table.slots != NULL) { |
| 5057 | kfree(session->bc_slot_table.slots); |
| 5058 | session->bc_slot_table.slots = NULL; |
| 5059 | } |
| 5060 | return; |
| 5061 | } |
| 5062 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5063 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5064 | * Initialize slot table |
| 5065 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5066 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 5067 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5068 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5069 | struct nfs4_slot *slot; |
| 5070 | int ret = -ENOMEM; |
| 5071 | |
| 5072 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 5073 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5074 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5075 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5076 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5077 | if (!slot) |
| 5078 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5079 | ret = 0; |
| 5080 | |
| 5081 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5082 | tbl->max_slots = max_slots; |
| 5083 | tbl->slots = slot; |
| 5084 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5085 | spin_unlock(&tbl->slot_tbl_lock); |
| 5086 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5087 | tbl, tbl->slots, tbl->max_slots); |
| 5088 | out: |
| 5089 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5090 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5091 | } |
| 5092 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5093 | /* |
| 5094 | * Initialize the forechannel and backchannel tables |
| 5095 | */ |
| 5096 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 5097 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5098 | struct nfs4_slot_table *tbl; |
| 5099 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5100 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5101 | tbl = &session->fc_slot_table; |
| 5102 | if (tbl->slots == NULL) { |
| 5103 | status = nfs4_init_slot_table(tbl, |
| 5104 | session->fc_attrs.max_reqs, 1); |
| 5105 | if (status) |
| 5106 | return status; |
| 5107 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5108 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5109 | tbl = &session->bc_slot_table; |
| 5110 | if (tbl->slots == NULL) { |
| 5111 | status = nfs4_init_slot_table(tbl, |
| 5112 | session->bc_attrs.max_reqs, 0); |
| 5113 | if (status) |
| 5114 | nfs4_destroy_slot_tables(session); |
| 5115 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5116 | |
| 5117 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5118 | } |
| 5119 | |
| 5120 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5121 | { |
| 5122 | struct nfs4_session *session; |
| 5123 | struct nfs4_slot_table *tbl; |
| 5124 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5125 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5126 | if (!session) |
| 5127 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5128 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5129 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5130 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5131 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5132 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5133 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5134 | |
| 5135 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5136 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5137 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5138 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5139 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5140 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5141 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5142 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5143 | session->clp = clp; |
| 5144 | return session; |
| 5145 | } |
| 5146 | |
| 5147 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5148 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5149 | nfs4_proc_destroy_session(session); |
| 5150 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 5151 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 5152 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 5153 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5154 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5155 | kfree(session); |
| 5156 | } |
| 5157 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5158 | /* |
| 5159 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5160 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5161 | * use them. |
| 5162 | * |
| 5163 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5164 | * always set csa_cachethis to FALSE because the current implementation |
| 5165 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5166 | */ |
| 5167 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5168 | { |
| 5169 | struct nfs4_session *session = args->client->cl_session; |
| 5170 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5171 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5172 | |
| 5173 | if (mxrqst_sz == 0) |
| 5174 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5175 | if (mxresp_sz == 0) |
| 5176 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5177 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5178 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5179 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5180 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 5181 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 5182 | |
| 5183 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5184 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5185 | __func__, |
| 5186 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5187 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5188 | |
| 5189 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5190 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5191 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5192 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5193 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5194 | args->bc_attrs.max_reqs = 1; |
| 5195 | |
| 5196 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5197 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5198 | __func__, |
| 5199 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5200 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5201 | args->bc_attrs.max_reqs); |
| 5202 | } |
| 5203 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5204 | 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] | 5205 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5206 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5207 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5208 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5209 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5210 | return -EINVAL; |
| 5211 | /* |
| 5212 | * Our requested max_ops is the minimum we need; we're not |
| 5213 | * prepared to break up compounds into smaller pieces than that. |
| 5214 | * So, no point even trying to continue if the server won't |
| 5215 | * cooperate: |
| 5216 | */ |
| 5217 | if (rcvd->max_ops < sent->max_ops) |
| 5218 | return -EINVAL; |
| 5219 | if (rcvd->max_reqs == 0) |
| 5220 | return -EINVAL; |
| 5221 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5222 | } |
| 5223 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5224 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5225 | { |
| 5226 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5227 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5228 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5229 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5230 | return -EINVAL; |
| 5231 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5232 | return -EINVAL; |
| 5233 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5234 | return -EINVAL; |
| 5235 | /* These would render the backchannel useless: */ |
| 5236 | if (rcvd->max_ops == 0) |
| 5237 | return -EINVAL; |
| 5238 | if (rcvd->max_reqs == 0) |
| 5239 | return -EINVAL; |
| 5240 | return 0; |
| 5241 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5242 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5243 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5244 | struct nfs4_session *session) |
| 5245 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5246 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5247 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5248 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5249 | if (ret) |
| 5250 | return ret; |
| 5251 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5252 | } |
| 5253 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5254 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5255 | { |
| 5256 | struct nfs4_session *session = clp->cl_session; |
| 5257 | struct nfs41_create_session_args args = { |
| 5258 | .client = clp, |
| 5259 | .cb_program = NFS4_CALLBACK, |
| 5260 | }; |
| 5261 | struct nfs41_create_session_res res = { |
| 5262 | .client = clp, |
| 5263 | }; |
| 5264 | struct rpc_message msg = { |
| 5265 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5266 | .rpc_argp = &args, |
| 5267 | .rpc_resp = &res, |
| 5268 | }; |
| 5269 | int status; |
| 5270 | |
| 5271 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5272 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5273 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5274 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5275 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5276 | if (!status) |
| 5277 | /* Verify the session's negotiated channel_attrs values */ |
| 5278 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5279 | if (!status) { |
| 5280 | /* Increment the clientid slot sequence id */ |
| 5281 | clp->cl_seqid++; |
| 5282 | } |
| 5283 | |
| 5284 | return status; |
| 5285 | } |
| 5286 | |
| 5287 | /* |
| 5288 | * Issues a CREATE_SESSION operation to the server. |
| 5289 | * It is the responsibility of the caller to verify the session is |
| 5290 | * expired before calling this routine. |
| 5291 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5292 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5293 | { |
| 5294 | int status; |
| 5295 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5296 | struct nfs4_session *session = clp->cl_session; |
| 5297 | |
| 5298 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5299 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5300 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5301 | if (status) |
| 5302 | goto out; |
| 5303 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5304 | /* Init and reset the fore channel */ |
| 5305 | status = nfs4_init_slot_tables(session); |
| 5306 | dprintk("slot table initialization returned %d\n", status); |
| 5307 | if (status) |
| 5308 | goto out; |
| 5309 | status = nfs4_reset_slot_tables(session); |
| 5310 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5311 | if (status) |
| 5312 | goto out; |
| 5313 | |
| 5314 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5315 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5316 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5317 | out: |
| 5318 | dprintk("<-- %s\n", __func__); |
| 5319 | return status; |
| 5320 | } |
| 5321 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5322 | /* |
| 5323 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5324 | * The caller must serialize access to this routine. |
| 5325 | */ |
| 5326 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5327 | { |
| 5328 | int status = 0; |
| 5329 | struct rpc_message msg; |
| 5330 | |
| 5331 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5332 | |
| 5333 | /* session is still being setup */ |
| 5334 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5335 | return status; |
| 5336 | |
| 5337 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5338 | msg.rpc_argp = session; |
| 5339 | msg.rpc_resp = NULL; |
| 5340 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5341 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5342 | |
| 5343 | if (status) |
| 5344 | printk(KERN_WARNING |
| 5345 | "Got error %d from the server on DESTROY_SESSION. " |
| 5346 | "Session has been destroyed regardless...\n", status); |
| 5347 | |
| 5348 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5349 | return status; |
| 5350 | } |
| 5351 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5352 | int nfs4_init_session(struct nfs_server *server) |
| 5353 | { |
| 5354 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5355 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5356 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5357 | int ret; |
| 5358 | |
| 5359 | if (!nfs4_has_session(clp)) |
| 5360 | return 0; |
| 5361 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5362 | session = clp->cl_session; |
| 5363 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5364 | return 0; |
| 5365 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5366 | rsize = server->rsize; |
| 5367 | if (rsize == 0) |
| 5368 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5369 | wsize = server->wsize; |
| 5370 | if (wsize == 0) |
| 5371 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5372 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5373 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5374 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5375 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5376 | ret = nfs4_recover_expired_lease(server); |
| 5377 | if (!ret) |
| 5378 | ret = nfs4_check_client_ready(clp); |
| 5379 | return ret; |
| 5380 | } |
| 5381 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5382 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5383 | { |
| 5384 | struct nfs4_session *session = clp->cl_session; |
| 5385 | int ret; |
| 5386 | |
| 5387 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5388 | return 0; |
| 5389 | |
| 5390 | ret = nfs4_client_recover_expired_lease(clp); |
| 5391 | if (!ret) |
| 5392 | /* Test for the DS role */ |
| 5393 | if (!is_ds_client(clp)) |
| 5394 | ret = -ENODEV; |
| 5395 | if (!ret) |
| 5396 | ret = nfs4_check_client_ready(clp); |
| 5397 | return ret; |
| 5398 | |
| 5399 | } |
| 5400 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5401 | |
| 5402 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5403 | /* |
| 5404 | * Renew the cl_session lease. |
| 5405 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5406 | struct nfs4_sequence_data { |
| 5407 | struct nfs_client *clp; |
| 5408 | struct nfs4_sequence_args args; |
| 5409 | struct nfs4_sequence_res res; |
| 5410 | }; |
| 5411 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5412 | static void nfs41_sequence_release(void *data) |
| 5413 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5414 | struct nfs4_sequence_data *calldata = data; |
| 5415 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5416 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5417 | if (atomic_read(&clp->cl_count) > 1) |
| 5418 | nfs4_schedule_state_renewal(clp); |
| 5419 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5420 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5421 | } |
| 5422 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5423 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5424 | { |
| 5425 | switch(task->tk_status) { |
| 5426 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5427 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5428 | return -EAGAIN; |
| 5429 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5430 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5431 | } |
| 5432 | return 0; |
| 5433 | } |
| 5434 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5435 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5436 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5437 | struct nfs4_sequence_data *calldata = data; |
| 5438 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5439 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5440 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5441 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5442 | |
| 5443 | if (task->tk_status < 0) { |
| 5444 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5445 | if (atomic_read(&clp->cl_count) == 1) |
| 5446 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5447 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5448 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5449 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5450 | return; |
| 5451 | } |
| 5452 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5453 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5454 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5455 | dprintk("<-- %s\n", __func__); |
| 5456 | } |
| 5457 | |
| 5458 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5459 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5460 | struct nfs4_sequence_data *calldata = data; |
| 5461 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5462 | struct nfs4_sequence_args *args; |
| 5463 | struct nfs4_sequence_res *res; |
| 5464 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5465 | args = task->tk_msg.rpc_argp; |
| 5466 | res = task->tk_msg.rpc_resp; |
| 5467 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5468 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5469 | return; |
| 5470 | rpc_call_start(task); |
| 5471 | } |
| 5472 | |
| 5473 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5474 | .rpc_call_done = nfs41_sequence_call_done, |
| 5475 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5476 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5477 | }; |
| 5478 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5479 | 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] | 5480 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5481 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5482 | struct rpc_message msg = { |
| 5483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5484 | .rpc_cred = cred, |
| 5485 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5486 | struct rpc_task_setup task_setup_data = { |
| 5487 | .rpc_client = clp->cl_rpcclient, |
| 5488 | .rpc_message = &msg, |
| 5489 | .callback_ops = &nfs41_sequence_ops, |
| 5490 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5491 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5492 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5493 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5494 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5495 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5496 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5497 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5498 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5499 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5500 | msg.rpc_argp = &calldata->args; |
| 5501 | msg.rpc_resp = &calldata->res; |
| 5502 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5503 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5504 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5505 | return rpc_run_task(&task_setup_data); |
| 5506 | } |
| 5507 | |
| 5508 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5509 | { |
| 5510 | struct rpc_task *task; |
| 5511 | int ret = 0; |
| 5512 | |
| 5513 | task = _nfs41_proc_sequence(clp, cred); |
| 5514 | if (IS_ERR(task)) |
| 5515 | ret = PTR_ERR(task); |
| 5516 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5517 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5518 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5519 | return ret; |
| 5520 | } |
| 5521 | |
| 5522 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5523 | { |
| 5524 | struct rpc_task *task; |
| 5525 | int ret; |
| 5526 | |
| 5527 | task = _nfs41_proc_sequence(clp, cred); |
| 5528 | if (IS_ERR(task)) { |
| 5529 | ret = PTR_ERR(task); |
| 5530 | goto out; |
| 5531 | } |
| 5532 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5533 | if (!ret) { |
| 5534 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5535 | |
| 5536 | if (task->tk_status == 0) |
| 5537 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5538 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5539 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5540 | rpc_put_task(task); |
| 5541 | out: |
| 5542 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5543 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5544 | } |
| 5545 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5546 | struct nfs4_reclaim_complete_data { |
| 5547 | struct nfs_client *clp; |
| 5548 | struct nfs41_reclaim_complete_args arg; |
| 5549 | struct nfs41_reclaim_complete_res res; |
| 5550 | }; |
| 5551 | |
| 5552 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5553 | { |
| 5554 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5555 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5556 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5557 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5558 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5559 | &calldata->res.seq_res, 0, task)) |
| 5560 | return; |
| 5561 | |
| 5562 | rpc_call_start(task); |
| 5563 | } |
| 5564 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5565 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5566 | { |
| 5567 | switch(task->tk_status) { |
| 5568 | case 0: |
| 5569 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5570 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5571 | break; |
| 5572 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5573 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5574 | /* fall through */ |
| 5575 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5576 | return -EAGAIN; |
| 5577 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5578 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5579 | } |
| 5580 | return 0; |
| 5581 | } |
| 5582 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5583 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5584 | { |
| 5585 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5586 | struct nfs_client *clp = calldata->clp; |
| 5587 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5588 | |
| 5589 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5590 | if (!nfs41_sequence_done(task, res)) |
| 5591 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5592 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5593 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5594 | rpc_restart_call_prepare(task); |
| 5595 | return; |
| 5596 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5597 | dprintk("<-- %s\n", __func__); |
| 5598 | } |
| 5599 | |
| 5600 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5601 | { |
| 5602 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5603 | |
| 5604 | kfree(calldata); |
| 5605 | } |
| 5606 | |
| 5607 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5608 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5609 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5610 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5611 | }; |
| 5612 | |
| 5613 | /* |
| 5614 | * Issue a global reclaim complete. |
| 5615 | */ |
| 5616 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5617 | { |
| 5618 | struct nfs4_reclaim_complete_data *calldata; |
| 5619 | struct rpc_task *task; |
| 5620 | struct rpc_message msg = { |
| 5621 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5622 | }; |
| 5623 | struct rpc_task_setup task_setup_data = { |
| 5624 | .rpc_client = clp->cl_rpcclient, |
| 5625 | .rpc_message = &msg, |
| 5626 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5627 | .flags = RPC_TASK_ASYNC, |
| 5628 | }; |
| 5629 | int status = -ENOMEM; |
| 5630 | |
| 5631 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5632 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5633 | if (calldata == NULL) |
| 5634 | goto out; |
| 5635 | calldata->clp = clp; |
| 5636 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5637 | |
| 5638 | msg.rpc_argp = &calldata->arg; |
| 5639 | msg.rpc_resp = &calldata->res; |
| 5640 | task_setup_data.callback_data = calldata; |
| 5641 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5642 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5643 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5644 | goto out; |
| 5645 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5646 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5647 | if (status == 0) |
| 5648 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5649 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5650 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5651 | out: |
| 5652 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5653 | return status; |
| 5654 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5655 | |
| 5656 | static void |
| 5657 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5658 | { |
| 5659 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5660 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5661 | |
| 5662 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5663 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5664 | * right now covering the LAYOUTGET we are about to send. |
| 5665 | * However, that is not so catastrophic, and there seems |
| 5666 | * to be no way to prevent it completely. |
| 5667 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5668 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5669 | &lgp->res.seq_res, 0, task)) |
| 5670 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5671 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5672 | NFS_I(lgp->args.inode)->layout, |
| 5673 | lgp->args.ctx->state)) { |
| 5674 | rpc_exit(task, NFS4_OK); |
| 5675 | return; |
| 5676 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5677 | rpc_call_start(task); |
| 5678 | } |
| 5679 | |
| 5680 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5681 | { |
| 5682 | struct nfs4_layoutget *lgp = calldata; |
| 5683 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5684 | |
| 5685 | dprintk("--> %s\n", __func__); |
| 5686 | |
| 5687 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5688 | return; |
| 5689 | |
| 5690 | switch (task->tk_status) { |
| 5691 | case 0: |
| 5692 | break; |
| 5693 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5694 | case -NFS4ERR_RECALLCONFLICT: |
| 5695 | task->tk_status = -NFS4ERR_DELAY; |
| 5696 | /* Fall through */ |
| 5697 | default: |
| 5698 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5699 | rpc_restart_call_prepare(task); |
| 5700 | return; |
| 5701 | } |
| 5702 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5703 | dprintk("<-- %s\n", __func__); |
| 5704 | } |
| 5705 | |
| 5706 | static void nfs4_layoutget_release(void *calldata) |
| 5707 | { |
| 5708 | struct nfs4_layoutget *lgp = calldata; |
| 5709 | |
| 5710 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5711 | put_nfs_open_context(lgp->args.ctx); |
| 5712 | kfree(calldata); |
| 5713 | dprintk("<-- %s\n", __func__); |
| 5714 | } |
| 5715 | |
| 5716 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5717 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5718 | .rpc_call_done = nfs4_layoutget_done, |
| 5719 | .rpc_release = nfs4_layoutget_release, |
| 5720 | }; |
| 5721 | |
| 5722 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5723 | { |
| 5724 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5725 | struct rpc_task *task; |
| 5726 | struct rpc_message msg = { |
| 5727 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5728 | .rpc_argp = &lgp->args, |
| 5729 | .rpc_resp = &lgp->res, |
| 5730 | }; |
| 5731 | struct rpc_task_setup task_setup_data = { |
| 5732 | .rpc_client = server->client, |
| 5733 | .rpc_message = &msg, |
| 5734 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5735 | .callback_data = lgp, |
| 5736 | .flags = RPC_TASK_ASYNC, |
| 5737 | }; |
| 5738 | int status = 0; |
| 5739 | |
| 5740 | dprintk("--> %s\n", __func__); |
| 5741 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5742 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5743 | lgp->res.seq_res.sr_slot = NULL; |
| 5744 | task = rpc_run_task(&task_setup_data); |
| 5745 | if (IS_ERR(task)) |
| 5746 | return PTR_ERR(task); |
| 5747 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5748 | if (status == 0) |
| 5749 | status = task->tk_status; |
| 5750 | if (status == 0) |
| 5751 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5752 | rpc_put_task(task); |
| 5753 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5754 | return status; |
| 5755 | } |
| 5756 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5757 | static void |
| 5758 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 5759 | { |
| 5760 | struct nfs4_layoutreturn *lrp = calldata; |
| 5761 | |
| 5762 | dprintk("--> %s\n", __func__); |
| 5763 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
| 5764 | &lrp->res.seq_res, 0, task)) |
| 5765 | return; |
| 5766 | rpc_call_start(task); |
| 5767 | } |
| 5768 | |
| 5769 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 5770 | { |
| 5771 | struct nfs4_layoutreturn *lrp = calldata; |
| 5772 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame^] | 5773 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5774 | |
| 5775 | dprintk("--> %s\n", __func__); |
| 5776 | |
| 5777 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 5778 | return; |
| 5779 | |
| 5780 | server = NFS_SERVER(lrp->args.inode); |
| 5781 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5782 | nfs_restart_rpc(task, lrp->clp); |
| 5783 | return; |
| 5784 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5785 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5786 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5787 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5788 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5789 | } else |
| 5790 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 5791 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5792 | lo->plh_block_lgets--; |
| 5793 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5794 | dprintk("<-- %s\n", __func__); |
| 5795 | } |
| 5796 | |
| 5797 | static void nfs4_layoutreturn_release(void *calldata) |
| 5798 | { |
| 5799 | struct nfs4_layoutreturn *lrp = calldata; |
| 5800 | |
| 5801 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame^] | 5802 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5803 | kfree(calldata); |
| 5804 | dprintk("<-- %s\n", __func__); |
| 5805 | } |
| 5806 | |
| 5807 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 5808 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 5809 | .rpc_call_done = nfs4_layoutreturn_done, |
| 5810 | .rpc_release = nfs4_layoutreturn_release, |
| 5811 | }; |
| 5812 | |
| 5813 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 5814 | { |
| 5815 | struct rpc_task *task; |
| 5816 | struct rpc_message msg = { |
| 5817 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 5818 | .rpc_argp = &lrp->args, |
| 5819 | .rpc_resp = &lrp->res, |
| 5820 | }; |
| 5821 | struct rpc_task_setup task_setup_data = { |
| 5822 | .rpc_client = lrp->clp->cl_rpcclient, |
| 5823 | .rpc_message = &msg, |
| 5824 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 5825 | .callback_data = lrp, |
| 5826 | }; |
| 5827 | int status; |
| 5828 | |
| 5829 | dprintk("--> %s\n", __func__); |
| 5830 | task = rpc_run_task(&task_setup_data); |
| 5831 | if (IS_ERR(task)) |
| 5832 | return PTR_ERR(task); |
| 5833 | status = task->tk_status; |
| 5834 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5835 | rpc_put_task(task); |
| 5836 | return status; |
| 5837 | } |
| 5838 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5839 | static int |
| 5840 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5841 | { |
| 5842 | struct nfs4_getdeviceinfo_args args = { |
| 5843 | .pdev = pdev, |
| 5844 | }; |
| 5845 | struct nfs4_getdeviceinfo_res res = { |
| 5846 | .pdev = pdev, |
| 5847 | }; |
| 5848 | struct rpc_message msg = { |
| 5849 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5850 | .rpc_argp = &args, |
| 5851 | .rpc_resp = &res, |
| 5852 | }; |
| 5853 | int status; |
| 5854 | |
| 5855 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5856 | 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] | 5857 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5858 | |
| 5859 | return status; |
| 5860 | } |
| 5861 | |
| 5862 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5863 | { |
| 5864 | struct nfs4_exception exception = { }; |
| 5865 | int err; |
| 5866 | |
| 5867 | do { |
| 5868 | err = nfs4_handle_exception(server, |
| 5869 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5870 | &exception); |
| 5871 | } while (exception.retry); |
| 5872 | return err; |
| 5873 | } |
| 5874 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5875 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5876 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 5877 | { |
| 5878 | struct nfs4_layoutcommit_data *data = calldata; |
| 5879 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5880 | |
| 5881 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
| 5882 | &data->res.seq_res, 1, task)) |
| 5883 | return; |
| 5884 | rpc_call_start(task); |
| 5885 | } |
| 5886 | |
| 5887 | static void |
| 5888 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 5889 | { |
| 5890 | struct nfs4_layoutcommit_data *data = calldata; |
| 5891 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5892 | |
| 5893 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5894 | return; |
| 5895 | |
| 5896 | switch (task->tk_status) { /* Just ignore these failures */ |
| 5897 | case NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 5898 | case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 5899 | case NFS4ERR_BADLAYOUT: /* no layout */ |
| 5900 | case NFS4ERR_GRACE: /* loca_recalim always false */ |
| 5901 | task->tk_status = 0; |
| 5902 | } |
| 5903 | |
| 5904 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5905 | nfs_restart_rpc(task, server->nfs_client); |
| 5906 | return; |
| 5907 | } |
| 5908 | |
| 5909 | if (task->tk_status == 0) |
| 5910 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 5911 | data->res.fattr); |
| 5912 | } |
| 5913 | |
| 5914 | static void nfs4_layoutcommit_release(void *calldata) |
| 5915 | { |
| 5916 | struct nfs4_layoutcommit_data *data = calldata; |
| 5917 | |
| 5918 | /* Matched by references in pnfs_set_layoutcommit */ |
| 5919 | put_lseg(data->lseg); |
| 5920 | put_rpccred(data->cred); |
| 5921 | kfree(data); |
| 5922 | } |
| 5923 | |
| 5924 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 5925 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 5926 | .rpc_call_done = nfs4_layoutcommit_done, |
| 5927 | .rpc_release = nfs4_layoutcommit_release, |
| 5928 | }; |
| 5929 | |
| 5930 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5931 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5932 | { |
| 5933 | struct rpc_message msg = { |
| 5934 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 5935 | .rpc_argp = &data->args, |
| 5936 | .rpc_resp = &data->res, |
| 5937 | .rpc_cred = data->cred, |
| 5938 | }; |
| 5939 | struct rpc_task_setup task_setup_data = { |
| 5940 | .task = &data->task, |
| 5941 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 5942 | .rpc_message = &msg, |
| 5943 | .callback_ops = &nfs4_layoutcommit_ops, |
| 5944 | .callback_data = data, |
| 5945 | .flags = RPC_TASK_ASYNC, |
| 5946 | }; |
| 5947 | struct rpc_task *task; |
| 5948 | int status = 0; |
| 5949 | |
| 5950 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 5951 | "lbw: %llu inode %lu\n", |
| 5952 | data->task.tk_pid, sync, |
| 5953 | data->args.lastbytewritten, |
| 5954 | data->args.inode->i_ino); |
| 5955 | |
| 5956 | task = rpc_run_task(&task_setup_data); |
| 5957 | if (IS_ERR(task)) |
| 5958 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5959 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5960 | goto out; |
| 5961 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5962 | if (status != 0) |
| 5963 | goto out; |
| 5964 | status = task->tk_status; |
| 5965 | out: |
| 5966 | dprintk("%s: status %d\n", __func__, status); |
| 5967 | rpc_put_task(task); |
| 5968 | return status; |
| 5969 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 5970 | |
| 5971 | static int |
| 5972 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5973 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 5974 | { |
| 5975 | struct nfs41_secinfo_no_name_args args = { |
| 5976 | .style = SECINFO_STYLE_CURRENT_FH, |
| 5977 | }; |
| 5978 | struct nfs4_secinfo_res res = { |
| 5979 | .flavors = flavors, |
| 5980 | }; |
| 5981 | struct rpc_message msg = { |
| 5982 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 5983 | .rpc_argp = &args, |
| 5984 | .rpc_resp = &res, |
| 5985 | }; |
| 5986 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 5987 | } |
| 5988 | |
| 5989 | static int |
| 5990 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5991 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 5992 | { |
| 5993 | struct nfs4_exception exception = { }; |
| 5994 | int err; |
| 5995 | do { |
| 5996 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 5997 | switch (err) { |
| 5998 | case 0: |
| 5999 | case -NFS4ERR_WRONGSEC: |
| 6000 | case -NFS4ERR_NOTSUPP: |
| 6001 | break; |
| 6002 | default: |
| 6003 | err = nfs4_handle_exception(server, err, &exception); |
| 6004 | } |
| 6005 | } while (exception.retry); |
| 6006 | return err; |
| 6007 | } |
| 6008 | |
| 6009 | static int |
| 6010 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6011 | struct nfs_fsinfo *info) |
| 6012 | { |
| 6013 | int err; |
| 6014 | struct page *page; |
| 6015 | rpc_authflavor_t flavor; |
| 6016 | struct nfs4_secinfo_flavors *flavors; |
| 6017 | |
| 6018 | page = alloc_page(GFP_KERNEL); |
| 6019 | if (!page) { |
| 6020 | err = -ENOMEM; |
| 6021 | goto out; |
| 6022 | } |
| 6023 | |
| 6024 | flavors = page_address(page); |
| 6025 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6026 | |
| 6027 | /* |
| 6028 | * Fall back on "guess and check" method if |
| 6029 | * the server doesn't support SECINFO_NO_NAME |
| 6030 | */ |
| 6031 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6032 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6033 | goto out_freepage; |
| 6034 | } |
| 6035 | if (err) |
| 6036 | goto out_freepage; |
| 6037 | |
| 6038 | flavor = nfs_find_best_sec(flavors); |
| 6039 | if (err == 0) |
| 6040 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6041 | |
| 6042 | out_freepage: |
| 6043 | put_page(page); |
| 6044 | if (err == -EACCES) |
| 6045 | return -EPERM; |
| 6046 | out: |
| 6047 | return err; |
| 6048 | } |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6049 | static int _nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6050 | { |
| 6051 | int status; |
| 6052 | struct nfs41_test_stateid_args args = { |
| 6053 | .stateid = &state->stateid, |
| 6054 | }; |
| 6055 | struct nfs41_test_stateid_res res; |
| 6056 | struct rpc_message msg = { |
| 6057 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6058 | .rpc_argp = &args, |
| 6059 | .rpc_resp = &res, |
| 6060 | }; |
| 6061 | args.seq_args.sa_session = res.seq_res.sr_session = NULL; |
| 6062 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); |
| 6063 | return status; |
| 6064 | } |
| 6065 | |
| 6066 | static int nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6067 | { |
| 6068 | struct nfs4_exception exception = { }; |
| 6069 | int err; |
| 6070 | do { |
| 6071 | err = nfs4_handle_exception(server, |
| 6072 | _nfs41_test_stateid(server, state), |
| 6073 | &exception); |
| 6074 | } while (exception.retry); |
| 6075 | return err; |
| 6076 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6077 | |
| 6078 | static int _nfs4_free_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6079 | { |
| 6080 | int status; |
| 6081 | struct nfs41_free_stateid_args args = { |
| 6082 | .stateid = &state->stateid, |
| 6083 | }; |
| 6084 | struct nfs41_free_stateid_res res; |
| 6085 | struct rpc_message msg = { |
| 6086 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6087 | .rpc_argp = &args, |
| 6088 | .rpc_resp = &res, |
| 6089 | }; |
| 6090 | |
| 6091 | args.seq_args.sa_session = res.seq_res.sr_session = NULL; |
| 6092 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); |
| 6093 | return status; |
| 6094 | } |
| 6095 | |
| 6096 | static int nfs41_free_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6097 | { |
| 6098 | struct nfs4_exception exception = { }; |
| 6099 | int err; |
| 6100 | do { |
| 6101 | err = nfs4_handle_exception(server, |
| 6102 | _nfs4_free_stateid(server, state), |
| 6103 | &exception); |
| 6104 | } while (exception.retry); |
| 6105 | return err; |
| 6106 | } |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6107 | #endif /* CONFIG_NFS_V4_1 */ |
| 6108 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6109 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6110 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6111 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6112 | .recover_open = nfs4_open_reclaim, |
| 6113 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6114 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6115 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6116 | }; |
| 6117 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6118 | #if defined(CONFIG_NFS_V4_1) |
| 6119 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 6120 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6121 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6122 | .recover_open = nfs4_open_reclaim, |
| 6123 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6124 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6125 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6126 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6127 | }; |
| 6128 | #endif /* CONFIG_NFS_V4_1 */ |
| 6129 | |
| 6130 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6131 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6132 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6133 | .recover_open = nfs4_open_expired, |
| 6134 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6135 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6136 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6137 | }; |
| 6138 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6139 | #if defined(CONFIG_NFS_V4_1) |
| 6140 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 6141 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6142 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6143 | .recover_open = nfs41_open_expired, |
| 6144 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6145 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6146 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6147 | }; |
| 6148 | #endif /* CONFIG_NFS_V4_1 */ |
| 6149 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6150 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 6151 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6152 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6153 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6154 | }; |
| 6155 | |
| 6156 | #if defined(CONFIG_NFS_V4_1) |
| 6157 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 6158 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6159 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6160 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6161 | }; |
| 6162 | #endif |
| 6163 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6164 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6165 | .minor_version = 0, |
| 6166 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6167 | .validate_stateid = nfs4_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6168 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6169 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6170 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6171 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6172 | }; |
| 6173 | |
| 6174 | #if defined(CONFIG_NFS_V4_1) |
| 6175 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6176 | .minor_version = 1, |
| 6177 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6178 | .validate_stateid = nfs41_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6179 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6180 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6181 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6182 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6183 | }; |
| 6184 | #endif |
| 6185 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6186 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6187 | [0] = &nfs_v4_0_minor_ops, |
| 6188 | #if defined(CONFIG_NFS_V4_1) |
| 6189 | [1] = &nfs_v4_1_minor_ops, |
| 6190 | #endif |
| 6191 | }; |
| 6192 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6193 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6194 | .permission = nfs_permission, |
| 6195 | .getattr = nfs_getattr, |
| 6196 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6197 | .getxattr = generic_getxattr, |
| 6198 | .setxattr = generic_setxattr, |
| 6199 | .listxattr = generic_listxattr, |
| 6200 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6201 | }; |
| 6202 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6203 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6204 | .version = 4, /* protocol version */ |
| 6205 | .dentry_ops = &nfs4_dentry_operations, |
| 6206 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6207 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6208 | .getroot = nfs4_proc_get_root, |
| 6209 | .getattr = nfs4_proc_getattr, |
| 6210 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6211 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6212 | .lookup = nfs4_proc_lookup, |
| 6213 | .access = nfs4_proc_access, |
| 6214 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6215 | .create = nfs4_proc_create, |
| 6216 | .remove = nfs4_proc_remove, |
| 6217 | .unlink_setup = nfs4_proc_unlink_setup, |
| 6218 | .unlink_done = nfs4_proc_unlink_done, |
| 6219 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6220 | .rename_setup = nfs4_proc_rename_setup, |
| 6221 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6222 | .link = nfs4_proc_link, |
| 6223 | .symlink = nfs4_proc_symlink, |
| 6224 | .mkdir = nfs4_proc_mkdir, |
| 6225 | .rmdir = nfs4_proc_remove, |
| 6226 | .readdir = nfs4_proc_readdir, |
| 6227 | .mknod = nfs4_proc_mknod, |
| 6228 | .statfs = nfs4_proc_statfs, |
| 6229 | .fsinfo = nfs4_proc_fsinfo, |
| 6230 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6231 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6232 | .decode_dirent = nfs4_decode_dirent, |
| 6233 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6234 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6235 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6236 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6237 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6238 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6239 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6240 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6241 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6242 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6243 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6244 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6245 | }; |
| 6246 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6247 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6248 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6249 | .list = nfs4_xattr_list_nfs4_acl, |
| 6250 | .get = nfs4_xattr_get_nfs4_acl, |
| 6251 | .set = nfs4_xattr_set_nfs4_acl, |
| 6252 | }; |
| 6253 | |
| 6254 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6255 | &nfs4_xattr_nfs4_acl_handler, |
| 6256 | NULL |
| 6257 | }; |
| 6258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6259 | /* |
| 6260 | * Local variables: |
| 6261 | * c-basic-offset: 8 |
| 6262 | * End: |
| 6263 | */ |