Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/sunrpc/clnt.h> |
| 44 | #include <linux/nfs.h> |
| 45 | #include <linux/nfs4.h> |
| 46 | #include <linux/nfs_fs.h> |
| 47 | #include <linux/nfs_page.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 49 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 50 | #include <linux/module.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 51 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 52 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 53 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 55 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 57 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 58 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 59 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 60 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 63 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 64 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 66 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 67 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 68 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 69 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 70 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 71 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 73 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 74 | static int _nfs4_proc_lookup(struct rpc_clnt *client, struct inode *dir, |
| 75 | const struct qstr *name, struct nfs_fh *fhandle, |
| 76 | struct nfs_fattr *fattr); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 77 | 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] | 78 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 79 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 80 | struct nfs4_state *state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 83 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 85 | if (err >= -1000) |
| 86 | return err; |
| 87 | switch (err) { |
| 88 | case -NFS4ERR_RESOURCE: |
| 89 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame^] | 90 | case -NFS4ERR_WRONGSEC: |
| 91 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 92 | case -NFS4ERR_BADOWNER: |
| 93 | case -NFS4ERR_BADNAME: |
| 94 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 95 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 97 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 98 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 100 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /* |
| 104 | * This is our standard bitmap for GETATTR requests. |
| 105 | */ |
| 106 | const u32 nfs4_fattr_bitmap[2] = { |
| 107 | FATTR4_WORD0_TYPE |
| 108 | | FATTR4_WORD0_CHANGE |
| 109 | | FATTR4_WORD0_SIZE |
| 110 | | FATTR4_WORD0_FSID |
| 111 | | FATTR4_WORD0_FILEID, |
| 112 | FATTR4_WORD1_MODE |
| 113 | | FATTR4_WORD1_NUMLINKS |
| 114 | | FATTR4_WORD1_OWNER |
| 115 | | FATTR4_WORD1_OWNER_GROUP |
| 116 | | FATTR4_WORD1_RAWDEV |
| 117 | | FATTR4_WORD1_SPACE_USED |
| 118 | | FATTR4_WORD1_TIME_ACCESS |
| 119 | | FATTR4_WORD1_TIME_METADATA |
| 120 | | FATTR4_WORD1_TIME_MODIFY |
| 121 | }; |
| 122 | |
| 123 | const u32 nfs4_statfs_bitmap[2] = { |
| 124 | FATTR4_WORD0_FILES_AVAIL |
| 125 | | FATTR4_WORD0_FILES_FREE |
| 126 | | FATTR4_WORD0_FILES_TOTAL, |
| 127 | FATTR4_WORD1_SPACE_AVAIL |
| 128 | | FATTR4_WORD1_SPACE_FREE |
| 129 | | FATTR4_WORD1_SPACE_TOTAL |
| 130 | }; |
| 131 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 132 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | FATTR4_WORD0_MAXLINK |
| 134 | | FATTR4_WORD0_MAXNAME, |
| 135 | 0 |
| 136 | }; |
| 137 | |
| 138 | const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE |
| 139 | | FATTR4_WORD0_MAXREAD |
| 140 | | FATTR4_WORD0_MAXWRITE |
| 141 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 142 | FATTR4_WORD1_TIME_DELTA |
Andy Adamson | 504913f | 2010-10-20 00:17:57 -0400 | [diff] [blame] | 143 | | FATTR4_WORD1_FS_LAYOUT_TYPES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 146 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 147 | FATTR4_WORD0_TYPE |
| 148 | | FATTR4_WORD0_CHANGE |
| 149 | | FATTR4_WORD0_SIZE |
| 150 | | FATTR4_WORD0_FSID |
| 151 | | FATTR4_WORD0_FILEID |
| 152 | | FATTR4_WORD0_FS_LOCATIONS, |
| 153 | FATTR4_WORD1_MODE |
| 154 | | FATTR4_WORD1_NUMLINKS |
| 155 | | FATTR4_WORD1_OWNER |
| 156 | | FATTR4_WORD1_OWNER_GROUP |
| 157 | | FATTR4_WORD1_RAWDEV |
| 158 | | FATTR4_WORD1_SPACE_USED |
| 159 | | FATTR4_WORD1_TIME_ACCESS |
| 160 | | FATTR4_WORD1_TIME_METADATA |
| 161 | | FATTR4_WORD1_TIME_MODIFY |
| 162 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 163 | }; |
| 164 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 165 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | struct nfs4_readdir_arg *readdir) |
| 167 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 168 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | BUG_ON(readdir->count < 80); |
| 171 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 172 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 174 | return; |
| 175 | } |
| 176 | |
| 177 | readdir->cookie = 0; |
| 178 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 179 | if (cookie == 2) |
| 180 | return; |
| 181 | |
| 182 | /* |
| 183 | * NFSv4 servers do not return entries for '.' and '..' |
| 184 | * Therefore, we fake these entries here. We let '.' |
| 185 | * have cookie 0 and '..' have cookie 1. Note that |
| 186 | * when talking to the server, we always send cookie 0 |
| 187 | * instead of 1 or 2. |
| 188 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 189 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | if (cookie == 0) { |
| 192 | *p++ = xdr_one; /* next */ |
| 193 | *p++ = xdr_zero; /* cookie, first word */ |
| 194 | *p++ = xdr_one; /* cookie, second word */ |
| 195 | *p++ = xdr_one; /* entry len */ |
| 196 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 197 | p++; |
| 198 | *p++ = xdr_one; /* bitmap length */ |
| 199 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 200 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 201 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | *p++ = xdr_one; /* next */ |
| 205 | *p++ = xdr_zero; /* cookie, first word */ |
| 206 | *p++ = xdr_two; /* cookie, second word */ |
| 207 | *p++ = xdr_two; /* entry len */ |
| 208 | memcpy(p, "..\0\0", 4); /* entry */ |
| 209 | p++; |
| 210 | *p++ = xdr_one; /* bitmap length */ |
| 211 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 212 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 213 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | readdir->pgbase = (char *)p - (char *)start; |
| 216 | readdir->count -= readdir->pgbase; |
| 217 | kunmap_atomic(start, KM_USER0); |
| 218 | } |
| 219 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 220 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 221 | { |
| 222 | int res; |
| 223 | |
| 224 | might_sleep(); |
| 225 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 226 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 227 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 228 | return res; |
| 229 | } |
| 230 | |
| 231 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 232 | { |
| 233 | int res = 0; |
| 234 | |
| 235 | might_sleep(); |
| 236 | |
| 237 | if (*timeout <= 0) |
| 238 | *timeout = NFS4_POLL_RETRY_MIN; |
| 239 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 240 | *timeout = NFS4_POLL_RETRY_MAX; |
| 241 | schedule_timeout_killable(*timeout); |
| 242 | if (fatal_signal_pending(current)) |
| 243 | res = -ERESTARTSYS; |
| 244 | *timeout <<= 1; |
| 245 | return res; |
| 246 | } |
| 247 | |
| 248 | /* This is the error handling routine for processes that are allowed |
| 249 | * to sleep. |
| 250 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 251 | 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] | 252 | { |
| 253 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 254 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 255 | int ret = errorcode; |
| 256 | |
| 257 | exception->retry = 0; |
| 258 | switch(errorcode) { |
| 259 | case 0: |
| 260 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 261 | case -NFS4ERR_ADMIN_REVOKED: |
| 262 | case -NFS4ERR_BAD_STATEID: |
| 263 | case -NFS4ERR_OPENMODE: |
| 264 | if (state == NULL) |
| 265 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 266 | nfs4_schedule_stateid_recovery(server, state); |
| 267 | goto wait_on_recovery; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 268 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 269 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 270 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 271 | nfs4_schedule_lease_recovery(clp); |
| 272 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 273 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 274 | case -NFS4ERR_BADSESSION: |
| 275 | case -NFS4ERR_BADSLOT: |
| 276 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 277 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 278 | case -NFS4ERR_DEADSESSION: |
| 279 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 280 | case -NFS4ERR_SEQ_MISORDERED: |
| 281 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 282 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 283 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 284 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 285 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 286 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 287 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 288 | if (exception->timeout > HZ) { |
| 289 | /* We have retried a decent amount, time to |
| 290 | * fail |
| 291 | */ |
| 292 | ret = -EBUSY; |
| 293 | break; |
| 294 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 295 | case -NFS4ERR_GRACE: |
| 296 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 297 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 298 | ret = nfs4_delay(server->client, &exception->timeout); |
| 299 | if (ret != 0) |
| 300 | break; |
| 301 | case -NFS4ERR_OLD_STATEID: |
| 302 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 303 | break; |
| 304 | case -NFS4ERR_BADOWNER: |
| 305 | /* The following works around a Linux server bug! */ |
| 306 | case -NFS4ERR_BADNAME: |
| 307 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 308 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 309 | exception->retry = 1; |
| 310 | printk(KERN_WARNING "NFS: v4 server %s " |
| 311 | "does not accept raw " |
| 312 | "uid/gids. " |
| 313 | "Reenabling the idmapper.\n", |
| 314 | server->nfs_client->cl_hostname); |
| 315 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 316 | } |
| 317 | /* We failed to handle the error */ |
| 318 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 319 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 320 | ret = nfs4_wait_clnt_recover(clp); |
| 321 | if (ret == 0) |
| 322 | exception->retry = 1; |
| 323 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 327 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | spin_lock(&clp->cl_lock); |
| 330 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 331 | clp->cl_last_renewal = timestamp; |
| 332 | spin_unlock(&clp->cl_lock); |
| 333 | } |
| 334 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 335 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 336 | { |
| 337 | do_renew_lease(server->nfs_client, timestamp); |
| 338 | } |
| 339 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 340 | #if defined(CONFIG_NFS_V4_1) |
| 341 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 342 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 343 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 344 | * |
| 345 | * freeing a slot is trivially done by clearing its respective bit |
| 346 | * in the bitmap. |
| 347 | * If the freed slotid equals highest_used_slotid we want to update it |
| 348 | * so that the server would be able to size down the slot table if needed, |
| 349 | * otherwise we know that the highest_used_slotid is still in use. |
| 350 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 351 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 352 | * highest slotid in use. |
| 353 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 354 | * |
| 355 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 356 | */ |
| 357 | static void |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 358 | 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] | 359 | { |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 360 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 361 | int slotid = free_slotid; |
| 362 | |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 363 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 364 | /* clear used bit in bitmap */ |
| 365 | __clear_bit(slotid, tbl->used_slots); |
| 366 | |
| 367 | /* update highest_used_slotid when it is freed */ |
| 368 | if (slotid == tbl->highest_used_slotid) { |
| 369 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 370 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 371 | tbl->highest_used_slotid = slotid; |
| 372 | else |
| 373 | tbl->highest_used_slotid = -1; |
| 374 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 375 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 376 | free_slotid, tbl->highest_used_slotid); |
| 377 | } |
| 378 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 379 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 380 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 381 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 382 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 383 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 384 | struct rpc_task *task; |
| 385 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 386 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 387 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 388 | if (task) |
| 389 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 390 | return; |
| 391 | } |
| 392 | |
| 393 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 394 | return; |
| 395 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 396 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 397 | complete(&ses->fc_slot_table.complete); |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | * Signal state manager thread if session back channel is drained |
| 402 | */ |
| 403 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 404 | { |
| 405 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 406 | ses->bc_slot_table.highest_used_slotid != -1) |
| 407 | return; |
| 408 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 409 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 412 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 413 | { |
| 414 | struct nfs4_slot_table *tbl; |
| 415 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 416 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 417 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 418 | /* just wake up the next guy waiting since |
| 419 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 420 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 421 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 422 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 423 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 424 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 425 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 426 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 427 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 428 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 429 | } |
| 430 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 431 | 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] | 432 | { |
| 433 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 434 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 435 | |
| 436 | /* |
| 437 | * sr_status remains 1 if an RPC level error occurred. The server |
| 438 | * may or may not have processed the sequence operation.. |
| 439 | * Proceed as if the server received and processed the sequence |
| 440 | * operation. |
| 441 | */ |
| 442 | if (res->sr_status == 1) |
| 443 | res->sr_status = NFS_OK; |
| 444 | |
| 445 | /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 446 | if (!res->sr_slot) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 447 | goto out; |
| 448 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 449 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 450 | switch (res->sr_status) { |
| 451 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 452 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 453 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 454 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 455 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 456 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 457 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 458 | if (res->sr_status_flags != 0) |
| 459 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 460 | break; |
| 461 | case -NFS4ERR_DELAY: |
| 462 | /* The server detected a resend of the RPC call and |
| 463 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 464 | * of RFC5661. |
| 465 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 466 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 467 | __func__, |
| 468 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 469 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 470 | goto out_retry; |
| 471 | default: |
| 472 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 473 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 474 | } |
| 475 | out: |
| 476 | /* The session may be reset by one of the error handlers. */ |
| 477 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 478 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 479 | return 1; |
| 480 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 481 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 482 | goto out; |
| 483 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 484 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 485 | } |
| 486 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 487 | static int nfs4_sequence_done(struct rpc_task *task, |
| 488 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 489 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 490 | if (res->sr_session == NULL) |
| 491 | return 1; |
| 492 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 493 | } |
| 494 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 495 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 496 | * nfs4_find_slot - efficiently look for a free slot |
| 497 | * |
| 498 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 499 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 500 | * and respectively set up the sequence operation args. |
| 501 | * 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] | 502 | * |
| 503 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 504 | */ |
| 505 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 506 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 507 | { |
| 508 | int slotid; |
| 509 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 510 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 511 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 512 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 513 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 514 | tbl->max_slots); |
| 515 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 516 | if (slotid >= tbl->max_slots) |
| 517 | goto out; |
| 518 | __set_bit(slotid, tbl->used_slots); |
| 519 | if (slotid > tbl->highest_used_slotid) |
| 520 | tbl->highest_used_slotid = slotid; |
| 521 | ret_id = slotid; |
| 522 | out: |
| 523 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 524 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 525 | return ret_id; |
| 526 | } |
| 527 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 528 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 529 | struct nfs4_sequence_args *args, |
| 530 | struct nfs4_sequence_res *res, |
| 531 | int cache_reply, |
| 532 | struct rpc_task *task) |
| 533 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 534 | struct nfs4_slot *slot; |
| 535 | struct nfs4_slot_table *tbl; |
| 536 | u8 slotid; |
| 537 | |
| 538 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 539 | /* slot already allocated? */ |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 540 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 541 | return 0; |
| 542 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 543 | tbl = &session->fc_slot_table; |
| 544 | |
| 545 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 546 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 547 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 548 | /* |
| 549 | * The state manager will wait until the slot table is empty. |
| 550 | * Schedule the reset thread |
| 551 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 552 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 553 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 554 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 555 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 556 | } |
| 557 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 558 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 559 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 560 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 561 | spin_unlock(&tbl->slot_tbl_lock); |
| 562 | dprintk("%s enforce FIFO order\n", __func__); |
| 563 | return -EAGAIN; |
| 564 | } |
| 565 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 566 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 567 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 568 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 569 | spin_unlock(&tbl->slot_tbl_lock); |
| 570 | dprintk("<-- %s: no free slots\n", __func__); |
| 571 | return -EAGAIN; |
| 572 | } |
| 573 | spin_unlock(&tbl->slot_tbl_lock); |
| 574 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 575 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 576 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 577 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 578 | args->sa_slotid = slotid; |
| 579 | args->sa_cache_this = cache_reply; |
| 580 | |
| 581 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 582 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 583 | res->sr_session = session; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 584 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 585 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 586 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 587 | /* |
| 588 | * sr_status is only set in decode_sequence, and so will remain |
| 589 | * set to 1 if an rpc level failure occurs. |
| 590 | */ |
| 591 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 592 | return 0; |
| 593 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 594 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 595 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 596 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 597 | struct nfs4_sequence_args *args, |
| 598 | struct nfs4_sequence_res *res, |
| 599 | int cache_reply, |
| 600 | struct rpc_task *task) |
| 601 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 602 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 603 | int ret = 0; |
| 604 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 605 | if (session == NULL) { |
| 606 | args->sa_session = NULL; |
| 607 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 608 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 609 | } |
| 610 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 611 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 612 | __func__, session->clp, session, res->sr_slot ? |
| 613 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 614 | |
| 615 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 616 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 617 | out: |
| 618 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 619 | return ret; |
| 620 | } |
| 621 | |
| 622 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 623 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 624 | struct nfs4_sequence_args *seq_args; |
| 625 | struct nfs4_sequence_res *seq_res; |
| 626 | int cache_reply; |
| 627 | }; |
| 628 | |
| 629 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 630 | { |
| 631 | struct nfs41_call_sync_data *data = calldata; |
| 632 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 633 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 634 | |
| 635 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 636 | data->seq_res, data->cache_reply, task)) |
| 637 | return; |
| 638 | rpc_call_start(task); |
| 639 | } |
| 640 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 641 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 642 | { |
| 643 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 644 | nfs41_call_sync_prepare(task, calldata); |
| 645 | } |
| 646 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 647 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 648 | { |
| 649 | struct nfs41_call_sync_data *data = calldata; |
| 650 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 651 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 652 | } |
| 653 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 654 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 655 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 656 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 657 | }; |
| 658 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 659 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 660 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 661 | .rpc_call_done = nfs41_call_sync_done, |
| 662 | }; |
| 663 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 664 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 665 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 666 | struct rpc_message *msg, |
| 667 | struct nfs4_sequence_args *args, |
| 668 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 669 | int cache_reply, |
| 670 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 671 | { |
| 672 | int ret; |
| 673 | struct rpc_task *task; |
| 674 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 675 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 676 | .seq_args = args, |
| 677 | .seq_res = res, |
| 678 | .cache_reply = cache_reply, |
| 679 | }; |
| 680 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 681 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 682 | .rpc_message = msg, |
| 683 | .callback_ops = &nfs41_call_sync_ops, |
| 684 | .callback_data = &data |
| 685 | }; |
| 686 | |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 687 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 688 | if (privileged) |
| 689 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 690 | task = rpc_run_task(&task_setup); |
| 691 | if (IS_ERR(task)) |
| 692 | ret = PTR_ERR(task); |
| 693 | else { |
| 694 | ret = task->tk_status; |
| 695 | rpc_put_task(task); |
| 696 | } |
| 697 | return ret; |
| 698 | } |
| 699 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 700 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 701 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 702 | struct rpc_message *msg, |
| 703 | struct nfs4_sequence_args *args, |
| 704 | struct nfs4_sequence_res *res, |
| 705 | int cache_reply) |
| 706 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 707 | 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] | 708 | } |
| 709 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 710 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 711 | static int nfs4_sequence_done(struct rpc_task *task, |
| 712 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 713 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 714 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 715 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 716 | #endif /* CONFIG_NFS_V4_1 */ |
| 717 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 718 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 719 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 720 | struct rpc_message *msg, |
| 721 | struct nfs4_sequence_args *args, |
| 722 | struct nfs4_sequence_res *res, |
| 723 | int cache_reply) |
| 724 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 725 | args->sa_session = res->sr_session = NULL; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 726 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 727 | } |
| 728 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 729 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 730 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 731 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 732 | struct rpc_message *msg, |
| 733 | struct nfs4_sequence_args *args, |
| 734 | struct nfs4_sequence_res *res, |
| 735 | int cache_reply) |
| 736 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 737 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 738 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 739 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 740 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 741 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 743 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 745 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 746 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
| 747 | if (!cinfo->atomic || cinfo->before != nfsi->change_attr) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 748 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 749 | nfsi->change_attr = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 750 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 753 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 754 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 755 | struct nfs_openargs o_arg; |
| 756 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 757 | struct nfs_open_confirmargs c_arg; |
| 758 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 759 | struct nfs_fattr f_attr; |
| 760 | struct nfs_fattr dir_attr; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 761 | struct path path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 762 | struct dentry *dir; |
| 763 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 764 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 765 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 766 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 767 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 768 | int rpc_status; |
| 769 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 770 | }; |
| 771 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 772 | |
| 773 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 774 | { |
| 775 | p->o_res.f_attr = &p->f_attr; |
| 776 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 777 | p->o_res.seqid = p->o_arg.seqid; |
| 778 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 779 | p->o_res.server = p->o_arg.server; |
| 780 | nfs_fattr_init(&p->f_attr); |
| 781 | nfs_fattr_init(&p->dir_attr); |
| 782 | } |
| 783 | |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 784 | static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 785 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 786 | const struct iattr *attrs, |
| 787 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 788 | { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 789 | struct dentry *parent = dget_parent(path->dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 790 | struct inode *dir = parent->d_inode; |
| 791 | struct nfs_server *server = NFS_SERVER(dir); |
| 792 | struct nfs4_opendata *p; |
| 793 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 794 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 795 | if (p == NULL) |
| 796 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 797 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 798 | if (p->o_arg.seqid == NULL) |
| 799 | goto err_free; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 800 | path_get(path); |
| 801 | p->path = *path; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 802 | p->dir = parent; |
| 803 | p->owner = sp; |
| 804 | atomic_inc(&sp->so_count); |
| 805 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 806 | p->o_arg.open_flags = flags; |
| 807 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 808 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 809 | p->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 810 | p->o_arg.name = &p->path.dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 811 | p->o_arg.server = server; |
| 812 | p->o_arg.bitmask = server->attr_bitmask; |
| 813 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 814 | if (flags & O_CREAT) { |
| 815 | u32 *s; |
| 816 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 817 | p->o_arg.u.attrs = &p->attrs; |
| 818 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 819 | s = (u32 *) p->o_arg.u.verifier.data; |
| 820 | s[0] = jiffies; |
| 821 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 822 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 823 | p->c_arg.fh = &p->o_res.fh; |
| 824 | p->c_arg.stateid = &p->o_res.stateid; |
| 825 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 826 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 827 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | return p; |
| 829 | err_free: |
| 830 | kfree(p); |
| 831 | err: |
| 832 | dput(parent); |
| 833 | return NULL; |
| 834 | } |
| 835 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 836 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 837 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 838 | struct nfs4_opendata *p = container_of(kref, |
| 839 | struct nfs4_opendata, kref); |
| 840 | |
| 841 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 842 | if (p->state != NULL) |
| 843 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 844 | nfs4_put_state_owner(p->owner); |
| 845 | dput(p->dir); |
Jan Blunck | 31f31db | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 846 | path_put(&p->path); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 847 | kfree(p); |
| 848 | } |
| 849 | |
| 850 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 851 | { |
| 852 | if (p != NULL) |
| 853 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 854 | } |
| 855 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 856 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 857 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 858 | int ret; |
| 859 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 860 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 861 | return ret; |
| 862 | } |
| 863 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 864 | 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] | 865 | { |
| 866 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 867 | |
| 868 | if (open_mode & O_EXCL) |
| 869 | goto out; |
| 870 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 871 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 872 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 873 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 874 | break; |
| 875 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 876 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 877 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 878 | break; |
| 879 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 880 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 881 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 882 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 883 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 884 | return ret; |
| 885 | } |
| 886 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 887 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 888 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 889 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 890 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 891 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 892 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 893 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 894 | return 1; |
| 895 | } |
| 896 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 897 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 898 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 899 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 900 | case FMODE_WRITE: |
| 901 | state->n_wronly++; |
| 902 | break; |
| 903 | case FMODE_READ: |
| 904 | state->n_rdonly++; |
| 905 | break; |
| 906 | case FMODE_READ|FMODE_WRITE: |
| 907 | state->n_rdwr++; |
| 908 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 909 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 910 | } |
| 911 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 912 | 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] | 913 | { |
| 914 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 915 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 916 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 917 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 918 | case FMODE_READ: |
| 919 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 920 | break; |
| 921 | case FMODE_WRITE: |
| 922 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 923 | break; |
| 924 | case FMODE_READ|FMODE_WRITE: |
| 925 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 926 | } |
| 927 | } |
| 928 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 929 | 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] | 930 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 931 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 932 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 933 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 934 | } |
| 935 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 936 | 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] | 937 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 938 | /* |
| 939 | * Protect the call to nfs4_state_set_mode_locked and |
| 940 | * serialise the stateid update |
| 941 | */ |
| 942 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 943 | if (deleg_stateid != NULL) { |
| 944 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 945 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 946 | } |
| 947 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 948 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 949 | write_sequnlock(&state->seqlock); |
| 950 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 951 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 952 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 955 | 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] | 956 | { |
| 957 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 958 | struct nfs_delegation *deleg_cur; |
| 959 | int ret = 0; |
| 960 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 961 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 962 | |
| 963 | rcu_read_lock(); |
| 964 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 965 | if (deleg_cur == NULL) |
| 966 | goto no_delegation; |
| 967 | |
| 968 | spin_lock(&deleg_cur->lock); |
| 969 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 970 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 971 | goto no_delegation_unlock; |
| 972 | |
| 973 | if (delegation == NULL) |
| 974 | delegation = &deleg_cur->stateid; |
| 975 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 976 | goto no_delegation_unlock; |
| 977 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 978 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 979 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 980 | ret = 1; |
| 981 | no_delegation_unlock: |
| 982 | spin_unlock(&deleg_cur->lock); |
| 983 | no_delegation: |
| 984 | rcu_read_unlock(); |
| 985 | |
| 986 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 987 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 988 | ret = 1; |
| 989 | } |
| 990 | |
| 991 | return ret; |
| 992 | } |
| 993 | |
| 994 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 995 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 996 | { |
| 997 | struct nfs_delegation *delegation; |
| 998 | |
| 999 | rcu_read_lock(); |
| 1000 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1001 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1002 | rcu_read_unlock(); |
| 1003 | return; |
| 1004 | } |
| 1005 | rcu_read_unlock(); |
| 1006 | nfs_inode_return_delegation(inode); |
| 1007 | } |
| 1008 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1009 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1010 | { |
| 1011 | struct nfs4_state *state = opendata->state; |
| 1012 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1013 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1014 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 1015 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1016 | nfs4_stateid stateid; |
| 1017 | int ret = -EAGAIN; |
| 1018 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1019 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1020 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1021 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1022 | if (can_open_cached(state, fmode, open_mode)) { |
| 1023 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1024 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1025 | goto out_return_state; |
| 1026 | } |
| 1027 | spin_unlock(&state->owner->so_lock); |
| 1028 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1029 | rcu_read_lock(); |
| 1030 | delegation = rcu_dereference(nfsi->delegation); |
| 1031 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1032 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1033 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1034 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1035 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1036 | /* Save the delegation */ |
| 1037 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1038 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1039 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1040 | if (ret != 0) |
| 1041 | goto out; |
| 1042 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1043 | |
| 1044 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1045 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1046 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1047 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1048 | out: |
| 1049 | return ERR_PTR(ret); |
| 1050 | out_return_state: |
| 1051 | atomic_inc(&state->count); |
| 1052 | return state; |
| 1053 | } |
| 1054 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1055 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1056 | { |
| 1057 | struct inode *inode; |
| 1058 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1059 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1060 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1061 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1062 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1063 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1064 | goto out; |
| 1065 | } |
| 1066 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1067 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1068 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1069 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1070 | 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] | 1071 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1072 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1073 | goto err; |
| 1074 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1075 | state = nfs4_get_open_state(inode, data->owner); |
| 1076 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1077 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1078 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1079 | int delegation_flags = 0; |
| 1080 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1081 | rcu_read_lock(); |
| 1082 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1083 | if (delegation) |
| 1084 | delegation_flags = delegation->flags; |
| 1085 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1086 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1087 | nfs_inode_set_delegation(state->inode, |
| 1088 | data->owner->so_cred, |
| 1089 | &data->o_res); |
| 1090 | else |
| 1091 | nfs_inode_reclaim_delegation(state->inode, |
| 1092 | data->owner->so_cred, |
| 1093 | &data->o_res); |
| 1094 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1095 | |
| 1096 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1097 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1098 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1099 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1100 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1101 | err_put_inode: |
| 1102 | iput(inode); |
| 1103 | err: |
| 1104 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1105 | } |
| 1106 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1107 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1108 | { |
| 1109 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1110 | struct nfs_open_context *ctx; |
| 1111 | |
| 1112 | spin_lock(&state->inode->i_lock); |
| 1113 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1114 | if (ctx->state != state) |
| 1115 | continue; |
| 1116 | get_nfs_open_context(ctx); |
| 1117 | spin_unlock(&state->inode->i_lock); |
| 1118 | return ctx; |
| 1119 | } |
| 1120 | spin_unlock(&state->inode->i_lock); |
| 1121 | return ERR_PTR(-ENOENT); |
| 1122 | } |
| 1123 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1124 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1125 | { |
| 1126 | struct nfs4_opendata *opendata; |
| 1127 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1128 | 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] | 1129 | if (opendata == NULL) |
| 1130 | return ERR_PTR(-ENOMEM); |
| 1131 | opendata->state = state; |
| 1132 | atomic_inc(&state->count); |
| 1133 | return opendata; |
| 1134 | } |
| 1135 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1136 | 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] | 1137 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1138 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1139 | int ret; |
| 1140 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1141 | opendata->o_arg.open_flags = 0; |
| 1142 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1143 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1144 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1145 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1146 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1147 | if (ret != 0) |
| 1148 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1149 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1150 | if (IS_ERR(newstate)) |
| 1151 | return PTR_ERR(newstate); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1152 | nfs4_close_state(&opendata->path, newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1153 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1158 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1159 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1160 | int ret; |
| 1161 | |
| 1162 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1163 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1164 | smp_rmb(); |
| 1165 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1166 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1167 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1168 | if (ret != 0) |
| 1169 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1170 | if (newstate != state) |
| 1171 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1172 | } |
| 1173 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1174 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1175 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1176 | if (ret != 0) |
| 1177 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1178 | if (newstate != state) |
| 1179 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1180 | } |
| 1181 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1182 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1183 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1184 | if (ret != 0) |
| 1185 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1186 | if (newstate != state) |
| 1187 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1188 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1189 | /* |
| 1190 | * We may have performed cached opens for all three recoveries. |
| 1191 | * Check if we need to update the current stateid. |
| 1192 | */ |
| 1193 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1194 | 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] | 1195 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1196 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1197 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1198 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1199 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | /* |
| 1204 | * OPEN_RECLAIM: |
| 1205 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1207 | 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] | 1208 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1209 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1210 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1211 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | int status; |
| 1213 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1214 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1215 | if (IS_ERR(opendata)) |
| 1216 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1217 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1218 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1219 | rcu_read_lock(); |
| 1220 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1221 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1222 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1223 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1224 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1225 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1226 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | return status; |
| 1228 | } |
| 1229 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1230 | 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] | 1231 | { |
| 1232 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1233 | struct nfs4_exception exception = { }; |
| 1234 | int err; |
| 1235 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1236 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1237 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1238 | break; |
| 1239 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | } while (exception.retry); |
| 1241 | return err; |
| 1242 | } |
| 1243 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1244 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1245 | { |
| 1246 | struct nfs_open_context *ctx; |
| 1247 | int ret; |
| 1248 | |
| 1249 | ctx = nfs4_state_find_open_context(state); |
| 1250 | if (IS_ERR(ctx)) |
| 1251 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1252 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1253 | put_nfs_open_context(ctx); |
| 1254 | return ret; |
| 1255 | } |
| 1256 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1257 | 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] | 1258 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1259 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1260 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1262 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1263 | if (IS_ERR(opendata)) |
| 1264 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1265 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1266 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1267 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1268 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1269 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1270 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1273 | 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] | 1274 | { |
| 1275 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1276 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | int err; |
| 1278 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1279 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | switch (err) { |
| 1281 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1282 | case -ENOENT: |
| 1283 | case -ESTALE: |
| 1284 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1285 | case -NFS4ERR_BADSESSION: |
| 1286 | case -NFS4ERR_BADSLOT: |
| 1287 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1288 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1289 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1290 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1291 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | case -NFS4ERR_STALE_CLIENTID: |
| 1293 | case -NFS4ERR_STALE_STATEID: |
| 1294 | case -NFS4ERR_EXPIRED: |
| 1295 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1296 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1297 | goto out; |
| 1298 | case -ERESTARTSYS: |
| 1299 | /* |
| 1300 | * The show must go on: exit, but mark the |
| 1301 | * stateid as needing recovery. |
| 1302 | */ |
| 1303 | case -NFS4ERR_ADMIN_REVOKED: |
| 1304 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1305 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1306 | case -EKEYEXPIRED: |
| 1307 | /* |
| 1308 | * User RPCSEC_GSS context has expired. |
| 1309 | * We cannot recover this stateid now, so |
| 1310 | * skip it and allow recovery thread to |
| 1311 | * proceed. |
| 1312 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1313 | case -ENOMEM: |
| 1314 | err = 0; |
| 1315 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | } |
| 1317 | err = nfs4_handle_exception(server, err, &exception); |
| 1318 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1319 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | return err; |
| 1321 | } |
| 1322 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1323 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1324 | { |
| 1325 | struct nfs4_opendata *data = calldata; |
| 1326 | |
| 1327 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1328 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1329 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1330 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1331 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1332 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1333 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1334 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | static void nfs4_open_confirm_release(void *calldata) |
| 1338 | { |
| 1339 | struct nfs4_opendata *data = calldata; |
| 1340 | struct nfs4_state *state = NULL; |
| 1341 | |
| 1342 | /* If this request hasn't been cancelled, do nothing */ |
| 1343 | if (data->cancelled == 0) |
| 1344 | goto out_free; |
| 1345 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1346 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1347 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1348 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1349 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1350 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1351 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1352 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1356 | .rpc_call_done = nfs4_open_confirm_done, |
| 1357 | .rpc_release = nfs4_open_confirm_release, |
| 1358 | }; |
| 1359 | |
| 1360 | /* |
| 1361 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1362 | */ |
| 1363 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1364 | { |
| 1365 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1366 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1367 | struct rpc_message msg = { |
| 1368 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1369 | .rpc_argp = &data->c_arg, |
| 1370 | .rpc_resp = &data->c_res, |
| 1371 | .rpc_cred = data->owner->so_cred, |
| 1372 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1373 | struct rpc_task_setup task_setup_data = { |
| 1374 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1375 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1376 | .callback_ops = &nfs4_open_confirm_ops, |
| 1377 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1378 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1379 | .flags = RPC_TASK_ASYNC, |
| 1380 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | int status; |
| 1382 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1383 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1384 | data->rpc_done = 0; |
| 1385 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1386 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1387 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1388 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1389 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1390 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1391 | if (status != 0) { |
| 1392 | data->cancelled = 1; |
| 1393 | smp_wmb(); |
| 1394 | } else |
| 1395 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1396 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | return status; |
| 1398 | } |
| 1399 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1400 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1402 | struct nfs4_opendata *data = calldata; |
| 1403 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1404 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1405 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1406 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1407 | /* |
| 1408 | * Check if we still need to send an OPEN call, or if we can use |
| 1409 | * a delegation instead. |
| 1410 | */ |
| 1411 | if (data->state != NULL) { |
| 1412 | struct nfs_delegation *delegation; |
| 1413 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1414 | 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] | 1415 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1416 | rcu_read_lock(); |
| 1417 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1418 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1419 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1420 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1421 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1422 | } |
| 1423 | rcu_read_unlock(); |
| 1424 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1425 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1426 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1427 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1428 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1429 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1430 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1431 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1432 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1433 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1434 | &data->o_arg.seq_args, |
| 1435 | &data->o_res.seq_res, 1, task)) |
| 1436 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1437 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1438 | return; |
| 1439 | out_no_action: |
| 1440 | task->tk_action = NULL; |
| 1441 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1442 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1444 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1445 | { |
| 1446 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1447 | nfs4_open_prepare(task, calldata); |
| 1448 | } |
| 1449 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1450 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1451 | { |
| 1452 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1454 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1455 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1456 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1457 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1458 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1459 | if (task->tk_status == 0) { |
| 1460 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1461 | case S_IFREG: |
| 1462 | break; |
| 1463 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1464 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1465 | break; |
| 1466 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1467 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1468 | break; |
| 1469 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1470 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1471 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1472 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1473 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1474 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1475 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1476 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1477 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1478 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1479 | static void nfs4_open_release(void *calldata) |
| 1480 | { |
| 1481 | struct nfs4_opendata *data = calldata; |
| 1482 | struct nfs4_state *state = NULL; |
| 1483 | |
| 1484 | /* If this request hasn't been cancelled, do nothing */ |
| 1485 | if (data->cancelled == 0) |
| 1486 | goto out_free; |
| 1487 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1488 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1489 | goto out_free; |
| 1490 | /* In case we need an open_confirm, no cleanup! */ |
| 1491 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1492 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1493 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1494 | if (!IS_ERR(state)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1495 | nfs4_close_state(&data->path, state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1496 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1497 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1501 | .rpc_call_prepare = nfs4_open_prepare, |
| 1502 | .rpc_call_done = nfs4_open_done, |
| 1503 | .rpc_release = nfs4_open_release, |
| 1504 | }; |
| 1505 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1506 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1507 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1508 | .rpc_call_done = nfs4_open_done, |
| 1509 | .rpc_release = nfs4_open_release, |
| 1510 | }; |
| 1511 | |
| 1512 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1513 | { |
| 1514 | struct inode *dir = data->dir->d_inode; |
| 1515 | struct nfs_server *server = NFS_SERVER(dir); |
| 1516 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1517 | struct nfs_openres *o_res = &data->o_res; |
| 1518 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1519 | struct rpc_message msg = { |
| 1520 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1521 | .rpc_argp = o_arg, |
| 1522 | .rpc_resp = o_res, |
| 1523 | .rpc_cred = data->owner->so_cred, |
| 1524 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1525 | struct rpc_task_setup task_setup_data = { |
| 1526 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1527 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1528 | .callback_ops = &nfs4_open_ops, |
| 1529 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1530 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1531 | .flags = RPC_TASK_ASYNC, |
| 1532 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1533 | int status; |
| 1534 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1535 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1536 | data->rpc_done = 0; |
| 1537 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1538 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1539 | if (isrecover) |
| 1540 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1541 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1542 | if (IS_ERR(task)) |
| 1543 | return PTR_ERR(task); |
| 1544 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1545 | if (status != 0) { |
| 1546 | data->cancelled = 1; |
| 1547 | smp_wmb(); |
| 1548 | } else |
| 1549 | status = data->rpc_status; |
| 1550 | rpc_put_task(task); |
| 1551 | |
| 1552 | return status; |
| 1553 | } |
| 1554 | |
| 1555 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1556 | { |
| 1557 | struct inode *dir = data->dir->d_inode; |
| 1558 | struct nfs_openres *o_res = &data->o_res; |
| 1559 | int status; |
| 1560 | |
| 1561 | status = nfs4_run_open_task(data, 1); |
| 1562 | if (status != 0 || !data->rpc_done) |
| 1563 | return status; |
| 1564 | |
| 1565 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1566 | |
| 1567 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1568 | status = _nfs4_proc_open_confirm(data); |
| 1569 | if (status != 0) |
| 1570 | return status; |
| 1571 | } |
| 1572 | |
| 1573 | return status; |
| 1574 | } |
| 1575 | |
| 1576 | /* |
| 1577 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1578 | */ |
| 1579 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1580 | { |
| 1581 | struct inode *dir = data->dir->d_inode; |
| 1582 | struct nfs_server *server = NFS_SERVER(dir); |
| 1583 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1584 | struct nfs_openres *o_res = &data->o_res; |
| 1585 | int status; |
| 1586 | |
| 1587 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1588 | if (status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1589 | return status; |
| 1590 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1591 | if (o_arg->open_flags & O_CREAT) { |
| 1592 | update_changeattr(dir, &o_res->cinfo); |
| 1593 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1594 | } else |
| 1595 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1596 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1597 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1599 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1601 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | } |
| 1603 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1604 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1605 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | } |
| 1607 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1608 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1609 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1610 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1611 | int ret; |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1612 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1613 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1614 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1615 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1616 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1617 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1618 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1619 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1620 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1621 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1622 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1623 | return ret; |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1624 | } |
| 1625 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1626 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1627 | { |
| 1628 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1629 | } |
| 1630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | /* |
| 1632 | * OPEN_EXPIRED: |
| 1633 | * reclaim state on the server after a network partition. |
| 1634 | * Assumes caller holds the appropriate lock |
| 1635 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1636 | 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] | 1637 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1638 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1639 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1641 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1642 | if (IS_ERR(opendata)) |
| 1643 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1644 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1645 | if (ret == -ESTALE) |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1646 | d_drop(ctx->path.dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1647 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1648 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1651 | 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] | 1652 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1653 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1654 | struct nfs4_exception exception = { }; |
| 1655 | int err; |
| 1656 | |
| 1657 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1658 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1659 | switch (err) { |
| 1660 | default: |
| 1661 | goto out; |
| 1662 | case -NFS4ERR_GRACE: |
| 1663 | case -NFS4ERR_DELAY: |
| 1664 | nfs4_handle_exception(server, err, &exception); |
| 1665 | err = 0; |
| 1666 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1667 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1668 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1669 | return err; |
| 1670 | } |
| 1671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1673 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1675 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1677 | ctx = nfs4_state_find_open_context(state); |
| 1678 | if (IS_ERR(ctx)) |
| 1679 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1680 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1681 | put_nfs_open_context(ctx); |
| 1682 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1686 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1687 | * fields corresponding to attributes that were used to store the verifier. |
| 1688 | * Make sure we clobber those fields in the later setattr call |
| 1689 | */ |
| 1690 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1691 | { |
| 1692 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1693 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1694 | sattr->ia_valid |= ATTR_ATIME; |
| 1695 | |
| 1696 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1697 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1698 | sattr->ia_valid |= ATTR_MTIME; |
| 1699 | } |
| 1700 | |
| 1701 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1702 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1704 | 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] | 1705 | { |
| 1706 | struct nfs4_state_owner *sp; |
| 1707 | struct nfs4_state *state = NULL; |
| 1708 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1709 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1710 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | |
| 1712 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | status = -ENOMEM; |
| 1714 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1715 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1716 | goto out_err; |
| 1717 | } |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1718 | status = nfs4_recover_expired_lease(server); |
| 1719 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1720 | goto err_put_state_owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1721 | if (path->dentry->d_inode != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1722 | nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode); |
Trond Myklebust | 58d9714a | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1723 | status = -ENOMEM; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 1724 | opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1725 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1726 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1728 | if (path->dentry->d_inode != NULL) |
| 1729 | opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp); |
| 1730 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1731 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1733 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1735 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1736 | status = PTR_ERR(state); |
| 1737 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1738 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1739 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1740 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1741 | |
| 1742 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1743 | nfs4_exclusive_attrset(opendata, sattr); |
| 1744 | |
| 1745 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1746 | status = nfs4_do_setattr(state->inode, cred, |
| 1747 | opendata->o_res.f_attr, sattr, |
| 1748 | state); |
| 1749 | if (status == 0) |
| 1750 | nfs_setattr_update_inode(state->inode, sattr); |
| 1751 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1752 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1753 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | *res = state; |
| 1756 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1757 | err_opendata_put: |
| 1758 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1759 | err_put_state_owner: |
| 1760 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | *res = NULL; |
| 1763 | return status; |
| 1764 | } |
| 1765 | |
| 1766 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1767 | 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] | 1768 | { |
| 1769 | struct nfs4_exception exception = { }; |
| 1770 | struct nfs4_state *res; |
| 1771 | int status; |
| 1772 | |
| 1773 | do { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1774 | status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | if (status == 0) |
| 1776 | break; |
| 1777 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1778 | * book-keeping w.r.t. state-changing operations |
| 1779 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1780 | * It is actually a sign of a bug on the client or on the server. |
| 1781 | * |
| 1782 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1783 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | * have unhashed the old state_owner for us, and that we can |
| 1785 | * therefore safely retry using a new one. We should still warn |
| 1786 | * the user though... |
| 1787 | */ |
| 1788 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1789 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1790 | " returned a bad sequence-id error!\n", |
| 1791 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | exception.retry = 1; |
| 1793 | continue; |
| 1794 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1795 | /* |
| 1796 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1797 | * state before it received the OPEN_CONFIRM. |
| 1798 | * Recover by retrying the request as per the discussion |
| 1799 | * on Page 181 of RFC3530. |
| 1800 | */ |
| 1801 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1802 | exception.retry = 1; |
| 1803 | continue; |
| 1804 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1805 | if (status == -EAGAIN) { |
| 1806 | /* We must have found a delegation */ |
| 1807 | exception.retry = 1; |
| 1808 | continue; |
| 1809 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1811 | status, &exception)); |
| 1812 | } while (exception.retry); |
| 1813 | return res; |
| 1814 | } |
| 1815 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1816 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1817 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1818 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1820 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1822 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | .iap = sattr, |
| 1824 | .server = server, |
| 1825 | .bitmask = server->attr_bitmask, |
| 1826 | }; |
| 1827 | struct nfs_setattrres res = { |
| 1828 | .fattr = fattr, |
| 1829 | .server = server, |
| 1830 | }; |
| 1831 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1832 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1833 | .rpc_argp = &arg, |
| 1834 | .rpc_resp = &res, |
| 1835 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1837 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1838 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1840 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1842 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1843 | /* Use that stateid */ |
| 1844 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1845 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1846 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1848 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1849 | 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] | 1850 | if (status == 0 && state != NULL) |
| 1851 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1852 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1855 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1856 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1857 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1859 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | struct nfs4_exception exception = { }; |
| 1861 | int err; |
| 1862 | do { |
| 1863 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1864 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | &exception); |
| 1866 | } while (exception.retry); |
| 1867 | return err; |
| 1868 | } |
| 1869 | |
| 1870 | struct nfs4_closedata { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 1871 | struct path path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | struct inode *inode; |
| 1873 | struct nfs4_state *state; |
| 1874 | struct nfs_closeargs arg; |
| 1875 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1876 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1877 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1878 | bool roc; |
| 1879 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | }; |
| 1881 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1882 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1883 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1884 | struct nfs4_closedata *calldata = data; |
| 1885 | struct nfs4_state_owner *sp = calldata->state->owner; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1886 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1887 | if (calldata->roc) |
| 1888 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1889 | nfs4_put_open_state(calldata->state); |
| 1890 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1891 | nfs4_put_state_owner(sp); |
Jan Blunck | 31f31db | 2008-05-02 13:42:45 -0700 | [diff] [blame] | 1892 | path_put(&calldata->path); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1893 | kfree(calldata); |
| 1894 | } |
| 1895 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1896 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1897 | fmode_t fmode) |
| 1898 | { |
| 1899 | spin_lock(&state->owner->so_lock); |
| 1900 | if (!(fmode & FMODE_READ)) |
| 1901 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1902 | if (!(fmode & FMODE_WRITE)) |
| 1903 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1904 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1905 | spin_unlock(&state->owner->so_lock); |
| 1906 | } |
| 1907 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1908 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1910 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1913 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1914 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1915 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | /* hmm. we are done with the inode, and in the process of freeing |
| 1917 | * the state_owner. we keep this around to process errors |
| 1918 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | switch (task->tk_status) { |
| 1920 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1921 | if (calldata->roc) |
| 1922 | pnfs_roc_set_barrier(state->inode, |
| 1923 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1924 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1925 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1926 | nfs4_close_clear_stateid_flags(state, |
| 1927 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | break; |
| 1929 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1930 | case -NFS4ERR_OLD_STATEID: |
| 1931 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1933 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1934 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1936 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1937 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1939 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1940 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1943 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1945 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1946 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1947 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1948 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1949 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1950 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1951 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1952 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1953 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1954 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1955 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1956 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1957 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1958 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1959 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1960 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1961 | } |
| 1962 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1963 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1964 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1965 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1966 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1967 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1968 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1969 | |
| 1970 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1971 | /* Note: exit _without_ calling nfs4_close_done */ |
| 1972 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1973 | return; |
| 1974 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1975 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1976 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1977 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1978 | if (calldata->roc && |
| 1979 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 1980 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 1981 | task, NULL); |
| 1982 | return; |
| 1983 | } |
| 1984 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1985 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1986 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1987 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1988 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 1989 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 1990 | 1, task)) |
| 1991 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1992 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1995 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1996 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1997 | .rpc_call_done = nfs4_close_done, |
| 1998 | .rpc_release = nfs4_free_closedata, |
| 1999 | }; |
| 2000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | /* |
| 2002 | * It is possible for data to be read/written from a mem-mapped file |
| 2003 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2004 | * This means that we can't safely call nfsv4 close on a file until |
| 2005 | * the inode is cleared. This in turn means that we are not good |
| 2006 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2007 | * share state even when we are done with one of the three share |
| 2008 | * stateid's in the inode. |
| 2009 | * |
| 2010 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2011 | */ |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2012 | 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] | 2013 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2014 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2016 | struct nfs4_state_owner *sp = state->owner; |
| 2017 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2018 | struct rpc_message msg = { |
| 2019 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2020 | .rpc_cred = state->owner->so_cred, |
| 2021 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2022 | struct rpc_task_setup task_setup_data = { |
| 2023 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2024 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2025 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2026 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2027 | .flags = RPC_TASK_ASYNC, |
| 2028 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2029 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2031 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2033 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2034 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2036 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2037 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2039 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2040 | if (calldata->arg.seqid == NULL) |
| 2041 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2042 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2043 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2044 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2045 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2046 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2047 | calldata->roc = roc; |
Al Viro | f694869 | 2010-01-30 13:51:04 -0500 | [diff] [blame] | 2048 | path_get(path); |
| 2049 | calldata->path = *path; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2050 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2051 | msg.rpc_argp = &calldata->arg; |
| 2052 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2053 | task_setup_data.callback_data = calldata; |
| 2054 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2055 | if (IS_ERR(task)) |
| 2056 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2057 | status = 0; |
| 2058 | if (wait) |
| 2059 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2060 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2061 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2062 | out_free_calldata: |
| 2063 | kfree(calldata); |
| 2064 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2065 | if (roc) |
| 2066 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2067 | nfs4_put_open_state(state); |
| 2068 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2069 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2072 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2073 | 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] | 2074 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | struct nfs4_state *state; |
| 2076 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2077 | /* Protect against concurrent sillydeletes */ |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2078 | 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] | 2079 | if (IS_ERR(state)) |
| 2080 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2081 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2082 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2085 | 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] | 2086 | { |
| 2087 | if (ctx->state == NULL) |
| 2088 | return; |
| 2089 | if (is_sync) |
| 2090 | nfs4_close_sync(&ctx->path, ctx->state, ctx->mode); |
| 2091 | else |
| 2092 | nfs4_close_state(&ctx->path, ctx->state, ctx->mode); |
| 2093 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | |
| 2095 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2096 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2097 | struct nfs4_server_caps_arg args = { |
| 2098 | .fhandle = fhandle, |
| 2099 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | struct nfs4_server_caps_res res = {}; |
| 2101 | struct rpc_message msg = { |
| 2102 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2103 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | .rpc_resp = &res, |
| 2105 | }; |
| 2106 | int status; |
| 2107 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2108 | 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] | 2109 | if (status == 0) { |
| 2110 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2111 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2112 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2113 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2114 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2115 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2117 | server->caps |= NFS_CAP_ACLS; |
| 2118 | if (res.has_links != 0) |
| 2119 | server->caps |= NFS_CAP_HARDLINKS; |
| 2120 | if (res.has_symlinks != 0) |
| 2121 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2122 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2123 | server->caps |= NFS_CAP_FILEID; |
| 2124 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2125 | server->caps |= NFS_CAP_MODE; |
| 2126 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2127 | server->caps |= NFS_CAP_NLINK; |
| 2128 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2129 | server->caps |= NFS_CAP_OWNER; |
| 2130 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2131 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2132 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2133 | server->caps |= NFS_CAP_ATIME; |
| 2134 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2135 | server->caps |= NFS_CAP_CTIME; |
| 2136 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2137 | server->caps |= NFS_CAP_MTIME; |
| 2138 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2139 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2140 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2141 | 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] | 2142 | server->acl_bitmask = res.acl_bitmask; |
| 2143 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | return status; |
| 2146 | } |
| 2147 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2148 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | { |
| 2150 | struct nfs4_exception exception = { }; |
| 2151 | int err; |
| 2152 | do { |
| 2153 | err = nfs4_handle_exception(server, |
| 2154 | _nfs4_server_capabilities(server, fhandle), |
| 2155 | &exception); |
| 2156 | } while (exception.retry); |
| 2157 | return err; |
| 2158 | } |
| 2159 | |
| 2160 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2161 | struct nfs_fsinfo *info) |
| 2162 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | struct nfs4_lookup_root_arg args = { |
| 2164 | .bitmask = nfs4_fattr_bitmap, |
| 2165 | }; |
| 2166 | struct nfs4_lookup_res res = { |
| 2167 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2168 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | .fh = fhandle, |
| 2170 | }; |
| 2171 | struct rpc_message msg = { |
| 2172 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2173 | .rpc_argp = &args, |
| 2174 | .rpc_resp = &res, |
| 2175 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2176 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2177 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2178 | 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] | 2179 | } |
| 2180 | |
| 2181 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2182 | struct nfs_fsinfo *info) |
| 2183 | { |
| 2184 | struct nfs4_exception exception = { }; |
| 2185 | int err; |
| 2186 | do { |
| 2187 | err = nfs4_handle_exception(server, |
| 2188 | _nfs4_lookup_root(server, fhandle, info), |
| 2189 | &exception); |
| 2190 | } while (exception.retry); |
| 2191 | return err; |
| 2192 | } |
| 2193 | |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2194 | /* |
| 2195 | * get the file handle for the "/" directory on the server |
| 2196 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2198 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | int status; |
| 2201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | status = nfs4_lookup_root(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | if (status == 0) |
| 2204 | status = nfs4_server_capabilities(server, fhandle); |
| 2205 | if (status == 0) |
| 2206 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2207 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2210 | /* |
| 2211 | * Get locations and (maybe) other attributes of a referral. |
| 2212 | * Note that we'll actually follow the referral later when |
| 2213 | * we detect fsid mismatch in inode revalidation |
| 2214 | */ |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 2215 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2216 | { |
| 2217 | int status = -ENOMEM; |
| 2218 | struct page *page = NULL; |
| 2219 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2220 | |
| 2221 | page = alloc_page(GFP_KERNEL); |
| 2222 | if (page == NULL) |
| 2223 | goto out; |
| 2224 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2225 | if (locations == NULL) |
| 2226 | goto out; |
| 2227 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2228 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2229 | if (status != 0) |
| 2230 | goto out; |
| 2231 | /* Make sure server returned a different fsid for the referral */ |
| 2232 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2233 | dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2234 | status = -EIO; |
| 2235 | goto out; |
| 2236 | } |
| 2237 | |
| 2238 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
| 2239 | fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL; |
| 2240 | if (!fattr->mode) |
| 2241 | fattr->mode = S_IFDIR; |
| 2242 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2243 | out: |
| 2244 | if (page) |
| 2245 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2246 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2247 | return status; |
| 2248 | } |
| 2249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2251 | { |
| 2252 | struct nfs4_getattr_arg args = { |
| 2253 | .fh = fhandle, |
| 2254 | .bitmask = server->attr_bitmask, |
| 2255 | }; |
| 2256 | struct nfs4_getattr_res res = { |
| 2257 | .fattr = fattr, |
| 2258 | .server = server, |
| 2259 | }; |
| 2260 | struct rpc_message msg = { |
| 2261 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2262 | .rpc_argp = &args, |
| 2263 | .rpc_resp = &res, |
| 2264 | }; |
| 2265 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2266 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2267 | 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] | 2268 | } |
| 2269 | |
| 2270 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2271 | { |
| 2272 | struct nfs4_exception exception = { }; |
| 2273 | int err; |
| 2274 | do { |
| 2275 | err = nfs4_handle_exception(server, |
| 2276 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2277 | &exception); |
| 2278 | } while (exception.retry); |
| 2279 | return err; |
| 2280 | } |
| 2281 | |
| 2282 | /* |
| 2283 | * The file is not closed if it is opened due to the a request to change |
| 2284 | * the size of the file. The open call will not be needed once the |
| 2285 | * VFS layer lookup-intents are implemented. |
| 2286 | * |
| 2287 | * Close is called when the inode is destroyed. |
| 2288 | * If we haven't opened the file for O_WRONLY, we |
| 2289 | * need to in the size_change case to obtain a stateid. |
| 2290 | * |
| 2291 | * Got race? |
| 2292 | * Because OPEN is always done by name in nfsv4, it is |
| 2293 | * possible that we opened a different file by the same |
| 2294 | * name. We can recognize this race condition, but we |
| 2295 | * can't do anything about it besides returning an error. |
| 2296 | * |
| 2297 | * This will be fixed with VFS changes (lookup-intent). |
| 2298 | */ |
| 2299 | static int |
| 2300 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2301 | struct iattr *sattr) |
| 2302 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2303 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2304 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2305 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | int status; |
| 2307 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2308 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2310 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2311 | if (sattr->ia_valid & ATTR_FILE) { |
| 2312 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2313 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2314 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2315 | if (ctx) { |
| 2316 | cred = ctx->cred; |
| 2317 | state = ctx->state; |
| 2318 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2322 | if (status == 0) |
| 2323 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | return status; |
| 2325 | } |
| 2326 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2327 | static int _nfs4_proc_lookupfh(struct rpc_clnt *clnt, struct nfs_server *server, |
| 2328 | const struct nfs_fh *dirfh, const struct qstr *name, |
| 2329 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2330 | { |
| 2331 | int status; |
| 2332 | struct nfs4_lookup_arg args = { |
| 2333 | .bitmask = server->attr_bitmask, |
| 2334 | .dir_fh = dirfh, |
| 2335 | .name = name, |
| 2336 | }; |
| 2337 | struct nfs4_lookup_res res = { |
| 2338 | .server = server, |
| 2339 | .fattr = fattr, |
| 2340 | .fh = fhandle, |
| 2341 | }; |
| 2342 | struct rpc_message msg = { |
| 2343 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2344 | .rpc_argp = &args, |
| 2345 | .rpc_resp = &res, |
| 2346 | }; |
| 2347 | |
| 2348 | nfs_fattr_init(fattr); |
| 2349 | |
| 2350 | dprintk("NFS call lookupfh %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2351 | 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] | 2352 | dprintk("NFS reply lookupfh: %d\n", status); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2353 | return status; |
| 2354 | } |
| 2355 | |
| 2356 | static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh, |
| 2357 | struct qstr *name, struct nfs_fh *fhandle, |
| 2358 | struct nfs_fattr *fattr) |
| 2359 | { |
| 2360 | struct nfs4_exception exception = { }; |
| 2361 | int err; |
| 2362 | do { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2363 | err = _nfs4_proc_lookupfh(server->client, server, dirfh, name, fhandle, fattr); |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2364 | /* FIXME: !!!! */ |
| 2365 | if (err == -NFS4ERR_MOVED) { |
| 2366 | err = -EREMOTE; |
| 2367 | break; |
| 2368 | } |
| 2369 | err = nfs4_handle_exception(server, err, &exception); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2370 | } while (exception.retry); |
| 2371 | return err; |
| 2372 | } |
| 2373 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2374 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2375 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2376 | struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | { |
Trond Myklebust | 4e56e08 | 2007-07-01 18:13:52 -0400 | [diff] [blame] | 2378 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | |
| 2380 | dprintk("NFS call lookup %s\n", name->name); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2381 | 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] | 2382 | if (status == -NFS4ERR_MOVED) |
| 2383 | status = nfs4_get_referral(dir, name, fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | dprintk("NFS reply lookup: %d\n", status); |
| 2385 | return status; |
| 2386 | } |
| 2387 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame^] | 2388 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2389 | { |
| 2390 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2391 | fattr->fsid.major = 1; |
| 2392 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2393 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2394 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2395 | fattr->nlink = 2; |
| 2396 | } |
| 2397 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2398 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2399 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | { |
| 2401 | struct nfs4_exception exception = { }; |
| 2402 | int err; |
| 2403 | do { |
| 2404 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2405 | _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | &exception); |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame^] | 2407 | if (err == -EPERM) |
| 2408 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | } while (exception.retry); |
| 2410 | return err; |
| 2411 | } |
| 2412 | |
| 2413 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2414 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2415 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | struct nfs4_accessargs args = { |
| 2417 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2418 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2420 | struct nfs4_accessres res = { |
| 2421 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2422 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | struct rpc_message msg = { |
| 2424 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2425 | .rpc_argp = &args, |
| 2426 | .rpc_resp = &res, |
| 2427 | .rpc_cred = entry->cred, |
| 2428 | }; |
| 2429 | int mode = entry->mask; |
| 2430 | int status; |
| 2431 | |
| 2432 | /* |
| 2433 | * Determine which access bits we want to ask for... |
| 2434 | */ |
| 2435 | if (mode & MAY_READ) |
| 2436 | args.access |= NFS4_ACCESS_READ; |
| 2437 | if (S_ISDIR(inode->i_mode)) { |
| 2438 | if (mode & MAY_WRITE) |
| 2439 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2440 | if (mode & MAY_EXEC) |
| 2441 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2442 | } else { |
| 2443 | if (mode & MAY_WRITE) |
| 2444 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2445 | if (mode & MAY_EXEC) |
| 2446 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2447 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2448 | |
| 2449 | res.fattr = nfs_alloc_fattr(); |
| 2450 | if (res.fattr == NULL) |
| 2451 | return -ENOMEM; |
| 2452 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2453 | 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] | 2454 | if (!status) { |
| 2455 | entry->mask = 0; |
| 2456 | if (res.access & NFS4_ACCESS_READ) |
| 2457 | entry->mask |= MAY_READ; |
| 2458 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2459 | entry->mask |= MAY_WRITE; |
| 2460 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2461 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2462 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2464 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | return status; |
| 2466 | } |
| 2467 | |
| 2468 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2469 | { |
| 2470 | struct nfs4_exception exception = { }; |
| 2471 | int err; |
| 2472 | do { |
| 2473 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2474 | _nfs4_proc_access(inode, entry), |
| 2475 | &exception); |
| 2476 | } while (exception.retry); |
| 2477 | return err; |
| 2478 | } |
| 2479 | |
| 2480 | /* |
| 2481 | * TODO: For the time being, we don't try to get any attributes |
| 2482 | * along with any of the zero-copy operations READ, READDIR, |
| 2483 | * READLINK, WRITE. |
| 2484 | * |
| 2485 | * In the case of the first three, we want to put the GETATTR |
| 2486 | * after the read-type operation -- this is because it is hard |
| 2487 | * to predict the length of a GETATTR response in v4, and thus |
| 2488 | * align the READ data correctly. This means that the GETATTR |
| 2489 | * may end up partially falling into the page cache, and we should |
| 2490 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2491 | * To do this efficiently, we need to know the total length |
| 2492 | * of data received, which doesn't seem to be available outside |
| 2493 | * of the RPC layer. |
| 2494 | * |
| 2495 | * In the case of WRITE, we also want to put the GETATTR after |
| 2496 | * the operation -- in this case because we want to make sure |
| 2497 | * we get the post-operation mtime and size. This means that |
| 2498 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2499 | * of it which would leave room in the 'tail' iovec. |
| 2500 | * |
| 2501 | * Both of these changes to the XDR layer would in fact be quite |
| 2502 | * minor, but I decided to leave them for a subsequent patch. |
| 2503 | */ |
| 2504 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2505 | unsigned int pgbase, unsigned int pglen) |
| 2506 | { |
| 2507 | struct nfs4_readlink args = { |
| 2508 | .fh = NFS_FH(inode), |
| 2509 | .pgbase = pgbase, |
| 2510 | .pglen = pglen, |
| 2511 | .pages = &page, |
| 2512 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2513 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | struct rpc_message msg = { |
| 2515 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2516 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2517 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | }; |
| 2519 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2520 | 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] | 2521 | } |
| 2522 | |
| 2523 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2524 | unsigned int pgbase, unsigned int pglen) |
| 2525 | { |
| 2526 | struct nfs4_exception exception = { }; |
| 2527 | int err; |
| 2528 | do { |
| 2529 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2530 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2531 | &exception); |
| 2532 | } while (exception.retry); |
| 2533 | return err; |
| 2534 | } |
| 2535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | /* |
| 2537 | * Got race? |
| 2538 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2539 | * Until then, this create/open method is prone to inefficiency and race |
| 2540 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2541 | * placed on the wire. |
| 2542 | * |
| 2543 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2544 | * The file will be opened again in the subsequent VFS open call |
| 2545 | * (nfs4_proc_file_open). |
| 2546 | * |
| 2547 | * The open for read will just hang around to be used by any process that |
| 2548 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2549 | */ |
| 2550 | |
| 2551 | static int |
| 2552 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2553 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | { |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2555 | struct path my_path = { |
Trond Myklebust | ad389da | 2007-06-05 12:30:00 -0400 | [diff] [blame] | 2556 | .dentry = dentry, |
| 2557 | }; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2558 | struct path *path = &my_path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2560 | struct rpc_cred *cred = NULL; |
| 2561 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | int status = 0; |
| 2563 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2564 | if (ctx != NULL) { |
| 2565 | cred = ctx->cred; |
| 2566 | path = &ctx->path; |
| 2567 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2569 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2570 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2571 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | if (IS_ERR(state)) { |
| 2573 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2574 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2576 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2577 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2578 | if (ctx != NULL) |
| 2579 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2580 | else |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2581 | nfs4_close_sync(path, state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | out: |
| 2583 | return status; |
| 2584 | } |
| 2585 | |
| 2586 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2587 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2588 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2589 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2591 | .name.len = name->len, |
| 2592 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2593 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2595 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2596 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2597 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2599 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2600 | .rpc_argp = &args, |
| 2601 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2603 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2604 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2605 | res.dir_attr = nfs_alloc_fattr(); |
| 2606 | if (res.dir_attr == NULL) |
| 2607 | goto out; |
| 2608 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2609 | 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] | 2610 | if (status == 0) { |
| 2611 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2612 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2613 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2614 | nfs_free_fattr(res.dir_attr); |
| 2615 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | return status; |
| 2617 | } |
| 2618 | |
| 2619 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2620 | { |
| 2621 | struct nfs4_exception exception = { }; |
| 2622 | int err; |
| 2623 | do { |
| 2624 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2625 | _nfs4_proc_remove(dir, name), |
| 2626 | &exception); |
| 2627 | } while (exception.retry); |
| 2628 | return err; |
| 2629 | } |
| 2630 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2631 | 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] | 2632 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2633 | struct nfs_server *server = NFS_SERVER(dir); |
| 2634 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2635 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2637 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2638 | res->server = server; |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2639 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | } |
| 2642 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2643 | 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] | 2644 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2645 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2646 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2647 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2648 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2649 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2650 | return 0; |
| 2651 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2652 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2653 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2656 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2657 | { |
| 2658 | struct nfs_server *server = NFS_SERVER(dir); |
| 2659 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2660 | struct nfs_renameres *res = msg->rpc_resp; |
| 2661 | |
| 2662 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2663 | arg->bitmask = server->attr_bitmask; |
| 2664 | res->server = server; |
| 2665 | } |
| 2666 | |
| 2667 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2668 | struct inode *new_dir) |
| 2669 | { |
| 2670 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2671 | |
| 2672 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2673 | return 0; |
| 2674 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2675 | return 0; |
| 2676 | |
| 2677 | update_changeattr(old_dir, &res->old_cinfo); |
| 2678 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2679 | update_changeattr(new_dir, &res->new_cinfo); |
| 2680 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2681 | return 1; |
| 2682 | } |
| 2683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2685 | struct inode *new_dir, struct qstr *new_name) |
| 2686 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2687 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2688 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | .old_dir = NFS_FH(old_dir), |
| 2690 | .new_dir = NFS_FH(new_dir), |
| 2691 | .old_name = old_name, |
| 2692 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2693 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2695 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2696 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2697 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | struct rpc_message msg = { |
| 2699 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2700 | .rpc_argp = &arg, |
| 2701 | .rpc_resp = &res, |
| 2702 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2703 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2705 | res.old_fattr = nfs_alloc_fattr(); |
| 2706 | res.new_fattr = nfs_alloc_fattr(); |
| 2707 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2708 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2709 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2710 | 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] | 2711 | if (!status) { |
| 2712 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2713 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2715 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2717 | out: |
| 2718 | nfs_free_fattr(res.new_fattr); |
| 2719 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | return status; |
| 2721 | } |
| 2722 | |
| 2723 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2724 | struct inode *new_dir, struct qstr *new_name) |
| 2725 | { |
| 2726 | struct nfs4_exception exception = { }; |
| 2727 | int err; |
| 2728 | do { |
| 2729 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2730 | _nfs4_proc_rename(old_dir, old_name, |
| 2731 | new_dir, new_name), |
| 2732 | &exception); |
| 2733 | } while (exception.retry); |
| 2734 | return err; |
| 2735 | } |
| 2736 | |
| 2737 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2738 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2739 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | struct nfs4_link_arg arg = { |
| 2741 | .fh = NFS_FH(inode), |
| 2742 | .dir_fh = NFS_FH(dir), |
| 2743 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2744 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2746 | struct nfs4_link_res res = { |
| 2747 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2748 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | struct rpc_message msg = { |
| 2750 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2751 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2752 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2754 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2756 | res.fattr = nfs_alloc_fattr(); |
| 2757 | res.dir_attr = nfs_alloc_fattr(); |
| 2758 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2759 | goto out; |
| 2760 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2761 | 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] | 2762 | if (!status) { |
| 2763 | update_changeattr(dir, &res.cinfo); |
| 2764 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2765 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2766 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2767 | out: |
| 2768 | nfs_free_fattr(res.dir_attr); |
| 2769 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | return status; |
| 2771 | } |
| 2772 | |
| 2773 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2774 | { |
| 2775 | struct nfs4_exception exception = { }; |
| 2776 | int err; |
| 2777 | do { |
| 2778 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2779 | _nfs4_proc_link(inode, dir, name), |
| 2780 | &exception); |
| 2781 | } while (exception.retry); |
| 2782 | return err; |
| 2783 | } |
| 2784 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2785 | struct nfs4_createdata { |
| 2786 | struct rpc_message msg; |
| 2787 | struct nfs4_create_arg arg; |
| 2788 | struct nfs4_create_res res; |
| 2789 | struct nfs_fh fh; |
| 2790 | struct nfs_fattr fattr; |
| 2791 | struct nfs_fattr dir_fattr; |
| 2792 | }; |
| 2793 | |
| 2794 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2795 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2796 | { |
| 2797 | struct nfs4_createdata *data; |
| 2798 | |
| 2799 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2800 | if (data != NULL) { |
| 2801 | struct nfs_server *server = NFS_SERVER(dir); |
| 2802 | |
| 2803 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2804 | data->msg.rpc_argp = &data->arg; |
| 2805 | data->msg.rpc_resp = &data->res; |
| 2806 | data->arg.dir_fh = NFS_FH(dir); |
| 2807 | data->arg.server = server; |
| 2808 | data->arg.name = name; |
| 2809 | data->arg.attrs = sattr; |
| 2810 | data->arg.ftype = ftype; |
| 2811 | data->arg.bitmask = server->attr_bitmask; |
| 2812 | data->res.server = server; |
| 2813 | data->res.fh = &data->fh; |
| 2814 | data->res.fattr = &data->fattr; |
| 2815 | data->res.dir_fattr = &data->dir_fattr; |
| 2816 | nfs_fattr_init(data->res.fattr); |
| 2817 | nfs_fattr_init(data->res.dir_fattr); |
| 2818 | } |
| 2819 | return data; |
| 2820 | } |
| 2821 | |
| 2822 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2823 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2824 | 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] | 2825 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2826 | if (status == 0) { |
| 2827 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2828 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2829 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2830 | } |
| 2831 | return status; |
| 2832 | } |
| 2833 | |
| 2834 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2835 | { |
| 2836 | kfree(data); |
| 2837 | } |
| 2838 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2839 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2840 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2842 | struct nfs4_createdata *data; |
| 2843 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2845 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2846 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2847 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2848 | status = -ENOMEM; |
| 2849 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2850 | if (data == NULL) |
| 2851 | goto out; |
| 2852 | |
| 2853 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2854 | data->arg.u.symlink.pages = &page; |
| 2855 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2857 | status = nfs4_do_create(dir, dentry, data); |
| 2858 | |
| 2859 | nfs4_free_createdata(data); |
| 2860 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | return status; |
| 2862 | } |
| 2863 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2864 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2865 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | { |
| 2867 | struct nfs4_exception exception = { }; |
| 2868 | int err; |
| 2869 | do { |
| 2870 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2871 | _nfs4_proc_symlink(dir, dentry, page, |
| 2872 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 | &exception); |
| 2874 | } while (exception.retry); |
| 2875 | return err; |
| 2876 | } |
| 2877 | |
| 2878 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2879 | struct iattr *sattr) |
| 2880 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2881 | struct nfs4_createdata *data; |
| 2882 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2884 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2885 | if (data == NULL) |
| 2886 | goto out; |
| 2887 | |
| 2888 | status = nfs4_do_create(dir, dentry, data); |
| 2889 | |
| 2890 | nfs4_free_createdata(data); |
| 2891 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | return status; |
| 2893 | } |
| 2894 | |
| 2895 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2896 | struct iattr *sattr) |
| 2897 | { |
| 2898 | struct nfs4_exception exception = { }; |
| 2899 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2900 | |
| 2901 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | do { |
| 2903 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2904 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2905 | &exception); |
| 2906 | } while (exception.retry); |
| 2907 | return err; |
| 2908 | } |
| 2909 | |
| 2910 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2911 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | { |
| 2913 | struct inode *dir = dentry->d_inode; |
| 2914 | struct nfs4_readdir_arg args = { |
| 2915 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2916 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | .pgbase = 0, |
| 2918 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2919 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2920 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | }; |
| 2922 | struct nfs4_readdir_res res; |
| 2923 | struct rpc_message msg = { |
| 2924 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2925 | .rpc_argp = &args, |
| 2926 | .rpc_resp = &res, |
| 2927 | .rpc_cred = cred, |
| 2928 | }; |
| 2929 | int status; |
| 2930 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2931 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2932 | dentry->d_parent->d_name.name, |
| 2933 | dentry->d_name.name, |
| 2934 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2936 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2937 | 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] | 2938 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 2940 | status += args.pgbase; |
| 2941 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 2942 | |
| 2943 | nfs_invalidate_atime(dir); |
| 2944 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2945 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | return status; |
| 2947 | } |
| 2948 | |
| 2949 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2950 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | { |
| 2952 | struct nfs4_exception exception = { }; |
| 2953 | int err; |
| 2954 | do { |
| 2955 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 2956 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2957 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | &exception); |
| 2959 | } while (exception.retry); |
| 2960 | return err; |
| 2961 | } |
| 2962 | |
| 2963 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2964 | struct iattr *sattr, dev_t rdev) |
| 2965 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2966 | struct nfs4_createdata *data; |
| 2967 | int mode = sattr->ia_mode; |
| 2968 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | |
| 2970 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 2971 | 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] | 2972 | |
| 2973 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 2974 | if (data == NULL) |
| 2975 | goto out; |
| 2976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2978 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2980 | data->arg.ftype = NF4BLK; |
| 2981 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2982 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2983 | } |
| 2984 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2985 | data->arg.ftype = NF4CHR; |
| 2986 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 2987 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2990 | status = nfs4_do_create(dir, dentry, data); |
| 2991 | |
| 2992 | nfs4_free_createdata(data); |
| 2993 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | return status; |
| 2995 | } |
| 2996 | |
| 2997 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 2998 | struct iattr *sattr, dev_t rdev) |
| 2999 | { |
| 3000 | struct nfs4_exception exception = { }; |
| 3001 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3002 | |
| 3003 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | do { |
| 3005 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3006 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3007 | &exception); |
| 3008 | } while (exception.retry); |
| 3009 | return err; |
| 3010 | } |
| 3011 | |
| 3012 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3013 | struct nfs_fsstat *fsstat) |
| 3014 | { |
| 3015 | struct nfs4_statfs_arg args = { |
| 3016 | .fh = fhandle, |
| 3017 | .bitmask = server->attr_bitmask, |
| 3018 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3019 | struct nfs4_statfs_res res = { |
| 3020 | .fsstat = fsstat, |
| 3021 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | struct rpc_message msg = { |
| 3023 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3024 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3025 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | }; |
| 3027 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3028 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3029 | 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] | 3030 | } |
| 3031 | |
| 3032 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3033 | { |
| 3034 | struct nfs4_exception exception = { }; |
| 3035 | int err; |
| 3036 | do { |
| 3037 | err = nfs4_handle_exception(server, |
| 3038 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3039 | &exception); |
| 3040 | } while (exception.retry); |
| 3041 | return err; |
| 3042 | } |
| 3043 | |
| 3044 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3045 | struct nfs_fsinfo *fsinfo) |
| 3046 | { |
| 3047 | struct nfs4_fsinfo_arg args = { |
| 3048 | .fh = fhandle, |
| 3049 | .bitmask = server->attr_bitmask, |
| 3050 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3051 | struct nfs4_fsinfo_res res = { |
| 3052 | .fsinfo = fsinfo, |
| 3053 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | struct rpc_message msg = { |
| 3055 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3056 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3057 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | }; |
| 3059 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3060 | 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] | 3061 | } |
| 3062 | |
| 3063 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3064 | { |
| 3065 | struct nfs4_exception exception = { }; |
| 3066 | int err; |
| 3067 | |
| 3068 | do { |
| 3069 | err = nfs4_handle_exception(server, |
| 3070 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3071 | &exception); |
| 3072 | } while (exception.retry); |
| 3073 | return err; |
| 3074 | } |
| 3075 | |
| 3076 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3077 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3078 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3080 | } |
| 3081 | |
| 3082 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3083 | struct nfs_pathconf *pathconf) |
| 3084 | { |
| 3085 | struct nfs4_pathconf_arg args = { |
| 3086 | .fh = fhandle, |
| 3087 | .bitmask = server->attr_bitmask, |
| 3088 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3089 | struct nfs4_pathconf_res res = { |
| 3090 | .pathconf = pathconf, |
| 3091 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | struct rpc_message msg = { |
| 3093 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3094 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3095 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | }; |
| 3097 | |
| 3098 | /* None of the pathconf attributes are mandatory to implement */ |
| 3099 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3100 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3101 | return 0; |
| 3102 | } |
| 3103 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3104 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3105 | 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] | 3106 | } |
| 3107 | |
| 3108 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3109 | struct nfs_pathconf *pathconf) |
| 3110 | { |
| 3111 | struct nfs4_exception exception = { }; |
| 3112 | int err; |
| 3113 | |
| 3114 | do { |
| 3115 | err = nfs4_handle_exception(server, |
| 3116 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3117 | &exception); |
| 3118 | } while (exception.retry); |
| 3119 | return err; |
| 3120 | } |
| 3121 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3122 | 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] | 3123 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3124 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3126 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3127 | nfs_restart_rpc(task, server->nfs_client); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3128 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3130 | |
| 3131 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3133 | renew_lease(server, data->timestamp); |
| 3134 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | } |
| 3136 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3137 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3138 | { |
| 3139 | |
| 3140 | dprintk("--> %s\n", __func__); |
| 3141 | |
| 3142 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3143 | return -EAGAIN; |
| 3144 | |
| 3145 | return data->read_done_cb(task, data); |
| 3146 | } |
| 3147 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3148 | 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] | 3149 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3151 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3152 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3155 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3156 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3157 | { |
| 3158 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3159 | put_lseg(data->lseg); |
| 3160 | data->lseg = NULL; |
| 3161 | /* offsets will differ in the dense stripe case */ |
| 3162 | data->args.offset = data->mds_offset; |
| 3163 | data->ds_clp = NULL; |
| 3164 | data->args.fh = NFS_FH(data->inode); |
| 3165 | data->read_done_cb = nfs4_read_done_cb; |
| 3166 | task->tk_ops = data->mds_ops; |
| 3167 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3168 | } |
| 3169 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3170 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3171 | 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] | 3172 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | struct inode *inode = data->inode; |
| 3174 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3175 | 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] | 3176 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3177 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3179 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3181 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3182 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3183 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | } |
| 3185 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3186 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3187 | { |
| 3188 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3189 | return -EAGAIN; |
| 3190 | return data->write_done_cb(task, data); |
| 3191 | } |
| 3192 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3193 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3194 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3195 | { |
| 3196 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3197 | put_lseg(data->lseg); |
| 3198 | data->lseg = NULL; |
| 3199 | data->ds_clp = NULL; |
| 3200 | data->write_done_cb = nfs4_write_done_cb; |
| 3201 | data->args.fh = NFS_FH(data->inode); |
| 3202 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3203 | data->args.offset = data->mds_offset; |
| 3204 | data->res.fattr = &data->fattr; |
| 3205 | task->tk_ops = data->mds_ops; |
| 3206 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3207 | } |
| 3208 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3209 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3210 | 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] | 3211 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3212 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3213 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3214 | if (data->lseg) { |
| 3215 | data->args.bitmask = NULL; |
| 3216 | data->res.fattr = NULL; |
| 3217 | } else |
| 3218 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3219 | if (!data->write_done_cb) |
| 3220 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3221 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | data->timestamp = jiffies; |
| 3223 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3224 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3227 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | struct inode *inode = data->inode; |
| 3230 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3231 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3232 | return -EAGAIN; |
| 3233 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3234 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 3235 | nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3236 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3238 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3239 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3242 | 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] | 3243 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3244 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 3246 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3247 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3248 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3251 | struct nfs4_renewdata { |
| 3252 | struct nfs_client *client; |
| 3253 | unsigned long timestamp; |
| 3254 | }; |
| 3255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | /* |
| 3257 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3258 | * standalone procedure for queueing an asynchronous RENEW. |
| 3259 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3260 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3261 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3262 | struct nfs4_renewdata *data = calldata; |
| 3263 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3264 | |
Alexandros Batsakis | 0851de0 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3265 | if (atomic_read(&clp->cl_count) > 1) |
| 3266 | nfs4_schedule_state_renewal(clp); |
| 3267 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3268 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3269 | } |
| 3270 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3271 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3273 | struct nfs4_renewdata *data = calldata; |
| 3274 | struct nfs_client *clp = data->client; |
| 3275 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | |
| 3277 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3278 | /* Unless we're shutting down, schedule state recovery! */ |
| 3279 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0) |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3280 | nfs4_schedule_lease_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | return; |
| 3282 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3283 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3286 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3287 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3288 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3289 | }; |
| 3290 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3291 | 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] | 3292 | { |
| 3293 | struct rpc_message msg = { |
| 3294 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3295 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3296 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3298 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | |
Alexandros Batsakis | 0851de0 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3300 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3301 | return -EIO; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3302 | data = kmalloc(sizeof(*data), GFP_KERNEL); |
| 3303 | if (data == NULL) |
| 3304 | return -ENOMEM; |
| 3305 | data->client = clp; |
| 3306 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3308 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | } |
| 3310 | |
David Howells | adfa6f9 | 2006-08-22 20:06:08 -0400 | [diff] [blame] | 3311 | int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | { |
| 3313 | struct rpc_message msg = { |
| 3314 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3315 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3316 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | }; |
| 3318 | unsigned long now = jiffies; |
| 3319 | int status; |
| 3320 | |
| 3321 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3322 | if (status < 0) |
| 3323 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3324 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | return 0; |
| 3326 | } |
| 3327 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3328 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3329 | { |
| 3330 | return (server->caps & NFS_CAP_ACLS) |
| 3331 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3332 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3333 | } |
| 3334 | |
| 3335 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3336 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3337 | * the stack. |
| 3338 | */ |
| 3339 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3340 | |
| 3341 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3342 | struct page **pages, unsigned int *pgbase) |
| 3343 | { |
| 3344 | const void *p = buf; |
| 3345 | |
| 3346 | *pgbase = offset_in_page(buf); |
| 3347 | p -= *pgbase; |
| 3348 | while (p < buf + buflen) { |
| 3349 | *(pages++) = virt_to_page(p); |
| 3350 | p += PAGE_CACHE_SIZE; |
| 3351 | } |
| 3352 | } |
| 3353 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3354 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3355 | struct page **pages, unsigned int *pgbase) |
| 3356 | { |
| 3357 | struct page *newpage, **spages; |
| 3358 | int rc = 0; |
| 3359 | size_t len; |
| 3360 | spages = pages; |
| 3361 | |
| 3362 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3363 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3364 | newpage = alloc_page(GFP_KERNEL); |
| 3365 | |
| 3366 | if (newpage == NULL) |
| 3367 | goto unwind; |
| 3368 | memcpy(page_address(newpage), buf, len); |
| 3369 | buf += len; |
| 3370 | buflen -= len; |
| 3371 | *pages++ = newpage; |
| 3372 | rc++; |
| 3373 | } while (buflen != 0); |
| 3374 | |
| 3375 | return rc; |
| 3376 | |
| 3377 | unwind: |
| 3378 | for(; rc > 0; rc--) |
| 3379 | __free_page(spages[rc-1]); |
| 3380 | return -ENOMEM; |
| 3381 | } |
| 3382 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3383 | struct nfs4_cached_acl { |
| 3384 | int cached; |
| 3385 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3386 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3387 | }; |
| 3388 | |
| 3389 | 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] | 3390 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3391 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3392 | |
| 3393 | spin_lock(&inode->i_lock); |
| 3394 | kfree(nfsi->nfs4_acl); |
| 3395 | nfsi->nfs4_acl = acl; |
| 3396 | spin_unlock(&inode->i_lock); |
| 3397 | } |
| 3398 | |
| 3399 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3400 | { |
| 3401 | nfs4_set_cached_acl(inode, NULL); |
| 3402 | } |
| 3403 | |
| 3404 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3405 | { |
| 3406 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3407 | struct nfs4_cached_acl *acl; |
| 3408 | int ret = -ENOENT; |
| 3409 | |
| 3410 | spin_lock(&inode->i_lock); |
| 3411 | acl = nfsi->nfs4_acl; |
| 3412 | if (acl == NULL) |
| 3413 | goto out; |
| 3414 | if (buf == NULL) /* user is just asking for length */ |
| 3415 | goto out_len; |
| 3416 | if (acl->cached == 0) |
| 3417 | goto out; |
| 3418 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3419 | if (acl->len > buflen) |
| 3420 | goto out; |
| 3421 | memcpy(buf, acl->data, acl->len); |
| 3422 | out_len: |
| 3423 | ret = acl->len; |
| 3424 | out: |
| 3425 | spin_unlock(&inode->i_lock); |
| 3426 | return ret; |
| 3427 | } |
| 3428 | |
| 3429 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3430 | { |
| 3431 | struct nfs4_cached_acl *acl; |
| 3432 | |
| 3433 | if (buf && acl_len <= PAGE_SIZE) { |
| 3434 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3435 | if (acl == NULL) |
| 3436 | goto out; |
| 3437 | acl->cached = 1; |
| 3438 | memcpy(acl->data, buf, acl_len); |
| 3439 | } else { |
| 3440 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3441 | if (acl == NULL) |
| 3442 | goto out; |
| 3443 | acl->cached = 0; |
| 3444 | } |
| 3445 | acl->len = acl_len; |
| 3446 | out: |
| 3447 | nfs4_set_cached_acl(inode, acl); |
| 3448 | } |
| 3449 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3450 | 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] | 3451 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3452 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3453 | struct nfs_getaclargs args = { |
| 3454 | .fh = NFS_FH(inode), |
| 3455 | .acl_pages = pages, |
| 3456 | .acl_len = buflen, |
| 3457 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3458 | struct nfs_getaclres res = { |
| 3459 | .acl_len = buflen, |
| 3460 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3461 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3462 | struct rpc_message msg = { |
| 3463 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3464 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3465 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3466 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3467 | struct page *localpage = NULL; |
| 3468 | int ret; |
| 3469 | |
| 3470 | if (buflen < PAGE_SIZE) { |
| 3471 | /* As long as we're doing a round trip to the server anyway, |
| 3472 | * let's be prepared for a page of acl data. */ |
| 3473 | localpage = alloc_page(GFP_KERNEL); |
| 3474 | resp_buf = page_address(localpage); |
| 3475 | if (localpage == NULL) |
| 3476 | return -ENOMEM; |
| 3477 | args.acl_pages[0] = localpage; |
| 3478 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3479 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3480 | } else { |
| 3481 | resp_buf = buf; |
| 3482 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3483 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3484 | 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] | 3485 | if (ret) |
| 3486 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3487 | if (res.acl_len > args.acl_len) |
| 3488 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3489 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3490 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3491 | if (buf) { |
| 3492 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3493 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3494 | goto out_free; |
| 3495 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3496 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3497 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3498 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3499 | out_free: |
| 3500 | if (localpage) |
| 3501 | __free_page(localpage); |
| 3502 | return ret; |
| 3503 | } |
| 3504 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3505 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3506 | { |
| 3507 | struct nfs4_exception exception = { }; |
| 3508 | ssize_t ret; |
| 3509 | do { |
| 3510 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3511 | if (ret >= 0) |
| 3512 | break; |
| 3513 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3514 | } while (exception.retry); |
| 3515 | return ret; |
| 3516 | } |
| 3517 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3518 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3519 | { |
| 3520 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3521 | int ret; |
| 3522 | |
| 3523 | if (!nfs4_server_supports_acls(server)) |
| 3524 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3525 | ret = nfs_revalidate_inode(server, inode); |
| 3526 | if (ret < 0) |
| 3527 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3528 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3529 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3530 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3531 | if (ret != -ENOENT) |
| 3532 | return ret; |
| 3533 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3534 | } |
| 3535 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3536 | 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] | 3537 | { |
| 3538 | struct nfs_server *server = NFS_SERVER(inode); |
| 3539 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3540 | struct nfs_setaclargs arg = { |
| 3541 | .fh = NFS_FH(inode), |
| 3542 | .acl_pages = pages, |
| 3543 | .acl_len = buflen, |
| 3544 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3545 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3546 | struct rpc_message msg = { |
| 3547 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3548 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3549 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3550 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3551 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3552 | |
| 3553 | if (!nfs4_server_supports_acls(server)) |
| 3554 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3555 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3556 | if (i < 0) |
| 3557 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3558 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3559 | 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] | 3560 | |
| 3561 | /* |
| 3562 | * Free each page after tx, so the only ref left is |
| 3563 | * held by the network stack |
| 3564 | */ |
| 3565 | for (; i > 0; i--) |
| 3566 | put_page(pages[i-1]); |
| 3567 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3568 | /* |
| 3569 | * Acl update can result in inode attribute update. |
| 3570 | * so mark the attribute cache invalid. |
| 3571 | */ |
| 3572 | spin_lock(&inode->i_lock); |
| 3573 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3574 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3575 | nfs_access_zap_cache(inode); |
| 3576 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3577 | return ret; |
| 3578 | } |
| 3579 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3580 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3581 | { |
| 3582 | struct nfs4_exception exception = { }; |
| 3583 | int err; |
| 3584 | do { |
| 3585 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3586 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3587 | &exception); |
| 3588 | } while (exception.retry); |
| 3589 | return err; |
| 3590 | } |
| 3591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3593 | 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] | 3594 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3595 | struct nfs_client *clp = server->nfs_client; |
| 3596 | |
| 3597 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | return 0; |
| 3599 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3600 | case -NFS4ERR_ADMIN_REVOKED: |
| 3601 | case -NFS4ERR_BAD_STATEID: |
| 3602 | case -NFS4ERR_OPENMODE: |
| 3603 | if (state == NULL) |
| 3604 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3605 | nfs4_schedule_stateid_recovery(server, state); |
| 3606 | goto wait_on_recovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3608 | case -NFS4ERR_STALE_CLIENTID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3610 | nfs4_schedule_lease_recovery(clp); |
| 3611 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3612 | #if defined(CONFIG_NFS_V4_1) |
| 3613 | case -NFS4ERR_BADSESSION: |
| 3614 | case -NFS4ERR_BADSLOT: |
| 3615 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3616 | case -NFS4ERR_DEADSESSION: |
| 3617 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3618 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3619 | case -NFS4ERR_SEQ_MISORDERED: |
| 3620 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3621 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3622 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3623 | task->tk_status = 0; |
| 3624 | return -EAGAIN; |
| 3625 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3627 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3628 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3629 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3631 | task->tk_status = 0; |
| 3632 | return -EAGAIN; |
| 3633 | case -NFS4ERR_OLD_STATEID: |
| 3634 | task->tk_status = 0; |
| 3635 | return -EAGAIN; |
| 3636 | } |
| 3637 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3638 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3639 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3640 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3641 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3642 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3643 | task->tk_status = 0; |
| 3644 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3647 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3648 | unsigned short port, struct rpc_cred *cred, |
| 3649 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | { |
| 3651 | nfs4_verifier sc_verifier; |
| 3652 | struct nfs4_setclientid setclientid = { |
| 3653 | .sc_verifier = &sc_verifier, |
| 3654 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3655 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | }; |
| 3657 | struct rpc_message msg = { |
| 3658 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3659 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3660 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3661 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3663 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3664 | int loop = 0; |
| 3665 | int status; |
| 3666 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3667 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3669 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3670 | |
| 3671 | for(;;) { |
| 3672 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3673 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3674 | clp->cl_ipaddr, |
| 3675 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3676 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3677 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3678 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3679 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3680 | clp->cl_id_uniquifier); |
| 3681 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3682 | sizeof(setclientid.sc_netid), |
| 3683 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3684 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3686 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3688 | |
| 3689 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3690 | if (status != -NFS4ERR_CLID_INUSE) |
| 3691 | break; |
| 3692 | if (signalled()) |
| 3693 | break; |
| 3694 | if (loop++ & 1) |
J. Bruce Fields | 611c96c | 2010-12-13 19:05:46 -0500 | [diff] [blame] | 3695 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | else |
| 3697 | if (++clp->cl_id_uniquifier == 0) |
| 3698 | break; |
| 3699 | } |
| 3700 | return status; |
| 3701 | } |
| 3702 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3703 | static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3704 | struct nfs4_setclientid_res *arg, |
| 3705 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3706 | { |
| 3707 | struct nfs_fsinfo fsinfo; |
| 3708 | struct rpc_message msg = { |
| 3709 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3710 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3712 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | }; |
| 3714 | unsigned long now; |
| 3715 | int status; |
| 3716 | |
| 3717 | now = jiffies; |
| 3718 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3719 | if (status == 0) { |
| 3720 | spin_lock(&clp->cl_lock); |
| 3721 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3722 | clp->cl_last_renewal = now; |
| 3723 | spin_unlock(&clp->cl_lock); |
| 3724 | } |
| 3725 | return status; |
| 3726 | } |
| 3727 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3728 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
| 3729 | struct nfs4_setclientid_res *arg, |
| 3730 | struct rpc_cred *cred) |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3731 | { |
Benny Halevy | 77e0367 | 2008-06-24 20:25:57 +0300 | [diff] [blame] | 3732 | long timeout = 0; |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3733 | int err; |
| 3734 | do { |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3735 | err = _nfs4_proc_setclientid_confirm(clp, arg, cred); |
Trond Myklebust | 51581f3 | 2006-03-20 13:44:47 -0500 | [diff] [blame] | 3736 | switch (err) { |
| 3737 | case 0: |
| 3738 | return err; |
| 3739 | case -NFS4ERR_RESOURCE: |
| 3740 | /* The IBM lawyers misread another document! */ |
| 3741 | case -NFS4ERR_DELAY: |
| 3742 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 3743 | } |
| 3744 | } while (err == 0); |
| 3745 | return err; |
| 3746 | } |
| 3747 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3748 | struct nfs4_delegreturndata { |
| 3749 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3750 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3751 | struct nfs_fh fh; |
| 3752 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3753 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3754 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3755 | int rpc_status; |
| 3756 | }; |
| 3757 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3758 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3759 | { |
| 3760 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3761 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3762 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3763 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3764 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3765 | switch (task->tk_status) { |
| 3766 | case -NFS4ERR_STALE_STATEID: |
| 3767 | case -NFS4ERR_EXPIRED: |
| 3768 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3769 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3770 | break; |
| 3771 | default: |
| 3772 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3773 | -EAGAIN) { |
| 3774 | nfs_restart_rpc(task, data->res.server->nfs_client); |
| 3775 | return; |
| 3776 | } |
| 3777 | } |
| 3778 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3779 | } |
| 3780 | |
| 3781 | static void nfs4_delegreturn_release(void *calldata) |
| 3782 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3783 | kfree(calldata); |
| 3784 | } |
| 3785 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3786 | #if defined(CONFIG_NFS_V4_1) |
| 3787 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3788 | { |
| 3789 | struct nfs4_delegreturndata *d_data; |
| 3790 | |
| 3791 | d_data = (struct nfs4_delegreturndata *)data; |
| 3792 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3793 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3794 | &d_data->args.seq_args, |
| 3795 | &d_data->res.seq_res, 1, task)) |
| 3796 | return; |
| 3797 | rpc_call_start(task); |
| 3798 | } |
| 3799 | #endif /* CONFIG_NFS_V4_1 */ |
| 3800 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3801 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3802 | #if defined(CONFIG_NFS_V4_1) |
| 3803 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3804 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3805 | .rpc_call_done = nfs4_delegreturn_done, |
| 3806 | .rpc_release = nfs4_delegreturn_release, |
| 3807 | }; |
| 3808 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3809 | 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] | 3810 | { |
| 3811 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3812 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3813 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3814 | struct rpc_message msg = { |
| 3815 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3816 | .rpc_cred = cred, |
| 3817 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3818 | struct rpc_task_setup task_setup_data = { |
| 3819 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3820 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3821 | .callback_ops = &nfs4_delegreturn_ops, |
| 3822 | .flags = RPC_TASK_ASYNC, |
| 3823 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3824 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3825 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3826 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3827 | if (data == NULL) |
| 3828 | return -ENOMEM; |
| 3829 | data->args.fhandle = &data->fh; |
| 3830 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3831 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3832 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3833 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3834 | data->res.fattr = &data->fattr; |
| 3835 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3836 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3837 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3838 | data->rpc_status = 0; |
| 3839 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3840 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3841 | msg.rpc_argp = &data->args; |
| 3842 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3843 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3844 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3845 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3846 | if (!issync) |
| 3847 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3848 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3849 | if (status != 0) |
| 3850 | goto out; |
| 3851 | status = data->rpc_status; |
| 3852 | if (status != 0) |
| 3853 | goto out; |
| 3854 | nfs_refresh_inode(inode, &data->fattr); |
| 3855 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3856 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3857 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | } |
| 3859 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3860 | 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] | 3861 | { |
| 3862 | struct nfs_server *server = NFS_SERVER(inode); |
| 3863 | struct nfs4_exception exception = { }; |
| 3864 | int err; |
| 3865 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3866 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | switch (err) { |
| 3868 | case -NFS4ERR_STALE_STATEID: |
| 3869 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | case 0: |
| 3871 | return 0; |
| 3872 | } |
| 3873 | err = nfs4_handle_exception(server, err, &exception); |
| 3874 | } while (exception.retry); |
| 3875 | return err; |
| 3876 | } |
| 3877 | |
| 3878 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3879 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3880 | |
| 3881 | /* |
| 3882 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3883 | */ |
| 3884 | static unsigned long |
| 3885 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3886 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3887 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | timeout <<= 1; |
| 3889 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3890 | return NFS4_LOCK_MAXTIMEOUT; |
| 3891 | return timeout; |
| 3892 | } |
| 3893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3894 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3895 | { |
| 3896 | struct inode *inode = state->inode; |
| 3897 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3898 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3899 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3901 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3903 | struct nfs_lockt_res res = { |
| 3904 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | }; |
| 3906 | struct rpc_message msg = { |
| 3907 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3908 | .rpc_argp = &arg, |
| 3909 | .rpc_resp = &res, |
| 3910 | .rpc_cred = state->owner->so_cred, |
| 3911 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | struct nfs4_lock_state *lsp; |
| 3913 | int status; |
| 3914 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3915 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3916 | status = nfs4_set_lock_state(state, request); |
| 3917 | if (status != 0) |
| 3918 | goto out; |
| 3919 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3920 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3921 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3922 | 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] | 3923 | switch (status) { |
| 3924 | case 0: |
| 3925 | request->fl_type = F_UNLCK; |
| 3926 | break; |
| 3927 | case -NFS4ERR_DENIED: |
| 3928 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3930 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3931 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | return status; |
| 3933 | } |
| 3934 | |
| 3935 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3936 | { |
| 3937 | struct nfs4_exception exception = { }; |
| 3938 | int err; |
| 3939 | |
| 3940 | do { |
| 3941 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 3942 | _nfs4_proc_getlk(state, cmd, request), |
| 3943 | &exception); |
| 3944 | } while (exception.retry); |
| 3945 | return err; |
| 3946 | } |
| 3947 | |
| 3948 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 3949 | { |
| 3950 | int res = 0; |
| 3951 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 3952 | case FL_POSIX: |
| 3953 | res = posix_lock_file_wait(file, fl); |
| 3954 | break; |
| 3955 | case FL_FLOCK: |
| 3956 | res = flock_lock_file_wait(file, fl); |
| 3957 | break; |
| 3958 | default: |
| 3959 | BUG(); |
| 3960 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | return res; |
| 3962 | } |
| 3963 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3964 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3965 | struct nfs_locku_args arg; |
| 3966 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3967 | struct nfs4_lock_state *lsp; |
| 3968 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3969 | struct file_lock fl; |
| 3970 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3971 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 3972 | }; |
| 3973 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3974 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 3975 | struct nfs_open_context *ctx, |
| 3976 | struct nfs4_lock_state *lsp, |
| 3977 | struct nfs_seqid *seqid) |
| 3978 | { |
| 3979 | struct nfs4_unlockdata *p; |
| 3980 | struct inode *inode = lsp->ls_state->inode; |
| 3981 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3982 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3983 | if (p == NULL) |
| 3984 | return NULL; |
| 3985 | p->arg.fh = NFS_FH(inode); |
| 3986 | p->arg.fl = &p->fl; |
| 3987 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 3988 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3989 | p->arg.stateid = &lsp->ls_stateid; |
| 3990 | p->lsp = lsp; |
| 3991 | atomic_inc(&lsp->ls_count); |
| 3992 | /* Ensure we don't close file until we're done freeing locks! */ |
| 3993 | p->ctx = get_nfs_open_context(ctx); |
| 3994 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 3995 | p->server = NFS_SERVER(inode); |
| 3996 | return p; |
| 3997 | } |
| 3998 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 3999 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4000 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4001 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4002 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4003 | nfs4_put_lock_state(calldata->lsp); |
| 4004 | put_nfs_open_context(calldata->ctx); |
| 4005 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4008 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4009 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4010 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4011 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4012 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4013 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4014 | switch (task->tk_status) { |
| 4015 | case 0: |
| 4016 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4017 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4018 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4019 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4020 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4021 | case -NFS4ERR_BAD_STATEID: |
| 4022 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4023 | case -NFS4ERR_STALE_STATEID: |
| 4024 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4025 | break; |
| 4026 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4027 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4028 | nfs_restart_rpc(task, |
Trond Myklebust | d61e612 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 4029 | calldata->server->nfs_client); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4030 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4033 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4034 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4035 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4037 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4038 | return; |
| 4039 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4040 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4041 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4042 | return; |
| 4043 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4044 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4045 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4046 | &calldata->arg.seq_args, |
| 4047 | &calldata->res.seq_res, 1, task)) |
| 4048 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4049 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | } |
| 4051 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4052 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4053 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4054 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4055 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4056 | }; |
| 4057 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4058 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4059 | struct nfs_open_context *ctx, |
| 4060 | struct nfs4_lock_state *lsp, |
| 4061 | struct nfs_seqid *seqid) |
| 4062 | { |
| 4063 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4064 | struct rpc_message msg = { |
| 4065 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4066 | .rpc_cred = ctx->cred, |
| 4067 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4068 | struct rpc_task_setup task_setup_data = { |
| 4069 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4070 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4071 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4072 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4073 | .flags = RPC_TASK_ASYNC, |
| 4074 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4075 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4076 | /* Ensure this is an unlock - when canceling a lock, the |
| 4077 | * canceled lock is passed in, and it won't be an unlock. |
| 4078 | */ |
| 4079 | fl->fl_type = F_UNLCK; |
| 4080 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4081 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4082 | if (data == NULL) { |
| 4083 | nfs_free_seqid(seqid); |
| 4084 | return ERR_PTR(-ENOMEM); |
| 4085 | } |
| 4086 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4087 | msg.rpc_argp = &data->arg; |
| 4088 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4089 | task_setup_data.callback_data = data; |
| 4090 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4091 | } |
| 4092 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4094 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4095 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4096 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4097 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4098 | struct rpc_task *task; |
| 4099 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4100 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4102 | status = nfs4_set_lock_state(state, request); |
| 4103 | /* Unlock _before_ we do the RPC call */ |
| 4104 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4105 | down_read(&nfsi->rwsem); |
| 4106 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4107 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4108 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4109 | } |
| 4110 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4111 | if (status != 0) |
| 4112 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4113 | /* Is this a delegated lock? */ |
| 4114 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4115 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4116 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4117 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4118 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4119 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4120 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4121 | 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] | 4122 | status = PTR_ERR(task); |
| 4123 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4124 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4125 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4126 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4127 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4128 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4129 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | } |
| 4131 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4132 | struct nfs4_lockdata { |
| 4133 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4134 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4135 | struct nfs4_lock_state *lsp; |
| 4136 | struct nfs_open_context *ctx; |
| 4137 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4138 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4139 | int rpc_status; |
| 4140 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4141 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4142 | }; |
| 4143 | |
| 4144 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4145 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4146 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4147 | { |
| 4148 | struct nfs4_lockdata *p; |
| 4149 | struct inode *inode = lsp->ls_state->inode; |
| 4150 | struct nfs_server *server = NFS_SERVER(inode); |
| 4151 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4152 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4153 | if (p == NULL) |
| 4154 | return NULL; |
| 4155 | |
| 4156 | p->arg.fh = NFS_FH(inode); |
| 4157 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4158 | 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] | 4159 | if (p->arg.open_seqid == NULL) |
| 4160 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4161 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4162 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4163 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4164 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4165 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4166 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4167 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4168 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4169 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4170 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4171 | atomic_inc(&lsp->ls_count); |
| 4172 | p->ctx = get_nfs_open_context(ctx); |
| 4173 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4174 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4175 | out_free_seqid: |
| 4176 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4177 | out_free: |
| 4178 | kfree(p); |
| 4179 | return NULL; |
| 4180 | } |
| 4181 | |
| 4182 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4183 | { |
| 4184 | struct nfs4_lockdata *data = calldata; |
| 4185 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4186 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4187 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4188 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4189 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4190 | /* Do we need to do an open_to_lock_owner? */ |
| 4191 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4192 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4193 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4194 | data->arg.open_stateid = &state->stateid; |
| 4195 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4196 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4197 | } else |
| 4198 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4199 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4200 | if (nfs4_setup_sequence(data->server, |
| 4201 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4202 | &data->res.seq_res, 1, task)) |
| 4203 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4204 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4205 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4206 | } |
| 4207 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4208 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4209 | { |
| 4210 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4211 | nfs4_lock_prepare(task, calldata); |
| 4212 | } |
| 4213 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4214 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4215 | { |
| 4216 | struct nfs4_lockdata *data = calldata; |
| 4217 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4218 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4219 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4220 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4221 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4222 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4223 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4224 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4225 | if (data->rpc_status == 0) |
| 4226 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4227 | else |
| 4228 | goto out; |
| 4229 | } |
| 4230 | if (data->rpc_status == 0) { |
| 4231 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4232 | sizeof(data->lsp->ls_stateid.data)); |
| 4233 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Trond Myklebust | 88be9f9 | 2007-06-05 10:42:27 -0400 | [diff] [blame] | 4234 | renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4235 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4236 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4237 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4238 | } |
| 4239 | |
| 4240 | static void nfs4_lock_release(void *calldata) |
| 4241 | { |
| 4242 | struct nfs4_lockdata *data = calldata; |
| 4243 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4244 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4245 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4246 | if (data->cancelled != 0) { |
| 4247 | struct rpc_task *task; |
| 4248 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4249 | data->arg.lock_seqid); |
| 4250 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4251 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4252 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4253 | } else |
| 4254 | nfs_free_seqid(data->arg.lock_seqid); |
| 4255 | nfs4_put_lock_state(data->lsp); |
| 4256 | put_nfs_open_context(data->ctx); |
| 4257 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4258 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4262 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4263 | .rpc_call_done = nfs4_lock_done, |
| 4264 | .rpc_release = nfs4_lock_release, |
| 4265 | }; |
| 4266 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4267 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4268 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4269 | .rpc_call_done = nfs4_lock_done, |
| 4270 | .rpc_release = nfs4_lock_release, |
| 4271 | }; |
| 4272 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4273 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4274 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4275 | switch (error) { |
| 4276 | case -NFS4ERR_ADMIN_REVOKED: |
| 4277 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4278 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4279 | if (new_lock_owner != 0 || |
| 4280 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4281 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4282 | break; |
| 4283 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4284 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4285 | case -NFS4ERR_EXPIRED: |
| 4286 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4287 | }; |
| 4288 | } |
| 4289 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4290 | 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] | 4291 | { |
| 4292 | struct nfs4_lockdata *data; |
| 4293 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4294 | struct rpc_message msg = { |
| 4295 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4296 | .rpc_cred = state->owner->so_cred, |
| 4297 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4298 | struct rpc_task_setup task_setup_data = { |
| 4299 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4300 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4301 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4302 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4303 | .flags = RPC_TASK_ASYNC, |
| 4304 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4305 | int ret; |
| 4306 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4307 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4308 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4309 | fl->fl_u.nfs4_fl.owner, |
| 4310 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4311 | if (data == NULL) |
| 4312 | return -ENOMEM; |
| 4313 | if (IS_SETLKW(cmd)) |
| 4314 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4315 | if (recovery_type > NFS_LOCK_NEW) { |
| 4316 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4317 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4318 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4319 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4320 | msg.rpc_argp = &data->arg; |
| 4321 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4322 | task_setup_data.callback_data = data; |
| 4323 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4324 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4325 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4326 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4327 | if (ret == 0) { |
| 4328 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4329 | if (ret) |
| 4330 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4331 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4332 | } else |
| 4333 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4334 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4335 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4336 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4340 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4341 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4342 | struct nfs4_exception exception = { }; |
| 4343 | int err; |
| 4344 | |
| 4345 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4346 | /* Cache the lock if possible... */ |
| 4347 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4348 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4349 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4350 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4351 | break; |
| 4352 | nfs4_handle_exception(server, err, &exception); |
| 4353 | } while (exception.retry); |
| 4354 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4358 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4359 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4360 | struct nfs4_exception exception = { }; |
| 4361 | int err; |
| 4362 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4363 | err = nfs4_set_lock_state(state, request); |
| 4364 | if (err != 0) |
| 4365 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4366 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4367 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4368 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4369 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4370 | switch (err) { |
| 4371 | default: |
| 4372 | goto out; |
| 4373 | case -NFS4ERR_GRACE: |
| 4374 | case -NFS4ERR_DELAY: |
| 4375 | nfs4_handle_exception(server, err, &exception); |
| 4376 | err = 0; |
| 4377 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4378 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4379 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4380 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4384 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4385 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4386 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4387 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4389 | if ((fl_flags & FL_POSIX) && |
| 4390 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4391 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4392 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4393 | status = nfs4_set_lock_state(state, request); |
| 4394 | if (status != 0) |
| 4395 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4396 | request->fl_flags |= FL_ACCESS; |
| 4397 | status = do_vfs_lock(request->fl_file, request); |
| 4398 | if (status < 0) |
| 4399 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4400 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4401 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4402 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4403 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4404 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4405 | status = do_vfs_lock(request->fl_file, request); |
| 4406 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4407 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4408 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4409 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4410 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4411 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4412 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4413 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4414 | 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] | 4415 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4416 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4417 | out: |
| 4418 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | return status; |
| 4420 | } |
| 4421 | |
| 4422 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4423 | { |
| 4424 | struct nfs4_exception exception = { }; |
| 4425 | int err; |
| 4426 | |
| 4427 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4428 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4429 | if (err == -NFS4ERR_DENIED) |
| 4430 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4432 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | } while (exception.retry); |
| 4434 | return err; |
| 4435 | } |
| 4436 | |
| 4437 | static int |
| 4438 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4439 | { |
| 4440 | struct nfs_open_context *ctx; |
| 4441 | struct nfs4_state *state; |
| 4442 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4443 | int status; |
| 4444 | |
| 4445 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4446 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4447 | state = ctx->state; |
| 4448 | |
| 4449 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4450 | return -EINVAL; |
| 4451 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4452 | if (IS_GETLK(cmd)) { |
| 4453 | if (state != NULL) |
| 4454 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4455 | return 0; |
| 4456 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | |
| 4458 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4459 | return -EINVAL; |
| 4460 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4461 | if (request->fl_type == F_UNLCK) { |
| 4462 | if (state != NULL) |
| 4463 | return nfs4_proc_unlck(state, cmd, request); |
| 4464 | return 0; |
| 4465 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4467 | if (state == NULL) |
| 4468 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4469 | do { |
| 4470 | status = nfs4_proc_setlk(state, cmd, request); |
| 4471 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4472 | break; |
| 4473 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4474 | status = -ERESTARTSYS; |
| 4475 | if (signalled()) |
| 4476 | break; |
| 4477 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | return status; |
| 4479 | } |
| 4480 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4481 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4482 | { |
| 4483 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4484 | struct nfs4_exception exception = { }; |
| 4485 | int err; |
| 4486 | |
| 4487 | err = nfs4_set_lock_state(state, fl); |
| 4488 | if (err != 0) |
| 4489 | goto out; |
| 4490 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4491 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4492 | switch (err) { |
| 4493 | default: |
| 4494 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4495 | __func__, err); |
| 4496 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4497 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4498 | goto out; |
| 4499 | case -NFS4ERR_EXPIRED: |
| 4500 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4501 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4502 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4503 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4504 | case -NFS4ERR_BADSESSION: |
| 4505 | case -NFS4ERR_BADSLOT: |
| 4506 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4507 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4508 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4509 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4510 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4511 | case -ERESTARTSYS: |
| 4512 | /* |
| 4513 | * The show must go on: exit, but mark the |
| 4514 | * stateid as needing recovery. |
| 4515 | */ |
| 4516 | case -NFS4ERR_ADMIN_REVOKED: |
| 4517 | case -NFS4ERR_BAD_STATEID: |
| 4518 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4519 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4520 | err = 0; |
| 4521 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4522 | case -EKEYEXPIRED: |
| 4523 | /* |
| 4524 | * User RPCSEC_GSS context has expired. |
| 4525 | * We cannot recover this stateid now, so |
| 4526 | * skip it and allow recovery thread to |
| 4527 | * proceed. |
| 4528 | */ |
| 4529 | err = 0; |
| 4530 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4531 | case -ENOMEM: |
| 4532 | case -NFS4ERR_DENIED: |
| 4533 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4534 | err = 0; |
| 4535 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4536 | case -NFS4ERR_DELAY: |
| 4537 | break; |
| 4538 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4539 | err = nfs4_handle_exception(server, err, &exception); |
| 4540 | } while (exception.retry); |
| 4541 | out: |
| 4542 | return err; |
| 4543 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4544 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4545 | static void nfs4_release_lockowner_release(void *calldata) |
| 4546 | { |
| 4547 | kfree(calldata); |
| 4548 | } |
| 4549 | |
| 4550 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4551 | .rpc_release = nfs4_release_lockowner_release, |
| 4552 | }; |
| 4553 | |
| 4554 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4555 | { |
| 4556 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4557 | struct nfs_release_lockowner_args *args; |
| 4558 | struct rpc_message msg = { |
| 4559 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4560 | }; |
| 4561 | |
| 4562 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4563 | return; |
| 4564 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4565 | if (!args) |
| 4566 | return; |
| 4567 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4568 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4569 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4570 | msg.rpc_argp = args; |
| 4571 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4572 | } |
| 4573 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4574 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4575 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4576 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4577 | const void *buf, size_t buflen, |
| 4578 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4579 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4580 | if (strcmp(key, "") != 0) |
| 4581 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4582 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4583 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4584 | } |
| 4585 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4586 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4587 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4588 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4589 | if (strcmp(key, "") != 0) |
| 4590 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4591 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4592 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4593 | } |
| 4594 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4595 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4596 | size_t list_len, const char *name, |
| 4597 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4598 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4599 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4600 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4601 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4602 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4603 | |
| 4604 | if (list && len <= list_len) |
| 4605 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4606 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4607 | } |
| 4608 | |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4609 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4610 | { |
| 4611 | if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) && |
| 4612 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4613 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
| 4614 | return; |
| 4615 | |
| 4616 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4617 | NFS_ATTR_FATTR_NLINK; |
| 4618 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4619 | fattr->nlink = 2; |
| 4620 | } |
| 4621 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4622 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4623 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4624 | { |
| 4625 | struct nfs_server *server = NFS_SERVER(dir); |
| 4626 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4627 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
| 4628 | [1] = FATTR4_WORD1_MOUNTED_ON_FILEID, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4629 | }; |
| 4630 | struct nfs4_fs_locations_arg args = { |
| 4631 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4632 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4633 | .page = page, |
| 4634 | .bitmask = bitmask, |
| 4635 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4636 | struct nfs4_fs_locations_res res = { |
| 4637 | .fs_locations = fs_locations, |
| 4638 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4639 | struct rpc_message msg = { |
| 4640 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4641 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4642 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4643 | }; |
| 4644 | int status; |
| 4645 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4646 | dprintk("%s: start\n", __func__); |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4647 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4648 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4649 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4650 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4651 | nfs_fixup_referral_attributes(&fs_locations->fattr); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4652 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4653 | return status; |
| 4654 | } |
| 4655 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4656 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4657 | { |
| 4658 | int status; |
| 4659 | struct nfs4_secinfo_arg args = { |
| 4660 | .dir_fh = NFS_FH(dir), |
| 4661 | .name = name, |
| 4662 | }; |
| 4663 | struct nfs4_secinfo_res res = { |
| 4664 | .flavors = flavors, |
| 4665 | }; |
| 4666 | struct rpc_message msg = { |
| 4667 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4668 | .rpc_argp = &args, |
| 4669 | .rpc_resp = &res, |
| 4670 | }; |
| 4671 | |
| 4672 | dprintk("NFS call secinfo %s\n", name->name); |
| 4673 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4674 | dprintk("NFS reply secinfo: %d\n", status); |
| 4675 | return status; |
| 4676 | } |
| 4677 | |
| 4678 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4679 | { |
| 4680 | struct nfs4_exception exception = { }; |
| 4681 | int err; |
| 4682 | do { |
| 4683 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4684 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4685 | &exception); |
| 4686 | } while (exception.retry); |
| 4687 | return err; |
| 4688 | } |
| 4689 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4690 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4691 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4692 | * Check the exchange flags returned by the server for invalid flags, having |
| 4693 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4694 | * DS flags set. |
| 4695 | */ |
| 4696 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4697 | { |
| 4698 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4699 | goto out_inval; |
| 4700 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4701 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4702 | goto out_inval; |
| 4703 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4704 | goto out_inval; |
| 4705 | return NFS_OK; |
| 4706 | out_inval: |
| 4707 | return -NFS4ERR_INVAL; |
| 4708 | } |
| 4709 | |
| 4710 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4711 | * nfs4_proc_exchange_id() |
| 4712 | * |
| 4713 | * Since the clientid has expired, all compounds using sessions |
| 4714 | * associated with the stale clientid will be returning |
| 4715 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4716 | * be in some phase of session reset. |
| 4717 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4718 | 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] | 4719 | { |
| 4720 | nfs4_verifier verifier; |
| 4721 | struct nfs41_exchange_id_args args = { |
| 4722 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4723 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4724 | }; |
| 4725 | struct nfs41_exchange_id_res res = { |
| 4726 | .client = clp, |
| 4727 | }; |
| 4728 | int status; |
| 4729 | struct rpc_message msg = { |
| 4730 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4731 | .rpc_argp = &args, |
| 4732 | .rpc_resp = &res, |
| 4733 | .rpc_cred = cred, |
| 4734 | }; |
| 4735 | __be32 *p; |
| 4736 | |
| 4737 | dprintk("--> %s\n", __func__); |
| 4738 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4739 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4740 | p = (u32 *)verifier.data; |
| 4741 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4742 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4743 | args.verifier = &verifier; |
| 4744 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4745 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4746 | "%s/%s.%s/%u", |
| 4747 | clp->cl_ipaddr, |
| 4748 | init_utsname()->nodename, |
| 4749 | init_utsname()->domainname, |
| 4750 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4751 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4752 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 4753 | if (!status) |
| 4754 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4755 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4756 | return status; |
| 4757 | } |
| 4758 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4759 | struct nfs4_get_lease_time_data { |
| 4760 | struct nfs4_get_lease_time_args *args; |
| 4761 | struct nfs4_get_lease_time_res *res; |
| 4762 | struct nfs_client *clp; |
| 4763 | }; |
| 4764 | |
| 4765 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4766 | void *calldata) |
| 4767 | { |
| 4768 | int ret; |
| 4769 | struct nfs4_get_lease_time_data *data = |
| 4770 | (struct nfs4_get_lease_time_data *)calldata; |
| 4771 | |
| 4772 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4773 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4774 | /* just setup sequence, do not trigger session recovery |
| 4775 | since we're invoked within one */ |
| 4776 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4777 | &data->args->la_seq_args, |
| 4778 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4779 | |
| 4780 | BUG_ON(ret == -EAGAIN); |
| 4781 | rpc_call_start(task); |
| 4782 | dprintk("<-- %s\n", __func__); |
| 4783 | } |
| 4784 | |
| 4785 | /* |
| 4786 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4787 | * from sequence operation or clientid errors. |
| 4788 | */ |
| 4789 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4790 | { |
| 4791 | struct nfs4_get_lease_time_data *data = |
| 4792 | (struct nfs4_get_lease_time_data *)calldata; |
| 4793 | |
| 4794 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4795 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4796 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4797 | switch (task->tk_status) { |
| 4798 | case -NFS4ERR_DELAY: |
| 4799 | case -NFS4ERR_GRACE: |
| 4800 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4801 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4802 | task->tk_status = 0; |
Trond Myklebust | 0110ee1 | 2009-12-07 09:00:24 -0500 | [diff] [blame] | 4803 | nfs_restart_rpc(task, data->clp); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4804 | return; |
| 4805 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4806 | dprintk("<-- %s\n", __func__); |
| 4807 | } |
| 4808 | |
| 4809 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4810 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4811 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4812 | }; |
| 4813 | |
| 4814 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4815 | { |
| 4816 | struct rpc_task *task; |
| 4817 | struct nfs4_get_lease_time_args args; |
| 4818 | struct nfs4_get_lease_time_res res = { |
| 4819 | .lr_fsinfo = fsinfo, |
| 4820 | }; |
| 4821 | struct nfs4_get_lease_time_data data = { |
| 4822 | .args = &args, |
| 4823 | .res = &res, |
| 4824 | .clp = clp, |
| 4825 | }; |
| 4826 | struct rpc_message msg = { |
| 4827 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4828 | .rpc_argp = &args, |
| 4829 | .rpc_resp = &res, |
| 4830 | }; |
| 4831 | struct rpc_task_setup task_setup = { |
| 4832 | .rpc_client = clp->cl_rpcclient, |
| 4833 | .rpc_message = &msg, |
| 4834 | .callback_ops = &nfs4_get_lease_time_ops, |
| 4835 | .callback_data = &data |
| 4836 | }; |
| 4837 | int status; |
| 4838 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4839 | dprintk("--> %s\n", __func__); |
| 4840 | task = rpc_run_task(&task_setup); |
| 4841 | |
| 4842 | if (IS_ERR(task)) |
| 4843 | status = PTR_ERR(task); |
| 4844 | else { |
| 4845 | status = task->tk_status; |
| 4846 | rpc_put_task(task); |
| 4847 | } |
| 4848 | dprintk("<-- %s return %d\n", __func__, status); |
| 4849 | |
| 4850 | return status; |
| 4851 | } |
| 4852 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4853 | /* |
| 4854 | * Reset a slot table |
| 4855 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4856 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4857 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4858 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4859 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4860 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4861 | int ret = 0; |
| 4862 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4863 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4864 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4865 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4866 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4867 | if (max_reqs != tbl->max_slots) { |
| 4868 | ret = -ENOMEM; |
| 4869 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4870 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4871 | if (!new) |
| 4872 | goto out; |
| 4873 | ret = 0; |
| 4874 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4875 | } |
| 4876 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4877 | if (new) { |
| 4878 | tbl->slots = new; |
| 4879 | tbl->max_slots = max_reqs; |
| 4880 | } |
| 4881 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4882 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4883 | spin_unlock(&tbl->slot_tbl_lock); |
| 4884 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4885 | tbl, tbl->slots, tbl->max_slots); |
| 4886 | out: |
| 4887 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4888 | return ret; |
| 4889 | } |
| 4890 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4891 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4892 | * Reset the forechannel and backchannel slot tables |
| 4893 | */ |
| 4894 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 4895 | { |
| 4896 | int status; |
| 4897 | |
| 4898 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4899 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4900 | if (status) |
| 4901 | return status; |
| 4902 | |
| 4903 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4904 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4905 | return status; |
| 4906 | } |
| 4907 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4908 | /* Destroy the slot table */ |
| 4909 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 4910 | { |
| 4911 | if (session->fc_slot_table.slots != NULL) { |
| 4912 | kfree(session->fc_slot_table.slots); |
| 4913 | session->fc_slot_table.slots = NULL; |
| 4914 | } |
| 4915 | if (session->bc_slot_table.slots != NULL) { |
| 4916 | kfree(session->bc_slot_table.slots); |
| 4917 | session->bc_slot_table.slots = NULL; |
| 4918 | } |
| 4919 | return; |
| 4920 | } |
| 4921 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4922 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4923 | * Initialize slot table |
| 4924 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4925 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 4926 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4927 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4928 | struct nfs4_slot *slot; |
| 4929 | int ret = -ENOMEM; |
| 4930 | |
| 4931 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 4932 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4933 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4934 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4935 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4936 | if (!slot) |
| 4937 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4938 | ret = 0; |
| 4939 | |
| 4940 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4941 | tbl->max_slots = max_slots; |
| 4942 | tbl->slots = slot; |
| 4943 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 4944 | spin_unlock(&tbl->slot_tbl_lock); |
| 4945 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 4946 | tbl, tbl->slots, tbl->max_slots); |
| 4947 | out: |
| 4948 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 4949 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 4950 | } |
| 4951 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4952 | /* |
| 4953 | * Initialize the forechannel and backchannel tables |
| 4954 | */ |
| 4955 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 4956 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4957 | struct nfs4_slot_table *tbl; |
| 4958 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4959 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4960 | tbl = &session->fc_slot_table; |
| 4961 | if (tbl->slots == NULL) { |
| 4962 | status = nfs4_init_slot_table(tbl, |
| 4963 | session->fc_attrs.max_reqs, 1); |
| 4964 | if (status) |
| 4965 | return status; |
| 4966 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 4967 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 4968 | tbl = &session->bc_slot_table; |
| 4969 | if (tbl->slots == NULL) { |
| 4970 | status = nfs4_init_slot_table(tbl, |
| 4971 | session->bc_attrs.max_reqs, 0); |
| 4972 | if (status) |
| 4973 | nfs4_destroy_slot_tables(session); |
| 4974 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4975 | |
| 4976 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4977 | } |
| 4978 | |
| 4979 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 4980 | { |
| 4981 | struct nfs4_session *session; |
| 4982 | struct nfs4_slot_table *tbl; |
| 4983 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4984 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4985 | if (!session) |
| 4986 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 4987 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4988 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4989 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4990 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4991 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4992 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4993 | |
| 4994 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 4995 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4996 | spin_lock_init(&tbl->slot_tbl_lock); |
| 4997 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 4998 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 4999 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5000 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5001 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5002 | session->clp = clp; |
| 5003 | return session; |
| 5004 | } |
| 5005 | |
| 5006 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5007 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5008 | nfs4_proc_destroy_session(session); |
| 5009 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 5010 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 5011 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 5012 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5013 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5014 | kfree(session); |
| 5015 | } |
| 5016 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5017 | /* |
| 5018 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5019 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5020 | * use them. |
| 5021 | * |
| 5022 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5023 | * always set csa_cachethis to FALSE because the current implementation |
| 5024 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5025 | */ |
| 5026 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5027 | { |
| 5028 | struct nfs4_session *session = args->client->cl_session; |
| 5029 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5030 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5031 | |
| 5032 | if (mxrqst_sz == 0) |
| 5033 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5034 | if (mxresp_sz == 0) |
| 5035 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5036 | /* Fore channel attributes */ |
| 5037 | args->fc_attrs.headerpadsz = 0; |
| 5038 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5039 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5040 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 5041 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 5042 | |
| 5043 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5044 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5045 | __func__, |
| 5046 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5047 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5048 | |
| 5049 | /* Back channel attributes */ |
| 5050 | args->bc_attrs.headerpadsz = 0; |
| 5051 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5052 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5053 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5054 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5055 | args->bc_attrs.max_reqs = 1; |
| 5056 | |
| 5057 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5058 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5059 | __func__, |
| 5060 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5061 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5062 | args->bc_attrs.max_reqs); |
| 5063 | } |
| 5064 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5065 | 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] | 5066 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5067 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5068 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5069 | |
| 5070 | if (rcvd->headerpadsz > sent->headerpadsz) |
| 5071 | return -EINVAL; |
| 5072 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5073 | return -EINVAL; |
| 5074 | /* |
| 5075 | * Our requested max_ops is the minimum we need; we're not |
| 5076 | * prepared to break up compounds into smaller pieces than that. |
| 5077 | * So, no point even trying to continue if the server won't |
| 5078 | * cooperate: |
| 5079 | */ |
| 5080 | if (rcvd->max_ops < sent->max_ops) |
| 5081 | return -EINVAL; |
| 5082 | if (rcvd->max_reqs == 0) |
| 5083 | return -EINVAL; |
| 5084 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5085 | } |
| 5086 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5087 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5088 | { |
| 5089 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5090 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5091 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5092 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5093 | return -EINVAL; |
| 5094 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5095 | return -EINVAL; |
| 5096 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5097 | return -EINVAL; |
| 5098 | /* These would render the backchannel useless: */ |
| 5099 | if (rcvd->max_ops == 0) |
| 5100 | return -EINVAL; |
| 5101 | if (rcvd->max_reqs == 0) |
| 5102 | return -EINVAL; |
| 5103 | return 0; |
| 5104 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5105 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5106 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5107 | struct nfs4_session *session) |
| 5108 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5109 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5110 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5111 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5112 | if (ret) |
| 5113 | return ret; |
| 5114 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5115 | } |
| 5116 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5117 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5118 | { |
| 5119 | struct nfs4_session *session = clp->cl_session; |
| 5120 | struct nfs41_create_session_args args = { |
| 5121 | .client = clp, |
| 5122 | .cb_program = NFS4_CALLBACK, |
| 5123 | }; |
| 5124 | struct nfs41_create_session_res res = { |
| 5125 | .client = clp, |
| 5126 | }; |
| 5127 | struct rpc_message msg = { |
| 5128 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5129 | .rpc_argp = &args, |
| 5130 | .rpc_resp = &res, |
| 5131 | }; |
| 5132 | int status; |
| 5133 | |
| 5134 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5135 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5136 | |
| 5137 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5138 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5139 | if (!status) |
| 5140 | /* Verify the session's negotiated channel_attrs values */ |
| 5141 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5142 | if (!status) { |
| 5143 | /* Increment the clientid slot sequence id */ |
| 5144 | clp->cl_seqid++; |
| 5145 | } |
| 5146 | |
| 5147 | return status; |
| 5148 | } |
| 5149 | |
| 5150 | /* |
| 5151 | * Issues a CREATE_SESSION operation to the server. |
| 5152 | * It is the responsibility of the caller to verify the session is |
| 5153 | * expired before calling this routine. |
| 5154 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5155 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5156 | { |
| 5157 | int status; |
| 5158 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5159 | struct nfs4_session *session = clp->cl_session; |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5160 | long timeout = 0; |
| 5161 | int err; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5162 | |
| 5163 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5164 | |
Ricardo Labiaga | 7d6d63d | 2011-03-09 13:13:44 -0500 | [diff] [blame] | 5165 | do { |
| 5166 | status = _nfs4_proc_create_session(clp); |
| 5167 | if (status == -NFS4ERR_DELAY) { |
| 5168 | err = nfs4_delay(clp->cl_rpcclient, &timeout); |
| 5169 | if (err) |
| 5170 | status = err; |
| 5171 | } |
| 5172 | } while (status == -NFS4ERR_DELAY); |
| 5173 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5174 | if (status) |
| 5175 | goto out; |
| 5176 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5177 | /* Init and reset the fore channel */ |
| 5178 | status = nfs4_init_slot_tables(session); |
| 5179 | dprintk("slot table initialization returned %d\n", status); |
| 5180 | if (status) |
| 5181 | goto out; |
| 5182 | status = nfs4_reset_slot_tables(session); |
| 5183 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5184 | if (status) |
| 5185 | goto out; |
| 5186 | |
| 5187 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5188 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5189 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5190 | out: |
| 5191 | dprintk("<-- %s\n", __func__); |
| 5192 | return status; |
| 5193 | } |
| 5194 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5195 | /* |
| 5196 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5197 | * The caller must serialize access to this routine. |
| 5198 | */ |
| 5199 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5200 | { |
| 5201 | int status = 0; |
| 5202 | struct rpc_message msg; |
| 5203 | |
| 5204 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5205 | |
| 5206 | /* session is still being setup */ |
| 5207 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5208 | return status; |
| 5209 | |
| 5210 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5211 | msg.rpc_argp = session; |
| 5212 | msg.rpc_resp = NULL; |
| 5213 | msg.rpc_cred = NULL; |
| 5214 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0); |
| 5215 | |
| 5216 | if (status) |
| 5217 | printk(KERN_WARNING |
| 5218 | "Got error %d from the server on DESTROY_SESSION. " |
| 5219 | "Session has been destroyed regardless...\n", status); |
| 5220 | |
| 5221 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5222 | return status; |
| 5223 | } |
| 5224 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5225 | int nfs4_init_session(struct nfs_server *server) |
| 5226 | { |
| 5227 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5228 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5229 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5230 | int ret; |
| 5231 | |
| 5232 | if (!nfs4_has_session(clp)) |
| 5233 | return 0; |
| 5234 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5235 | session = clp->cl_session; |
| 5236 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5237 | return 0; |
| 5238 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5239 | rsize = server->rsize; |
| 5240 | if (rsize == 0) |
| 5241 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5242 | wsize = server->wsize; |
| 5243 | if (wsize == 0) |
| 5244 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5245 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5246 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5247 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5248 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5249 | ret = nfs4_recover_expired_lease(server); |
| 5250 | if (!ret) |
| 5251 | ret = nfs4_check_client_ready(clp); |
| 5252 | return ret; |
| 5253 | } |
| 5254 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5255 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5256 | { |
| 5257 | struct nfs4_session *session = clp->cl_session; |
| 5258 | int ret; |
| 5259 | |
| 5260 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5261 | return 0; |
| 5262 | |
| 5263 | ret = nfs4_client_recover_expired_lease(clp); |
| 5264 | if (!ret) |
| 5265 | /* Test for the DS role */ |
| 5266 | if (!is_ds_client(clp)) |
| 5267 | ret = -ENODEV; |
| 5268 | if (!ret) |
| 5269 | ret = nfs4_check_client_ready(clp); |
| 5270 | return ret; |
| 5271 | |
| 5272 | } |
| 5273 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5274 | |
| 5275 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5276 | /* |
| 5277 | * Renew the cl_session lease. |
| 5278 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5279 | struct nfs4_sequence_data { |
| 5280 | struct nfs_client *clp; |
| 5281 | struct nfs4_sequence_args args; |
| 5282 | struct nfs4_sequence_res res; |
| 5283 | }; |
| 5284 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5285 | static void nfs41_sequence_release(void *data) |
| 5286 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5287 | struct nfs4_sequence_data *calldata = data; |
| 5288 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5289 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5290 | if (atomic_read(&clp->cl_count) > 1) |
| 5291 | nfs4_schedule_state_renewal(clp); |
| 5292 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5293 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5294 | } |
| 5295 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5296 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5297 | { |
| 5298 | switch(task->tk_status) { |
| 5299 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5300 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5301 | return -EAGAIN; |
| 5302 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5303 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5304 | } |
| 5305 | return 0; |
| 5306 | } |
| 5307 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5308 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5309 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5310 | struct nfs4_sequence_data *calldata = data; |
| 5311 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5312 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5313 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5314 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5315 | |
| 5316 | if (task->tk_status < 0) { |
| 5317 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5318 | if (atomic_read(&clp->cl_count) == 1) |
| 5319 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5320 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5321 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5322 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5323 | return; |
| 5324 | } |
| 5325 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5326 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5327 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5328 | dprintk("<-- %s\n", __func__); |
| 5329 | } |
| 5330 | |
| 5331 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5332 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5333 | struct nfs4_sequence_data *calldata = data; |
| 5334 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5335 | struct nfs4_sequence_args *args; |
| 5336 | struct nfs4_sequence_res *res; |
| 5337 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5338 | args = task->tk_msg.rpc_argp; |
| 5339 | res = task->tk_msg.rpc_resp; |
| 5340 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5341 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5342 | return; |
| 5343 | rpc_call_start(task); |
| 5344 | } |
| 5345 | |
| 5346 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5347 | .rpc_call_done = nfs41_sequence_call_done, |
| 5348 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5349 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5350 | }; |
| 5351 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5352 | 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] | 5353 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5354 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5355 | struct rpc_message msg = { |
| 5356 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5357 | .rpc_cred = cred, |
| 5358 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5359 | struct rpc_task_setup task_setup_data = { |
| 5360 | .rpc_client = clp->cl_rpcclient, |
| 5361 | .rpc_message = &msg, |
| 5362 | .callback_ops = &nfs41_sequence_ops, |
| 5363 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5364 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5365 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5366 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5367 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f30 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5368 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5369 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5370 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5371 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5372 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5373 | msg.rpc_argp = &calldata->args; |
| 5374 | msg.rpc_resp = &calldata->res; |
| 5375 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5376 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5377 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5378 | return rpc_run_task(&task_setup_data); |
| 5379 | } |
| 5380 | |
| 5381 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5382 | { |
| 5383 | struct rpc_task *task; |
| 5384 | int ret = 0; |
| 5385 | |
| 5386 | task = _nfs41_proc_sequence(clp, cred); |
| 5387 | if (IS_ERR(task)) |
| 5388 | ret = PTR_ERR(task); |
| 5389 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5390 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5391 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5392 | return ret; |
| 5393 | } |
| 5394 | |
| 5395 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5396 | { |
| 5397 | struct rpc_task *task; |
| 5398 | int ret; |
| 5399 | |
| 5400 | task = _nfs41_proc_sequence(clp, cred); |
| 5401 | if (IS_ERR(task)) { |
| 5402 | ret = PTR_ERR(task); |
| 5403 | goto out; |
| 5404 | } |
| 5405 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5406 | if (!ret) { |
| 5407 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5408 | |
| 5409 | if (task->tk_status == 0) |
| 5410 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5411 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5412 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5413 | rpc_put_task(task); |
| 5414 | out: |
| 5415 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5416 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5417 | } |
| 5418 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5419 | struct nfs4_reclaim_complete_data { |
| 5420 | struct nfs_client *clp; |
| 5421 | struct nfs41_reclaim_complete_args arg; |
| 5422 | struct nfs41_reclaim_complete_res res; |
| 5423 | }; |
| 5424 | |
| 5425 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5426 | { |
| 5427 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5428 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5429 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5430 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5431 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5432 | &calldata->res.seq_res, 0, task)) |
| 5433 | return; |
| 5434 | |
| 5435 | rpc_call_start(task); |
| 5436 | } |
| 5437 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5438 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5439 | { |
| 5440 | switch(task->tk_status) { |
| 5441 | case 0: |
| 5442 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5443 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5444 | break; |
| 5445 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5446 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5447 | return -EAGAIN; |
| 5448 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5449 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5450 | } |
| 5451 | return 0; |
| 5452 | } |
| 5453 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5454 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5455 | { |
| 5456 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5457 | struct nfs_client *clp = calldata->clp; |
| 5458 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5459 | |
| 5460 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5461 | if (!nfs41_sequence_done(task, res)) |
| 5462 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5463 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5464 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5465 | rpc_restart_call_prepare(task); |
| 5466 | return; |
| 5467 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5468 | dprintk("<-- %s\n", __func__); |
| 5469 | } |
| 5470 | |
| 5471 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5472 | { |
| 5473 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5474 | |
| 5475 | kfree(calldata); |
| 5476 | } |
| 5477 | |
| 5478 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5479 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5480 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5481 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5482 | }; |
| 5483 | |
| 5484 | /* |
| 5485 | * Issue a global reclaim complete. |
| 5486 | */ |
| 5487 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5488 | { |
| 5489 | struct nfs4_reclaim_complete_data *calldata; |
| 5490 | struct rpc_task *task; |
| 5491 | struct rpc_message msg = { |
| 5492 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5493 | }; |
| 5494 | struct rpc_task_setup task_setup_data = { |
| 5495 | .rpc_client = clp->cl_rpcclient, |
| 5496 | .rpc_message = &msg, |
| 5497 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5498 | .flags = RPC_TASK_ASYNC, |
| 5499 | }; |
| 5500 | int status = -ENOMEM; |
| 5501 | |
| 5502 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5503 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5504 | if (calldata == NULL) |
| 5505 | goto out; |
| 5506 | calldata->clp = clp; |
| 5507 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5508 | |
| 5509 | msg.rpc_argp = &calldata->arg; |
| 5510 | msg.rpc_resp = &calldata->res; |
| 5511 | task_setup_data.callback_data = calldata; |
| 5512 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5513 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5514 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5515 | goto out; |
| 5516 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5517 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5518 | if (status == 0) |
| 5519 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5520 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5521 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5522 | out: |
| 5523 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5524 | return status; |
| 5525 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5526 | |
| 5527 | static void |
| 5528 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5529 | { |
| 5530 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5531 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5532 | |
| 5533 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5534 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5535 | * right now covering the LAYOUTGET we are about to send. |
| 5536 | * However, that is not so catastrophic, and there seems |
| 5537 | * to be no way to prevent it completely. |
| 5538 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5539 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5540 | &lgp->res.seq_res, 0, task)) |
| 5541 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5542 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5543 | NFS_I(lgp->args.inode)->layout, |
| 5544 | lgp->args.ctx->state)) { |
| 5545 | rpc_exit(task, NFS4_OK); |
| 5546 | return; |
| 5547 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5548 | rpc_call_start(task); |
| 5549 | } |
| 5550 | |
| 5551 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5552 | { |
| 5553 | struct nfs4_layoutget *lgp = calldata; |
| 5554 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5555 | |
| 5556 | dprintk("--> %s\n", __func__); |
| 5557 | |
| 5558 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5559 | return; |
| 5560 | |
| 5561 | switch (task->tk_status) { |
| 5562 | case 0: |
| 5563 | break; |
| 5564 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5565 | case -NFS4ERR_RECALLCONFLICT: |
| 5566 | task->tk_status = -NFS4ERR_DELAY; |
| 5567 | /* Fall through */ |
| 5568 | default: |
| 5569 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5570 | rpc_restart_call_prepare(task); |
| 5571 | return; |
| 5572 | } |
| 5573 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5574 | dprintk("<-- %s\n", __func__); |
| 5575 | } |
| 5576 | |
| 5577 | static void nfs4_layoutget_release(void *calldata) |
| 5578 | { |
| 5579 | struct nfs4_layoutget *lgp = calldata; |
| 5580 | |
| 5581 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5582 | if (lgp->res.layout.buf != NULL) |
| 5583 | free_page((unsigned long) lgp->res.layout.buf); |
| 5584 | put_nfs_open_context(lgp->args.ctx); |
| 5585 | kfree(calldata); |
| 5586 | dprintk("<-- %s\n", __func__); |
| 5587 | } |
| 5588 | |
| 5589 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5590 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5591 | .rpc_call_done = nfs4_layoutget_done, |
| 5592 | .rpc_release = nfs4_layoutget_release, |
| 5593 | }; |
| 5594 | |
| 5595 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5596 | { |
| 5597 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5598 | struct rpc_task *task; |
| 5599 | struct rpc_message msg = { |
| 5600 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5601 | .rpc_argp = &lgp->args, |
| 5602 | .rpc_resp = &lgp->res, |
| 5603 | }; |
| 5604 | struct rpc_task_setup task_setup_data = { |
| 5605 | .rpc_client = server->client, |
| 5606 | .rpc_message = &msg, |
| 5607 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5608 | .callback_data = lgp, |
| 5609 | .flags = RPC_TASK_ASYNC, |
| 5610 | }; |
| 5611 | int status = 0; |
| 5612 | |
| 5613 | dprintk("--> %s\n", __func__); |
| 5614 | |
| 5615 | lgp->res.layout.buf = (void *)__get_free_page(GFP_NOFS); |
| 5616 | if (lgp->res.layout.buf == NULL) { |
| 5617 | nfs4_layoutget_release(lgp); |
| 5618 | return -ENOMEM; |
| 5619 | } |
| 5620 | |
| 5621 | lgp->res.seq_res.sr_slot = NULL; |
| 5622 | task = rpc_run_task(&task_setup_data); |
| 5623 | if (IS_ERR(task)) |
| 5624 | return PTR_ERR(task); |
| 5625 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5626 | if (status == 0) |
| 5627 | status = task->tk_status; |
| 5628 | if (status == 0) |
| 5629 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5630 | rpc_put_task(task); |
| 5631 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5632 | return status; |
| 5633 | } |
| 5634 | |
| 5635 | static int |
| 5636 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5637 | { |
| 5638 | struct nfs4_getdeviceinfo_args args = { |
| 5639 | .pdev = pdev, |
| 5640 | }; |
| 5641 | struct nfs4_getdeviceinfo_res res = { |
| 5642 | .pdev = pdev, |
| 5643 | }; |
| 5644 | struct rpc_message msg = { |
| 5645 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5646 | .rpc_argp = &args, |
| 5647 | .rpc_resp = &res, |
| 5648 | }; |
| 5649 | int status; |
| 5650 | |
| 5651 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5652 | 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] | 5653 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5654 | |
| 5655 | return status; |
| 5656 | } |
| 5657 | |
| 5658 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5659 | { |
| 5660 | struct nfs4_exception exception = { }; |
| 5661 | int err; |
| 5662 | |
| 5663 | do { |
| 5664 | err = nfs4_handle_exception(server, |
| 5665 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5666 | &exception); |
| 5667 | } while (exception.retry); |
| 5668 | return err; |
| 5669 | } |
| 5670 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5671 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5672 | #endif /* CONFIG_NFS_V4_1 */ |
| 5673 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5674 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5675 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5676 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 | .recover_open = nfs4_open_reclaim, |
| 5678 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5679 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5680 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5681 | }; |
| 5682 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5683 | #if defined(CONFIG_NFS_V4_1) |
| 5684 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 5685 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 5686 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 5687 | .recover_open = nfs4_open_reclaim, |
| 5688 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5689 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5690 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5691 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5692 | }; |
| 5693 | #endif /* CONFIG_NFS_V4_1 */ |
| 5694 | |
| 5695 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 5696 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 5697 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5698 | .recover_open = nfs4_open_expired, |
| 5699 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5700 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 5701 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5702 | }; |
| 5703 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5704 | #if defined(CONFIG_NFS_V4_1) |
| 5705 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 5706 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 5707 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
| 5708 | .recover_open = nfs4_open_expired, |
| 5709 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5710 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 5711 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 5712 | }; |
| 5713 | #endif /* CONFIG_NFS_V4_1 */ |
| 5714 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5715 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 5716 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5717 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5718 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5719 | }; |
| 5720 | |
| 5721 | #if defined(CONFIG_NFS_V4_1) |
| 5722 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 5723 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 5724 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 5725 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 5726 | }; |
| 5727 | #endif |
| 5728 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5729 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 5730 | .minor_version = 0, |
| 5731 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5732 | .validate_stateid = nfs4_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5733 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 5734 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 5735 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5736 | }; |
| 5737 | |
| 5738 | #if defined(CONFIG_NFS_V4_1) |
| 5739 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 5740 | .minor_version = 1, |
| 5741 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5742 | .validate_stateid = nfs41_validate_delegation_stateid, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5743 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 5744 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 5745 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5746 | }; |
| 5747 | #endif |
| 5748 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5749 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 5750 | [0] = &nfs_v4_0_minor_ops, |
| 5751 | #if defined(CONFIG_NFS_V4_1) |
| 5752 | [1] = &nfs_v4_1_minor_ops, |
| 5753 | #endif |
| 5754 | }; |
| 5755 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 5756 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5757 | .permission = nfs_permission, |
| 5758 | .getattr = nfs_getattr, |
| 5759 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5760 | .getxattr = generic_getxattr, |
| 5761 | .setxattr = generic_setxattr, |
| 5762 | .listxattr = generic_listxattr, |
| 5763 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5764 | }; |
| 5765 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 5766 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5767 | .version = 4, /* protocol version */ |
| 5768 | .dentry_ops = &nfs4_dentry_operations, |
| 5769 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5770 | .file_inode_ops = &nfs4_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | .getroot = nfs4_proc_get_root, |
| 5772 | .getattr = nfs4_proc_getattr, |
| 5773 | .setattr = nfs4_proc_setattr, |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 5774 | .lookupfh = nfs4_proc_lookupfh, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | .lookup = nfs4_proc_lookup, |
| 5776 | .access = nfs4_proc_access, |
| 5777 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5778 | .create = nfs4_proc_create, |
| 5779 | .remove = nfs4_proc_remove, |
| 5780 | .unlink_setup = nfs4_proc_unlink_setup, |
| 5781 | .unlink_done = nfs4_proc_unlink_done, |
| 5782 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 5783 | .rename_setup = nfs4_proc_rename_setup, |
| 5784 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5785 | .link = nfs4_proc_link, |
| 5786 | .symlink = nfs4_proc_symlink, |
| 5787 | .mkdir = nfs4_proc_mkdir, |
| 5788 | .rmdir = nfs4_proc_remove, |
| 5789 | .readdir = nfs4_proc_readdir, |
| 5790 | .mknod = nfs4_proc_mknod, |
| 5791 | .statfs = nfs4_proc_statfs, |
| 5792 | .fsinfo = nfs4_proc_fsinfo, |
| 5793 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 5794 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5795 | .decode_dirent = nfs4_decode_dirent, |
| 5796 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5797 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5798 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5799 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5800 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 5801 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5802 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5803 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 5804 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 5805 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 5806 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5807 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | }; |
| 5809 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5810 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 5811 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 5812 | .list = nfs4_xattr_list_nfs4_acl, |
| 5813 | .get = nfs4_xattr_get_nfs4_acl, |
| 5814 | .set = nfs4_xattr_set_nfs4_acl, |
| 5815 | }; |
| 5816 | |
| 5817 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 5818 | &nfs4_xattr_nfs4_acl_handler, |
| 5819 | NULL |
| 5820 | }; |
| 5821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5822 | /* |
| 5823 | * Local variables: |
| 5824 | * c-basic-offset: 8 |
| 5825 | * End: |
| 5826 | */ |