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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 85 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 87 | if (err >= -1000) |
| 88 | return err; |
| 89 | switch (err) { |
| 90 | case -NFS4ERR_RESOURCE: |
| 91 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 92 | case -NFS4ERR_WRONGSEC: |
| 93 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 94 | case -NFS4ERR_BADOWNER: |
| 95 | case -NFS4ERR_BADNAME: |
| 96 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 97 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 99 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 100 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 102 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* |
| 106 | * This is our standard bitmap for GETATTR requests. |
| 107 | */ |
| 108 | const u32 nfs4_fattr_bitmap[2] = { |
| 109 | FATTR4_WORD0_TYPE |
| 110 | | FATTR4_WORD0_CHANGE |
| 111 | | FATTR4_WORD0_SIZE |
| 112 | | FATTR4_WORD0_FSID |
| 113 | | FATTR4_WORD0_FILEID, |
| 114 | FATTR4_WORD1_MODE |
| 115 | | FATTR4_WORD1_NUMLINKS |
| 116 | | FATTR4_WORD1_OWNER |
| 117 | | FATTR4_WORD1_OWNER_GROUP |
| 118 | | FATTR4_WORD1_RAWDEV |
| 119 | | FATTR4_WORD1_SPACE_USED |
| 120 | | FATTR4_WORD1_TIME_ACCESS |
| 121 | | FATTR4_WORD1_TIME_METADATA |
| 122 | | FATTR4_WORD1_TIME_MODIFY |
| 123 | }; |
| 124 | |
| 125 | const u32 nfs4_statfs_bitmap[2] = { |
| 126 | FATTR4_WORD0_FILES_AVAIL |
| 127 | | FATTR4_WORD0_FILES_FREE |
| 128 | | FATTR4_WORD0_FILES_TOTAL, |
| 129 | FATTR4_WORD1_SPACE_AVAIL |
| 130 | | FATTR4_WORD1_SPACE_FREE |
| 131 | | FATTR4_WORD1_SPACE_TOTAL |
| 132 | }; |
| 133 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 134 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | FATTR4_WORD0_MAXLINK |
| 136 | | FATTR4_WORD0_MAXNAME, |
| 137 | 0 |
| 138 | }; |
| 139 | |
| 140 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 141 | | FATTR4_WORD0_MAXREAD |
| 142 | | FATTR4_WORD0_MAXWRITE |
| 143 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 144 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 145 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 148 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 149 | FATTR4_WORD0_TYPE |
| 150 | | FATTR4_WORD0_CHANGE |
| 151 | | FATTR4_WORD0_SIZE |
| 152 | | FATTR4_WORD0_FSID |
| 153 | | FATTR4_WORD0_FILEID |
| 154 | | FATTR4_WORD0_FS_LOCATIONS, |
| 155 | FATTR4_WORD1_MODE |
| 156 | | FATTR4_WORD1_NUMLINKS |
| 157 | | FATTR4_WORD1_OWNER |
| 158 | | FATTR4_WORD1_OWNER_GROUP |
| 159 | | FATTR4_WORD1_RAWDEV |
| 160 | | FATTR4_WORD1_SPACE_USED |
| 161 | | FATTR4_WORD1_TIME_ACCESS |
| 162 | | FATTR4_WORD1_TIME_METADATA |
| 163 | | FATTR4_WORD1_TIME_MODIFY |
| 164 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 165 | }; |
| 166 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 167 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | struct nfs4_readdir_arg *readdir) |
| 169 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 170 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
| 172 | BUG_ON(readdir->count < 80); |
| 173 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 174 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | readdir->cookie = 0; |
| 180 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 181 | if (cookie == 2) |
| 182 | return; |
| 183 | |
| 184 | /* |
| 185 | * NFSv4 servers do not return entries for '.' and '..' |
| 186 | * Therefore, we fake these entries here. We let '.' |
| 187 | * have cookie 0 and '..' have cookie 1. Note that |
| 188 | * when talking to the server, we always send cookie 0 |
| 189 | * instead of 1 or 2. |
| 190 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 191 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | if (cookie == 0) { |
| 194 | *p++ = xdr_one; /* next */ |
| 195 | *p++ = xdr_zero; /* cookie, first word */ |
| 196 | *p++ = xdr_one; /* cookie, second word */ |
| 197 | *p++ = xdr_one; /* entry len */ |
| 198 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 199 | p++; |
| 200 | *p++ = xdr_one; /* bitmap length */ |
| 201 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 202 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 203 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | *p++ = xdr_one; /* next */ |
| 207 | *p++ = xdr_zero; /* cookie, first word */ |
| 208 | *p++ = xdr_two; /* cookie, second word */ |
| 209 | *p++ = xdr_two; /* entry len */ |
| 210 | memcpy(p, "..\0\0", 4); /* entry */ |
| 211 | p++; |
| 212 | *p++ = xdr_one; /* bitmap length */ |
| 213 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 214 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 215 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | readdir->pgbase = (char *)p - (char *)start; |
| 218 | readdir->count -= readdir->pgbase; |
| 219 | kunmap_atomic(start, KM_USER0); |
| 220 | } |
| 221 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 222 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 223 | { |
| 224 | int res; |
| 225 | |
| 226 | might_sleep(); |
| 227 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 228 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 229 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 230 | return res; |
| 231 | } |
| 232 | |
| 233 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 234 | { |
| 235 | int res = 0; |
| 236 | |
| 237 | might_sleep(); |
| 238 | |
| 239 | if (*timeout <= 0) |
| 240 | *timeout = NFS4_POLL_RETRY_MIN; |
| 241 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 242 | *timeout = NFS4_POLL_RETRY_MAX; |
| 243 | schedule_timeout_killable(*timeout); |
| 244 | if (fatal_signal_pending(current)) |
| 245 | res = -ERESTARTSYS; |
| 246 | *timeout <<= 1; |
| 247 | return res; |
| 248 | } |
| 249 | |
| 250 | /* This is the error handling routine for processes that are allowed |
| 251 | * to sleep. |
| 252 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 253 | 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] | 254 | { |
| 255 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 256 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 257 | int ret = errorcode; |
| 258 | |
| 259 | exception->retry = 0; |
| 260 | switch(errorcode) { |
| 261 | case 0: |
| 262 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 263 | case -NFS4ERR_ADMIN_REVOKED: |
| 264 | case -NFS4ERR_BAD_STATEID: |
| 265 | case -NFS4ERR_OPENMODE: |
| 266 | if (state == NULL) |
| 267 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 268 | nfs4_schedule_stateid_recovery(server, state); |
| 269 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 270 | case -NFS4ERR_EXPIRED: |
| 271 | if (state != NULL) |
| 272 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 273 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 274 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 275 | nfs4_schedule_lease_recovery(clp); |
| 276 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 277 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 278 | case -NFS4ERR_BADSESSION: |
| 279 | case -NFS4ERR_BADSLOT: |
| 280 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 281 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 282 | case -NFS4ERR_DEADSESSION: |
| 283 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 284 | case -NFS4ERR_SEQ_MISORDERED: |
| 285 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 286 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 287 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 288 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 289 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 290 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 291 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 292 | if (exception->timeout > HZ) { |
| 293 | /* We have retried a decent amount, time to |
| 294 | * fail |
| 295 | */ |
| 296 | ret = -EBUSY; |
| 297 | break; |
| 298 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 299 | case -NFS4ERR_GRACE: |
| 300 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 301 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 302 | ret = nfs4_delay(server->client, &exception->timeout); |
| 303 | if (ret != 0) |
| 304 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 305 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 306 | case -NFS4ERR_OLD_STATEID: |
| 307 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 308 | break; |
| 309 | case -NFS4ERR_BADOWNER: |
| 310 | /* The following works around a Linux server bug! */ |
| 311 | case -NFS4ERR_BADNAME: |
| 312 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 313 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 314 | exception->retry = 1; |
| 315 | printk(KERN_WARNING "NFS: v4 server %s " |
| 316 | "does not accept raw " |
| 317 | "uid/gids. " |
| 318 | "Reenabling the idmapper.\n", |
| 319 | server->nfs_client->cl_hostname); |
| 320 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 321 | } |
| 322 | /* We failed to handle the error */ |
| 323 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 324 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 325 | ret = nfs4_wait_clnt_recover(clp); |
| 326 | if (ret == 0) |
| 327 | exception->retry = 1; |
| 328 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 332 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | spin_lock(&clp->cl_lock); |
| 335 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 336 | clp->cl_last_renewal = timestamp; |
| 337 | spin_unlock(&clp->cl_lock); |
| 338 | } |
| 339 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 340 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 341 | { |
| 342 | do_renew_lease(server->nfs_client, timestamp); |
| 343 | } |
| 344 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 345 | #if defined(CONFIG_NFS_V4_1) |
| 346 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 347 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 348 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 349 | * |
| 350 | * freeing a slot is trivially done by clearing its respective bit |
| 351 | * in the bitmap. |
| 352 | * If the freed slotid equals highest_used_slotid we want to update it |
| 353 | * so that the server would be able to size down the slot table if needed, |
| 354 | * otherwise we know that the highest_used_slotid is still in use. |
| 355 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 356 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 357 | * highest slotid in use. |
| 358 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 359 | * |
| 360 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 361 | */ |
| 362 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 363 | 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] | 364 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 365 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 366 | int slotid = free_slotid; |
| 367 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 368 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 369 | /* clear used bit in bitmap */ |
| 370 | __clear_bit(slotid, tbl->used_slots); |
| 371 | |
| 372 | /* update highest_used_slotid when it is freed */ |
| 373 | if (slotid == tbl->highest_used_slotid) { |
| 374 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 375 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 376 | tbl->highest_used_slotid = slotid; |
| 377 | else |
| 378 | tbl->highest_used_slotid = -1; |
| 379 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 380 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 381 | free_slotid, tbl->highest_used_slotid); |
| 382 | } |
| 383 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 384 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 385 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 386 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 387 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 388 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 389 | struct rpc_task *task; |
| 390 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 391 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 392 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 393 | if (task) |
| 394 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 395 | return; |
| 396 | } |
| 397 | |
| 398 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 399 | return; |
| 400 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 401 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 402 | complete(&ses->fc_slot_table.complete); |
| 403 | } |
| 404 | |
| 405 | /* |
| 406 | * Signal state manager thread if session back channel is drained |
| 407 | */ |
| 408 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 409 | { |
| 410 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 411 | ses->bc_slot_table.highest_used_slotid != -1) |
| 412 | return; |
| 413 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 414 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 417 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 418 | { |
| 419 | struct nfs4_slot_table *tbl; |
| 420 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 421 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 422 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 423 | /* just wake up the next guy waiting since |
| 424 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 425 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 426 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 427 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 428 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 429 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 430 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 431 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 432 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 433 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 434 | } |
| 435 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 436 | 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] | 437 | { |
| 438 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 439 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 440 | |
| 441 | /* |
| 442 | * sr_status remains 1 if an RPC level error occurred. The server |
| 443 | * may or may not have processed the sequence operation.. |
| 444 | * Proceed as if the server received and processed the sequence |
| 445 | * operation. |
| 446 | */ |
| 447 | if (res->sr_status == 1) |
| 448 | res->sr_status = NFS_OK; |
| 449 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 450 | /* don't increment the sequence number if the task wasn't sent */ |
| 451 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 452 | goto out; |
| 453 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 454 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 455 | switch (res->sr_status) { |
| 456 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 457 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 458 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 459 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 460 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 461 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 462 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 463 | if (res->sr_status_flags != 0) |
| 464 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 465 | break; |
| 466 | case -NFS4ERR_DELAY: |
| 467 | /* The server detected a resend of the RPC call and |
| 468 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 469 | * of RFC5661. |
| 470 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 471 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 472 | __func__, |
| 473 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 474 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 475 | goto out_retry; |
| 476 | default: |
| 477 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 478 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 479 | } |
| 480 | out: |
| 481 | /* The session may be reset by one of the error handlers. */ |
| 482 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 483 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 484 | return 1; |
| 485 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 486 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 487 | goto out; |
| 488 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 489 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 490 | } |
| 491 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 492 | static int nfs4_sequence_done(struct rpc_task *task, |
| 493 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 494 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 495 | if (res->sr_session == NULL) |
| 496 | return 1; |
| 497 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 498 | } |
| 499 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 500 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 501 | * nfs4_find_slot - efficiently look for a free slot |
| 502 | * |
| 503 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 504 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 505 | * and respectively set up the sequence operation args. |
| 506 | * 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] | 507 | * |
| 508 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 509 | */ |
| 510 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 511 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 512 | { |
| 513 | int slotid; |
| 514 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 515 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 516 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 517 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 518 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 519 | tbl->max_slots); |
| 520 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 521 | if (slotid >= tbl->max_slots) |
| 522 | goto out; |
| 523 | __set_bit(slotid, tbl->used_slots); |
| 524 | if (slotid > tbl->highest_used_slotid) |
| 525 | tbl->highest_used_slotid = slotid; |
| 526 | ret_id = slotid; |
| 527 | out: |
| 528 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 529 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 530 | return ret_id; |
| 531 | } |
| 532 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 533 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 534 | struct nfs4_sequence_args *args, |
| 535 | struct nfs4_sequence_res *res, |
| 536 | int cache_reply, |
| 537 | struct rpc_task *task) |
| 538 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 539 | struct nfs4_slot *slot; |
| 540 | struct nfs4_slot_table *tbl; |
| 541 | u8 slotid; |
| 542 | |
| 543 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 544 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 545 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 546 | return 0; |
| 547 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 548 | tbl = &session->fc_slot_table; |
| 549 | |
| 550 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 551 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 552 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 553 | /* |
| 554 | * The state manager will wait until the slot table is empty. |
| 555 | * Schedule the reset thread |
| 556 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 557 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 558 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 559 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 560 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 561 | } |
| 562 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 563 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 564 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 565 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 566 | spin_unlock(&tbl->slot_tbl_lock); |
| 567 | dprintk("%s enforce FIFO order\n", __func__); |
| 568 | return -EAGAIN; |
| 569 | } |
| 570 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 571 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 572 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 573 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 574 | spin_unlock(&tbl->slot_tbl_lock); |
| 575 | dprintk("<-- %s: no free slots\n", __func__); |
| 576 | return -EAGAIN; |
| 577 | } |
| 578 | spin_unlock(&tbl->slot_tbl_lock); |
| 579 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 580 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 581 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 582 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 583 | args->sa_slotid = slotid; |
| 584 | args->sa_cache_this = cache_reply; |
| 585 | |
| 586 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 587 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 588 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 589 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 590 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 591 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 592 | /* |
| 593 | * sr_status is only set in decode_sequence, and so will remain |
| 594 | * set to 1 if an rpc level failure occurs. |
| 595 | */ |
| 596 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 597 | return 0; |
| 598 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 599 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 600 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 601 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 602 | struct nfs4_sequence_args *args, |
| 603 | struct nfs4_sequence_res *res, |
| 604 | int cache_reply, |
| 605 | struct rpc_task *task) |
| 606 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 607 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 608 | int ret = 0; |
| 609 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 610 | if (session == NULL) { |
| 611 | args->sa_session = NULL; |
| 612 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 613 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 614 | } |
| 615 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 616 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 617 | __func__, session->clp, session, res->sr_slot ? |
| 618 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 619 | |
| 620 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 621 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 622 | out: |
| 623 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 624 | return ret; |
| 625 | } |
| 626 | |
| 627 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 628 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 629 | struct nfs4_sequence_args *seq_args; |
| 630 | struct nfs4_sequence_res *seq_res; |
| 631 | int cache_reply; |
| 632 | }; |
| 633 | |
| 634 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 635 | { |
| 636 | struct nfs41_call_sync_data *data = calldata; |
| 637 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 638 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 639 | |
| 640 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 641 | data->seq_res, data->cache_reply, task)) |
| 642 | return; |
| 643 | rpc_call_start(task); |
| 644 | } |
| 645 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 646 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 647 | { |
| 648 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 649 | nfs41_call_sync_prepare(task, calldata); |
| 650 | } |
| 651 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 652 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 653 | { |
| 654 | struct nfs41_call_sync_data *data = calldata; |
| 655 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 656 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 657 | } |
| 658 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 659 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 660 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 661 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 662 | }; |
| 663 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 664 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 665 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 666 | .rpc_call_done = nfs41_call_sync_done, |
| 667 | }; |
| 668 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 669 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 670 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 671 | struct rpc_message *msg, |
| 672 | struct nfs4_sequence_args *args, |
| 673 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 674 | int cache_reply, |
| 675 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 676 | { |
| 677 | int ret; |
| 678 | struct rpc_task *task; |
| 679 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 680 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 681 | .seq_args = args, |
| 682 | .seq_res = res, |
| 683 | .cache_reply = cache_reply, |
| 684 | }; |
| 685 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 686 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 687 | .rpc_message = msg, |
| 688 | .callback_ops = &nfs41_call_sync_ops, |
| 689 | .callback_data = &data |
| 690 | }; |
| 691 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 692 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 693 | if (privileged) |
| 694 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 695 | task = rpc_run_task(&task_setup); |
| 696 | if (IS_ERR(task)) |
| 697 | ret = PTR_ERR(task); |
| 698 | else { |
| 699 | ret = task->tk_status; |
| 700 | rpc_put_task(task); |
| 701 | } |
| 702 | return ret; |
| 703 | } |
| 704 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 705 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 706 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 707 | struct rpc_message *msg, |
| 708 | struct nfs4_sequence_args *args, |
| 709 | struct nfs4_sequence_res *res, |
| 710 | int cache_reply) |
| 711 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 712 | 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] | 713 | } |
| 714 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 715 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 716 | static int nfs4_sequence_done(struct rpc_task *task, |
| 717 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 718 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 719 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 720 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 721 | #endif /* CONFIG_NFS_V4_1 */ |
| 722 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 723 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 724 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 725 | struct rpc_message *msg, |
| 726 | struct nfs4_sequence_args *args, |
| 727 | struct nfs4_sequence_res *res, |
| 728 | int cache_reply) |
| 729 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 730 | args->sa_session = res->sr_session = NULL; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 731 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 732 | } |
| 733 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 734 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 735 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 736 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 737 | struct rpc_message *msg, |
| 738 | struct nfs4_sequence_args *args, |
| 739 | struct nfs4_sequence_res *res, |
| 740 | int cache_reply) |
| 741 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 742 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 743 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 744 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 745 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 746 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 748 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 750 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 751 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 752 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 753 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 754 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 755 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 758 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 759 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 760 | struct nfs_openargs o_arg; |
| 761 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 762 | struct nfs_open_confirmargs c_arg; |
| 763 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 764 | struct nfs_fattr f_attr; |
| 765 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 766 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 767 | struct dentry *dir; |
| 768 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 769 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 770 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 771 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 772 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 773 | int rpc_status; |
| 774 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 775 | }; |
| 776 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 777 | |
| 778 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 779 | { |
| 780 | p->o_res.f_attr = &p->f_attr; |
| 781 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 782 | p->o_res.seqid = p->o_arg.seqid; |
| 783 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 784 | p->o_res.server = p->o_arg.server; |
| 785 | nfs_fattr_init(&p->f_attr); |
| 786 | nfs_fattr_init(&p->dir_attr); |
| 787 | } |
| 788 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 789 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 790 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 791 | const struct iattr *attrs, |
| 792 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 793 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 794 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 795 | struct inode *dir = parent->d_inode; |
| 796 | struct nfs_server *server = NFS_SERVER(dir); |
| 797 | struct nfs4_opendata *p; |
| 798 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 799 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 800 | if (p == NULL) |
| 801 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 802 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 803 | if (p->o_arg.seqid == NULL) |
| 804 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 805 | path_get(path); |
| 806 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 807 | p->dir = parent; |
| 808 | p->owner = sp; |
| 809 | atomic_inc(&sp->so_count); |
| 810 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 811 | p->o_arg.open_flags = flags; |
| 812 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 813 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 814 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 815 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 816 | p->o_arg.server = server; |
| 817 | p->o_arg.bitmask = server->attr_bitmask; |
| 818 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 819 | if (flags & O_CREAT) { |
| 820 | u32 *s; |
| 821 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | p->o_arg.u.attrs = &p->attrs; |
| 823 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 824 | s = (u32 *) p->o_arg.u.verifier.data; |
| 825 | s[0] = jiffies; |
| 826 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 827 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 828 | p->c_arg.fh = &p->o_res.fh; |
| 829 | p->c_arg.stateid = &p->o_res.stateid; |
| 830 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 831 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 832 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 833 | return p; |
| 834 | err_free: |
| 835 | kfree(p); |
| 836 | err: |
| 837 | dput(parent); |
| 838 | return NULL; |
| 839 | } |
| 840 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 841 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 842 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 843 | struct nfs4_opendata *p = container_of(kref, |
| 844 | struct nfs4_opendata, kref); |
| 845 | |
| 846 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 847 | if (p->state != NULL) |
| 848 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 849 | nfs4_put_state_owner(p->owner); |
| 850 | dput(p->dir); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 851 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 852 | kfree(p); |
| 853 | } |
| 854 | |
| 855 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 856 | { |
| 857 | if (p != NULL) |
| 858 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 859 | } |
| 860 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 861 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 862 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 863 | int ret; |
| 864 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 865 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 866 | return ret; |
| 867 | } |
| 868 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 869 | 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] | 870 | { |
| 871 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 872 | |
| 873 | if (open_mode & O_EXCL) |
| 874 | goto out; |
| 875 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 876 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 877 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 878 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 879 | break; |
| 880 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 881 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 882 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 883 | break; |
| 884 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 885 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 886 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 887 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 888 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 889 | return ret; |
| 890 | } |
| 891 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 892 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 893 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 894 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 895 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 896 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 897 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 898 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 899 | return 1; |
| 900 | } |
| 901 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 902 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 903 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 904 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 905 | case FMODE_WRITE: |
| 906 | state->n_wronly++; |
| 907 | break; |
| 908 | case FMODE_READ: |
| 909 | state->n_rdonly++; |
| 910 | break; |
| 911 | case FMODE_READ|FMODE_WRITE: |
| 912 | state->n_rdwr++; |
| 913 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 914 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 915 | } |
| 916 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 917 | 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] | 918 | { |
| 919 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 920 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 921 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 922 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 923 | case FMODE_READ: |
| 924 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 925 | break; |
| 926 | case FMODE_WRITE: |
| 927 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 928 | break; |
| 929 | case FMODE_READ|FMODE_WRITE: |
| 930 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 931 | } |
| 932 | } |
| 933 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 934 | 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] | 935 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 936 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 937 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 938 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 939 | } |
| 940 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 941 | 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] | 942 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 943 | /* |
| 944 | * Protect the call to nfs4_state_set_mode_locked and |
| 945 | * serialise the stateid update |
| 946 | */ |
| 947 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 948 | if (deleg_stateid != NULL) { |
| 949 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 950 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 951 | } |
| 952 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 953 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 954 | write_sequnlock(&state->seqlock); |
| 955 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 956 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 957 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 960 | 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] | 961 | { |
| 962 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 963 | struct nfs_delegation *deleg_cur; |
| 964 | int ret = 0; |
| 965 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 966 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 967 | |
| 968 | rcu_read_lock(); |
| 969 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 970 | if (deleg_cur == NULL) |
| 971 | goto no_delegation; |
| 972 | |
| 973 | spin_lock(&deleg_cur->lock); |
| 974 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 975 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 976 | goto no_delegation_unlock; |
| 977 | |
| 978 | if (delegation == NULL) |
| 979 | delegation = &deleg_cur->stateid; |
| 980 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 981 | goto no_delegation_unlock; |
| 982 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 983 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 984 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 985 | ret = 1; |
| 986 | no_delegation_unlock: |
| 987 | spin_unlock(&deleg_cur->lock); |
| 988 | no_delegation: |
| 989 | rcu_read_unlock(); |
| 990 | |
| 991 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 992 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 993 | ret = 1; |
| 994 | } |
| 995 | |
| 996 | return ret; |
| 997 | } |
| 998 | |
| 999 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1000 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1001 | { |
| 1002 | struct nfs_delegation *delegation; |
| 1003 | |
| 1004 | rcu_read_lock(); |
| 1005 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1006 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1007 | rcu_read_unlock(); |
| 1008 | return; |
| 1009 | } |
| 1010 | rcu_read_unlock(); |
| 1011 | nfs_inode_return_delegation(inode); |
| 1012 | } |
| 1013 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1014 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1015 | { |
| 1016 | struct nfs4_state *state = opendata->state; |
| 1017 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1018 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1019 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 1020 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1021 | nfs4_stateid stateid; |
| 1022 | int ret = -EAGAIN; |
| 1023 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1024 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1025 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1026 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1027 | if (can_open_cached(state, fmode, open_mode)) { |
| 1028 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1029 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1030 | goto out_return_state; |
| 1031 | } |
| 1032 | spin_unlock(&state->owner->so_lock); |
| 1033 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1034 | rcu_read_lock(); |
| 1035 | delegation = rcu_dereference(nfsi->delegation); |
| 1036 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1037 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1038 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1039 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1040 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1041 | /* Save the delegation */ |
| 1042 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1043 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1044 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1045 | if (ret != 0) |
| 1046 | goto out; |
| 1047 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1048 | |
| 1049 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1050 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1051 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1052 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1053 | out: |
| 1054 | return ERR_PTR(ret); |
| 1055 | out_return_state: |
| 1056 | atomic_inc(&state->count); |
| 1057 | return state; |
| 1058 | } |
| 1059 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1060 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1061 | { |
| 1062 | struct inode *inode; |
| 1063 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1064 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1065 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1066 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1067 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1068 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1069 | goto out; |
| 1070 | } |
| 1071 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1072 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1073 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1074 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1075 | 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] | 1076 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1077 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1078 | goto err; |
| 1079 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1080 | state = nfs4_get_open_state(inode, data->owner); |
| 1081 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1082 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1083 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1084 | int delegation_flags = 0; |
| 1085 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1086 | rcu_read_lock(); |
| 1087 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1088 | if (delegation) |
| 1089 | delegation_flags = delegation->flags; |
| 1090 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1091 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1092 | nfs_inode_set_delegation(state->inode, |
| 1093 | data->owner->so_cred, |
| 1094 | &data->o_res); |
| 1095 | else |
| 1096 | nfs_inode_reclaim_delegation(state->inode, |
| 1097 | data->owner->so_cred, |
| 1098 | &data->o_res); |
| 1099 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1100 | |
| 1101 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1102 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1103 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1104 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1105 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1106 | err_put_inode: |
| 1107 | iput(inode); |
| 1108 | err: |
| 1109 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1110 | } |
| 1111 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1112 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1113 | { |
| 1114 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1115 | struct nfs_open_context *ctx; |
| 1116 | |
| 1117 | spin_lock(&state->inode->i_lock); |
| 1118 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1119 | if (ctx->state != state) |
| 1120 | continue; |
| 1121 | get_nfs_open_context(ctx); |
| 1122 | spin_unlock(&state->inode->i_lock); |
| 1123 | return ctx; |
| 1124 | } |
| 1125 | spin_unlock(&state->inode->i_lock); |
| 1126 | return ERR_PTR(-ENOENT); |
| 1127 | } |
| 1128 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1129 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1130 | { |
| 1131 | struct nfs4_opendata *opendata; |
| 1132 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1133 | 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] | 1134 | if (opendata == NULL) |
| 1135 | return ERR_PTR(-ENOMEM); |
| 1136 | opendata->state = state; |
| 1137 | atomic_inc(&state->count); |
| 1138 | return opendata; |
| 1139 | } |
| 1140 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1141 | 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] | 1142 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1143 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1144 | int ret; |
| 1145 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1146 | opendata->o_arg.open_flags = 0; |
| 1147 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1148 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1149 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1150 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1151 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1152 | if (ret != 0) |
| 1153 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1154 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1155 | if (IS_ERR(newstate)) |
| 1156 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1157 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1158 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1159 | return 0; |
| 1160 | } |
| 1161 | |
| 1162 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1163 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1164 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1165 | int ret; |
| 1166 | |
| 1167 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1168 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1169 | smp_rmb(); |
| 1170 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1171 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1172 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1173 | if (ret != 0) |
| 1174 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1175 | if (newstate != state) |
| 1176 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1177 | } |
| 1178 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1179 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1180 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1181 | if (ret != 0) |
| 1182 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1183 | if (newstate != state) |
| 1184 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1185 | } |
| 1186 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1187 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1188 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1189 | if (ret != 0) |
| 1190 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1191 | if (newstate != state) |
| 1192 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1193 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1194 | /* |
| 1195 | * We may have performed cached opens for all three recoveries. |
| 1196 | * Check if we need to update the current stateid. |
| 1197 | */ |
| 1198 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1199 | 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] | 1200 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1201 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1202 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1203 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1204 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1205 | return 0; |
| 1206 | } |
| 1207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | /* |
| 1209 | * OPEN_RECLAIM: |
| 1210 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1212 | 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] | 1213 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1214 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1215 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1216 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | int status; |
| 1218 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1219 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1220 | if (IS_ERR(opendata)) |
| 1221 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1222 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1223 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1224 | rcu_read_lock(); |
| 1225 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1226 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1227 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1228 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1229 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1230 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1231 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | return status; |
| 1233 | } |
| 1234 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1235 | 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] | 1236 | { |
| 1237 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1238 | struct nfs4_exception exception = { }; |
| 1239 | int err; |
| 1240 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1241 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1242 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1243 | break; |
| 1244 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | } while (exception.retry); |
| 1246 | return err; |
| 1247 | } |
| 1248 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1249 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1250 | { |
| 1251 | struct nfs_open_context *ctx; |
| 1252 | int ret; |
| 1253 | |
| 1254 | ctx = nfs4_state_find_open_context(state); |
| 1255 | if (IS_ERR(ctx)) |
| 1256 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1257 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1258 | put_nfs_open_context(ctx); |
| 1259 | return ret; |
| 1260 | } |
| 1261 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1262 | 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] | 1263 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1264 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1265 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1267 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1268 | if (IS_ERR(opendata)) |
| 1269 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1270 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1271 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1272 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1273 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1274 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1275 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1278 | 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] | 1279 | { |
| 1280 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1281 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | int err; |
| 1283 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1284 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | switch (err) { |
| 1286 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1287 | case -ENOENT: |
| 1288 | case -ESTALE: |
| 1289 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1290 | case -NFS4ERR_BADSESSION: |
| 1291 | case -NFS4ERR_BADSLOT: |
| 1292 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1293 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1294 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1295 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1296 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | case -NFS4ERR_STALE_CLIENTID: |
| 1298 | case -NFS4ERR_STALE_STATEID: |
| 1299 | case -NFS4ERR_EXPIRED: |
| 1300 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1301 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1302 | goto out; |
| 1303 | case -ERESTARTSYS: |
| 1304 | /* |
| 1305 | * The show must go on: exit, but mark the |
| 1306 | * stateid as needing recovery. |
| 1307 | */ |
| 1308 | case -NFS4ERR_ADMIN_REVOKED: |
| 1309 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1310 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1311 | case -EKEYEXPIRED: |
| 1312 | /* |
| 1313 | * User RPCSEC_GSS context has expired. |
| 1314 | * We cannot recover this stateid now, so |
| 1315 | * skip it and allow recovery thread to |
| 1316 | * proceed. |
| 1317 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1318 | case -ENOMEM: |
| 1319 | err = 0; |
| 1320 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | } |
| 1322 | err = nfs4_handle_exception(server, err, &exception); |
| 1323 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1324 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | return err; |
| 1326 | } |
| 1327 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1328 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1329 | { |
| 1330 | struct nfs4_opendata *data = calldata; |
| 1331 | |
| 1332 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1333 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1334 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1335 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1336 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1337 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1338 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1339 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | static void nfs4_open_confirm_release(void *calldata) |
| 1343 | { |
| 1344 | struct nfs4_opendata *data = calldata; |
| 1345 | struct nfs4_state *state = NULL; |
| 1346 | |
| 1347 | /* If this request hasn't been cancelled, do nothing */ |
| 1348 | if (data->cancelled == 0) |
| 1349 | goto out_free; |
| 1350 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1351 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1352 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1353 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1354 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1355 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1356 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1357 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1361 | .rpc_call_done = nfs4_open_confirm_done, |
| 1362 | .rpc_release = nfs4_open_confirm_release, |
| 1363 | }; |
| 1364 | |
| 1365 | /* |
| 1366 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1367 | */ |
| 1368 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1369 | { |
| 1370 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1371 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1372 | struct rpc_message msg = { |
| 1373 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1374 | .rpc_argp = &data->c_arg, |
| 1375 | .rpc_resp = &data->c_res, |
| 1376 | .rpc_cred = data->owner->so_cred, |
| 1377 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1378 | struct rpc_task_setup task_setup_data = { |
| 1379 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1380 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1381 | .callback_ops = &nfs4_open_confirm_ops, |
| 1382 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1383 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1384 | .flags = RPC_TASK_ASYNC, |
| 1385 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | int status; |
| 1387 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1388 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1389 | data->rpc_done = 0; |
| 1390 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1391 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1392 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1393 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1394 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1395 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1396 | if (status != 0) { |
| 1397 | data->cancelled = 1; |
| 1398 | smp_wmb(); |
| 1399 | } else |
| 1400 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1401 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | return status; |
| 1403 | } |
| 1404 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1405 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1407 | struct nfs4_opendata *data = calldata; |
| 1408 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1409 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1410 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1411 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1412 | /* |
| 1413 | * Check if we still need to send an OPEN call, or if we can use |
| 1414 | * a delegation instead. |
| 1415 | */ |
| 1416 | if (data->state != NULL) { |
| 1417 | struct nfs_delegation *delegation; |
| 1418 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1419 | 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] | 1420 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1421 | rcu_read_lock(); |
| 1422 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1423 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1424 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1425 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1426 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1427 | } |
| 1428 | rcu_read_unlock(); |
| 1429 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1430 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1431 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1432 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1433 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1434 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1435 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1436 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1437 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1438 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1439 | &data->o_arg.seq_args, |
| 1440 | &data->o_res.seq_res, 1, task)) |
| 1441 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1442 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1443 | return; |
| 1444 | out_no_action: |
| 1445 | task->tk_action = NULL; |
| 1446 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1447 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1449 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1450 | { |
| 1451 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1452 | nfs4_open_prepare(task, calldata); |
| 1453 | } |
| 1454 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1455 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1456 | { |
| 1457 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1459 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1460 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1461 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1462 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1463 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1464 | if (task->tk_status == 0) { |
| 1465 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1466 | case S_IFREG: |
| 1467 | break; |
| 1468 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1469 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1470 | break; |
| 1471 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1472 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1473 | break; |
| 1474 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1475 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1476 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1477 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1478 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1479 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1480 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1481 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1482 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1483 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1484 | static void nfs4_open_release(void *calldata) |
| 1485 | { |
| 1486 | struct nfs4_opendata *data = calldata; |
| 1487 | struct nfs4_state *state = NULL; |
| 1488 | |
| 1489 | /* If this request hasn't been cancelled, do nothing */ |
| 1490 | if (data->cancelled == 0) |
| 1491 | goto out_free; |
| 1492 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1493 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1494 | goto out_free; |
| 1495 | /* In case we need an open_confirm, no cleanup! */ |
| 1496 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1497 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1498 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1499 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1500 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1501 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1502 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1506 | .rpc_call_prepare = nfs4_open_prepare, |
| 1507 | .rpc_call_done = nfs4_open_done, |
| 1508 | .rpc_release = nfs4_open_release, |
| 1509 | }; |
| 1510 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1511 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1512 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1513 | .rpc_call_done = nfs4_open_done, |
| 1514 | .rpc_release = nfs4_open_release, |
| 1515 | }; |
| 1516 | |
| 1517 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1518 | { |
| 1519 | struct inode *dir = data->dir->d_inode; |
| 1520 | struct nfs_server *server = NFS_SERVER(dir); |
| 1521 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1522 | struct nfs_openres *o_res = &data->o_res; |
| 1523 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1524 | struct rpc_message msg = { |
| 1525 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1526 | .rpc_argp = o_arg, |
| 1527 | .rpc_resp = o_res, |
| 1528 | .rpc_cred = data->owner->so_cred, |
| 1529 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1530 | struct rpc_task_setup task_setup_data = { |
| 1531 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1532 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1533 | .callback_ops = &nfs4_open_ops, |
| 1534 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1535 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1536 | .flags = RPC_TASK_ASYNC, |
| 1537 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1538 | int status; |
| 1539 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1540 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1541 | data->rpc_done = 0; |
| 1542 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1543 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1544 | if (isrecover) |
| 1545 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1546 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1547 | if (IS_ERR(task)) |
| 1548 | return PTR_ERR(task); |
| 1549 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1550 | if (status != 0) { |
| 1551 | data->cancelled = 1; |
| 1552 | smp_wmb(); |
| 1553 | } else |
| 1554 | status = data->rpc_status; |
| 1555 | rpc_put_task(task); |
| 1556 | |
| 1557 | return status; |
| 1558 | } |
| 1559 | |
| 1560 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1561 | { |
| 1562 | struct inode *dir = data->dir->d_inode; |
| 1563 | struct nfs_openres *o_res = &data->o_res; |
| 1564 | int status; |
| 1565 | |
| 1566 | status = nfs4_run_open_task(data, 1); |
| 1567 | if (status != 0 || !data->rpc_done) |
| 1568 | return status; |
| 1569 | |
| 1570 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1571 | |
| 1572 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1573 | status = _nfs4_proc_open_confirm(data); |
| 1574 | if (status != 0) |
| 1575 | return status; |
| 1576 | } |
| 1577 | |
| 1578 | return status; |
| 1579 | } |
| 1580 | |
| 1581 | /* |
| 1582 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1583 | */ |
| 1584 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1585 | { |
| 1586 | struct inode *dir = data->dir->d_inode; |
| 1587 | struct nfs_server *server = NFS_SERVER(dir); |
| 1588 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1589 | struct nfs_openres *o_res = &data->o_res; |
| 1590 | int status; |
| 1591 | |
| 1592 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1593 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1594 | return status; |
| 1595 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1596 | if (o_arg->open_flags & O_CREAT) { |
| 1597 | update_changeattr(dir, &o_res->cinfo); |
| 1598 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1599 | } else |
| 1600 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1601 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1602 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1604 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1606 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | } |
| 1608 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1609 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1610 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1613 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1614 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1615 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1616 | int ret; |
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 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1619 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1620 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1621 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1622 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1623 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1624 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1625 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1626 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1627 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1628 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1629 | } |
| 1630 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1631 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1632 | { |
| 1633 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1634 | } |
| 1635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | /* |
| 1637 | * OPEN_EXPIRED: |
| 1638 | * reclaim state on the server after a network partition. |
| 1639 | * Assumes caller holds the appropriate lock |
| 1640 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1641 | 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] | 1642 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1643 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1644 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1646 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1647 | if (IS_ERR(opendata)) |
| 1648 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1649 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1650 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1651 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1652 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1653 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1656 | 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] | 1657 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1658 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1659 | struct nfs4_exception exception = { }; |
| 1660 | int err; |
| 1661 | |
| 1662 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1663 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1664 | switch (err) { |
| 1665 | default: |
| 1666 | goto out; |
| 1667 | case -NFS4ERR_GRACE: |
| 1668 | case -NFS4ERR_DELAY: |
| 1669 | nfs4_handle_exception(server, err, &exception); |
| 1670 | err = 0; |
| 1671 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1672 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1673 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1674 | return err; |
| 1675 | } |
| 1676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1678 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1680 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1682 | ctx = nfs4_state_find_open_context(state); |
| 1683 | if (IS_ERR(ctx)) |
| 1684 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1685 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1686 | put_nfs_open_context(ctx); |
| 1687 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1691 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1692 | * fields corresponding to attributes that were used to store the verifier. |
| 1693 | * Make sure we clobber those fields in the later setattr call |
| 1694 | */ |
| 1695 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1696 | { |
| 1697 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1698 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1699 | sattr->ia_valid |= ATTR_ATIME; |
| 1700 | |
| 1701 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1702 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1703 | sattr->ia_valid |= ATTR_MTIME; |
| 1704 | } |
| 1705 | |
| 1706 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1707 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1709 | 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] | 1710 | { |
| 1711 | struct nfs4_state_owner *sp; |
| 1712 | struct nfs4_state *state = NULL; |
| 1713 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1714 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1715 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
| 1717 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | status = -ENOMEM; |
| 1719 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1720 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1721 | goto out_err; |
| 1722 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1723 | status = nfs4_recover_expired_lease(server); |
| 1724 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1725 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1726 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1727 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1728 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1729 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1730 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1731 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1733 | if (path->dentry->d_inode != NULL) |
| 1734 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1735 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1736 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1738 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1740 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1741 | status = PTR_ERR(state); |
| 1742 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1743 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1744 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1745 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1746 | |
| 1747 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1748 | nfs4_exclusive_attrset(opendata, sattr); |
| 1749 | |
| 1750 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1751 | status = nfs4_do_setattr(state->inode, cred, |
| 1752 | opendata->o_res.f_attr, sattr, |
| 1753 | state); |
| 1754 | if (status == 0) |
| 1755 | nfs_setattr_update_inode(state->inode, sattr); |
| 1756 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1757 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1758 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | *res = state; |
| 1761 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1762 | err_opendata_put: |
| 1763 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1764 | err_put_state_owner: |
| 1765 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | *res = NULL; |
| 1768 | return status; |
| 1769 | } |
| 1770 | |
| 1771 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1772 | 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] | 1773 | { |
| 1774 | struct nfs4_exception exception = { }; |
| 1775 | struct nfs4_state *res; |
| 1776 | int status; |
| 1777 | |
| 1778 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1779 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | if (status == 0) |
| 1781 | break; |
| 1782 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1783 | * book-keeping w.r.t. state-changing operations |
| 1784 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1785 | * It is actually a sign of a bug on the client or on the server. |
| 1786 | * |
| 1787 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1788 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | * have unhashed the old state_owner for us, and that we can |
| 1790 | * therefore safely retry using a new one. We should still warn |
| 1791 | * the user though... |
| 1792 | */ |
| 1793 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1794 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1795 | " returned a bad sequence-id error!\n", |
| 1796 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | exception.retry = 1; |
| 1798 | continue; |
| 1799 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1800 | /* |
| 1801 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1802 | * state before it received the OPEN_CONFIRM. |
| 1803 | * Recover by retrying the request as per the discussion |
| 1804 | * on Page 181 of RFC3530. |
| 1805 | */ |
| 1806 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1807 | exception.retry = 1; |
| 1808 | continue; |
| 1809 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1810 | if (status == -EAGAIN) { |
| 1811 | /* We must have found a delegation */ |
| 1812 | exception.retry = 1; |
| 1813 | continue; |
| 1814 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1816 | status, &exception)); |
| 1817 | } while (exception.retry); |
| 1818 | return res; |
| 1819 | } |
| 1820 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1821 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1822 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1823 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1825 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1827 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | .iap = sattr, |
| 1829 | .server = server, |
| 1830 | .bitmask = server->attr_bitmask, |
| 1831 | }; |
| 1832 | struct nfs_setattrres res = { |
| 1833 | .fattr = fattr, |
| 1834 | .server = server, |
| 1835 | }; |
| 1836 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1837 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1838 | .rpc_argp = &arg, |
| 1839 | .rpc_resp = &res, |
| 1840 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1842 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1843 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1845 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1847 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1848 | /* Use that stateid */ |
| 1849 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1850 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1851 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1853 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1854 | 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] | 1855 | if (status == 0 && state != NULL) |
| 1856 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1857 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1860 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1861 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1862 | struct nfs4_state *state) |
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 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | struct nfs4_exception exception = { }; |
| 1866 | int err; |
| 1867 | do { |
| 1868 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1869 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | &exception); |
| 1871 | } while (exception.retry); |
| 1872 | return err; |
| 1873 | } |
| 1874 | |
| 1875 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1876 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | struct inode *inode; |
| 1878 | struct nfs4_state *state; |
| 1879 | struct nfs_closeargs arg; |
| 1880 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1881 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1882 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1883 | bool roc; |
| 1884 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | }; |
| 1886 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1887 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1888 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1889 | struct nfs4_closedata *calldata = data; |
| 1890 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1891 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1892 | if (calldata->roc) |
| 1893 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1894 | nfs4_put_open_state(calldata->state); |
| 1895 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1896 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db1 | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1897 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1898 | kfree(calldata); |
| 1899 | } |
| 1900 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1901 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1902 | fmode_t fmode) |
| 1903 | { |
| 1904 | spin_lock(&state->owner->so_lock); |
| 1905 | if (!(fmode & FMODE_READ)) |
| 1906 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1907 | if (!(fmode & FMODE_WRITE)) |
| 1908 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1909 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1910 | spin_unlock(&state->owner->so_lock); |
| 1911 | } |
| 1912 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1913 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1915 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1918 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1919 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1920 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | /* hmm. we are done with the inode, and in the process of freeing |
| 1922 | * the state_owner. we keep this around to process errors |
| 1923 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | switch (task->tk_status) { |
| 1925 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1926 | if (calldata->roc) |
| 1927 | pnfs_roc_set_barrier(state->inode, |
| 1928 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1929 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1930 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1931 | nfs4_close_clear_stateid_flags(state, |
| 1932 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | break; |
| 1934 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1935 | case -NFS4ERR_OLD_STATEID: |
| 1936 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1938 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1939 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1941 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1942 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1944 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1945 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1948 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1950 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1951 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1952 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1953 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1954 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1955 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1956 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1957 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1958 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1959 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1960 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1961 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1962 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1963 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1964 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1965 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1966 | } |
| 1967 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1968 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1969 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1970 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1971 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1972 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1973 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1974 | |
| 1975 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1976 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1977 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1978 | return; |
| 1979 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1980 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1981 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1982 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1983 | if (calldata->roc && |
| 1984 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 1985 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 1986 | task, NULL); |
| 1987 | return; |
| 1988 | } |
| 1989 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1990 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1991 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1992 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1993 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1994 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1995 | 1, task)) |
| 1996 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1997 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2000 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2001 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2002 | .rpc_call_done = nfs4_close_done, |
| 2003 | .rpc_release = nfs4_free_closedata, |
| 2004 | }; |
| 2005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | /* |
| 2007 | * It is possible for data to be read/written from a mem-mapped file |
| 2008 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2009 | * This means that we can't safely call nfsv4 close on a file until |
| 2010 | * the inode is cleared. This in turn means that we are not good |
| 2011 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2012 | * share state even when we are done with one of the three share |
| 2013 | * stateid's in the inode. |
| 2014 | * |
| 2015 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2016 | */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2017 | 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] | 2018 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2019 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2021 | struct nfs4_state_owner *sp = state->owner; |
| 2022 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2023 | struct rpc_message msg = { |
| 2024 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2025 | .rpc_cred = state->owner->so_cred, |
| 2026 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2027 | struct rpc_task_setup task_setup_data = { |
| 2028 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2029 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2030 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2031 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2032 | .flags = RPC_TASK_ASYNC, |
| 2033 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2034 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2036 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2038 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2039 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2041 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2042 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2044 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2045 | if (calldata->arg.seqid == NULL) |
| 2046 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2047 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2048 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2049 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2050 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2051 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2052 | calldata->roc = roc; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2053 | path_get(path); |
| 2054 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2055 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2056 | msg.rpc_argp = &calldata->arg; |
| 2057 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2058 | task_setup_data.callback_data = calldata; |
| 2059 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2060 | if (IS_ERR(task)) |
| 2061 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2062 | status = 0; |
| 2063 | if (wait) |
| 2064 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2065 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2066 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2067 | out_free_calldata: |
| 2068 | kfree(calldata); |
| 2069 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2070 | if (roc) |
| 2071 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2072 | nfs4_put_open_state(state); |
| 2073 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2074 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2077 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2078 | 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] | 2079 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | struct nfs4_state *state; |
| 2081 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2082 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2083 | 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] | 2084 | if (IS_ERR(state)) |
| 2085 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2086 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2087 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2090 | 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] | 2091 | { |
| 2092 | if (ctx->state == NULL) |
| 2093 | return; |
| 2094 | if (is_sync) |
| 2095 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2096 | else |
| 2097 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2098 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | |
| 2100 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2101 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2102 | struct nfs4_server_caps_arg args = { |
| 2103 | .fhandle = fhandle, |
| 2104 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | struct nfs4_server_caps_res res = {}; |
| 2106 | struct rpc_message msg = { |
| 2107 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2108 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | .rpc_resp = &res, |
| 2110 | }; |
| 2111 | int status; |
| 2112 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2113 | 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] | 2114 | if (status == 0) { |
| 2115 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2116 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2117 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2118 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2119 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2120 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2122 | server->caps |= NFS_CAP_ACLS; |
| 2123 | if (res.has_links != 0) |
| 2124 | server->caps |= NFS_CAP_HARDLINKS; |
| 2125 | if (res.has_symlinks != 0) |
| 2126 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2127 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2128 | server->caps |= NFS_CAP_FILEID; |
| 2129 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2130 | server->caps |= NFS_CAP_MODE; |
| 2131 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2132 | server->caps |= NFS_CAP_NLINK; |
| 2133 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2134 | server->caps |= NFS_CAP_OWNER; |
| 2135 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2136 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2137 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2138 | server->caps |= NFS_CAP_ATIME; |
| 2139 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2140 | server->caps |= NFS_CAP_CTIME; |
| 2141 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2142 | server->caps |= NFS_CAP_MTIME; |
| 2143 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2144 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2145 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2146 | 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] | 2147 | server->acl_bitmask = res.acl_bitmask; |
| 2148 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | return status; |
| 2151 | } |
| 2152 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2153 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | { |
| 2155 | struct nfs4_exception exception = { }; |
| 2156 | int err; |
| 2157 | do { |
| 2158 | err = nfs4_handle_exception(server, |
| 2159 | _nfs4_server_capabilities(server, fhandle), |
| 2160 | &exception); |
| 2161 | } while (exception.retry); |
| 2162 | return err; |
| 2163 | } |
| 2164 | |
| 2165 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2166 | struct nfs_fsinfo *info) |
| 2167 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | struct nfs4_lookup_root_arg args = { |
| 2169 | .bitmask = nfs4_fattr_bitmap, |
| 2170 | }; |
| 2171 | struct nfs4_lookup_res res = { |
| 2172 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2173 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | .fh = fhandle, |
| 2175 | }; |
| 2176 | struct rpc_message msg = { |
| 2177 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2178 | .rpc_argp = &args, |
| 2179 | .rpc_resp = &res, |
| 2180 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2181 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2182 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2183 | 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] | 2184 | } |
| 2185 | |
| 2186 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2187 | struct nfs_fsinfo *info) |
| 2188 | { |
| 2189 | struct nfs4_exception exception = { }; |
| 2190 | int err; |
| 2191 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2192 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2193 | switch (err) { |
| 2194 | case 0: |
| 2195 | case -NFS4ERR_WRONGSEC: |
| 2196 | break; |
| 2197 | default: |
| 2198 | err = nfs4_handle_exception(server, err, &exception); |
| 2199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | } while (exception.retry); |
| 2201 | return err; |
| 2202 | } |
| 2203 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2204 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2205 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2206 | { |
| 2207 | struct rpc_auth *auth; |
| 2208 | int ret; |
| 2209 | |
| 2210 | auth = rpcauth_create(flavor, server->client); |
| 2211 | if (!auth) { |
| 2212 | ret = -EIO; |
| 2213 | goto out; |
| 2214 | } |
| 2215 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2216 | out: |
| 2217 | return ret; |
| 2218 | } |
| 2219 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2220 | 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] | 2221 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2223 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2224 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2226 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2227 | flav_array[len] = RPC_AUTH_NULL; |
| 2228 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2229 | |
| 2230 | for (i = 0; i < len; i++) { |
| 2231 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2232 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2233 | continue; |
| 2234 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2235 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2236 | /* |
| 2237 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2238 | * to access the mount. It could also mean that we tried to mount |
| 2239 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2240 | * existing mount programs don't handle -EACCES very well so it should |
| 2241 | * be mapped to -EPERM instead. |
| 2242 | */ |
| 2243 | if (status == -EACCES) |
| 2244 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2245 | return status; |
| 2246 | } |
| 2247 | |
| 2248 | /* |
| 2249 | * get the file handle for the "/" directory on the server |
| 2250 | */ |
| 2251 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2252 | struct nfs_fsinfo *info) |
| 2253 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame^] | 2254 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2255 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2256 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2257 | /* |
| 2258 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2259 | * by nfs4_map_errors() as this function exits. |
| 2260 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame^] | 2261 | 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] | 2262 | if (status == 0) |
| 2263 | status = nfs4_server_capabilities(server, fhandle); |
| 2264 | if (status == 0) |
| 2265 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2266 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2269 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2270 | /* |
| 2271 | * Get locations and (maybe) other attributes of a referral. |
| 2272 | * Note that we'll actually follow the referral later when |
| 2273 | * we detect fsid mismatch in inode revalidation |
| 2274 | */ |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2275 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, |
| 2276 | struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2277 | { |
| 2278 | int status = -ENOMEM; |
| 2279 | struct page *page = NULL; |
| 2280 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2281 | |
| 2282 | page = alloc_page(GFP_KERNEL); |
| 2283 | if (page == NULL) |
| 2284 | goto out; |
| 2285 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2286 | if (locations == NULL) |
| 2287 | goto out; |
| 2288 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2289 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2290 | if (status != 0) |
| 2291 | goto out; |
| 2292 | /* Make sure server returned a different fsid for the referral */ |
| 2293 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2294 | dprintk("%s: server did not return a different fsid for" |
| 2295 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2296 | status = -EIO; |
| 2297 | goto out; |
| 2298 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2299 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2300 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2301 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2302 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2303 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2304 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2305 | out: |
| 2306 | if (page) |
| 2307 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2308 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2309 | return status; |
| 2310 | } |
| 2311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2313 | { |
| 2314 | struct nfs4_getattr_arg args = { |
| 2315 | .fh = fhandle, |
| 2316 | .bitmask = server->attr_bitmask, |
| 2317 | }; |
| 2318 | struct nfs4_getattr_res res = { |
| 2319 | .fattr = fattr, |
| 2320 | .server = server, |
| 2321 | }; |
| 2322 | struct rpc_message msg = { |
| 2323 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2324 | .rpc_argp = &args, |
| 2325 | .rpc_resp = &res, |
| 2326 | }; |
| 2327 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2328 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2329 | 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] | 2330 | } |
| 2331 | |
| 2332 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2333 | { |
| 2334 | struct nfs4_exception exception = { }; |
| 2335 | int err; |
| 2336 | do { |
| 2337 | err = nfs4_handle_exception(server, |
| 2338 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2339 | &exception); |
| 2340 | } while (exception.retry); |
| 2341 | return err; |
| 2342 | } |
| 2343 | |
| 2344 | /* |
| 2345 | * The file is not closed if it is opened due to the a request to change |
| 2346 | * the size of the file. The open call will not be needed once the |
| 2347 | * VFS layer lookup-intents are implemented. |
| 2348 | * |
| 2349 | * Close is called when the inode is destroyed. |
| 2350 | * If we haven't opened the file for O_WRONLY, we |
| 2351 | * need to in the size_change case to obtain a stateid. |
| 2352 | * |
| 2353 | * Got race? |
| 2354 | * Because OPEN is always done by name in nfsv4, it is |
| 2355 | * possible that we opened a different file by the same |
| 2356 | * name. We can recognize this race condition, but we |
| 2357 | * can't do anything about it besides returning an error. |
| 2358 | * |
| 2359 | * This will be fixed with VFS changes (lookup-intent). |
| 2360 | */ |
| 2361 | static int |
| 2362 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2363 | struct iattr *sattr) |
| 2364 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2365 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2366 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2367 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | int status; |
| 2369 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2370 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2371 | pnfs_return_layout(inode); |
| 2372 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2373 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2375 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2376 | if (sattr->ia_valid & ATTR_FILE) { |
| 2377 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2378 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2379 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2380 | if (ctx) { |
| 2381 | cred = ctx->cred; |
| 2382 | state = ctx->state; |
| 2383 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2387 | if (status == 0) |
| 2388 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | return status; |
| 2390 | } |
| 2391 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2392 | static int _nfs4_proc_lookupfh(struct rpc_clnt *clnt, struct nfs_server *server, |
| 2393 | const struct nfs_fh *dirfh, const struct qstr *name, |
| 2394 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2395 | { |
| 2396 | int status; |
| 2397 | struct nfs4_lookup_arg args = { |
| 2398 | .bitmask = server->attr_bitmask, |
| 2399 | .dir_fh = dirfh, |
| 2400 | .name = name, |
| 2401 | }; |
| 2402 | struct nfs4_lookup_res res = { |
| 2403 | .server = server, |
| 2404 | .fattr = fattr, |
| 2405 | .fh = fhandle, |
| 2406 | }; |
| 2407 | struct rpc_message msg = { |
| 2408 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2409 | .rpc_argp = &args, |
| 2410 | .rpc_resp = &res, |
| 2411 | }; |
| 2412 | |
| 2413 | nfs_fattr_init(fattr); |
| 2414 | |
| 2415 | dprintk("NFS call lookupfh %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2416 | 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] | 2417 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2418 | return status; |
| 2419 | } |
| 2420 | |
| 2421 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2422 | struct qstr *name, struct nfs_fh *fhandle, |
| 2423 | struct nfs_fattr *fattr) |
| 2424 | { |
| 2425 | struct nfs4_exception exception = { }; |
| 2426 | int err; |
| 2427 | do { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2428 | err = _nfs4_proc_lookupfh(server->client, server, dirfh, name, fhandle, fattr); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2429 | /* FIXME: !!!! */ |
| 2430 | if (err == -NFS4ERR_MOVED) { |
| 2431 | err = -EREMOTE; |
| 2432 | break; |
| 2433 | } |
| 2434 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2435 | } while (exception.retry); |
| 2436 | return err; |
| 2437 | } |
| 2438 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2439 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2440 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2441 | struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2443 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | |
| 2445 | dprintk("NFS call lookup %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2446 | 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] | 2447 | if (status == -NFS4ERR_MOVED) |
| 2448 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | dprintk("NFS reply lookup: %d\n", status); |
| 2450 | return status; |
| 2451 | } |
| 2452 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2453 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2454 | { |
| 2455 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2456 | fattr->fsid.major = 1; |
| 2457 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2458 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2459 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2460 | fattr->nlink = 2; |
| 2461 | } |
| 2462 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2463 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2464 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | { |
| 2466 | struct nfs4_exception exception = { }; |
| 2467 | int err; |
| 2468 | do { |
| 2469 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2470 | _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | &exception); |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2472 | if (err == -EPERM) |
| 2473 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | } while (exception.retry); |
| 2475 | return err; |
| 2476 | } |
| 2477 | |
| 2478 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2479 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2480 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | struct nfs4_accessargs args = { |
| 2482 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2483 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2485 | struct nfs4_accessres res = { |
| 2486 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2487 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | struct rpc_message msg = { |
| 2489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2490 | .rpc_argp = &args, |
| 2491 | .rpc_resp = &res, |
| 2492 | .rpc_cred = entry->cred, |
| 2493 | }; |
| 2494 | int mode = entry->mask; |
| 2495 | int status; |
| 2496 | |
| 2497 | /* |
| 2498 | * Determine which access bits we want to ask for... |
| 2499 | */ |
| 2500 | if (mode & MAY_READ) |
| 2501 | args.access |= NFS4_ACCESS_READ; |
| 2502 | if (S_ISDIR(inode->i_mode)) { |
| 2503 | if (mode & MAY_WRITE) |
| 2504 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2505 | if (mode & MAY_EXEC) |
| 2506 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2507 | } else { |
| 2508 | if (mode & MAY_WRITE) |
| 2509 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2510 | if (mode & MAY_EXEC) |
| 2511 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2512 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2513 | |
| 2514 | res.fattr = nfs_alloc_fattr(); |
| 2515 | if (res.fattr == NULL) |
| 2516 | return -ENOMEM; |
| 2517 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2518 | 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] | 2519 | if (!status) { |
| 2520 | entry->mask = 0; |
| 2521 | if (res.access & NFS4_ACCESS_READ) |
| 2522 | entry->mask |= MAY_READ; |
| 2523 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2524 | entry->mask |= MAY_WRITE; |
| 2525 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2526 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2527 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2529 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | return status; |
| 2531 | } |
| 2532 | |
| 2533 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2534 | { |
| 2535 | struct nfs4_exception exception = { }; |
| 2536 | int err; |
| 2537 | do { |
| 2538 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2539 | _nfs4_proc_access(inode, entry), |
| 2540 | &exception); |
| 2541 | } while (exception.retry); |
| 2542 | return err; |
| 2543 | } |
| 2544 | |
| 2545 | /* |
| 2546 | * TODO: For the time being, we don't try to get any attributes |
| 2547 | * along with any of the zero-copy operations READ, READDIR, |
| 2548 | * READLINK, WRITE. |
| 2549 | * |
| 2550 | * In the case of the first three, we want to put the GETATTR |
| 2551 | * after the read-type operation -- this is because it is hard |
| 2552 | * to predict the length of a GETATTR response in v4, and thus |
| 2553 | * align the READ data correctly. This means that the GETATTR |
| 2554 | * may end up partially falling into the page cache, and we should |
| 2555 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2556 | * To do this efficiently, we need to know the total length |
| 2557 | * of data received, which doesn't seem to be available outside |
| 2558 | * of the RPC layer. |
| 2559 | * |
| 2560 | * In the case of WRITE, we also want to put the GETATTR after |
| 2561 | * the operation -- in this case because we want to make sure |
| 2562 | * we get the post-operation mtime and size. This means that |
| 2563 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2564 | * of it which would leave room in the 'tail' iovec. |
| 2565 | * |
| 2566 | * Both of these changes to the XDR layer would in fact be quite |
| 2567 | * minor, but I decided to leave them for a subsequent patch. |
| 2568 | */ |
| 2569 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2570 | unsigned int pgbase, unsigned int pglen) |
| 2571 | { |
| 2572 | struct nfs4_readlink args = { |
| 2573 | .fh = NFS_FH(inode), |
| 2574 | .pgbase = pgbase, |
| 2575 | .pglen = pglen, |
| 2576 | .pages = &page, |
| 2577 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2578 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | struct rpc_message msg = { |
| 2580 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2581 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2582 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | }; |
| 2584 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2585 | 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] | 2586 | } |
| 2587 | |
| 2588 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2589 | unsigned int pgbase, unsigned int pglen) |
| 2590 | { |
| 2591 | struct nfs4_exception exception = { }; |
| 2592 | int err; |
| 2593 | do { |
| 2594 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2595 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2596 | &exception); |
| 2597 | } while (exception.retry); |
| 2598 | return err; |
| 2599 | } |
| 2600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | /* |
| 2602 | * Got race? |
| 2603 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2604 | * Until then, this create/open method is prone to inefficiency and race |
| 2605 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2606 | * placed on the wire. |
| 2607 | * |
| 2608 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2609 | * The file will be opened again in the subsequent VFS open call |
| 2610 | * (nfs4_proc_file_open). |
| 2611 | * |
| 2612 | * The open for read will just hang around to be used by any process that |
| 2613 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2614 | */ |
| 2615 | |
| 2616 | static int |
| 2617 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2618 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2620 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2621 | .dentry = dentry, |
| 2622 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2623 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2625 | struct rpc_cred *cred = NULL; |
| 2626 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | int status = 0; |
| 2628 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2629 | if (ctx != NULL) { |
| 2630 | cred = ctx->cred; |
| 2631 | path = &ctx->path; |
| 2632 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2634 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2635 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2636 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | if (IS_ERR(state)) { |
| 2638 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2639 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2641 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2642 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2643 | if (ctx != NULL) |
| 2644 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2645 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2646 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | out: |
| 2648 | return status; |
| 2649 | } |
| 2650 | |
| 2651 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2652 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2653 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2654 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2656 | .name.len = name->len, |
| 2657 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2658 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2660 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2661 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2662 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2664 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2665 | .rpc_argp = &args, |
| 2666 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2668 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2670 | res.dir_attr = nfs_alloc_fattr(); |
| 2671 | if (res.dir_attr == NULL) |
| 2672 | goto out; |
| 2673 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2674 | 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] | 2675 | if (status == 0) { |
| 2676 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2677 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2678 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2679 | nfs_free_fattr(res.dir_attr); |
| 2680 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | return status; |
| 2682 | } |
| 2683 | |
| 2684 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2685 | { |
| 2686 | struct nfs4_exception exception = { }; |
| 2687 | int err; |
| 2688 | do { |
| 2689 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2690 | _nfs4_proc_remove(dir, name), |
| 2691 | &exception); |
| 2692 | } while (exception.retry); |
| 2693 | return err; |
| 2694 | } |
| 2695 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2696 | 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] | 2697 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2698 | struct nfs_server *server = NFS_SERVER(dir); |
| 2699 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2700 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2702 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2703 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2704 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2708 | 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] | 2709 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2710 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2711 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2712 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2713 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2714 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2715 | return 0; |
| 2716 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2717 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2718 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2721 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2722 | { |
| 2723 | struct nfs_server *server = NFS_SERVER(dir); |
| 2724 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2725 | struct nfs_renameres *res = msg->rpc_resp; |
| 2726 | |
| 2727 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2728 | arg->bitmask = server->attr_bitmask; |
| 2729 | res->server = server; |
| 2730 | } |
| 2731 | |
| 2732 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2733 | struct inode *new_dir) |
| 2734 | { |
| 2735 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2736 | |
| 2737 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2738 | return 0; |
| 2739 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2740 | return 0; |
| 2741 | |
| 2742 | update_changeattr(old_dir, &res->old_cinfo); |
| 2743 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2744 | update_changeattr(new_dir, &res->new_cinfo); |
| 2745 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2746 | return 1; |
| 2747 | } |
| 2748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2750 | struct inode *new_dir, struct qstr *new_name) |
| 2751 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2752 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2753 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | .old_dir = NFS_FH(old_dir), |
| 2755 | .new_dir = NFS_FH(new_dir), |
| 2756 | .old_name = old_name, |
| 2757 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2758 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2760 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2761 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2762 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | struct rpc_message msg = { |
| 2764 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2765 | .rpc_argp = &arg, |
| 2766 | .rpc_resp = &res, |
| 2767 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2768 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2770 | res.old_fattr = nfs_alloc_fattr(); |
| 2771 | res.new_fattr = nfs_alloc_fattr(); |
| 2772 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2773 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2775 | 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] | 2776 | if (!status) { |
| 2777 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2778 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2780 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2782 | out: |
| 2783 | nfs_free_fattr(res.new_fattr); |
| 2784 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | return status; |
| 2786 | } |
| 2787 | |
| 2788 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2789 | struct inode *new_dir, struct qstr *new_name) |
| 2790 | { |
| 2791 | struct nfs4_exception exception = { }; |
| 2792 | int err; |
| 2793 | do { |
| 2794 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2795 | _nfs4_proc_rename(old_dir, old_name, |
| 2796 | new_dir, new_name), |
| 2797 | &exception); |
| 2798 | } while (exception.retry); |
| 2799 | return err; |
| 2800 | } |
| 2801 | |
| 2802 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2803 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2804 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | struct nfs4_link_arg arg = { |
| 2806 | .fh = NFS_FH(inode), |
| 2807 | .dir_fh = NFS_FH(dir), |
| 2808 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2809 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2811 | struct nfs4_link_res res = { |
| 2812 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2813 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | struct rpc_message msg = { |
| 2815 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2816 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2817 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2819 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2821 | res.fattr = nfs_alloc_fattr(); |
| 2822 | res.dir_attr = nfs_alloc_fattr(); |
| 2823 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2824 | goto out; |
| 2825 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2826 | 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] | 2827 | if (!status) { |
| 2828 | update_changeattr(dir, &res.cinfo); |
| 2829 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2830 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2831 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2832 | out: |
| 2833 | nfs_free_fattr(res.dir_attr); |
| 2834 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | return status; |
| 2836 | } |
| 2837 | |
| 2838 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2839 | { |
| 2840 | struct nfs4_exception exception = { }; |
| 2841 | int err; |
| 2842 | do { |
| 2843 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2844 | _nfs4_proc_link(inode, dir, name), |
| 2845 | &exception); |
| 2846 | } while (exception.retry); |
| 2847 | return err; |
| 2848 | } |
| 2849 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2850 | struct nfs4_createdata { |
| 2851 | struct rpc_message msg; |
| 2852 | struct nfs4_create_arg arg; |
| 2853 | struct nfs4_create_res res; |
| 2854 | struct nfs_fh fh; |
| 2855 | struct nfs_fattr fattr; |
| 2856 | struct nfs_fattr dir_fattr; |
| 2857 | }; |
| 2858 | |
| 2859 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2860 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2861 | { |
| 2862 | struct nfs4_createdata *data; |
| 2863 | |
| 2864 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2865 | if (data != NULL) { |
| 2866 | struct nfs_server *server = NFS_SERVER(dir); |
| 2867 | |
| 2868 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2869 | data->msg.rpc_argp = &data->arg; |
| 2870 | data->msg.rpc_resp = &data->res; |
| 2871 | data->arg.dir_fh = NFS_FH(dir); |
| 2872 | data->arg.server = server; |
| 2873 | data->arg.name = name; |
| 2874 | data->arg.attrs = sattr; |
| 2875 | data->arg.ftype = ftype; |
| 2876 | data->arg.bitmask = server->attr_bitmask; |
| 2877 | data->res.server = server; |
| 2878 | data->res.fh = &data->fh; |
| 2879 | data->res.fattr = &data->fattr; |
| 2880 | data->res.dir_fattr = &data->dir_fattr; |
| 2881 | nfs_fattr_init(data->res.fattr); |
| 2882 | nfs_fattr_init(data->res.dir_fattr); |
| 2883 | } |
| 2884 | return data; |
| 2885 | } |
| 2886 | |
| 2887 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2888 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2889 | 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] | 2890 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2891 | if (status == 0) { |
| 2892 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2893 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2894 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2895 | } |
| 2896 | return status; |
| 2897 | } |
| 2898 | |
| 2899 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2900 | { |
| 2901 | kfree(data); |
| 2902 | } |
| 2903 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2904 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2905 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2907 | struct nfs4_createdata *data; |
| 2908 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2910 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2911 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2912 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2913 | status = -ENOMEM; |
| 2914 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2915 | if (data == NULL) |
| 2916 | goto out; |
| 2917 | |
| 2918 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2919 | data->arg.u.symlink.pages = &page; |
| 2920 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2922 | status = nfs4_do_create(dir, dentry, data); |
| 2923 | |
| 2924 | nfs4_free_createdata(data); |
| 2925 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | return status; |
| 2927 | } |
| 2928 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2929 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2930 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | { |
| 2932 | struct nfs4_exception exception = { }; |
| 2933 | int err; |
| 2934 | do { |
| 2935 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2936 | _nfs4_proc_symlink(dir, dentry, page, |
| 2937 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | &exception); |
| 2939 | } while (exception.retry); |
| 2940 | return err; |
| 2941 | } |
| 2942 | |
| 2943 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2944 | struct iattr *sattr) |
| 2945 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2946 | struct nfs4_createdata *data; |
| 2947 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2949 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2950 | if (data == NULL) |
| 2951 | goto out; |
| 2952 | |
| 2953 | status = nfs4_do_create(dir, dentry, data); |
| 2954 | |
| 2955 | nfs4_free_createdata(data); |
| 2956 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | return status; |
| 2958 | } |
| 2959 | |
| 2960 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2961 | struct iattr *sattr) |
| 2962 | { |
| 2963 | struct nfs4_exception exception = { }; |
| 2964 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2965 | |
| 2966 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | do { |
| 2968 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2969 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2970 | &exception); |
| 2971 | } while (exception.retry); |
| 2972 | return err; |
| 2973 | } |
| 2974 | |
| 2975 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2976 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | { |
| 2978 | struct inode *dir = dentry->d_inode; |
| 2979 | struct nfs4_readdir_arg args = { |
| 2980 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2981 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | .pgbase = 0, |
| 2983 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2984 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2985 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | }; |
| 2987 | struct nfs4_readdir_res res; |
| 2988 | struct rpc_message msg = { |
| 2989 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2990 | .rpc_argp = &args, |
| 2991 | .rpc_resp = &res, |
| 2992 | .rpc_cred = cred, |
| 2993 | }; |
| 2994 | int status; |
| 2995 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2996 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2997 | dentry->d_parent->d_name.name, |
| 2998 | dentry->d_name.name, |
| 2999 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 3001 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3002 | 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] | 3003 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3005 | status += args.pgbase; |
| 3006 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3007 | |
| 3008 | nfs_invalidate_atime(dir); |
| 3009 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3010 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | return status; |
| 3012 | } |
| 3013 | |
| 3014 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3015 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | { |
| 3017 | struct nfs4_exception exception = { }; |
| 3018 | int err; |
| 3019 | do { |
| 3020 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3021 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3022 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | &exception); |
| 3024 | } while (exception.retry); |
| 3025 | return err; |
| 3026 | } |
| 3027 | |
| 3028 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3029 | struct iattr *sattr, dev_t rdev) |
| 3030 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3031 | struct nfs4_createdata *data; |
| 3032 | int mode = sattr->ia_mode; |
| 3033 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | |
| 3035 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3036 | 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] | 3037 | |
| 3038 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3039 | if (data == NULL) |
| 3040 | goto out; |
| 3041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3043 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3045 | data->arg.ftype = NF4BLK; |
| 3046 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3047 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | } |
| 3049 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3050 | data->arg.ftype = NF4CHR; |
| 3051 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3052 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3055 | status = nfs4_do_create(dir, dentry, data); |
| 3056 | |
| 3057 | nfs4_free_createdata(data); |
| 3058 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | return status; |
| 3060 | } |
| 3061 | |
| 3062 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3063 | struct iattr *sattr, dev_t rdev) |
| 3064 | { |
| 3065 | struct nfs4_exception exception = { }; |
| 3066 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3067 | |
| 3068 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | do { |
| 3070 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3071 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3072 | &exception); |
| 3073 | } while (exception.retry); |
| 3074 | return err; |
| 3075 | } |
| 3076 | |
| 3077 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3078 | struct nfs_fsstat *fsstat) |
| 3079 | { |
| 3080 | struct nfs4_statfs_arg args = { |
| 3081 | .fh = fhandle, |
| 3082 | .bitmask = server->attr_bitmask, |
| 3083 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3084 | struct nfs4_statfs_res res = { |
| 3085 | .fsstat = fsstat, |
| 3086 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | struct rpc_message msg = { |
| 3088 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3089 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3090 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | }; |
| 3092 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3093 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3094 | 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] | 3095 | } |
| 3096 | |
| 3097 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3098 | { |
| 3099 | struct nfs4_exception exception = { }; |
| 3100 | int err; |
| 3101 | do { |
| 3102 | err = nfs4_handle_exception(server, |
| 3103 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3104 | &exception); |
| 3105 | } while (exception.retry); |
| 3106 | return err; |
| 3107 | } |
| 3108 | |
| 3109 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3110 | struct nfs_fsinfo *fsinfo) |
| 3111 | { |
| 3112 | struct nfs4_fsinfo_arg args = { |
| 3113 | .fh = fhandle, |
| 3114 | .bitmask = server->attr_bitmask, |
| 3115 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3116 | struct nfs4_fsinfo_res res = { |
| 3117 | .fsinfo = fsinfo, |
| 3118 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | struct rpc_message msg = { |
| 3120 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3121 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3122 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | }; |
| 3124 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3125 | 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] | 3126 | } |
| 3127 | |
| 3128 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3129 | { |
| 3130 | struct nfs4_exception exception = { }; |
| 3131 | int err; |
| 3132 | |
| 3133 | do { |
| 3134 | err = nfs4_handle_exception(server, |
| 3135 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3136 | &exception); |
| 3137 | } while (exception.retry); |
| 3138 | return err; |
| 3139 | } |
| 3140 | |
| 3141 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3142 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3143 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3145 | } |
| 3146 | |
| 3147 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3148 | struct nfs_pathconf *pathconf) |
| 3149 | { |
| 3150 | struct nfs4_pathconf_arg args = { |
| 3151 | .fh = fhandle, |
| 3152 | .bitmask = server->attr_bitmask, |
| 3153 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3154 | struct nfs4_pathconf_res res = { |
| 3155 | .pathconf = pathconf, |
| 3156 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | struct rpc_message msg = { |
| 3158 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3159 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3160 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | }; |
| 3162 | |
| 3163 | /* None of the pathconf attributes are mandatory to implement */ |
| 3164 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3165 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3166 | return 0; |
| 3167 | } |
| 3168 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3169 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3170 | 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] | 3171 | } |
| 3172 | |
| 3173 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3174 | struct nfs_pathconf *pathconf) |
| 3175 | { |
| 3176 | struct nfs4_exception exception = { }; |
| 3177 | int err; |
| 3178 | |
| 3179 | do { |
| 3180 | err = nfs4_handle_exception(server, |
| 3181 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3182 | &exception); |
| 3183 | } while (exception.retry); |
| 3184 | return err; |
| 3185 | } |
| 3186 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3187 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3188 | { |
| 3189 | nfs_invalidate_atime(data->inode); |
| 3190 | } |
| 3191 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3192 | 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] | 3193 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3194 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3196 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3197 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3198 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3200 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3201 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3203 | renew_lease(server, data->timestamp); |
| 3204 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | } |
| 3206 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3207 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3208 | { |
| 3209 | |
| 3210 | dprintk("--> %s\n", __func__); |
| 3211 | |
| 3212 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3213 | return -EAGAIN; |
| 3214 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3215 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3216 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3219 | 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] | 3220 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3222 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3223 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | } |
| 3225 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3226 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3227 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3228 | { |
| 3229 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3230 | put_lseg(data->lseg); |
| 3231 | data->lseg = NULL; |
| 3232 | /* offsets will differ in the dense stripe case */ |
| 3233 | data->args.offset = data->mds_offset; |
| 3234 | data->ds_clp = NULL; |
| 3235 | data->args.fh = NFS_FH(data->inode); |
| 3236 | data->read_done_cb = nfs4_read_done_cb; |
| 3237 | task->tk_ops = data->mds_ops; |
| 3238 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3239 | } |
| 3240 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3241 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3242 | 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] | 3243 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | struct inode *inode = data->inode; |
| 3245 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3246 | 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] | 3247 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3248 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3250 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3252 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3253 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3254 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3257 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3258 | { |
| 3259 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3260 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3261 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3262 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3263 | } |
| 3264 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3265 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3266 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3267 | { |
| 3268 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3269 | put_lseg(data->lseg); |
| 3270 | data->lseg = NULL; |
| 3271 | data->ds_clp = NULL; |
| 3272 | data->write_done_cb = nfs4_write_done_cb; |
| 3273 | data->args.fh = NFS_FH(data->inode); |
| 3274 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3275 | data->args.offset = data->mds_offset; |
| 3276 | data->res.fattr = &data->fattr; |
| 3277 | task->tk_ops = data->mds_ops; |
| 3278 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3279 | } |
| 3280 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3281 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3282 | 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] | 3283 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3284 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3285 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3286 | if (data->lseg) { |
| 3287 | data->args.bitmask = NULL; |
| 3288 | data->res.fattr = NULL; |
| 3289 | } else |
| 3290 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3291 | if (!data->write_done_cb) |
| 3292 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3293 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | data->timestamp = jiffies; |
| 3295 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3296 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | } |
| 3298 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3299 | 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] | 3300 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3302 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3303 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3304 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3305 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3307 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3308 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | } |
| 3310 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3311 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3312 | { |
| 3313 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3314 | return -EAGAIN; |
| 3315 | return data->write_done_cb(task, data); |
| 3316 | } |
| 3317 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3318 | 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] | 3319 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3320 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3321 | |
| 3322 | if (data->lseg) { |
| 3323 | data->args.bitmask = NULL; |
| 3324 | data->res.fattr = NULL; |
| 3325 | } else |
| 3326 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3327 | if (!data->write_done_cb) |
| 3328 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3329 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3330 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | } |
| 3332 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3333 | struct nfs4_renewdata { |
| 3334 | struct nfs_client *client; |
| 3335 | unsigned long timestamp; |
| 3336 | }; |
| 3337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | /* |
| 3339 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3340 | * standalone procedure for queueing an asynchronous RENEW. |
| 3341 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3342 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3343 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3344 | struct nfs4_renewdata *data = calldata; |
| 3345 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3346 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3347 | if (atomic_read(&clp->cl_count) > 1) |
| 3348 | nfs4_schedule_state_renewal(clp); |
| 3349 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3350 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3351 | } |
| 3352 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3353 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3355 | struct nfs4_renewdata *data = calldata; |
| 3356 | struct nfs_client *clp = data->client; |
| 3357 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | |
| 3359 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3360 | /* Unless we're shutting down, schedule state recovery! */ |
| 3361 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3362 | nfs4_schedule_lease_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | return; |
| 3364 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3365 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | } |
| 3367 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3368 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3369 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3370 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3371 | }; |
| 3372 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3373 | 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] | 3374 | { |
| 3375 | struct rpc_message msg = { |
| 3376 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3377 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3378 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3380 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3382 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3383 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3384 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3385 | if (data == NULL) |
| 3386 | return -ENOMEM; |
| 3387 | data->client = clp; |
| 3388 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3390 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3393 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | { |
| 3395 | struct rpc_message msg = { |
| 3396 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3397 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3398 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | }; |
| 3400 | unsigned long now = jiffies; |
| 3401 | int status; |
| 3402 | |
| 3403 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3404 | if (status < 0) |
| 3405 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3406 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | return 0; |
| 3408 | } |
| 3409 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3410 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3411 | { |
| 3412 | return (server->caps & NFS_CAP_ACLS) |
| 3413 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3414 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3415 | } |
| 3416 | |
| 3417 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3418 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3419 | * the stack. |
| 3420 | */ |
| 3421 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3422 | |
| 3423 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3424 | struct page **pages, unsigned int *pgbase) |
| 3425 | { |
| 3426 | const void *p = buf; |
| 3427 | |
| 3428 | *pgbase = offset_in_page(buf); |
| 3429 | p -= *pgbase; |
| 3430 | while (p < buf + buflen) { |
| 3431 | *(pages++) = virt_to_page(p); |
| 3432 | p += PAGE_CACHE_SIZE; |
| 3433 | } |
| 3434 | } |
| 3435 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3436 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3437 | struct page **pages, unsigned int *pgbase) |
| 3438 | { |
| 3439 | struct page *newpage, **spages; |
| 3440 | int rc = 0; |
| 3441 | size_t len; |
| 3442 | spages = pages; |
| 3443 | |
| 3444 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3445 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3446 | newpage = alloc_page(GFP_KERNEL); |
| 3447 | |
| 3448 | if (newpage == NULL) |
| 3449 | goto unwind; |
| 3450 | memcpy(page_address(newpage), buf, len); |
| 3451 | buf += len; |
| 3452 | buflen -= len; |
| 3453 | *pages++ = newpage; |
| 3454 | rc++; |
| 3455 | } while (buflen != 0); |
| 3456 | |
| 3457 | return rc; |
| 3458 | |
| 3459 | unwind: |
| 3460 | for(; rc > 0; rc--) |
| 3461 | __free_page(spages[rc-1]); |
| 3462 | return -ENOMEM; |
| 3463 | } |
| 3464 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3465 | struct nfs4_cached_acl { |
| 3466 | int cached; |
| 3467 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3468 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3469 | }; |
| 3470 | |
| 3471 | 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] | 3472 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3473 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3474 | |
| 3475 | spin_lock(&inode->i_lock); |
| 3476 | kfree(nfsi->nfs4_acl); |
| 3477 | nfsi->nfs4_acl = acl; |
| 3478 | spin_unlock(&inode->i_lock); |
| 3479 | } |
| 3480 | |
| 3481 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3482 | { |
| 3483 | nfs4_set_cached_acl(inode, NULL); |
| 3484 | } |
| 3485 | |
| 3486 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3487 | { |
| 3488 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3489 | struct nfs4_cached_acl *acl; |
| 3490 | int ret = -ENOENT; |
| 3491 | |
| 3492 | spin_lock(&inode->i_lock); |
| 3493 | acl = nfsi->nfs4_acl; |
| 3494 | if (acl == NULL) |
| 3495 | goto out; |
| 3496 | if (buf == NULL) /* user is just asking for length */ |
| 3497 | goto out_len; |
| 3498 | if (acl->cached == 0) |
| 3499 | goto out; |
| 3500 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3501 | if (acl->len > buflen) |
| 3502 | goto out; |
| 3503 | memcpy(buf, acl->data, acl->len); |
| 3504 | out_len: |
| 3505 | ret = acl->len; |
| 3506 | out: |
| 3507 | spin_unlock(&inode->i_lock); |
| 3508 | return ret; |
| 3509 | } |
| 3510 | |
| 3511 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3512 | { |
| 3513 | struct nfs4_cached_acl *acl; |
| 3514 | |
| 3515 | if (buf && acl_len <= PAGE_SIZE) { |
| 3516 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3517 | if (acl == NULL) |
| 3518 | goto out; |
| 3519 | acl->cached = 1; |
| 3520 | memcpy(acl->data, buf, acl_len); |
| 3521 | } else { |
| 3522 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3523 | if (acl == NULL) |
| 3524 | goto out; |
| 3525 | acl->cached = 0; |
| 3526 | } |
| 3527 | acl->len = acl_len; |
| 3528 | out: |
| 3529 | nfs4_set_cached_acl(inode, acl); |
| 3530 | } |
| 3531 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3532 | 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] | 3533 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3534 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3535 | struct nfs_getaclargs args = { |
| 3536 | .fh = NFS_FH(inode), |
| 3537 | .acl_pages = pages, |
| 3538 | .acl_len = buflen, |
| 3539 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3540 | struct nfs_getaclres res = { |
| 3541 | .acl_len = buflen, |
| 3542 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3543 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3544 | struct rpc_message msg = { |
| 3545 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3546 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3547 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3548 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3549 | struct page *localpage = NULL; |
| 3550 | int ret; |
| 3551 | |
| 3552 | if (buflen < PAGE_SIZE) { |
| 3553 | /* As long as we're doing a round trip to the server anyway, |
| 3554 | * let's be prepared for a page of acl data. */ |
| 3555 | localpage = alloc_page(GFP_KERNEL); |
| 3556 | resp_buf = page_address(localpage); |
| 3557 | if (localpage == NULL) |
| 3558 | return -ENOMEM; |
| 3559 | args.acl_pages[0] = localpage; |
| 3560 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3561 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3562 | } else { |
| 3563 | resp_buf = buf; |
| 3564 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3565 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3566 | 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] | 3567 | if (ret) |
| 3568 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3569 | if (res.acl_len > args.acl_len) |
| 3570 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3571 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3572 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3573 | if (buf) { |
| 3574 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3575 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3576 | goto out_free; |
| 3577 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3578 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3579 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3580 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3581 | out_free: |
| 3582 | if (localpage) |
| 3583 | __free_page(localpage); |
| 3584 | return ret; |
| 3585 | } |
| 3586 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3587 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3588 | { |
| 3589 | struct nfs4_exception exception = { }; |
| 3590 | ssize_t ret; |
| 3591 | do { |
| 3592 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3593 | if (ret >= 0) |
| 3594 | break; |
| 3595 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3596 | } while (exception.retry); |
| 3597 | return ret; |
| 3598 | } |
| 3599 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3600 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3601 | { |
| 3602 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3603 | int ret; |
| 3604 | |
| 3605 | if (!nfs4_server_supports_acls(server)) |
| 3606 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3607 | ret = nfs_revalidate_inode(server, inode); |
| 3608 | if (ret < 0) |
| 3609 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3610 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3611 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3612 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3613 | if (ret != -ENOENT) |
| 3614 | return ret; |
| 3615 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3616 | } |
| 3617 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3618 | static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3619 | { |
| 3620 | struct nfs_server *server = NFS_SERVER(inode); |
| 3621 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3622 | struct nfs_setaclargs arg = { |
| 3623 | .fh = NFS_FH(inode), |
| 3624 | .acl_pages = pages, |
| 3625 | .acl_len = buflen, |
| 3626 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3627 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3628 | struct rpc_message msg = { |
| 3629 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3630 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3631 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3632 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3633 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3634 | |
| 3635 | if (!nfs4_server_supports_acls(server)) |
| 3636 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3637 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3638 | if (i < 0) |
| 3639 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3640 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3641 | 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] | 3642 | |
| 3643 | /* |
| 3644 | * Free each page after tx, so the only ref left is |
| 3645 | * held by the network stack |
| 3646 | */ |
| 3647 | for (; i > 0; i--) |
| 3648 | put_page(pages[i-1]); |
| 3649 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3650 | /* |
| 3651 | * Acl update can result in inode attribute update. |
| 3652 | * so mark the attribute cache invalid. |
| 3653 | */ |
| 3654 | spin_lock(&inode->i_lock); |
| 3655 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3656 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3657 | nfs_access_zap_cache(inode); |
| 3658 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3659 | return ret; |
| 3660 | } |
| 3661 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3662 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3663 | { |
| 3664 | struct nfs4_exception exception = { }; |
| 3665 | int err; |
| 3666 | do { |
| 3667 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3668 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3669 | &exception); |
| 3670 | } while (exception.retry); |
| 3671 | return err; |
| 3672 | } |
| 3673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3675 | 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] | 3676 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3677 | struct nfs_client *clp = server->nfs_client; |
| 3678 | |
| 3679 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | return 0; |
| 3681 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3682 | case -NFS4ERR_ADMIN_REVOKED: |
| 3683 | case -NFS4ERR_BAD_STATEID: |
| 3684 | case -NFS4ERR_OPENMODE: |
| 3685 | if (state == NULL) |
| 3686 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3687 | nfs4_schedule_stateid_recovery(server, state); |
| 3688 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3689 | case -NFS4ERR_EXPIRED: |
| 3690 | if (state != NULL) |
| 3691 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3693 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3694 | nfs4_schedule_lease_recovery(clp); |
| 3695 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3696 | #if defined(CONFIG_NFS_V4_1) |
| 3697 | case -NFS4ERR_BADSESSION: |
| 3698 | case -NFS4ERR_BADSLOT: |
| 3699 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3700 | case -NFS4ERR_DEADSESSION: |
| 3701 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3702 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3703 | case -NFS4ERR_SEQ_MISORDERED: |
| 3704 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3705 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3706 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3707 | task->tk_status = 0; |
| 3708 | return -EAGAIN; |
| 3709 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3711 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3712 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3713 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3715 | task->tk_status = 0; |
| 3716 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3717 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | case -NFS4ERR_OLD_STATEID: |
| 3719 | task->tk_status = 0; |
| 3720 | return -EAGAIN; |
| 3721 | } |
| 3722 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3723 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3724 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3725 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3726 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3727 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3728 | task->tk_status = 0; |
| 3729 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3732 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3733 | unsigned short port, struct rpc_cred *cred, |
| 3734 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | { |
| 3736 | nfs4_verifier sc_verifier; |
| 3737 | struct nfs4_setclientid setclientid = { |
| 3738 | .sc_verifier = &sc_verifier, |
| 3739 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3740 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | }; |
| 3742 | struct rpc_message msg = { |
| 3743 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3744 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3745 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3746 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3748 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | int loop = 0; |
| 3750 | int status; |
| 3751 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3752 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3754 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3755 | |
| 3756 | for(;;) { |
| 3757 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3758 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3759 | clp->cl_ipaddr, |
| 3760 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3761 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3762 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3763 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3764 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3765 | clp->cl_id_uniquifier); |
| 3766 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3767 | sizeof(setclientid.sc_netid), |
| 3768 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3769 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3771 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3773 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3774 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | if (status != -NFS4ERR_CLID_INUSE) |
| 3776 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3777 | if (loop != 0) { |
| 3778 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3780 | } |
| 3781 | ++loop; |
| 3782 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | } |
| 3784 | return status; |
| 3785 | } |
| 3786 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3787 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3788 | struct nfs4_setclientid_res *arg, |
| 3789 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | { |
| 3791 | struct nfs_fsinfo fsinfo; |
| 3792 | struct rpc_message msg = { |
| 3793 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3794 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3796 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | }; |
| 3798 | unsigned long now; |
| 3799 | int status; |
| 3800 | |
| 3801 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3802 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | if (status == 0) { |
| 3804 | spin_lock(&clp->cl_lock); |
| 3805 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3806 | clp->cl_last_renewal = now; |
| 3807 | spin_unlock(&clp->cl_lock); |
| 3808 | } |
| 3809 | return status; |
| 3810 | } |
| 3811 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3812 | struct nfs4_delegreturndata { |
| 3813 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3814 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3815 | struct nfs_fh fh; |
| 3816 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3817 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3818 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3819 | int rpc_status; |
| 3820 | }; |
| 3821 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3822 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3823 | { |
| 3824 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3825 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3826 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3827 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3828 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3829 | switch (task->tk_status) { |
| 3830 | case -NFS4ERR_STALE_STATEID: |
| 3831 | case -NFS4ERR_EXPIRED: |
| 3832 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3833 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3834 | break; |
| 3835 | default: |
| 3836 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3837 | -EAGAIN) { |
| 3838 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3839 | return; |
| 3840 | } |
| 3841 | } |
| 3842 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | static void nfs4_delegreturn_release(void *calldata) |
| 3846 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3847 | kfree(calldata); |
| 3848 | } |
| 3849 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3850 | #if defined(CONFIG_NFS_V4_1) |
| 3851 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3852 | { |
| 3853 | struct nfs4_delegreturndata *d_data; |
| 3854 | |
| 3855 | d_data = (struct nfs4_delegreturndata *)data; |
| 3856 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3857 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3858 | &d_data->args.seq_args, |
| 3859 | &d_data->res.seq_res, 1, task)) |
| 3860 | return; |
| 3861 | rpc_call_start(task); |
| 3862 | } |
| 3863 | #endif /* CONFIG_NFS_V4_1 */ |
| 3864 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3865 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3866 | #if defined(CONFIG_NFS_V4_1) |
| 3867 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3868 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3869 | .rpc_call_done = nfs4_delegreturn_done, |
| 3870 | .rpc_release = nfs4_delegreturn_release, |
| 3871 | }; |
| 3872 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3873 | 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] | 3874 | { |
| 3875 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3876 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3877 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3878 | struct rpc_message msg = { |
| 3879 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3880 | .rpc_cred = cred, |
| 3881 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3882 | struct rpc_task_setup task_setup_data = { |
| 3883 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3884 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3885 | .callback_ops = &nfs4_delegreturn_ops, |
| 3886 | .flags = RPC_TASK_ASYNC, |
| 3887 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3888 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3889 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3890 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3891 | if (data == NULL) |
| 3892 | return -ENOMEM; |
| 3893 | data->args.fhandle = &data->fh; |
| 3894 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3895 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3896 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3897 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3898 | data->res.fattr = &data->fattr; |
| 3899 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3900 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3901 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3902 | data->rpc_status = 0; |
| 3903 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3904 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3905 | msg.rpc_argp = &data->args; |
| 3906 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3907 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3908 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3909 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3910 | if (!issync) |
| 3911 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3912 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3913 | if (status != 0) |
| 3914 | goto out; |
| 3915 | status = data->rpc_status; |
| 3916 | if (status != 0) |
| 3917 | goto out; |
| 3918 | nfs_refresh_inode(inode, &data->fattr); |
| 3919 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3920 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3921 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | } |
| 3923 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3924 | 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] | 3925 | { |
| 3926 | struct nfs_server *server = NFS_SERVER(inode); |
| 3927 | struct nfs4_exception exception = { }; |
| 3928 | int err; |
| 3929 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3930 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3931 | switch (err) { |
| 3932 | case -NFS4ERR_STALE_STATEID: |
| 3933 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | case 0: |
| 3935 | return 0; |
| 3936 | } |
| 3937 | err = nfs4_handle_exception(server, err, &exception); |
| 3938 | } while (exception.retry); |
| 3939 | return err; |
| 3940 | } |
| 3941 | |
| 3942 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3943 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3944 | |
| 3945 | /* |
| 3946 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3947 | */ |
| 3948 | static unsigned long |
| 3949 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3950 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3951 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3952 | timeout <<= 1; |
| 3953 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3954 | return NFS4_LOCK_MAXTIMEOUT; |
| 3955 | return timeout; |
| 3956 | } |
| 3957 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3959 | { |
| 3960 | struct inode *inode = state->inode; |
| 3961 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3962 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3963 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3965 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3967 | struct nfs_lockt_res res = { |
| 3968 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | }; |
| 3970 | struct rpc_message msg = { |
| 3971 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3972 | .rpc_argp = &arg, |
| 3973 | .rpc_resp = &res, |
| 3974 | .rpc_cred = state->owner->so_cred, |
| 3975 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | struct nfs4_lock_state *lsp; |
| 3977 | int status; |
| 3978 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3979 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3980 | status = nfs4_set_lock_state(state, request); |
| 3981 | if (status != 0) |
| 3982 | goto out; |
| 3983 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3984 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3985 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3986 | 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] | 3987 | switch (status) { |
| 3988 | case 0: |
| 3989 | request->fl_type = F_UNLCK; |
| 3990 | break; |
| 3991 | case -NFS4ERR_DENIED: |
| 3992 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3994 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3995 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | return status; |
| 3997 | } |
| 3998 | |
| 3999 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4000 | { |
| 4001 | struct nfs4_exception exception = { }; |
| 4002 | int err; |
| 4003 | |
| 4004 | do { |
| 4005 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4006 | _nfs4_proc_getlk(state, cmd, request), |
| 4007 | &exception); |
| 4008 | } while (exception.retry); |
| 4009 | return err; |
| 4010 | } |
| 4011 | |
| 4012 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4013 | { |
| 4014 | int res = 0; |
| 4015 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4016 | case FL_POSIX: |
| 4017 | res = posix_lock_file_wait(file, fl); |
| 4018 | break; |
| 4019 | case FL_FLOCK: |
| 4020 | res = flock_lock_file_wait(file, fl); |
| 4021 | break; |
| 4022 | default: |
| 4023 | BUG(); |
| 4024 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | return res; |
| 4026 | } |
| 4027 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4028 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4029 | struct nfs_locku_args arg; |
| 4030 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4031 | struct nfs4_lock_state *lsp; |
| 4032 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4033 | struct file_lock fl; |
| 4034 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4035 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4036 | }; |
| 4037 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4038 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4039 | struct nfs_open_context *ctx, |
| 4040 | struct nfs4_lock_state *lsp, |
| 4041 | struct nfs_seqid *seqid) |
| 4042 | { |
| 4043 | struct nfs4_unlockdata *p; |
| 4044 | struct inode *inode = lsp->ls_state->inode; |
| 4045 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4046 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4047 | if (p == NULL) |
| 4048 | return NULL; |
| 4049 | p->arg.fh = NFS_FH(inode); |
| 4050 | p->arg.fl = &p->fl; |
| 4051 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4052 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4053 | p->arg.stateid = &lsp->ls_stateid; |
| 4054 | p->lsp = lsp; |
| 4055 | atomic_inc(&lsp->ls_count); |
| 4056 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4057 | p->ctx = get_nfs_open_context(ctx); |
| 4058 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4059 | p->server = NFS_SERVER(inode); |
| 4060 | return p; |
| 4061 | } |
| 4062 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4063 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4064 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4065 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4066 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4067 | nfs4_put_lock_state(calldata->lsp); |
| 4068 | put_nfs_open_context(calldata->ctx); |
| 4069 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4072 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4073 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4074 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4075 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4076 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4077 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4078 | switch (task->tk_status) { |
| 4079 | case 0: |
| 4080 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4081 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4082 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4083 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4084 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4085 | case -NFS4ERR_BAD_STATEID: |
| 4086 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4087 | case -NFS4ERR_STALE_STATEID: |
| 4088 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4089 | break; |
| 4090 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4091 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4092 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 4093 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4094 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4095 | } |
| 4096 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4097 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4098 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4099 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4101 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4102 | return; |
| 4103 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4104 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4105 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4106 | return; |
| 4107 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4108 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4109 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4110 | &calldata->arg.seq_args, |
| 4111 | &calldata->res.seq_res, 1, task)) |
| 4112 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4113 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | } |
| 4115 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4116 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4117 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4118 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4119 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4120 | }; |
| 4121 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4122 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4123 | struct nfs_open_context *ctx, |
| 4124 | struct nfs4_lock_state *lsp, |
| 4125 | struct nfs_seqid *seqid) |
| 4126 | { |
| 4127 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4128 | struct rpc_message msg = { |
| 4129 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4130 | .rpc_cred = ctx->cred, |
| 4131 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4132 | struct rpc_task_setup task_setup_data = { |
| 4133 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4134 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4135 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4136 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4137 | .flags = RPC_TASK_ASYNC, |
| 4138 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4139 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4140 | /* Ensure this is an unlock - when canceling a lock, the |
| 4141 | * canceled lock is passed in, and it won't be an unlock. |
| 4142 | */ |
| 4143 | fl->fl_type = F_UNLCK; |
| 4144 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4145 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4146 | if (data == NULL) { |
| 4147 | nfs_free_seqid(seqid); |
| 4148 | return ERR_PTR(-ENOMEM); |
| 4149 | } |
| 4150 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4151 | msg.rpc_argp = &data->arg; |
| 4152 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4153 | task_setup_data.callback_data = data; |
| 4154 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4155 | } |
| 4156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4158 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4159 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4160 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4161 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4162 | struct rpc_task *task; |
| 4163 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4164 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4166 | status = nfs4_set_lock_state(state, request); |
| 4167 | /* Unlock _before_ we do the RPC call */ |
| 4168 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4169 | down_read(&nfsi->rwsem); |
| 4170 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4171 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4172 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4173 | } |
| 4174 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4175 | if (status != 0) |
| 4176 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4177 | /* Is this a delegated lock? */ |
| 4178 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4179 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4180 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4181 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4182 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4183 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4184 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4185 | 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] | 4186 | status = PTR_ERR(task); |
| 4187 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4188 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4189 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4190 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4191 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4192 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4193 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | } |
| 4195 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4196 | struct nfs4_lockdata { |
| 4197 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4198 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4199 | struct nfs4_lock_state *lsp; |
| 4200 | struct nfs_open_context *ctx; |
| 4201 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4202 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4203 | int rpc_status; |
| 4204 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4205 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4206 | }; |
| 4207 | |
| 4208 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4209 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4210 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4211 | { |
| 4212 | struct nfs4_lockdata *p; |
| 4213 | struct inode *inode = lsp->ls_state->inode; |
| 4214 | struct nfs_server *server = NFS_SERVER(inode); |
| 4215 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4216 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4217 | if (p == NULL) |
| 4218 | return NULL; |
| 4219 | |
| 4220 | p->arg.fh = NFS_FH(inode); |
| 4221 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4222 | 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] | 4223 | if (p->arg.open_seqid == NULL) |
| 4224 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4225 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4226 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4227 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4228 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4229 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4230 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4231 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4232 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4233 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4234 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4235 | atomic_inc(&lsp->ls_count); |
| 4236 | p->ctx = get_nfs_open_context(ctx); |
| 4237 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4238 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4239 | out_free_seqid: |
| 4240 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4241 | out_free: |
| 4242 | kfree(p); |
| 4243 | return NULL; |
| 4244 | } |
| 4245 | |
| 4246 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4247 | { |
| 4248 | struct nfs4_lockdata *data = calldata; |
| 4249 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4251 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4252 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4253 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4254 | /* Do we need to do an open_to_lock_owner? */ |
| 4255 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4256 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4257 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4258 | data->arg.open_stateid = &state->stateid; |
| 4259 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4260 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4261 | } else |
| 4262 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4263 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4264 | if (nfs4_setup_sequence(data->server, |
| 4265 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4266 | &data->res.seq_res, 1, task)) |
| 4267 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4268 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4269 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4270 | } |
| 4271 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4272 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4273 | { |
| 4274 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4275 | nfs4_lock_prepare(task, calldata); |
| 4276 | } |
| 4277 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4278 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4279 | { |
| 4280 | struct nfs4_lockdata *data = calldata; |
| 4281 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4282 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4283 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4284 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4285 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4286 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4287 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4288 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4289 | if (data->rpc_status == 0) |
| 4290 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4291 | else |
| 4292 | goto out; |
| 4293 | } |
| 4294 | if (data->rpc_status == 0) { |
| 4295 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4296 | sizeof(data->lsp->ls_stateid.data)); |
| 4297 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4298 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4299 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4300 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4301 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | static void nfs4_lock_release(void *calldata) |
| 4305 | { |
| 4306 | struct nfs4_lockdata *data = calldata; |
| 4307 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4308 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4309 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4310 | if (data->cancelled != 0) { |
| 4311 | struct rpc_task *task; |
| 4312 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4313 | data->arg.lock_seqid); |
| 4314 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4315 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4316 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4317 | } else |
| 4318 | nfs_free_seqid(data->arg.lock_seqid); |
| 4319 | nfs4_put_lock_state(data->lsp); |
| 4320 | put_nfs_open_context(data->ctx); |
| 4321 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4322 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4326 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4327 | .rpc_call_done = nfs4_lock_done, |
| 4328 | .rpc_release = nfs4_lock_release, |
| 4329 | }; |
| 4330 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4331 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4332 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4333 | .rpc_call_done = nfs4_lock_done, |
| 4334 | .rpc_release = nfs4_lock_release, |
| 4335 | }; |
| 4336 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4337 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4338 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4339 | switch (error) { |
| 4340 | case -NFS4ERR_ADMIN_REVOKED: |
| 4341 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4342 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4343 | if (new_lock_owner != 0 || |
| 4344 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4345 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4346 | break; |
| 4347 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4348 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4349 | case -NFS4ERR_EXPIRED: |
| 4350 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4351 | }; |
| 4352 | } |
| 4353 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4354 | 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] | 4355 | { |
| 4356 | struct nfs4_lockdata *data; |
| 4357 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4358 | struct rpc_message msg = { |
| 4359 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4360 | .rpc_cred = state->owner->so_cred, |
| 4361 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4362 | struct rpc_task_setup task_setup_data = { |
| 4363 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4364 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4365 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4366 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4367 | .flags = RPC_TASK_ASYNC, |
| 4368 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4369 | int ret; |
| 4370 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4371 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4372 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4373 | fl->fl_u.nfs4_fl.owner, |
| 4374 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4375 | if (data == NULL) |
| 4376 | return -ENOMEM; |
| 4377 | if (IS_SETLKW(cmd)) |
| 4378 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4379 | if (recovery_type > NFS_LOCK_NEW) { |
| 4380 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4381 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4382 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4383 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4384 | msg.rpc_argp = &data->arg; |
| 4385 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4386 | task_setup_data.callback_data = data; |
| 4387 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4388 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4389 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4390 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4391 | if (ret == 0) { |
| 4392 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4393 | if (ret) |
| 4394 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4395 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4396 | } else |
| 4397 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4398 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4399 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4400 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4404 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4405 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4406 | struct nfs4_exception exception = { }; |
| 4407 | int err; |
| 4408 | |
| 4409 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4410 | /* Cache the lock if possible... */ |
| 4411 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4412 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4413 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4414 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4415 | break; |
| 4416 | nfs4_handle_exception(server, err, &exception); |
| 4417 | } while (exception.retry); |
| 4418 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4422 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4423 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4424 | struct nfs4_exception exception = { }; |
| 4425 | int err; |
| 4426 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4427 | err = nfs4_set_lock_state(state, request); |
| 4428 | if (err != 0) |
| 4429 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4430 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4431 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4432 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4433 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4434 | switch (err) { |
| 4435 | default: |
| 4436 | goto out; |
| 4437 | case -NFS4ERR_GRACE: |
| 4438 | case -NFS4ERR_DELAY: |
| 4439 | nfs4_handle_exception(server, err, &exception); |
| 4440 | err = 0; |
| 4441 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4442 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4443 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4444 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4448 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4449 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4450 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4451 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4453 | if ((fl_flags & FL_POSIX) && |
| 4454 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4455 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4456 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4457 | status = nfs4_set_lock_state(state, request); |
| 4458 | if (status != 0) |
| 4459 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4460 | request->fl_flags |= FL_ACCESS; |
| 4461 | status = do_vfs_lock(request->fl_file, request); |
| 4462 | if (status < 0) |
| 4463 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4464 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4465 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4466 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4467 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4468 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4469 | status = do_vfs_lock(request->fl_file, request); |
| 4470 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4471 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4472 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4473 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4474 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4475 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4476 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4477 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4478 | 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] | 4479 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4480 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4481 | out: |
| 4482 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | return status; |
| 4484 | } |
| 4485 | |
| 4486 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4487 | { |
| 4488 | struct nfs4_exception exception = { }; |
| 4489 | int err; |
| 4490 | |
| 4491 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4492 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4493 | if (err == -NFS4ERR_DENIED) |
| 4494 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4496 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | } while (exception.retry); |
| 4498 | return err; |
| 4499 | } |
| 4500 | |
| 4501 | static int |
| 4502 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4503 | { |
| 4504 | struct nfs_open_context *ctx; |
| 4505 | struct nfs4_state *state; |
| 4506 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4507 | int status; |
| 4508 | |
| 4509 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4510 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | state = ctx->state; |
| 4512 | |
| 4513 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4514 | return -EINVAL; |
| 4515 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4516 | if (IS_GETLK(cmd)) { |
| 4517 | if (state != NULL) |
| 4518 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4519 | return 0; |
| 4520 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | |
| 4522 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4523 | return -EINVAL; |
| 4524 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4525 | if (request->fl_type == F_UNLCK) { |
| 4526 | if (state != NULL) |
| 4527 | return nfs4_proc_unlck(state, cmd, request); |
| 4528 | return 0; |
| 4529 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4531 | if (state == NULL) |
| 4532 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4533 | do { |
| 4534 | status = nfs4_proc_setlk(state, cmd, request); |
| 4535 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4536 | break; |
| 4537 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4538 | status = -ERESTARTSYS; |
| 4539 | if (signalled()) |
| 4540 | break; |
| 4541 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | return status; |
| 4543 | } |
| 4544 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4545 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4546 | { |
| 4547 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4548 | struct nfs4_exception exception = { }; |
| 4549 | int err; |
| 4550 | |
| 4551 | err = nfs4_set_lock_state(state, fl); |
| 4552 | if (err != 0) |
| 4553 | goto out; |
| 4554 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4555 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4556 | switch (err) { |
| 4557 | default: |
| 4558 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4559 | __func__, err); |
| 4560 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4561 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4562 | goto out; |
| 4563 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4564 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4565 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4566 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4567 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4568 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4569 | case -NFS4ERR_BADSESSION: |
| 4570 | case -NFS4ERR_BADSLOT: |
| 4571 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4572 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4573 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4574 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4575 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4576 | case -ERESTARTSYS: |
| 4577 | /* |
| 4578 | * The show must go on: exit, but mark the |
| 4579 | * stateid as needing recovery. |
| 4580 | */ |
| 4581 | case -NFS4ERR_ADMIN_REVOKED: |
| 4582 | case -NFS4ERR_BAD_STATEID: |
| 4583 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4584 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4585 | err = 0; |
| 4586 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4587 | case -EKEYEXPIRED: |
| 4588 | /* |
| 4589 | * User RPCSEC_GSS context has expired. |
| 4590 | * We cannot recover this stateid now, so |
| 4591 | * skip it and allow recovery thread to |
| 4592 | * proceed. |
| 4593 | */ |
| 4594 | err = 0; |
| 4595 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4596 | case -ENOMEM: |
| 4597 | case -NFS4ERR_DENIED: |
| 4598 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4599 | err = 0; |
| 4600 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4601 | case -NFS4ERR_DELAY: |
| 4602 | break; |
| 4603 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4604 | err = nfs4_handle_exception(server, err, &exception); |
| 4605 | } while (exception.retry); |
| 4606 | out: |
| 4607 | return err; |
| 4608 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4609 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4610 | static void nfs4_release_lockowner_release(void *calldata) |
| 4611 | { |
| 4612 | kfree(calldata); |
| 4613 | } |
| 4614 | |
| 4615 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4616 | .rpc_release = nfs4_release_lockowner_release, |
| 4617 | }; |
| 4618 | |
| 4619 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4620 | { |
| 4621 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4622 | struct nfs_release_lockowner_args *args; |
| 4623 | struct rpc_message msg = { |
| 4624 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4625 | }; |
| 4626 | |
| 4627 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4628 | return; |
| 4629 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4630 | if (!args) |
| 4631 | return; |
| 4632 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4633 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4634 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4635 | msg.rpc_argp = args; |
| 4636 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4637 | } |
| 4638 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4639 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4640 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4641 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4642 | const void *buf, size_t buflen, |
| 4643 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4644 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4645 | if (strcmp(key, "") != 0) |
| 4646 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4647 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4648 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4649 | } |
| 4650 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4651 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4652 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4653 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4654 | if (strcmp(key, "") != 0) |
| 4655 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4656 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4657 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4658 | } |
| 4659 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4660 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4661 | size_t list_len, const char *name, |
| 4662 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4663 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4664 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4665 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4666 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4667 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4668 | |
| 4669 | if (list && len <= list_len) |
| 4670 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4671 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4672 | } |
| 4673 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4674 | /* |
| 4675 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4676 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4677 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4678 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4679 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4680 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4681 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4682 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4683 | return; |
| 4684 | |
| 4685 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4686 | NFS_ATTR_FATTR_NLINK; |
| 4687 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4688 | fattr->nlink = 2; |
| 4689 | } |
| 4690 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4691 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4692 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4693 | { |
| 4694 | struct nfs_server *server = NFS_SERVER(dir); |
| 4695 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4696 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4697 | }; |
| 4698 | struct nfs4_fs_locations_arg args = { |
| 4699 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4700 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4701 | .page = page, |
| 4702 | .bitmask = bitmask, |
| 4703 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4704 | struct nfs4_fs_locations_res res = { |
| 4705 | .fs_locations = fs_locations, |
| 4706 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4707 | struct rpc_message msg = { |
| 4708 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4709 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4710 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4711 | }; |
| 4712 | int status; |
| 4713 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4714 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4715 | |
| 4716 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 4717 | * is not supported */ |
| 4718 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 4719 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 4720 | else |
| 4721 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 4722 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4723 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4724 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4725 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4726 | 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] | 4727 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4728 | return status; |
| 4729 | } |
| 4730 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4731 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4732 | { |
| 4733 | int status; |
| 4734 | struct nfs4_secinfo_arg args = { |
| 4735 | .dir_fh = NFS_FH(dir), |
| 4736 | .name = name, |
| 4737 | }; |
| 4738 | struct nfs4_secinfo_res res = { |
| 4739 | .flavors = flavors, |
| 4740 | }; |
| 4741 | struct rpc_message msg = { |
| 4742 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4743 | .rpc_argp = &args, |
| 4744 | .rpc_resp = &res, |
| 4745 | }; |
| 4746 | |
| 4747 | dprintk("NFS call secinfo %s\n", name->name); |
| 4748 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4749 | dprintk("NFS reply secinfo: %d\n", status); |
| 4750 | return status; |
| 4751 | } |
| 4752 | |
| 4753 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4754 | { |
| 4755 | struct nfs4_exception exception = { }; |
| 4756 | int err; |
| 4757 | do { |
| 4758 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4759 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4760 | &exception); |
| 4761 | } while (exception.retry); |
| 4762 | return err; |
| 4763 | } |
| 4764 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4765 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4766 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4767 | * Check the exchange flags returned by the server for invalid flags, having |
| 4768 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4769 | * DS flags set. |
| 4770 | */ |
| 4771 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4772 | { |
| 4773 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4774 | goto out_inval; |
| 4775 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4776 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4777 | goto out_inval; |
| 4778 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4779 | goto out_inval; |
| 4780 | return NFS_OK; |
| 4781 | out_inval: |
| 4782 | return -NFS4ERR_INVAL; |
| 4783 | } |
| 4784 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4785 | static bool |
| 4786 | nfs41_same_server_scope(struct server_scope *a, struct server_scope *b) |
| 4787 | { |
| 4788 | if (a->server_scope_sz == b->server_scope_sz && |
| 4789 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 4790 | return true; |
| 4791 | |
| 4792 | return false; |
| 4793 | } |
| 4794 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4795 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4796 | * nfs4_proc_exchange_id() |
| 4797 | * |
| 4798 | * Since the clientid has expired, all compounds using sessions |
| 4799 | * associated with the stale clientid will be returning |
| 4800 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4801 | * be in some phase of session reset. |
| 4802 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4803 | 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] | 4804 | { |
| 4805 | nfs4_verifier verifier; |
| 4806 | struct nfs41_exchange_id_args args = { |
| 4807 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4808 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4809 | }; |
| 4810 | struct nfs41_exchange_id_res res = { |
| 4811 | .client = clp, |
| 4812 | }; |
| 4813 | int status; |
| 4814 | struct rpc_message msg = { |
| 4815 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4816 | .rpc_argp = &args, |
| 4817 | .rpc_resp = &res, |
| 4818 | .rpc_cred = cred, |
| 4819 | }; |
| 4820 | __be32 *p; |
| 4821 | |
| 4822 | dprintk("--> %s\n", __func__); |
| 4823 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4824 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4825 | p = (u32 *)verifier.data; |
| 4826 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4827 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4828 | args.verifier = &verifier; |
| 4829 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4830 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4831 | "%s/%s.%s/%u", |
| 4832 | clp->cl_ipaddr, |
| 4833 | init_utsname()->nodename, |
| 4834 | init_utsname()->domainname, |
| 4835 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4836 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4837 | res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); |
| 4838 | if (unlikely(!res.server_scope)) |
| 4839 | return -ENOMEM; |
| 4840 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4841 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4842 | if (!status) |
| 4843 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4844 | |
| 4845 | if (!status) { |
| 4846 | if (clp->server_scope && |
| 4847 | !nfs41_same_server_scope(clp->server_scope, |
| 4848 | res.server_scope)) { |
| 4849 | dprintk("%s: server_scope mismatch detected\n", |
| 4850 | __func__); |
| 4851 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 4852 | kfree(clp->server_scope); |
| 4853 | clp->server_scope = NULL; |
| 4854 | } |
| 4855 | |
| 4856 | if (!clp->server_scope) |
| 4857 | clp->server_scope = res.server_scope; |
| 4858 | else |
| 4859 | kfree(res.server_scope); |
| 4860 | } |
| 4861 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4862 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4863 | return status; |
| 4864 | } |
| 4865 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4866 | struct nfs4_get_lease_time_data { |
| 4867 | struct nfs4_get_lease_time_args *args; |
| 4868 | struct nfs4_get_lease_time_res *res; |
| 4869 | struct nfs_client *clp; |
| 4870 | }; |
| 4871 | |
| 4872 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4873 | void *calldata) |
| 4874 | { |
| 4875 | int ret; |
| 4876 | struct nfs4_get_lease_time_data *data = |
| 4877 | (struct nfs4_get_lease_time_data *)calldata; |
| 4878 | |
| 4879 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4880 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4881 | /* just setup sequence, do not trigger session recovery |
| 4882 | since we're invoked within one */ |
| 4883 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4884 | &data->args->la_seq_args, |
| 4885 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4886 | |
| 4887 | BUG_ON(ret == -EAGAIN); |
| 4888 | rpc_call_start(task); |
| 4889 | dprintk("<-- %s\n", __func__); |
| 4890 | } |
| 4891 | |
| 4892 | /* |
| 4893 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4894 | * from sequence operation or clientid errors. |
| 4895 | */ |
| 4896 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4897 | { |
| 4898 | struct nfs4_get_lease_time_data *data = |
| 4899 | (struct nfs4_get_lease_time_data *)calldata; |
| 4900 | |
| 4901 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4902 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4903 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4904 | switch (task->tk_status) { |
| 4905 | case -NFS4ERR_DELAY: |
| 4906 | case -NFS4ERR_GRACE: |
| 4907 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4908 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4909 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4910 | /* fall through */ |
| 4911 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4912 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4913 | return; |
| 4914 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4915 | dprintk("<-- %s\n", __func__); |
| 4916 | } |
| 4917 | |
| 4918 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4919 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4920 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4921 | }; |
| 4922 | |
| 4923 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4924 | { |
| 4925 | struct rpc_task *task; |
| 4926 | struct nfs4_get_lease_time_args args; |
| 4927 | struct nfs4_get_lease_time_res res = { |
| 4928 | .lr_fsinfo = fsinfo, |
| 4929 | }; |
| 4930 | struct nfs4_get_lease_time_data data = { |
| 4931 | .args = &args, |
| 4932 | .res = &res, |
| 4933 | .clp = clp, |
| 4934 | }; |
| 4935 | struct rpc_message msg = { |
| 4936 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4937 | .rpc_argp = &args, |
| 4938 | .rpc_resp = &res, |
| 4939 | }; |
| 4940 | struct rpc_task_setup task_setup = { |
| 4941 | .rpc_client = clp->cl_rpcclient, |
| 4942 | .rpc_message = &msg, |
| 4943 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4944 | .callback_data = &data, |
| 4945 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4946 | }; |
| 4947 | int status; |
| 4948 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4949 | dprintk("--> %s\n", __func__); |
| 4950 | task = rpc_run_task(&task_setup); |
| 4951 | |
| 4952 | if (IS_ERR(task)) |
| 4953 | status = PTR_ERR(task); |
| 4954 | else { |
| 4955 | status = task->tk_status; |
| 4956 | rpc_put_task(task); |
| 4957 | } |
| 4958 | dprintk("<-- %s return %d\n", __func__, status); |
| 4959 | |
| 4960 | return status; |
| 4961 | } |
| 4962 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4963 | /* |
| 4964 | * Reset a slot table |
| 4965 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4966 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4967 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4968 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4969 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4970 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4971 | int ret = 0; |
| 4972 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4973 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4974 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4975 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4976 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4977 | if (max_reqs != tbl->max_slots) { |
| 4978 | ret = -ENOMEM; |
| 4979 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4980 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4981 | if (!new) |
| 4982 | goto out; |
| 4983 | ret = 0; |
| 4984 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4985 | } |
| 4986 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4987 | if (new) { |
| 4988 | tbl->slots = new; |
| 4989 | tbl->max_slots = max_reqs; |
| 4990 | } |
| 4991 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4992 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4993 | spin_unlock(&tbl->slot_tbl_lock); |
| 4994 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4995 | tbl, tbl->slots, tbl->max_slots); |
| 4996 | out: |
| 4997 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4998 | return ret; |
| 4999 | } |
| 5000 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5001 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5002 | * Reset the forechannel and backchannel slot tables |
| 5003 | */ |
| 5004 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 5005 | { |
| 5006 | int status; |
| 5007 | |
| 5008 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5009 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5010 | if (status) |
| 5011 | return status; |
| 5012 | |
| 5013 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5014 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5015 | return status; |
| 5016 | } |
| 5017 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5018 | /* Destroy the slot table */ |
| 5019 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5020 | { |
| 5021 | if (session->fc_slot_table.slots != NULL) { |
| 5022 | kfree(session->fc_slot_table.slots); |
| 5023 | session->fc_slot_table.slots = NULL; |
| 5024 | } |
| 5025 | if (session->bc_slot_table.slots != NULL) { |
| 5026 | kfree(session->bc_slot_table.slots); |
| 5027 | session->bc_slot_table.slots = NULL; |
| 5028 | } |
| 5029 | return; |
| 5030 | } |
| 5031 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5032 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5033 | * Initialize slot table |
| 5034 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5035 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 5036 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5037 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5038 | struct nfs4_slot *slot; |
| 5039 | int ret = -ENOMEM; |
| 5040 | |
| 5041 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 5042 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5043 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5044 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5045 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5046 | if (!slot) |
| 5047 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5048 | ret = 0; |
| 5049 | |
| 5050 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5051 | tbl->max_slots = max_slots; |
| 5052 | tbl->slots = slot; |
| 5053 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5054 | spin_unlock(&tbl->slot_tbl_lock); |
| 5055 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5056 | tbl, tbl->slots, tbl->max_slots); |
| 5057 | out: |
| 5058 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5059 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5060 | } |
| 5061 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5062 | /* |
| 5063 | * Initialize the forechannel and backchannel tables |
| 5064 | */ |
| 5065 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 5066 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5067 | struct nfs4_slot_table *tbl; |
| 5068 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5069 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5070 | tbl = &session->fc_slot_table; |
| 5071 | if (tbl->slots == NULL) { |
| 5072 | status = nfs4_init_slot_table(tbl, |
| 5073 | session->fc_attrs.max_reqs, 1); |
| 5074 | if (status) |
| 5075 | return status; |
| 5076 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5077 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5078 | tbl = &session->bc_slot_table; |
| 5079 | if (tbl->slots == NULL) { |
| 5080 | status = nfs4_init_slot_table(tbl, |
| 5081 | session->bc_attrs.max_reqs, 0); |
| 5082 | if (status) |
| 5083 | nfs4_destroy_slot_tables(session); |
| 5084 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5085 | |
| 5086 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5087 | } |
| 5088 | |
| 5089 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5090 | { |
| 5091 | struct nfs4_session *session; |
| 5092 | struct nfs4_slot_table *tbl; |
| 5093 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5094 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5095 | if (!session) |
| 5096 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5097 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5098 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5099 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5100 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5101 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5102 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5103 | |
| 5104 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5105 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5106 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5107 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5108 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5109 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5110 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5111 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5112 | session->clp = clp; |
| 5113 | return session; |
| 5114 | } |
| 5115 | |
| 5116 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5117 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5118 | nfs4_proc_destroy_session(session); |
| 5119 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 5120 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 5121 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 5122 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5123 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5124 | kfree(session); |
| 5125 | } |
| 5126 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5127 | /* |
| 5128 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5129 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5130 | * use them. |
| 5131 | * |
| 5132 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5133 | * always set csa_cachethis to FALSE because the current implementation |
| 5134 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5135 | */ |
| 5136 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5137 | { |
| 5138 | struct nfs4_session *session = args->client->cl_session; |
| 5139 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5140 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5141 | |
| 5142 | if (mxrqst_sz == 0) |
| 5143 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5144 | if (mxresp_sz == 0) |
| 5145 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5146 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5147 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5148 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5149 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 5150 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 5151 | |
| 5152 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5153 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5154 | __func__, |
| 5155 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5156 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5157 | |
| 5158 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5159 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5160 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5161 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5162 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5163 | args->bc_attrs.max_reqs = 1; |
| 5164 | |
| 5165 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5166 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5167 | __func__, |
| 5168 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5169 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5170 | args->bc_attrs.max_reqs); |
| 5171 | } |
| 5172 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5173 | 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] | 5174 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5175 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5176 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5177 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5178 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5179 | return -EINVAL; |
| 5180 | /* |
| 5181 | * Our requested max_ops is the minimum we need; we're not |
| 5182 | * prepared to break up compounds into smaller pieces than that. |
| 5183 | * So, no point even trying to continue if the server won't |
| 5184 | * cooperate: |
| 5185 | */ |
| 5186 | if (rcvd->max_ops < sent->max_ops) |
| 5187 | return -EINVAL; |
| 5188 | if (rcvd->max_reqs == 0) |
| 5189 | return -EINVAL; |
| 5190 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5191 | } |
| 5192 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5193 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5194 | { |
| 5195 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5196 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5197 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5198 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5199 | return -EINVAL; |
| 5200 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5201 | return -EINVAL; |
| 5202 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5203 | return -EINVAL; |
| 5204 | /* These would render the backchannel useless: */ |
| 5205 | if (rcvd->max_ops == 0) |
| 5206 | return -EINVAL; |
| 5207 | if (rcvd->max_reqs == 0) |
| 5208 | return -EINVAL; |
| 5209 | return 0; |
| 5210 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5211 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5212 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5213 | struct nfs4_session *session) |
| 5214 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5215 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5216 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5217 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5218 | if (ret) |
| 5219 | return ret; |
| 5220 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5221 | } |
| 5222 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5223 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5224 | { |
| 5225 | struct nfs4_session *session = clp->cl_session; |
| 5226 | struct nfs41_create_session_args args = { |
| 5227 | .client = clp, |
| 5228 | .cb_program = NFS4_CALLBACK, |
| 5229 | }; |
| 5230 | struct nfs41_create_session_res res = { |
| 5231 | .client = clp, |
| 5232 | }; |
| 5233 | struct rpc_message msg = { |
| 5234 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5235 | .rpc_argp = &args, |
| 5236 | .rpc_resp = &res, |
| 5237 | }; |
| 5238 | int status; |
| 5239 | |
| 5240 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5241 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5242 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5243 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5244 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5245 | if (!status) |
| 5246 | /* Verify the session's negotiated channel_attrs values */ |
| 5247 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5248 | if (!status) { |
| 5249 | /* Increment the clientid slot sequence id */ |
| 5250 | clp->cl_seqid++; |
| 5251 | } |
| 5252 | |
| 5253 | return status; |
| 5254 | } |
| 5255 | |
| 5256 | /* |
| 5257 | * Issues a CREATE_SESSION operation to the server. |
| 5258 | * It is the responsibility of the caller to verify the session is |
| 5259 | * expired before calling this routine. |
| 5260 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5261 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5262 | { |
| 5263 | int status; |
| 5264 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5265 | struct nfs4_session *session = clp->cl_session; |
| 5266 | |
| 5267 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5268 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5269 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5270 | if (status) |
| 5271 | goto out; |
| 5272 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5273 | /* Init and reset the fore channel */ |
| 5274 | status = nfs4_init_slot_tables(session); |
| 5275 | dprintk("slot table initialization returned %d\n", status); |
| 5276 | if (status) |
| 5277 | goto out; |
| 5278 | status = nfs4_reset_slot_tables(session); |
| 5279 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5280 | if (status) |
| 5281 | goto out; |
| 5282 | |
| 5283 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5284 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5285 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5286 | out: |
| 5287 | dprintk("<-- %s\n", __func__); |
| 5288 | return status; |
| 5289 | } |
| 5290 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5291 | /* |
| 5292 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5293 | * The caller must serialize access to this routine. |
| 5294 | */ |
| 5295 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5296 | { |
| 5297 | int status = 0; |
| 5298 | struct rpc_message msg; |
| 5299 | |
| 5300 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5301 | |
| 5302 | /* session is still being setup */ |
| 5303 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5304 | return status; |
| 5305 | |
| 5306 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5307 | msg.rpc_argp = session; |
| 5308 | msg.rpc_resp = NULL; |
| 5309 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5310 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5311 | |
| 5312 | if (status) |
| 5313 | printk(KERN_WARNING |
| 5314 | "Got error %d from the server on DESTROY_SESSION. " |
| 5315 | "Session has been destroyed regardless...\n", status); |
| 5316 | |
| 5317 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5318 | return status; |
| 5319 | } |
| 5320 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5321 | int nfs4_init_session(struct nfs_server *server) |
| 5322 | { |
| 5323 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5324 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5325 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5326 | int ret; |
| 5327 | |
| 5328 | if (!nfs4_has_session(clp)) |
| 5329 | return 0; |
| 5330 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5331 | session = clp->cl_session; |
| 5332 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5333 | return 0; |
| 5334 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5335 | rsize = server->rsize; |
| 5336 | if (rsize == 0) |
| 5337 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5338 | wsize = server->wsize; |
| 5339 | if (wsize == 0) |
| 5340 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5341 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5342 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5343 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5344 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5345 | ret = nfs4_recover_expired_lease(server); |
| 5346 | if (!ret) |
| 5347 | ret = nfs4_check_client_ready(clp); |
| 5348 | return ret; |
| 5349 | } |
| 5350 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5351 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5352 | { |
| 5353 | struct nfs4_session *session = clp->cl_session; |
| 5354 | int ret; |
| 5355 | |
| 5356 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5357 | return 0; |
| 5358 | |
| 5359 | ret = nfs4_client_recover_expired_lease(clp); |
| 5360 | if (!ret) |
| 5361 | /* Test for the DS role */ |
| 5362 | if (!is_ds_client(clp)) |
| 5363 | ret = -ENODEV; |
| 5364 | if (!ret) |
| 5365 | ret = nfs4_check_client_ready(clp); |
| 5366 | return ret; |
| 5367 | |
| 5368 | } |
| 5369 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5370 | |
| 5371 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5372 | /* |
| 5373 | * Renew the cl_session lease. |
| 5374 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5375 | struct nfs4_sequence_data { |
| 5376 | struct nfs_client *clp; |
| 5377 | struct nfs4_sequence_args args; |
| 5378 | struct nfs4_sequence_res res; |
| 5379 | }; |
| 5380 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5381 | static void nfs41_sequence_release(void *data) |
| 5382 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5383 | struct nfs4_sequence_data *calldata = data; |
| 5384 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5385 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5386 | if (atomic_read(&clp->cl_count) > 1) |
| 5387 | nfs4_schedule_state_renewal(clp); |
| 5388 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5389 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5390 | } |
| 5391 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5392 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5393 | { |
| 5394 | switch(task->tk_status) { |
| 5395 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5396 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5397 | return -EAGAIN; |
| 5398 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5399 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5400 | } |
| 5401 | return 0; |
| 5402 | } |
| 5403 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5404 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5405 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5406 | struct nfs4_sequence_data *calldata = data; |
| 5407 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5408 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5409 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5410 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5411 | |
| 5412 | if (task->tk_status < 0) { |
| 5413 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5414 | if (atomic_read(&clp->cl_count) == 1) |
| 5415 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5416 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5417 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5418 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5419 | return; |
| 5420 | } |
| 5421 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5422 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5423 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5424 | dprintk("<-- %s\n", __func__); |
| 5425 | } |
| 5426 | |
| 5427 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5428 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5429 | struct nfs4_sequence_data *calldata = data; |
| 5430 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5431 | struct nfs4_sequence_args *args; |
| 5432 | struct nfs4_sequence_res *res; |
| 5433 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5434 | args = task->tk_msg.rpc_argp; |
| 5435 | res = task->tk_msg.rpc_resp; |
| 5436 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5437 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5438 | return; |
| 5439 | rpc_call_start(task); |
| 5440 | } |
| 5441 | |
| 5442 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5443 | .rpc_call_done = nfs41_sequence_call_done, |
| 5444 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5445 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5446 | }; |
| 5447 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5448 | 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] | 5449 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5450 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5451 | struct rpc_message msg = { |
| 5452 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5453 | .rpc_cred = cred, |
| 5454 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5455 | struct rpc_task_setup task_setup_data = { |
| 5456 | .rpc_client = clp->cl_rpcclient, |
| 5457 | .rpc_message = &msg, |
| 5458 | .callback_ops = &nfs41_sequence_ops, |
| 5459 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5460 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5461 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5462 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5463 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5464 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5465 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5466 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5467 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5468 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5469 | msg.rpc_argp = &calldata->args; |
| 5470 | msg.rpc_resp = &calldata->res; |
| 5471 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5472 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5473 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5474 | return rpc_run_task(&task_setup_data); |
| 5475 | } |
| 5476 | |
| 5477 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5478 | { |
| 5479 | struct rpc_task *task; |
| 5480 | int ret = 0; |
| 5481 | |
| 5482 | task = _nfs41_proc_sequence(clp, cred); |
| 5483 | if (IS_ERR(task)) |
| 5484 | ret = PTR_ERR(task); |
| 5485 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5486 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5487 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5488 | return ret; |
| 5489 | } |
| 5490 | |
| 5491 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5492 | { |
| 5493 | struct rpc_task *task; |
| 5494 | int ret; |
| 5495 | |
| 5496 | task = _nfs41_proc_sequence(clp, cred); |
| 5497 | if (IS_ERR(task)) { |
| 5498 | ret = PTR_ERR(task); |
| 5499 | goto out; |
| 5500 | } |
| 5501 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5502 | if (!ret) { |
| 5503 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5504 | |
| 5505 | if (task->tk_status == 0) |
| 5506 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5507 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5508 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5509 | rpc_put_task(task); |
| 5510 | out: |
| 5511 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5512 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5513 | } |
| 5514 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5515 | struct nfs4_reclaim_complete_data { |
| 5516 | struct nfs_client *clp; |
| 5517 | struct nfs41_reclaim_complete_args arg; |
| 5518 | struct nfs41_reclaim_complete_res res; |
| 5519 | }; |
| 5520 | |
| 5521 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5522 | { |
| 5523 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5524 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5525 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5526 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5527 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5528 | &calldata->res.seq_res, 0, task)) |
| 5529 | return; |
| 5530 | |
| 5531 | rpc_call_start(task); |
| 5532 | } |
| 5533 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5534 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5535 | { |
| 5536 | switch(task->tk_status) { |
| 5537 | case 0: |
| 5538 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5539 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5540 | break; |
| 5541 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5542 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5543 | /* fall through */ |
| 5544 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5545 | return -EAGAIN; |
| 5546 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5547 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5548 | } |
| 5549 | return 0; |
| 5550 | } |
| 5551 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5552 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5553 | { |
| 5554 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5555 | struct nfs_client *clp = calldata->clp; |
| 5556 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5557 | |
| 5558 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5559 | if (!nfs41_sequence_done(task, res)) |
| 5560 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5561 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5562 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5563 | rpc_restart_call_prepare(task); |
| 5564 | return; |
| 5565 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5566 | dprintk("<-- %s\n", __func__); |
| 5567 | } |
| 5568 | |
| 5569 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5570 | { |
| 5571 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5572 | |
| 5573 | kfree(calldata); |
| 5574 | } |
| 5575 | |
| 5576 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5577 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5578 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5579 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5580 | }; |
| 5581 | |
| 5582 | /* |
| 5583 | * Issue a global reclaim complete. |
| 5584 | */ |
| 5585 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5586 | { |
| 5587 | struct nfs4_reclaim_complete_data *calldata; |
| 5588 | struct rpc_task *task; |
| 5589 | struct rpc_message msg = { |
| 5590 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5591 | }; |
| 5592 | struct rpc_task_setup task_setup_data = { |
| 5593 | .rpc_client = clp->cl_rpcclient, |
| 5594 | .rpc_message = &msg, |
| 5595 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5596 | .flags = RPC_TASK_ASYNC, |
| 5597 | }; |
| 5598 | int status = -ENOMEM; |
| 5599 | |
| 5600 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5601 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5602 | if (calldata == NULL) |
| 5603 | goto out; |
| 5604 | calldata->clp = clp; |
| 5605 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5606 | |
| 5607 | msg.rpc_argp = &calldata->arg; |
| 5608 | msg.rpc_resp = &calldata->res; |
| 5609 | task_setup_data.callback_data = calldata; |
| 5610 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5611 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5612 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5613 | goto out; |
| 5614 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5615 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5616 | if (status == 0) |
| 5617 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5618 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5619 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5620 | out: |
| 5621 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5622 | return status; |
| 5623 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5624 | |
| 5625 | static void |
| 5626 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5627 | { |
| 5628 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5629 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5630 | |
| 5631 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5632 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5633 | * right now covering the LAYOUTGET we are about to send. |
| 5634 | * However, that is not so catastrophic, and there seems |
| 5635 | * to be no way to prevent it completely. |
| 5636 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5637 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5638 | &lgp->res.seq_res, 0, task)) |
| 5639 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5640 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5641 | NFS_I(lgp->args.inode)->layout, |
| 5642 | lgp->args.ctx->state)) { |
| 5643 | rpc_exit(task, NFS4_OK); |
| 5644 | return; |
| 5645 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5646 | rpc_call_start(task); |
| 5647 | } |
| 5648 | |
| 5649 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5650 | { |
| 5651 | struct nfs4_layoutget *lgp = calldata; |
| 5652 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5653 | |
| 5654 | dprintk("--> %s\n", __func__); |
| 5655 | |
| 5656 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5657 | return; |
| 5658 | |
| 5659 | switch (task->tk_status) { |
| 5660 | case 0: |
| 5661 | break; |
| 5662 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5663 | case -NFS4ERR_RECALLCONFLICT: |
| 5664 | task->tk_status = -NFS4ERR_DELAY; |
| 5665 | /* Fall through */ |
| 5666 | default: |
| 5667 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5668 | rpc_restart_call_prepare(task); |
| 5669 | return; |
| 5670 | } |
| 5671 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5672 | dprintk("<-- %s\n", __func__); |
| 5673 | } |
| 5674 | |
| 5675 | static void nfs4_layoutget_release(void *calldata) |
| 5676 | { |
| 5677 | struct nfs4_layoutget *lgp = calldata; |
| 5678 | |
| 5679 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5680 | put_nfs_open_context(lgp->args.ctx); |
| 5681 | kfree(calldata); |
| 5682 | dprintk("<-- %s\n", __func__); |
| 5683 | } |
| 5684 | |
| 5685 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5686 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5687 | .rpc_call_done = nfs4_layoutget_done, |
| 5688 | .rpc_release = nfs4_layoutget_release, |
| 5689 | }; |
| 5690 | |
| 5691 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5692 | { |
| 5693 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5694 | struct rpc_task *task; |
| 5695 | struct rpc_message msg = { |
| 5696 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5697 | .rpc_argp = &lgp->args, |
| 5698 | .rpc_resp = &lgp->res, |
| 5699 | }; |
| 5700 | struct rpc_task_setup task_setup_data = { |
| 5701 | .rpc_client = server->client, |
| 5702 | .rpc_message = &msg, |
| 5703 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5704 | .callback_data = lgp, |
| 5705 | .flags = RPC_TASK_ASYNC, |
| 5706 | }; |
| 5707 | int status = 0; |
| 5708 | |
| 5709 | dprintk("--> %s\n", __func__); |
| 5710 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5711 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5712 | lgp->res.seq_res.sr_slot = NULL; |
| 5713 | task = rpc_run_task(&task_setup_data); |
| 5714 | if (IS_ERR(task)) |
| 5715 | return PTR_ERR(task); |
| 5716 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5717 | if (status == 0) |
| 5718 | status = task->tk_status; |
| 5719 | if (status == 0) |
| 5720 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5721 | rpc_put_task(task); |
| 5722 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5723 | return status; |
| 5724 | } |
| 5725 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5726 | static void |
| 5727 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 5728 | { |
| 5729 | struct nfs4_layoutreturn *lrp = calldata; |
| 5730 | |
| 5731 | dprintk("--> %s\n", __func__); |
| 5732 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
| 5733 | &lrp->res.seq_res, 0, task)) |
| 5734 | return; |
| 5735 | rpc_call_start(task); |
| 5736 | } |
| 5737 | |
| 5738 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 5739 | { |
| 5740 | struct nfs4_layoutreturn *lrp = calldata; |
| 5741 | struct nfs_server *server; |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5742 | struct pnfs_layout_hdr *lo = NFS_I(lrp->args.inode)->layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5743 | |
| 5744 | dprintk("--> %s\n", __func__); |
| 5745 | |
| 5746 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 5747 | return; |
| 5748 | |
| 5749 | server = NFS_SERVER(lrp->args.inode); |
| 5750 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5751 | nfs_restart_rpc(task, lrp->clp); |
| 5752 | return; |
| 5753 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5754 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5755 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5756 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5757 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5758 | } else |
| 5759 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 5760 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5761 | lo->plh_block_lgets--; |
| 5762 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5763 | dprintk("<-- %s\n", __func__); |
| 5764 | } |
| 5765 | |
| 5766 | static void nfs4_layoutreturn_release(void *calldata) |
| 5767 | { |
| 5768 | struct nfs4_layoutreturn *lrp = calldata; |
| 5769 | |
| 5770 | dprintk("--> %s\n", __func__); |
| 5771 | put_layout_hdr(NFS_I(lrp->args.inode)->layout); |
| 5772 | kfree(calldata); |
| 5773 | dprintk("<-- %s\n", __func__); |
| 5774 | } |
| 5775 | |
| 5776 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 5777 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 5778 | .rpc_call_done = nfs4_layoutreturn_done, |
| 5779 | .rpc_release = nfs4_layoutreturn_release, |
| 5780 | }; |
| 5781 | |
| 5782 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 5783 | { |
| 5784 | struct rpc_task *task; |
| 5785 | struct rpc_message msg = { |
| 5786 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 5787 | .rpc_argp = &lrp->args, |
| 5788 | .rpc_resp = &lrp->res, |
| 5789 | }; |
| 5790 | struct rpc_task_setup task_setup_data = { |
| 5791 | .rpc_client = lrp->clp->cl_rpcclient, |
| 5792 | .rpc_message = &msg, |
| 5793 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 5794 | .callback_data = lrp, |
| 5795 | }; |
| 5796 | int status; |
| 5797 | |
| 5798 | dprintk("--> %s\n", __func__); |
| 5799 | task = rpc_run_task(&task_setup_data); |
| 5800 | if (IS_ERR(task)) |
| 5801 | return PTR_ERR(task); |
| 5802 | status = task->tk_status; |
| 5803 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5804 | rpc_put_task(task); |
| 5805 | return status; |
| 5806 | } |
| 5807 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5808 | static int |
| 5809 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5810 | { |
| 5811 | struct nfs4_getdeviceinfo_args args = { |
| 5812 | .pdev = pdev, |
| 5813 | }; |
| 5814 | struct nfs4_getdeviceinfo_res res = { |
| 5815 | .pdev = pdev, |
| 5816 | }; |
| 5817 | struct rpc_message msg = { |
| 5818 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5819 | .rpc_argp = &args, |
| 5820 | .rpc_resp = &res, |
| 5821 | }; |
| 5822 | int status; |
| 5823 | |
| 5824 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5825 | 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] | 5826 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5827 | |
| 5828 | return status; |
| 5829 | } |
| 5830 | |
| 5831 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5832 | { |
| 5833 | struct nfs4_exception exception = { }; |
| 5834 | int err; |
| 5835 | |
| 5836 | do { |
| 5837 | err = nfs4_handle_exception(server, |
| 5838 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5839 | &exception); |
| 5840 | } while (exception.retry); |
| 5841 | return err; |
| 5842 | } |
| 5843 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5844 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5845 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 5846 | { |
| 5847 | struct nfs4_layoutcommit_data *data = calldata; |
| 5848 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5849 | |
| 5850 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
| 5851 | &data->res.seq_res, 1, task)) |
| 5852 | return; |
| 5853 | rpc_call_start(task); |
| 5854 | } |
| 5855 | |
| 5856 | static void |
| 5857 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 5858 | { |
| 5859 | struct nfs4_layoutcommit_data *data = calldata; |
| 5860 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5861 | |
| 5862 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5863 | return; |
| 5864 | |
| 5865 | switch (task->tk_status) { /* Just ignore these failures */ |
| 5866 | case NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 5867 | case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 5868 | case NFS4ERR_BADLAYOUT: /* no layout */ |
| 5869 | case NFS4ERR_GRACE: /* loca_recalim always false */ |
| 5870 | task->tk_status = 0; |
| 5871 | } |
| 5872 | |
| 5873 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5874 | nfs_restart_rpc(task, server->nfs_client); |
| 5875 | return; |
| 5876 | } |
| 5877 | |
| 5878 | if (task->tk_status == 0) |
| 5879 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 5880 | data->res.fattr); |
| 5881 | } |
| 5882 | |
| 5883 | static void nfs4_layoutcommit_release(void *calldata) |
| 5884 | { |
| 5885 | struct nfs4_layoutcommit_data *data = calldata; |
| 5886 | |
| 5887 | /* Matched by references in pnfs_set_layoutcommit */ |
| 5888 | put_lseg(data->lseg); |
| 5889 | put_rpccred(data->cred); |
| 5890 | kfree(data); |
| 5891 | } |
| 5892 | |
| 5893 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 5894 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 5895 | .rpc_call_done = nfs4_layoutcommit_done, |
| 5896 | .rpc_release = nfs4_layoutcommit_release, |
| 5897 | }; |
| 5898 | |
| 5899 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5900 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5901 | { |
| 5902 | struct rpc_message msg = { |
| 5903 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 5904 | .rpc_argp = &data->args, |
| 5905 | .rpc_resp = &data->res, |
| 5906 | .rpc_cred = data->cred, |
| 5907 | }; |
| 5908 | struct rpc_task_setup task_setup_data = { |
| 5909 | .task = &data->task, |
| 5910 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 5911 | .rpc_message = &msg, |
| 5912 | .callback_ops = &nfs4_layoutcommit_ops, |
| 5913 | .callback_data = data, |
| 5914 | .flags = RPC_TASK_ASYNC, |
| 5915 | }; |
| 5916 | struct rpc_task *task; |
| 5917 | int status = 0; |
| 5918 | |
| 5919 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 5920 | "lbw: %llu inode %lu\n", |
| 5921 | data->task.tk_pid, sync, |
| 5922 | data->args.lastbytewritten, |
| 5923 | data->args.inode->i_ino); |
| 5924 | |
| 5925 | task = rpc_run_task(&task_setup_data); |
| 5926 | if (IS_ERR(task)) |
| 5927 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5928 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5929 | goto out; |
| 5930 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5931 | if (status != 0) |
| 5932 | goto out; |
| 5933 | status = task->tk_status; |
| 5934 | out: |
| 5935 | dprintk("%s: status %d\n", __func__, status); |
| 5936 | rpc_put_task(task); |
| 5937 | return status; |
| 5938 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame^] | 5939 | |
| 5940 | static int |
| 5941 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5942 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 5943 | { |
| 5944 | struct nfs41_secinfo_no_name_args args = { |
| 5945 | .style = SECINFO_STYLE_CURRENT_FH, |
| 5946 | }; |
| 5947 | struct nfs4_secinfo_res res = { |
| 5948 | .flavors = flavors, |
| 5949 | }; |
| 5950 | struct rpc_message msg = { |
| 5951 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 5952 | .rpc_argp = &args, |
| 5953 | .rpc_resp = &res, |
| 5954 | }; |
| 5955 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 5956 | } |
| 5957 | |
| 5958 | static int |
| 5959 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5960 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 5961 | { |
| 5962 | struct nfs4_exception exception = { }; |
| 5963 | int err; |
| 5964 | do { |
| 5965 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 5966 | switch (err) { |
| 5967 | case 0: |
| 5968 | case -NFS4ERR_WRONGSEC: |
| 5969 | case -NFS4ERR_NOTSUPP: |
| 5970 | break; |
| 5971 | default: |
| 5972 | err = nfs4_handle_exception(server, err, &exception); |
| 5973 | } |
| 5974 | } while (exception.retry); |
| 5975 | return err; |
| 5976 | } |
| 5977 | |
| 5978 | static int |
| 5979 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 5980 | struct nfs_fsinfo *info) |
| 5981 | { |
| 5982 | int err; |
| 5983 | struct page *page; |
| 5984 | rpc_authflavor_t flavor; |
| 5985 | struct nfs4_secinfo_flavors *flavors; |
| 5986 | |
| 5987 | page = alloc_page(GFP_KERNEL); |
| 5988 | if (!page) { |
| 5989 | err = -ENOMEM; |
| 5990 | goto out; |
| 5991 | } |
| 5992 | |
| 5993 | flavors = page_address(page); |
| 5994 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 5995 | |
| 5996 | /* |
| 5997 | * Fall back on "guess and check" method if |
| 5998 | * the server doesn't support SECINFO_NO_NAME |
| 5999 | */ |
| 6000 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6001 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6002 | goto out_freepage; |
| 6003 | } |
| 6004 | if (err) |
| 6005 | goto out_freepage; |
| 6006 | |
| 6007 | flavor = nfs_find_best_sec(flavors); |
| 6008 | if (err == 0) |
| 6009 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6010 | |
| 6011 | out_freepage: |
| 6012 | put_page(page); |
| 6013 | if (err == -EACCES) |
| 6014 | return -EPERM; |
| 6015 | out: |
| 6016 | return err; |
| 6017 | } |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6018 | #endif /* CONFIG_NFS_V4_1 */ |
| 6019 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6020 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6021 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6022 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6023 | .recover_open = nfs4_open_reclaim, |
| 6024 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6025 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6026 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6027 | }; |
| 6028 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6029 | #if defined(CONFIG_NFS_V4_1) |
| 6030 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 6031 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6032 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6033 | .recover_open = nfs4_open_reclaim, |
| 6034 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6035 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6036 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6037 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6038 | }; |
| 6039 | #endif /* CONFIG_NFS_V4_1 */ |
| 6040 | |
| 6041 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6042 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6043 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6044 | .recover_open = nfs4_open_expired, |
| 6045 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6046 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6047 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6048 | }; |
| 6049 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6050 | #if defined(CONFIG_NFS_V4_1) |
| 6051 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 6052 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6053 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 6054 | .recover_open = nfs4_open_expired, |
| 6055 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6056 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6057 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6058 | }; |
| 6059 | #endif /* CONFIG_NFS_V4_1 */ |
| 6060 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6061 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 6062 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6063 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6064 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6065 | }; |
| 6066 | |
| 6067 | #if defined(CONFIG_NFS_V4_1) |
| 6068 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 6069 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6070 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6071 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6072 | }; |
| 6073 | #endif |
| 6074 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6075 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6076 | .minor_version = 0, |
| 6077 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6078 | .validate_stateid = nfs4_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame^] | 6079 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6080 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6081 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6082 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6083 | }; |
| 6084 | |
| 6085 | #if defined(CONFIG_NFS_V4_1) |
| 6086 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6087 | .minor_version = 1, |
| 6088 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6089 | .validate_stateid = nfs41_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame^] | 6090 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6091 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6092 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6093 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6094 | }; |
| 6095 | #endif |
| 6096 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6097 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6098 | [0] = &nfs_v4_0_minor_ops, |
| 6099 | #if defined(CONFIG_NFS_V4_1) |
| 6100 | [1] = &nfs_v4_1_minor_ops, |
| 6101 | #endif |
| 6102 | }; |
| 6103 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6104 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6105 | .permission = nfs_permission, |
| 6106 | .getattr = nfs_getattr, |
| 6107 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6108 | .getxattr = generic_getxattr, |
| 6109 | .setxattr = generic_setxattr, |
| 6110 | .listxattr = generic_listxattr, |
| 6111 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6112 | }; |
| 6113 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6114 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6115 | .version = 4, /* protocol version */ |
| 6116 | .dentry_ops = &nfs4_dentry_operations, |
| 6117 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6118 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6119 | .getroot = nfs4_proc_get_root, |
| 6120 | .getattr = nfs4_proc_getattr, |
| 6121 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 6122 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6123 | .lookup = nfs4_proc_lookup, |
| 6124 | .access = nfs4_proc_access, |
| 6125 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6126 | .create = nfs4_proc_create, |
| 6127 | .remove = nfs4_proc_remove, |
| 6128 | .unlink_setup = nfs4_proc_unlink_setup, |
| 6129 | .unlink_done = nfs4_proc_unlink_done, |
| 6130 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6131 | .rename_setup = nfs4_proc_rename_setup, |
| 6132 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6133 | .link = nfs4_proc_link, |
| 6134 | .symlink = nfs4_proc_symlink, |
| 6135 | .mkdir = nfs4_proc_mkdir, |
| 6136 | .rmdir = nfs4_proc_remove, |
| 6137 | .readdir = nfs4_proc_readdir, |
| 6138 | .mknod = nfs4_proc_mknod, |
| 6139 | .statfs = nfs4_proc_statfs, |
| 6140 | .fsinfo = nfs4_proc_fsinfo, |
| 6141 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6142 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6143 | .decode_dirent = nfs4_decode_dirent, |
| 6144 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6145 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6146 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6147 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6148 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6149 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6150 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6151 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6152 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6153 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6154 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6155 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6156 | }; |
| 6157 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6158 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6159 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6160 | .list = nfs4_xattr_list_nfs4_acl, |
| 6161 | .get = nfs4_xattr_get_nfs4_acl, |
| 6162 | .set = nfs4_xattr_set_nfs4_acl, |
| 6163 | }; |
| 6164 | |
| 6165 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6166 | &nfs4_xattr_nfs4_acl_handler, |
| 6167 | NULL |
| 6168 | }; |
| 6169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6170 | /* |
| 6171 | * Local variables: |
| 6172 | * c-basic-offset: 8 |
| 6173 | * End: |
| 6174 | */ |