Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/nfs/nfs4proc.c |
| 3 | * |
| 4 | * Client-side procedure declarations for NFSv4. |
| 5 | * |
| 6 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * Kendrick Smith <kmsmith@umich.edu> |
| 10 | * Andy Adamson <andros@umich.edu> |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * 1. Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * 2. Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in the |
| 20 | * documentation and/or other materials provided with the distribution. |
| 21 | * 3. Neither the name of the University nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * |
| 25 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 26 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 32 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/delay.h> |
| 40 | #include <linux/errno.h> |
| 41 | #include <linux/string.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/sunrpc/clnt.h> |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 44 | #include <linux/sunrpc/gss_api.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/nfs.h> |
| 46 | #include <linux/nfs4.h> |
| 47 | #include <linux/nfs_fs.h> |
| 48 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 49 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 51 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 52 | #include <linux/module.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 53 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 54 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 55 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 57 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 59 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 60 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 61 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 62 | #include "pnfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 65 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 66 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 68 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 69 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 70 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 71 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 72 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 73 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 75 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 76 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 77 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 78 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 79 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 80 | #ifdef CONFIG_NFS_V4_1 |
| 81 | static int nfs41_test_stateid(struct nfs_server *, struct nfs4_state *); |
| 82 | static int nfs41_free_stateid(struct nfs_server *, struct nfs4_state *); |
| 83 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 85 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 87 | if (err >= -1000) |
| 88 | return err; |
| 89 | switch (err) { |
| 90 | case -NFS4ERR_RESOURCE: |
| 91 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 92 | case -NFS4ERR_WRONGSEC: |
| 93 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 94 | case -NFS4ERR_BADOWNER: |
| 95 | case -NFS4ERR_BADNAME: |
| 96 | return -EINVAL; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 97 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 99 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 100 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 102 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* |
| 106 | * This is our standard bitmap for GETATTR requests. |
| 107 | */ |
| 108 | const u32 nfs4_fattr_bitmap[2] = { |
| 109 | FATTR4_WORD0_TYPE |
| 110 | | FATTR4_WORD0_CHANGE |
| 111 | | FATTR4_WORD0_SIZE |
| 112 | | FATTR4_WORD0_FSID |
| 113 | | FATTR4_WORD0_FILEID, |
| 114 | FATTR4_WORD1_MODE |
| 115 | | FATTR4_WORD1_NUMLINKS |
| 116 | | FATTR4_WORD1_OWNER |
| 117 | | FATTR4_WORD1_OWNER_GROUP |
| 118 | | FATTR4_WORD1_RAWDEV |
| 119 | | FATTR4_WORD1_SPACE_USED |
| 120 | | FATTR4_WORD1_TIME_ACCESS |
| 121 | | FATTR4_WORD1_TIME_METADATA |
| 122 | | FATTR4_WORD1_TIME_MODIFY |
| 123 | }; |
| 124 | |
| 125 | const u32 nfs4_statfs_bitmap[2] = { |
| 126 | FATTR4_WORD0_FILES_AVAIL |
| 127 | | FATTR4_WORD0_FILES_FREE |
| 128 | | FATTR4_WORD0_FILES_TOTAL, |
| 129 | FATTR4_WORD1_SPACE_AVAIL |
| 130 | | FATTR4_WORD1_SPACE_FREE |
| 131 | | FATTR4_WORD1_SPACE_TOTAL |
| 132 | }; |
| 133 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 134 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | FATTR4_WORD0_MAXLINK |
| 136 | | FATTR4_WORD0_MAXNAME, |
| 137 | 0 |
| 138 | }; |
| 139 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 140 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | | FATTR4_WORD0_MAXREAD |
| 142 | | FATTR4_WORD0_MAXWRITE |
| 143 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 144 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 145 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 146 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | }; |
| 148 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 149 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 150 | FATTR4_WORD0_TYPE |
| 151 | | FATTR4_WORD0_CHANGE |
| 152 | | FATTR4_WORD0_SIZE |
| 153 | | FATTR4_WORD0_FSID |
| 154 | | FATTR4_WORD0_FILEID |
| 155 | | FATTR4_WORD0_FS_LOCATIONS, |
| 156 | FATTR4_WORD1_MODE |
| 157 | | FATTR4_WORD1_NUMLINKS |
| 158 | | FATTR4_WORD1_OWNER |
| 159 | | FATTR4_WORD1_OWNER_GROUP |
| 160 | | FATTR4_WORD1_RAWDEV |
| 161 | | FATTR4_WORD1_SPACE_USED |
| 162 | | FATTR4_WORD1_TIME_ACCESS |
| 163 | | FATTR4_WORD1_TIME_METADATA |
| 164 | | FATTR4_WORD1_TIME_MODIFY |
| 165 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 166 | }; |
| 167 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 168 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | struct nfs4_readdir_arg *readdir) |
| 170 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 171 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | BUG_ON(readdir->count < 80); |
| 174 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 175 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | readdir->cookie = 0; |
| 181 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 182 | if (cookie == 2) |
| 183 | return; |
| 184 | |
| 185 | /* |
| 186 | * NFSv4 servers do not return entries for '.' and '..' |
| 187 | * Therefore, we fake these entries here. We let '.' |
| 188 | * have cookie 0 and '..' have cookie 1. Note that |
| 189 | * when talking to the server, we always send cookie 0 |
| 190 | * instead of 1 or 2. |
| 191 | */ |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 192 | start = p = kmap_atomic(*readdir->pages, KM_USER0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | if (cookie == 0) { |
| 195 | *p++ = xdr_one; /* next */ |
| 196 | *p++ = xdr_zero; /* cookie, first word */ |
| 197 | *p++ = xdr_one; /* cookie, second word */ |
| 198 | *p++ = xdr_one; /* entry len */ |
| 199 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 200 | p++; |
| 201 | *p++ = xdr_one; /* bitmap length */ |
| 202 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 203 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 204 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | *p++ = xdr_one; /* next */ |
| 208 | *p++ = xdr_zero; /* cookie, first word */ |
| 209 | *p++ = xdr_two; /* cookie, second word */ |
| 210 | *p++ = xdr_two; /* entry len */ |
| 211 | memcpy(p, "..\0\0", 4); /* entry */ |
| 212 | p++; |
| 213 | *p++ = xdr_one; /* bitmap length */ |
| 214 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 215 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 216 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | readdir->pgbase = (char *)p - (char *)start; |
| 219 | readdir->count -= readdir->pgbase; |
| 220 | kunmap_atomic(start, KM_USER0); |
| 221 | } |
| 222 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 223 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 224 | { |
| 225 | int res; |
| 226 | |
| 227 | might_sleep(); |
| 228 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 229 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 230 | nfs_wait_bit_killable, TASK_KILLABLE); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 231 | return res; |
| 232 | } |
| 233 | |
| 234 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 235 | { |
| 236 | int res = 0; |
| 237 | |
| 238 | might_sleep(); |
| 239 | |
| 240 | if (*timeout <= 0) |
| 241 | *timeout = NFS4_POLL_RETRY_MIN; |
| 242 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 243 | *timeout = NFS4_POLL_RETRY_MAX; |
| 244 | schedule_timeout_killable(*timeout); |
| 245 | if (fatal_signal_pending(current)) |
| 246 | res = -ERESTARTSYS; |
| 247 | *timeout <<= 1; |
| 248 | return res; |
| 249 | } |
| 250 | |
| 251 | /* This is the error handling routine for processes that are allowed |
| 252 | * to sleep. |
| 253 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 254 | 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] | 255 | { |
| 256 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 257 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 258 | int ret = errorcode; |
| 259 | |
| 260 | exception->retry = 0; |
| 261 | switch(errorcode) { |
| 262 | case 0: |
| 263 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 264 | case -NFS4ERR_ADMIN_REVOKED: |
| 265 | case -NFS4ERR_BAD_STATEID: |
| 266 | case -NFS4ERR_OPENMODE: |
| 267 | if (state == NULL) |
| 268 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 269 | nfs4_schedule_stateid_recovery(server, state); |
| 270 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 271 | case -NFS4ERR_EXPIRED: |
| 272 | if (state != NULL) |
| 273 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 274 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 275 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 276 | nfs4_schedule_lease_recovery(clp); |
| 277 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 278 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 279 | case -NFS4ERR_BADSESSION: |
| 280 | case -NFS4ERR_BADSLOT: |
| 281 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 282 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 283 | case -NFS4ERR_DEADSESSION: |
| 284 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 285 | case -NFS4ERR_SEQ_MISORDERED: |
| 286 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 287 | errorcode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 288 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 289 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 290 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 291 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 292 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 293 | if (exception->timeout > HZ) { |
| 294 | /* We have retried a decent amount, time to |
| 295 | * fail |
| 296 | */ |
| 297 | ret = -EBUSY; |
| 298 | break; |
| 299 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 300 | case -NFS4ERR_GRACE: |
| 301 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 302 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 303 | ret = nfs4_delay(server->client, &exception->timeout); |
| 304 | if (ret != 0) |
| 305 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 306 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 307 | case -NFS4ERR_OLD_STATEID: |
| 308 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 309 | break; |
| 310 | case -NFS4ERR_BADOWNER: |
| 311 | /* The following works around a Linux server bug! */ |
| 312 | case -NFS4ERR_BADNAME: |
| 313 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 314 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 315 | exception->retry = 1; |
| 316 | printk(KERN_WARNING "NFS: v4 server %s " |
| 317 | "does not accept raw " |
| 318 | "uid/gids. " |
| 319 | "Reenabling the idmapper.\n", |
| 320 | server->nfs_client->cl_hostname); |
| 321 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 322 | } |
| 323 | /* We failed to handle the error */ |
| 324 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 325 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 326 | ret = nfs4_wait_clnt_recover(clp); |
| 327 | if (ret == 0) |
| 328 | exception->retry = 1; |
| 329 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 333 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | spin_lock(&clp->cl_lock); |
| 336 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 337 | clp->cl_last_renewal = timestamp; |
| 338 | spin_unlock(&clp->cl_lock); |
| 339 | } |
| 340 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 341 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 342 | { |
| 343 | do_renew_lease(server->nfs_client, timestamp); |
| 344 | } |
| 345 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 346 | #if defined(CONFIG_NFS_V4_1) |
| 347 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 348 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 349 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 350 | * |
| 351 | * freeing a slot is trivially done by clearing its respective bit |
| 352 | * in the bitmap. |
| 353 | * If the freed slotid equals highest_used_slotid we want to update it |
| 354 | * so that the server would be able to size down the slot table if needed, |
| 355 | * otherwise we know that the highest_used_slotid is still in use. |
| 356 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 357 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 358 | * highest slotid in use. |
| 359 | * If none found, highest_used_slotid is set to -1. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 360 | * |
| 361 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 362 | */ |
| 363 | static void |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 364 | 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] | 365 | { |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 366 | int free_slotid = free_slot - tbl->slots; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 367 | int slotid = free_slotid; |
| 368 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 369 | BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 370 | /* clear used bit in bitmap */ |
| 371 | __clear_bit(slotid, tbl->used_slots); |
| 372 | |
| 373 | /* update highest_used_slotid when it is freed */ |
| 374 | if (slotid == tbl->highest_used_slotid) { |
| 375 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 376 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 377 | tbl->highest_used_slotid = slotid; |
| 378 | else |
| 379 | tbl->highest_used_slotid = -1; |
| 380 | } |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 381 | dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, |
| 382 | free_slotid, tbl->highest_used_slotid); |
| 383 | } |
| 384 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 385 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 386 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 387 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 388 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 389 | { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 390 | struct rpc_task *task; |
| 391 | |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 392 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 393 | task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); |
| 394 | if (task) |
| 395 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 396 | return; |
| 397 | } |
| 398 | |
| 399 | if (ses->fc_slot_table.highest_used_slotid != -1) |
| 400 | return; |
| 401 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 402 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 403 | complete(&ses->fc_slot_table.complete); |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | * Signal state manager thread if session back channel is drained |
| 408 | */ |
| 409 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 410 | { |
| 411 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
| 412 | ses->bc_slot_table.highest_used_slotid != -1) |
| 413 | return; |
| 414 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 415 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 418 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 419 | { |
| 420 | struct nfs4_slot_table *tbl; |
| 421 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 422 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 423 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 424 | /* just wake up the next guy waiting since |
| 425 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 426 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 427 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 428 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 429 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 430 | spin_lock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 431 | nfs4_free_slot(tbl, res->sr_slot); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 432 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 433 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 434 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 435 | } |
| 436 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 437 | 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] | 438 | { |
| 439 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 440 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 441 | |
| 442 | /* |
| 443 | * sr_status remains 1 if an RPC level error occurred. The server |
| 444 | * may or may not have processed the sequence operation.. |
| 445 | * Proceed as if the server received and processed the sequence |
| 446 | * operation. |
| 447 | */ |
| 448 | if (res->sr_status == 1) |
| 449 | res->sr_status = NFS_OK; |
| 450 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 451 | /* don't increment the sequence number if the task wasn't sent */ |
| 452 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 453 | goto out; |
| 454 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 455 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 456 | switch (res->sr_status) { |
| 457 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 458 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 459 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 460 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 461 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 462 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 463 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 464 | if (res->sr_status_flags != 0) |
| 465 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 466 | break; |
| 467 | case -NFS4ERR_DELAY: |
| 468 | /* The server detected a resend of the RPC call and |
| 469 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 470 | * of RFC5661. |
| 471 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 472 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 473 | __func__, |
| 474 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 475 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 476 | goto out_retry; |
| 477 | default: |
| 478 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 479 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 480 | } |
| 481 | out: |
| 482 | /* The session may be reset by one of the error handlers. */ |
| 483 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 484 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 485 | return 1; |
| 486 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 487 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 488 | goto out; |
| 489 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 490 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 491 | } |
| 492 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 493 | static int nfs4_sequence_done(struct rpc_task *task, |
| 494 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 495 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 496 | if (res->sr_session == NULL) |
| 497 | return 1; |
| 498 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 499 | } |
| 500 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 501 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 502 | * nfs4_find_slot - efficiently look for a free slot |
| 503 | * |
| 504 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 505 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 506 | * and respectively set up the sequence operation args. |
| 507 | * 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] | 508 | * |
| 509 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 510 | */ |
| 511 | static u8 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 512 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 513 | { |
| 514 | int slotid; |
| 515 | u8 ret_id = NFS4_MAX_SLOT_TABLE; |
| 516 | BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE); |
| 517 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 518 | dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", |
| 519 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 520 | tbl->max_slots); |
| 521 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 522 | if (slotid >= tbl->max_slots) |
| 523 | goto out; |
| 524 | __set_bit(slotid, tbl->used_slots); |
| 525 | if (slotid > tbl->highest_used_slotid) |
| 526 | tbl->highest_used_slotid = slotid; |
| 527 | ret_id = slotid; |
| 528 | out: |
| 529 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 530 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 531 | return ret_id; |
| 532 | } |
| 533 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 534 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 535 | struct nfs4_sequence_args *args, |
| 536 | struct nfs4_sequence_res *res, |
| 537 | int cache_reply, |
| 538 | struct rpc_task *task) |
| 539 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 540 | struct nfs4_slot *slot; |
| 541 | struct nfs4_slot_table *tbl; |
| 542 | u8 slotid; |
| 543 | |
| 544 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 545 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 546 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 547 | return 0; |
| 548 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 549 | tbl = &session->fc_slot_table; |
| 550 | |
| 551 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 552 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 553 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 554 | /* |
| 555 | * The state manager will wait until the slot table is empty. |
| 556 | * Schedule the reset thread |
| 557 | */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 558 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 559 | spin_unlock(&tbl->slot_tbl_lock); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 560 | dprintk("%s Schedule Session Reset\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 561 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 564 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 565 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 566 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 567 | spin_unlock(&tbl->slot_tbl_lock); |
| 568 | dprintk("%s enforce FIFO order\n", __func__); |
| 569 | return -EAGAIN; |
| 570 | } |
| 571 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 572 | slotid = nfs4_find_slot(tbl); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 573 | if (slotid == NFS4_MAX_SLOT_TABLE) { |
| 574 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 575 | spin_unlock(&tbl->slot_tbl_lock); |
| 576 | dprintk("<-- %s: no free slots\n", __func__); |
| 577 | return -EAGAIN; |
| 578 | } |
| 579 | spin_unlock(&tbl->slot_tbl_lock); |
| 580 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 581 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 582 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 583 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 584 | args->sa_slotid = slotid; |
| 585 | args->sa_cache_this = cache_reply; |
| 586 | |
| 587 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 588 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 589 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 590 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 591 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 592 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 593 | /* |
| 594 | * sr_status is only set in decode_sequence, and so will remain |
| 595 | * set to 1 if an rpc level failure occurs. |
| 596 | */ |
| 597 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 598 | return 0; |
| 599 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 600 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 601 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 602 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 603 | struct nfs4_sequence_args *args, |
| 604 | struct nfs4_sequence_res *res, |
| 605 | int cache_reply, |
| 606 | struct rpc_task *task) |
| 607 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 608 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 609 | int ret = 0; |
| 610 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 611 | if (session == NULL) { |
| 612 | args->sa_session = NULL; |
| 613 | res->sr_session = NULL; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 614 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 615 | } |
| 616 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 617 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 618 | __func__, session->clp, session, res->sr_slot ? |
| 619 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 620 | |
| 621 | ret = nfs41_setup_sequence(session, args, res, cache_reply, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 622 | task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 623 | out: |
| 624 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 625 | return ret; |
| 626 | } |
| 627 | |
| 628 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 629 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 630 | struct nfs4_sequence_args *seq_args; |
| 631 | struct nfs4_sequence_res *seq_res; |
| 632 | int cache_reply; |
| 633 | }; |
| 634 | |
| 635 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 636 | { |
| 637 | struct nfs41_call_sync_data *data = calldata; |
| 638 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 639 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 640 | |
| 641 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 642 | data->seq_res, data->cache_reply, task)) |
| 643 | return; |
| 644 | rpc_call_start(task); |
| 645 | } |
| 646 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 647 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 648 | { |
| 649 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 650 | nfs41_call_sync_prepare(task, calldata); |
| 651 | } |
| 652 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 653 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 654 | { |
| 655 | struct nfs41_call_sync_data *data = calldata; |
| 656 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 657 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 658 | } |
| 659 | |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 660 | struct rpc_call_ops nfs41_call_sync_ops = { |
| 661 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 662 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 663 | }; |
| 664 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 665 | struct rpc_call_ops nfs41_call_priv_sync_ops = { |
| 666 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 667 | .rpc_call_done = nfs41_call_sync_done, |
| 668 | }; |
| 669 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 670 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 671 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 672 | struct rpc_message *msg, |
| 673 | struct nfs4_sequence_args *args, |
| 674 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 675 | int cache_reply, |
| 676 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | { |
| 678 | int ret; |
| 679 | struct rpc_task *task; |
| 680 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 681 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 682 | .seq_args = args, |
| 683 | .seq_res = res, |
| 684 | .cache_reply = cache_reply, |
| 685 | }; |
| 686 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 687 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 688 | .rpc_message = msg, |
| 689 | .callback_ops = &nfs41_call_sync_ops, |
| 690 | .callback_data = &data |
| 691 | }; |
| 692 | |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 693 | res->sr_slot = NULL; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 694 | if (privileged) |
| 695 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 696 | task = rpc_run_task(&task_setup); |
| 697 | if (IS_ERR(task)) |
| 698 | ret = PTR_ERR(task); |
| 699 | else { |
| 700 | ret = task->tk_status; |
| 701 | rpc_put_task(task); |
| 702 | } |
| 703 | return ret; |
| 704 | } |
| 705 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 706 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 707 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 708 | struct rpc_message *msg, |
| 709 | struct nfs4_sequence_args *args, |
| 710 | struct nfs4_sequence_res *res, |
| 711 | int cache_reply) |
| 712 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 713 | 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] | 714 | } |
| 715 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 716 | #else |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 717 | static int nfs4_sequence_done(struct rpc_task *task, |
| 718 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 719 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 720 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 721 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 722 | #endif /* CONFIG_NFS_V4_1 */ |
| 723 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 724 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 725 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 726 | struct rpc_message *msg, |
| 727 | struct nfs4_sequence_args *args, |
| 728 | struct nfs4_sequence_res *res, |
| 729 | int cache_reply) |
| 730 | { |
Benny Halevy | f375297 | 2009-04-01 09:22:04 -0400 | [diff] [blame] | 731 | args->sa_session = res->sr_session = NULL; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 732 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 733 | } |
| 734 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 735 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 736 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 737 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 738 | struct rpc_message *msg, |
| 739 | struct nfs4_sequence_args *args, |
| 740 | struct nfs4_sequence_res *res, |
| 741 | int cache_reply) |
| 742 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 743 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 744 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 745 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 746 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 747 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 749 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 751 | spin_lock(&dir->i_lock); |
Trond Myklebust | 40d2470 | 2007-10-08 09:24:22 -0400 | [diff] [blame] | 752 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 753 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 754 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 755 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 756 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 759 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 760 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 761 | struct nfs_openargs o_arg; |
| 762 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 763 | struct nfs_open_confirmargs c_arg; |
| 764 | struct nfs_open_confirmres c_res; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 765 | struct nfs_fattr f_attr; |
| 766 | struct nfs_fattr dir_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 767 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 768 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 769 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 770 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 771 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 772 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 773 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 774 | int rpc_status; |
| 775 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 776 | }; |
| 777 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 778 | |
| 779 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 780 | { |
| 781 | p->o_res.f_attr = &p->f_attr; |
| 782 | p->o_res.dir_attr = &p->dir_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 783 | p->o_res.seqid = p->o_arg.seqid; |
| 784 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 785 | p->o_res.server = p->o_arg.server; |
| 786 | nfs_fattr_init(&p->f_attr); |
| 787 | nfs_fattr_init(&p->dir_attr); |
| 788 | } |
| 789 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 790 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 791 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 792 | const struct iattr *attrs, |
| 793 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 794 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 795 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 796 | struct inode *dir = parent->d_inode; |
| 797 | struct nfs_server *server = NFS_SERVER(dir); |
| 798 | struct nfs4_opendata *p; |
| 799 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 800 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 801 | if (p == NULL) |
| 802 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 803 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 804 | if (p->o_arg.seqid == NULL) |
| 805 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 806 | nfs_sb_active(dentry->d_sb); |
| 807 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 808 | p->dir = parent; |
| 809 | p->owner = sp; |
| 810 | atomic_inc(&sp->so_count); |
| 811 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 812 | p->o_arg.open_flags = flags; |
| 813 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 814 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 815 | p->o_arg.id = sp->so_owner_id.id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 816 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 817 | p->o_arg.server = server; |
| 818 | p->o_arg.bitmask = server->attr_bitmask; |
| 819 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 820 | if (flags & O_CREAT) { |
| 821 | u32 *s; |
| 822 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | p->o_arg.u.attrs = &p->attrs; |
| 824 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 825 | s = (u32 *) p->o_arg.u.verifier.data; |
| 826 | s[0] = jiffies; |
| 827 | s[1] = current->pid; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 829 | p->c_arg.fh = &p->o_res.fh; |
| 830 | p->c_arg.stateid = &p->o_res.stateid; |
| 831 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 832 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 833 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 834 | return p; |
| 835 | err_free: |
| 836 | kfree(p); |
| 837 | err: |
| 838 | dput(parent); |
| 839 | return NULL; |
| 840 | } |
| 841 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 842 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 843 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 844 | struct nfs4_opendata *p = container_of(kref, |
| 845 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 846 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 847 | |
| 848 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 849 | if (p->state != NULL) |
| 850 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 851 | nfs4_put_state_owner(p->owner); |
| 852 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 853 | dput(p->dentry); |
| 854 | nfs_sb_deactive(sb); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 855 | kfree(p); |
| 856 | } |
| 857 | |
| 858 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 859 | { |
| 860 | if (p != NULL) |
| 861 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 862 | } |
| 863 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 864 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 865 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 866 | int ret; |
| 867 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 868 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 869 | return ret; |
| 870 | } |
| 871 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 872 | static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 873 | { |
| 874 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 875 | |
| 876 | if (open_mode & O_EXCL) |
| 877 | goto out; |
| 878 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 879 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 880 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 881 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 882 | break; |
| 883 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 884 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 885 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 886 | break; |
| 887 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 888 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 889 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 890 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 891 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 892 | return ret; |
| 893 | } |
| 894 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 895 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 896 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 897 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 898 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 899 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 900 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 901 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 902 | return 1; |
| 903 | } |
| 904 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 905 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 906 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 907 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 908 | case FMODE_WRITE: |
| 909 | state->n_wronly++; |
| 910 | break; |
| 911 | case FMODE_READ: |
| 912 | state->n_rdonly++; |
| 913 | break; |
| 914 | case FMODE_READ|FMODE_WRITE: |
| 915 | state->n_rdwr++; |
| 916 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 917 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 920 | static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 921 | { |
| 922 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 923 | memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); |
| 924 | memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 925 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 926 | case FMODE_READ: |
| 927 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 928 | break; |
| 929 | case FMODE_WRITE: |
| 930 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 931 | break; |
| 932 | case FMODE_READ|FMODE_WRITE: |
| 933 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 934 | } |
| 935 | } |
| 936 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 937 | static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 938 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 939 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 940 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 941 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 942 | } |
| 943 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 944 | static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 946 | /* |
| 947 | * Protect the call to nfs4_state_set_mode_locked and |
| 948 | * serialise the stateid update |
| 949 | */ |
| 950 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 951 | if (deleg_stateid != NULL) { |
| 952 | memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); |
| 953 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 954 | } |
| 955 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 956 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 957 | write_sequnlock(&state->seqlock); |
| 958 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 959 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 960 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 963 | static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 964 | { |
| 965 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 966 | struct nfs_delegation *deleg_cur; |
| 967 | int ret = 0; |
| 968 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 969 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 970 | |
| 971 | rcu_read_lock(); |
| 972 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 973 | if (deleg_cur == NULL) |
| 974 | goto no_delegation; |
| 975 | |
| 976 | spin_lock(&deleg_cur->lock); |
| 977 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 978 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 979 | goto no_delegation_unlock; |
| 980 | |
| 981 | if (delegation == NULL) |
| 982 | delegation = &deleg_cur->stateid; |
| 983 | else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) |
| 984 | goto no_delegation_unlock; |
| 985 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 986 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 987 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 988 | ret = 1; |
| 989 | no_delegation_unlock: |
| 990 | spin_unlock(&deleg_cur->lock); |
| 991 | no_delegation: |
| 992 | rcu_read_unlock(); |
| 993 | |
| 994 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 995 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 996 | ret = 1; |
| 997 | } |
| 998 | |
| 999 | return ret; |
| 1000 | } |
| 1001 | |
| 1002 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1003 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1004 | { |
| 1005 | struct nfs_delegation *delegation; |
| 1006 | |
| 1007 | rcu_read_lock(); |
| 1008 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1009 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1010 | rcu_read_unlock(); |
| 1011 | return; |
| 1012 | } |
| 1013 | rcu_read_unlock(); |
| 1014 | nfs_inode_return_delegation(inode); |
| 1015 | } |
| 1016 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1017 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1018 | { |
| 1019 | struct nfs4_state *state = opendata->state; |
| 1020 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1021 | struct nfs_delegation *delegation; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1022 | int open_mode = opendata->o_arg.open_flags & O_EXCL; |
| 1023 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1024 | nfs4_stateid stateid; |
| 1025 | int ret = -EAGAIN; |
| 1026 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1027 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1028 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1029 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1030 | if (can_open_cached(state, fmode, open_mode)) { |
| 1031 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1032 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1033 | goto out_return_state; |
| 1034 | } |
| 1035 | spin_unlock(&state->owner->so_lock); |
| 1036 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1037 | rcu_read_lock(); |
| 1038 | delegation = rcu_dereference(nfsi->delegation); |
| 1039 | if (delegation == NULL || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1040 | !can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1041 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1042 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1043 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1044 | /* Save the delegation */ |
| 1045 | memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); |
| 1046 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1047 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1048 | if (ret != 0) |
| 1049 | goto out; |
| 1050 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1051 | |
| 1052 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1053 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1054 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1055 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1056 | out: |
| 1057 | return ERR_PTR(ret); |
| 1058 | out_return_state: |
| 1059 | atomic_inc(&state->count); |
| 1060 | return state; |
| 1061 | } |
| 1062 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1063 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1064 | { |
| 1065 | struct inode *inode; |
| 1066 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1067 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1068 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1069 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1070 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1071 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1072 | goto out; |
| 1073 | } |
| 1074 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1075 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1076 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1077 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1078 | inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1079 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1080 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1081 | goto err; |
| 1082 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1083 | state = nfs4_get_open_state(inode, data->owner); |
| 1084 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1085 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1086 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1087 | int delegation_flags = 0; |
| 1088 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1089 | rcu_read_lock(); |
| 1090 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1091 | if (delegation) |
| 1092 | delegation_flags = delegation->flags; |
| 1093 | rcu_read_unlock(); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1094 | if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1095 | nfs_inode_set_delegation(state->inode, |
| 1096 | data->owner->so_cred, |
| 1097 | &data->o_res); |
| 1098 | else |
| 1099 | nfs_inode_reclaim_delegation(state->inode, |
| 1100 | data->owner->so_cred, |
| 1101 | &data->o_res); |
| 1102 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1103 | |
| 1104 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1105 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1106 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1107 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1108 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1109 | err_put_inode: |
| 1110 | iput(inode); |
| 1111 | err: |
| 1112 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1115 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1116 | { |
| 1117 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1118 | struct nfs_open_context *ctx; |
| 1119 | |
| 1120 | spin_lock(&state->inode->i_lock); |
| 1121 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1122 | if (ctx->state != state) |
| 1123 | continue; |
| 1124 | get_nfs_open_context(ctx); |
| 1125 | spin_unlock(&state->inode->i_lock); |
| 1126 | return ctx; |
| 1127 | } |
| 1128 | spin_unlock(&state->inode->i_lock); |
| 1129 | return ERR_PTR(-ENOENT); |
| 1130 | } |
| 1131 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1132 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1133 | { |
| 1134 | struct nfs4_opendata *opendata; |
| 1135 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1136 | opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, NULL, GFP_NOFS); |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1137 | if (opendata == NULL) |
| 1138 | return ERR_PTR(-ENOMEM); |
| 1139 | opendata->state = state; |
| 1140 | atomic_inc(&state->count); |
| 1141 | return opendata; |
| 1142 | } |
| 1143 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1144 | static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res) |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1145 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1146 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1147 | int ret; |
| 1148 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1149 | opendata->o_arg.open_flags = 0; |
| 1150 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1151 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1152 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1153 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1154 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1155 | if (ret != 0) |
| 1156 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1157 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1158 | if (IS_ERR(newstate)) |
| 1159 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1160 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1161 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1162 | return 0; |
| 1163 | } |
| 1164 | |
| 1165 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1166 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1167 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1168 | int ret; |
| 1169 | |
| 1170 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1171 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1172 | smp_rmb(); |
| 1173 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1174 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1175 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1176 | if (ret != 0) |
| 1177 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1178 | if (newstate != state) |
| 1179 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1180 | } |
| 1181 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1182 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1183 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1184 | if (ret != 0) |
| 1185 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1186 | if (newstate != state) |
| 1187 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1188 | } |
| 1189 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1190 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1191 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1192 | if (ret != 0) |
| 1193 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1194 | if (newstate != state) |
| 1195 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1196 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1197 | /* |
| 1198 | * We may have performed cached opens for all three recoveries. |
| 1199 | * Check if we need to update the current stateid. |
| 1200 | */ |
| 1201 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
| 1202 | memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1203 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1204 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1205 | memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1206 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1207 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1208 | return 0; |
| 1209 | } |
| 1210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | /* |
| 1212 | * OPEN_RECLAIM: |
| 1213 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1215 | static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1217 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1218 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1219 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | int status; |
| 1221 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1222 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1223 | if (IS_ERR(opendata)) |
| 1224 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1225 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1226 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1227 | rcu_read_lock(); |
| 1228 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1229 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1230 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1231 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1232 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1233 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1234 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | return status; |
| 1236 | } |
| 1237 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1238 | static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | { |
| 1240 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1241 | struct nfs4_exception exception = { }; |
| 1242 | int err; |
| 1243 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1244 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1245 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1246 | break; |
| 1247 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | } while (exception.retry); |
| 1249 | return err; |
| 1250 | } |
| 1251 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1252 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1253 | { |
| 1254 | struct nfs_open_context *ctx; |
| 1255 | int ret; |
| 1256 | |
| 1257 | ctx = nfs4_state_find_open_context(state); |
| 1258 | if (IS_ERR(ctx)) |
| 1259 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1260 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1261 | put_nfs_open_context(ctx); |
| 1262 | return ret; |
| 1263 | } |
| 1264 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1265 | static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1267 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1268 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1270 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1271 | if (IS_ERR(opendata)) |
| 1272 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1273 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1274 | memcpy(opendata->o_arg.u.delegation.data, stateid->data, |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1275 | sizeof(opendata->o_arg.u.delegation.data)); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1276 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1277 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1278 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1281 | int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | { |
| 1283 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1284 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | int err; |
| 1286 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1287 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | switch (err) { |
| 1289 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1290 | case -ENOENT: |
| 1291 | case -ESTALE: |
| 1292 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1293 | case -NFS4ERR_BADSESSION: |
| 1294 | case -NFS4ERR_BADSLOT: |
| 1295 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1296 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1297 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1298 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1299 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | case -NFS4ERR_STALE_CLIENTID: |
| 1301 | case -NFS4ERR_STALE_STATEID: |
| 1302 | case -NFS4ERR_EXPIRED: |
| 1303 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1304 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1305 | goto out; |
| 1306 | case -ERESTARTSYS: |
| 1307 | /* |
| 1308 | * The show must go on: exit, but mark the |
| 1309 | * stateid as needing recovery. |
| 1310 | */ |
| 1311 | case -NFS4ERR_ADMIN_REVOKED: |
| 1312 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1313 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1314 | case -EKEYEXPIRED: |
| 1315 | /* |
| 1316 | * User RPCSEC_GSS context has expired. |
| 1317 | * We cannot recover this stateid now, so |
| 1318 | * skip it and allow recovery thread to |
| 1319 | * proceed. |
| 1320 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1321 | case -ENOMEM: |
| 1322 | err = 0; |
| 1323 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | } |
| 1325 | err = nfs4_handle_exception(server, err, &exception); |
| 1326 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1327 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | return err; |
| 1329 | } |
| 1330 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1331 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1332 | { |
| 1333 | struct nfs4_opendata *data = calldata; |
| 1334 | |
| 1335 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1336 | if (data->rpc_status == 0) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1337 | memcpy(data->o_res.stateid.data, data->c_res.stateid.data, |
| 1338 | sizeof(data->o_res.stateid.data)); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1339 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1340 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1341 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1342 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static void nfs4_open_confirm_release(void *calldata) |
| 1346 | { |
| 1347 | struct nfs4_opendata *data = calldata; |
| 1348 | struct nfs4_state *state = NULL; |
| 1349 | |
| 1350 | /* If this request hasn't been cancelled, do nothing */ |
| 1351 | if (data->cancelled == 0) |
| 1352 | goto out_free; |
| 1353 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1354 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1355 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1356 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1357 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1358 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1359 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1360 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1364 | .rpc_call_done = nfs4_open_confirm_done, |
| 1365 | .rpc_release = nfs4_open_confirm_release, |
| 1366 | }; |
| 1367 | |
| 1368 | /* |
| 1369 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1370 | */ |
| 1371 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1372 | { |
| 1373 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1374 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1375 | struct rpc_message msg = { |
| 1376 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1377 | .rpc_argp = &data->c_arg, |
| 1378 | .rpc_resp = &data->c_res, |
| 1379 | .rpc_cred = data->owner->so_cred, |
| 1380 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1381 | struct rpc_task_setup task_setup_data = { |
| 1382 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1383 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1384 | .callback_ops = &nfs4_open_confirm_ops, |
| 1385 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1386 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1387 | .flags = RPC_TASK_ASYNC, |
| 1388 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | int status; |
| 1390 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1391 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1392 | data->rpc_done = 0; |
| 1393 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1394 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1395 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1396 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1397 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1398 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1399 | if (status != 0) { |
| 1400 | data->cancelled = 1; |
| 1401 | smp_wmb(); |
| 1402 | } else |
| 1403 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1404 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | return status; |
| 1406 | } |
| 1407 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1408 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1410 | struct nfs4_opendata *data = calldata; |
| 1411 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1412 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1413 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1414 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1415 | /* |
| 1416 | * Check if we still need to send an OPEN call, or if we can use |
| 1417 | * a delegation instead. |
| 1418 | */ |
| 1419 | if (data->state != NULL) { |
| 1420 | struct nfs_delegation *delegation; |
| 1421 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1422 | if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags)) |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1423 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1424 | rcu_read_lock(); |
| 1425 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
| 1426 | if (delegation != NULL && |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1427 | test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1428 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1429 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1430 | } |
| 1431 | rcu_read_unlock(); |
| 1432 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1433 | /* Update sequence id. */ |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 1434 | data->o_arg.id = sp->so_owner_id.id; |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1435 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1436 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1437 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1438 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1439 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1440 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1441 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1442 | &data->o_arg.seq_args, |
| 1443 | &data->o_res.seq_res, 1, task)) |
| 1444 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1445 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1446 | return; |
| 1447 | out_no_action: |
| 1448 | task->tk_action = NULL; |
| 1449 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1452 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1453 | { |
| 1454 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1455 | nfs4_open_prepare(task, calldata); |
| 1456 | } |
| 1457 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1458 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1459 | { |
| 1460 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1462 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1463 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1464 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1465 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1466 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1467 | if (task->tk_status == 0) { |
| 1468 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1469 | case S_IFREG: |
| 1470 | break; |
| 1471 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1472 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1473 | break; |
| 1474 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1475 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1476 | break; |
| 1477 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1478 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1479 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1480 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1481 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1482 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1483 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1484 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1485 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1486 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1487 | static void nfs4_open_release(void *calldata) |
| 1488 | { |
| 1489 | struct nfs4_opendata *data = calldata; |
| 1490 | struct nfs4_state *state = NULL; |
| 1491 | |
| 1492 | /* If this request hasn't been cancelled, do nothing */ |
| 1493 | if (data->cancelled == 0) |
| 1494 | goto out_free; |
| 1495 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1496 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1497 | goto out_free; |
| 1498 | /* In case we need an open_confirm, no cleanup! */ |
| 1499 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1500 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1501 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1502 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1503 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1504 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1505 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1509 | .rpc_call_prepare = nfs4_open_prepare, |
| 1510 | .rpc_call_done = nfs4_open_done, |
| 1511 | .rpc_release = nfs4_open_release, |
| 1512 | }; |
| 1513 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1514 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1515 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1516 | .rpc_call_done = nfs4_open_done, |
| 1517 | .rpc_release = nfs4_open_release, |
| 1518 | }; |
| 1519 | |
| 1520 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1521 | { |
| 1522 | struct inode *dir = data->dir->d_inode; |
| 1523 | struct nfs_server *server = NFS_SERVER(dir); |
| 1524 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1525 | struct nfs_openres *o_res = &data->o_res; |
| 1526 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1527 | struct rpc_message msg = { |
| 1528 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1529 | .rpc_argp = o_arg, |
| 1530 | .rpc_resp = o_res, |
| 1531 | .rpc_cred = data->owner->so_cred, |
| 1532 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1533 | struct rpc_task_setup task_setup_data = { |
| 1534 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1535 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1536 | .callback_ops = &nfs4_open_ops, |
| 1537 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1538 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1539 | .flags = RPC_TASK_ASYNC, |
| 1540 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1541 | int status; |
| 1542 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1543 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1544 | data->rpc_done = 0; |
| 1545 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1546 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1547 | if (isrecover) |
| 1548 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1549 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1550 | if (IS_ERR(task)) |
| 1551 | return PTR_ERR(task); |
| 1552 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1553 | if (status != 0) { |
| 1554 | data->cancelled = 1; |
| 1555 | smp_wmb(); |
| 1556 | } else |
| 1557 | status = data->rpc_status; |
| 1558 | rpc_put_task(task); |
| 1559 | |
| 1560 | return status; |
| 1561 | } |
| 1562 | |
| 1563 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1564 | { |
| 1565 | struct inode *dir = data->dir->d_inode; |
| 1566 | struct nfs_openres *o_res = &data->o_res; |
| 1567 | int status; |
| 1568 | |
| 1569 | status = nfs4_run_open_task(data, 1); |
| 1570 | if (status != 0 || !data->rpc_done) |
| 1571 | return status; |
| 1572 | |
| 1573 | nfs_refresh_inode(dir, o_res->dir_attr); |
| 1574 | |
| 1575 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1576 | status = _nfs4_proc_open_confirm(data); |
| 1577 | if (status != 0) |
| 1578 | return status; |
| 1579 | } |
| 1580 | |
| 1581 | return status; |
| 1582 | } |
| 1583 | |
| 1584 | /* |
| 1585 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1586 | */ |
| 1587 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1588 | { |
| 1589 | struct inode *dir = data->dir->d_inode; |
| 1590 | struct nfs_server *server = NFS_SERVER(dir); |
| 1591 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1592 | struct nfs_openres *o_res = &data->o_res; |
| 1593 | int status; |
| 1594 | |
| 1595 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1596 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1597 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1598 | if (status != 0) { |
| 1599 | if (status == -NFS4ERR_BADNAME && |
| 1600 | !(o_arg->open_flags & O_CREAT)) |
| 1601 | return -ENOENT; |
| 1602 | return status; |
| 1603 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1604 | |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1605 | if (o_arg->open_flags & O_CREAT) { |
| 1606 | update_changeattr(dir, &o_res->cinfo); |
| 1607 | nfs_post_op_update_inode(dir, o_res->dir_attr); |
| 1608 | } else |
| 1609 | nfs_refresh_inode(dir, o_res->dir_attr); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1610 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1611 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1613 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1615 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | } |
| 1617 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1618 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1619 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1622 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1623 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1624 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1625 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1626 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1627 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1628 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1629 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1630 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1631 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1632 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1633 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1634 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1635 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1636 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1637 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1638 | } |
| 1639 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1640 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1641 | { |
| 1642 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1643 | } |
| 1644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | /* |
| 1646 | * OPEN_EXPIRED: |
| 1647 | * reclaim state on the server after a network partition. |
| 1648 | * Assumes caller holds the appropriate lock |
| 1649 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1650 | 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] | 1651 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1652 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1653 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1655 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1656 | if (IS_ERR(opendata)) |
| 1657 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1658 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1659 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1660 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1661 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1662 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1665 | 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] | 1666 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1667 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1668 | struct nfs4_exception exception = { }; |
| 1669 | int err; |
| 1670 | |
| 1671 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1672 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1673 | switch (err) { |
| 1674 | default: |
| 1675 | goto out; |
| 1676 | case -NFS4ERR_GRACE: |
| 1677 | case -NFS4ERR_DELAY: |
| 1678 | nfs4_handle_exception(server, err, &exception); |
| 1679 | err = 0; |
| 1680 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1681 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1682 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1683 | return err; |
| 1684 | } |
| 1685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1687 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1689 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1691 | ctx = nfs4_state_find_open_context(state); |
| 1692 | if (IS_ERR(ctx)) |
| 1693 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1694 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1695 | put_nfs_open_context(ctx); |
| 1696 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1699 | #if defined(CONFIG_NFS_V4_1) |
| 1700 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1701 | { |
| 1702 | int status; |
| 1703 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1704 | |
| 1705 | status = nfs41_test_stateid(server, state); |
| 1706 | if (status == NFS_OK) |
| 1707 | return 0; |
| 1708 | nfs41_free_stateid(server, state); |
| 1709 | return nfs4_open_expired(sp, state); |
| 1710 | } |
| 1711 | #endif |
| 1712 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1714 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1715 | * fields corresponding to attributes that were used to store the verifier. |
| 1716 | * Make sure we clobber those fields in the later setattr call |
| 1717 | */ |
| 1718 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1719 | { |
| 1720 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1721 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1722 | sattr->ia_valid |= ATTR_ATIME; |
| 1723 | |
| 1724 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1725 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1726 | sattr->ia_valid |= ATTR_MTIME; |
| 1727 | } |
| 1728 | |
| 1729 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1730 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | */ |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1732 | static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, 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] | 1733 | { |
| 1734 | struct nfs4_state_owner *sp; |
| 1735 | struct nfs4_state *state = NULL; |
| 1736 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1737 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1738 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | |
| 1740 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | status = -ENOMEM; |
| 1742 | if (!(sp = nfs4_get_state_owner(server, cred))) { |
| 1743 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1744 | goto out_err; |
| 1745 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1746 | status = nfs4_recover_expired_lease(server); |
| 1747 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1748 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1749 | if (dentry->d_inode != NULL) |
| 1750 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1751 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1752 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1753 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1754 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1756 | if (dentry->d_inode != NULL) |
| 1757 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1758 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1759 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1761 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1763 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1764 | status = PTR_ERR(state); |
| 1765 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1766 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1767 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1768 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1769 | |
| 1770 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1771 | nfs4_exclusive_attrset(opendata, sattr); |
| 1772 | |
| 1773 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1774 | status = nfs4_do_setattr(state->inode, cred, |
| 1775 | opendata->o_res.f_attr, sattr, |
| 1776 | state); |
| 1777 | if (status == 0) |
| 1778 | nfs_setattr_update_inode(state->inode, sattr); |
| 1779 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1780 | } |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1781 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | *res = state; |
| 1784 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1785 | err_opendata_put: |
| 1786 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1787 | err_put_state_owner: |
| 1788 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | *res = NULL; |
| 1791 | return status; |
| 1792 | } |
| 1793 | |
| 1794 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1795 | static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | { |
| 1797 | struct nfs4_exception exception = { }; |
| 1798 | struct nfs4_state *res; |
| 1799 | int status; |
| 1800 | |
| 1801 | do { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1802 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, &res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | if (status == 0) |
| 1804 | break; |
| 1805 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1806 | * book-keeping w.r.t. state-changing operations |
| 1807 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1808 | * It is actually a sign of a bug on the client or on the server. |
| 1809 | * |
| 1810 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1811 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | * have unhashed the old state_owner for us, and that we can |
| 1813 | * therefore safely retry using a new one. We should still warn |
| 1814 | * the user though... |
| 1815 | */ |
| 1816 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 1817 | printk(KERN_WARNING "NFS: v4 server %s " |
| 1818 | " returned a bad sequence-id error!\n", |
| 1819 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | exception.retry = 1; |
| 1821 | continue; |
| 1822 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 1823 | /* |
| 1824 | * BAD_STATEID on OPEN means that the server cancelled our |
| 1825 | * state before it received the OPEN_CONFIRM. |
| 1826 | * Recover by retrying the request as per the discussion |
| 1827 | * on Page 181 of RFC3530. |
| 1828 | */ |
| 1829 | if (status == -NFS4ERR_BAD_STATEID) { |
| 1830 | exception.retry = 1; |
| 1831 | continue; |
| 1832 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1833 | if (status == -EAGAIN) { |
| 1834 | /* We must have found a delegation */ |
| 1835 | exception.retry = 1; |
| 1836 | continue; |
| 1837 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 1839 | status, &exception)); |
| 1840 | } while (exception.retry); |
| 1841 | return res; |
| 1842 | } |
| 1843 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1844 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1845 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1846 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1848 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1850 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | .iap = sattr, |
| 1852 | .server = server, |
| 1853 | .bitmask = server->attr_bitmask, |
| 1854 | }; |
| 1855 | struct nfs_setattrres res = { |
| 1856 | .fattr = fattr, |
| 1857 | .server = server, |
| 1858 | }; |
| 1859 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1860 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 1861 | .rpc_argp = &arg, |
| 1862 | .rpc_resp = &res, |
| 1863 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1865 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1866 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 1868 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1870 | if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { |
| 1871 | /* Use that stateid */ |
| 1872 | } else if (state != NULL) { |
Trond Myklebust | 77041ed | 2010-07-01 12:49:11 -0400 | [diff] [blame] | 1873 | nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid); |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1874 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); |
| 1876 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 1877 | 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] | 1878 | if (status == 0 && state != NULL) |
| 1879 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 1880 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1883 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 1884 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 1885 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 1887 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | struct nfs4_exception exception = { }; |
| 1889 | int err; |
| 1890 | do { |
| 1891 | err = nfs4_handle_exception(server, |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 1892 | _nfs4_do_setattr(inode, cred, fattr, sattr, state), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | &exception); |
| 1894 | } while (exception.retry); |
| 1895 | return err; |
| 1896 | } |
| 1897 | |
| 1898 | struct nfs4_closedata { |
| 1899 | struct inode *inode; |
| 1900 | struct nfs4_state *state; |
| 1901 | struct nfs_closeargs arg; |
| 1902 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1903 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1904 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1905 | bool roc; |
| 1906 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | }; |
| 1908 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1909 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1910 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1911 | struct nfs4_closedata *calldata = data; |
| 1912 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1913 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1914 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1915 | if (calldata->roc) |
| 1916 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1917 | nfs4_put_open_state(calldata->state); |
| 1918 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1919 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1920 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1921 | kfree(calldata); |
| 1922 | } |
| 1923 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1924 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 1925 | fmode_t fmode) |
| 1926 | { |
| 1927 | spin_lock(&state->owner->so_lock); |
| 1928 | if (!(fmode & FMODE_READ)) |
| 1929 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1930 | if (!(fmode & FMODE_WRITE)) |
| 1931 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1932 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1933 | spin_unlock(&state->owner->so_lock); |
| 1934 | } |
| 1935 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1936 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1938 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 1941 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1942 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 1943 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | /* hmm. we are done with the inode, and in the process of freeing |
| 1945 | * the state_owner. we keep this around to process errors |
| 1946 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | switch (task->tk_status) { |
| 1948 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 1949 | if (calldata->roc) |
| 1950 | pnfs_roc_set_barrier(state->inode, |
| 1951 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 1952 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1953 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1954 | nfs4_close_clear_stateid_flags(state, |
| 1955 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | break; |
| 1957 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1958 | case -NFS4ERR_OLD_STATEID: |
| 1959 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1961 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 1962 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1964 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 1965 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 1967 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 1968 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1971 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 1973 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1974 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1975 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1976 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1977 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 1978 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1979 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1980 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 1981 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1982 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1983 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1984 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1985 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1986 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1987 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1988 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1989 | } |
| 1990 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1991 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1992 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1993 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1994 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 1995 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 1996 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 1997 | |
| 1998 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 1999 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2000 | task->tk_action = NULL; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2001 | return; |
| 2002 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2003 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2004 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2005 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2006 | if (calldata->roc && |
| 2007 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { |
| 2008 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, |
| 2009 | task, NULL); |
| 2010 | return; |
| 2011 | } |
| 2012 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2013 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2014 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2015 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 2016 | if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), |
Andy Adamson | 19ddab0 | 2009-04-01 09:22:20 -0400 | [diff] [blame] | 2017 | &calldata->arg.seq_args, &calldata->res.seq_res, |
| 2018 | 1, task)) |
| 2019 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2020 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2023 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2024 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2025 | .rpc_call_done = nfs4_close_done, |
| 2026 | .rpc_release = nfs4_free_closedata, |
| 2027 | }; |
| 2028 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | /* |
| 2030 | * It is possible for data to be read/written from a mem-mapped file |
| 2031 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2032 | * This means that we can't safely call nfsv4 close on a file until |
| 2033 | * the inode is cleared. This in turn means that we are not good |
| 2034 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2035 | * share state even when we are done with one of the three share |
| 2036 | * stateid's in the inode. |
| 2037 | * |
| 2038 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2039 | */ |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2040 | int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2042 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2044 | struct nfs4_state_owner *sp = state->owner; |
| 2045 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2046 | struct rpc_message msg = { |
| 2047 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2048 | .rpc_cred = state->owner->so_cred, |
| 2049 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2050 | struct rpc_task_setup task_setup_data = { |
| 2051 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2052 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2053 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2054 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2055 | .flags = RPC_TASK_ASYNC, |
| 2056 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2057 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2059 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2061 | goto out; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2062 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2064 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2065 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2067 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2068 | if (calldata->arg.seqid == NULL) |
| 2069 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2070 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2071 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2072 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2073 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2074 | calldata->res.server = server; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2075 | calldata->roc = roc; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2076 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2077 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2078 | msg.rpc_argp = &calldata->arg; |
| 2079 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2080 | task_setup_data.callback_data = calldata; |
| 2081 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2082 | if (IS_ERR(task)) |
| 2083 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2084 | status = 0; |
| 2085 | if (wait) |
| 2086 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2087 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2088 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2089 | out_free_calldata: |
| 2090 | kfree(calldata); |
| 2091 | out: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2092 | if (roc) |
| 2093 | pnfs_roc_release(state->inode); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2094 | nfs4_put_open_state(state); |
| 2095 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2096 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2099 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2100 | 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] | 2101 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | struct nfs4_state *state; |
| 2103 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2104 | /* Protect against concurrent sillydeletes */ |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2105 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, ctx->cred); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2106 | if (IS_ERR(state)) |
| 2107 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2108 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2109 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2112 | 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] | 2113 | { |
| 2114 | if (ctx->state == NULL) |
| 2115 | return; |
| 2116 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2117 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2118 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2119 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | |
| 2122 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2123 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2124 | struct nfs4_server_caps_arg args = { |
| 2125 | .fhandle = fhandle, |
| 2126 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | struct nfs4_server_caps_res res = {}; |
| 2128 | struct rpc_message msg = { |
| 2129 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2130 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | .rpc_resp = &res, |
| 2132 | }; |
| 2133 | int status; |
| 2134 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2135 | 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] | 2136 | if (status == 0) { |
| 2137 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2138 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2139 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2140 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2141 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2142 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2144 | server->caps |= NFS_CAP_ACLS; |
| 2145 | if (res.has_links != 0) |
| 2146 | server->caps |= NFS_CAP_HARDLINKS; |
| 2147 | if (res.has_symlinks != 0) |
| 2148 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460c | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2149 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2150 | server->caps |= NFS_CAP_FILEID; |
| 2151 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2152 | server->caps |= NFS_CAP_MODE; |
| 2153 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2154 | server->caps |= NFS_CAP_NLINK; |
| 2155 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2156 | server->caps |= NFS_CAP_OWNER; |
| 2157 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2158 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2159 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2160 | server->caps |= NFS_CAP_ATIME; |
| 2161 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2162 | server->caps |= NFS_CAP_CTIME; |
| 2163 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2164 | server->caps |= NFS_CAP_MTIME; |
| 2165 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2166 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2167 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2168 | 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] | 2169 | server->acl_bitmask = res.acl_bitmask; |
| 2170 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | return status; |
| 2173 | } |
| 2174 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2175 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | { |
| 2177 | struct nfs4_exception exception = { }; |
| 2178 | int err; |
| 2179 | do { |
| 2180 | err = nfs4_handle_exception(server, |
| 2181 | _nfs4_server_capabilities(server, fhandle), |
| 2182 | &exception); |
| 2183 | } while (exception.retry); |
| 2184 | return err; |
| 2185 | } |
| 2186 | |
| 2187 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2188 | struct nfs_fsinfo *info) |
| 2189 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | struct nfs4_lookup_root_arg args = { |
| 2191 | .bitmask = nfs4_fattr_bitmap, |
| 2192 | }; |
| 2193 | struct nfs4_lookup_res res = { |
| 2194 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2195 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | .fh = fhandle, |
| 2197 | }; |
| 2198 | struct rpc_message msg = { |
| 2199 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2200 | .rpc_argp = &args, |
| 2201 | .rpc_resp = &res, |
| 2202 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2203 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2204 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2205 | 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] | 2206 | } |
| 2207 | |
| 2208 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2209 | struct nfs_fsinfo *info) |
| 2210 | { |
| 2211 | struct nfs4_exception exception = { }; |
| 2212 | int err; |
| 2213 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2214 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2215 | switch (err) { |
| 2216 | case 0: |
| 2217 | case -NFS4ERR_WRONGSEC: |
| 2218 | break; |
| 2219 | default: |
| 2220 | err = nfs4_handle_exception(server, err, &exception); |
| 2221 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | } while (exception.retry); |
| 2223 | return err; |
| 2224 | } |
| 2225 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2226 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2227 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2228 | { |
| 2229 | struct rpc_auth *auth; |
| 2230 | int ret; |
| 2231 | |
| 2232 | auth = rpcauth_create(flavor, server->client); |
| 2233 | if (!auth) { |
| 2234 | ret = -EIO; |
| 2235 | goto out; |
| 2236 | } |
| 2237 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2238 | out: |
| 2239 | return ret; |
| 2240 | } |
| 2241 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2242 | static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 2243 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2245 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2246 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2248 | len = gss_mech_list_pseudoflavors(&flav_array[0]); |
| 2249 | flav_array[len] = RPC_AUTH_NULL; |
| 2250 | len += 1; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2251 | |
| 2252 | for (i = 0; i < len; i++) { |
| 2253 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2254 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2255 | continue; |
| 2256 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2257 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2258 | /* |
| 2259 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2260 | * to access the mount. It could also mean that we tried to mount |
| 2261 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2262 | * existing mount programs don't handle -EACCES very well so it should |
| 2263 | * be mapped to -EPERM instead. |
| 2264 | */ |
| 2265 | if (status == -EACCES) |
| 2266 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2267 | return status; |
| 2268 | } |
| 2269 | |
| 2270 | /* |
| 2271 | * get the file handle for the "/" directory on the server |
| 2272 | */ |
| 2273 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2274 | struct nfs_fsinfo *info) |
| 2275 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2276 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2277 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2278 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2279 | /* |
| 2280 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2281 | * by nfs4_map_errors() as this function exits. |
| 2282 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2283 | status = nfs_v4_minor_ops[minor_version]->find_root_sec(server, fhandle, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | if (status == 0) |
| 2285 | status = nfs4_server_capabilities(server, fhandle); |
| 2286 | if (status == 0) |
| 2287 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2288 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | } |
| 2290 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2291 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2292 | /* |
| 2293 | * Get locations and (maybe) other attributes of a referral. |
| 2294 | * Note that we'll actually follow the referral later when |
| 2295 | * we detect fsid mismatch in inode revalidation |
| 2296 | */ |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2297 | static int nfs4_get_referral(struct inode *dir, const struct qstr *name, |
| 2298 | struct nfs_fattr *fattr, struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2299 | { |
| 2300 | int status = -ENOMEM; |
| 2301 | struct page *page = NULL; |
| 2302 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2303 | |
| 2304 | page = alloc_page(GFP_KERNEL); |
| 2305 | if (page == NULL) |
| 2306 | goto out; |
| 2307 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2308 | if (locations == NULL) |
| 2309 | goto out; |
| 2310 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 2311 | status = nfs4_proc_fs_locations(dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2312 | if (status != 0) |
| 2313 | goto out; |
| 2314 | /* Make sure server returned a different fsid for the referral */ |
| 2315 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2316 | dprintk("%s: server did not return a different fsid for" |
| 2317 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2318 | status = -EIO; |
| 2319 | goto out; |
| 2320 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2321 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2322 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2323 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2324 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2325 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2326 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2327 | out: |
| 2328 | if (page) |
| 2329 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2330 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2331 | return status; |
| 2332 | } |
| 2333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2335 | { |
| 2336 | struct nfs4_getattr_arg args = { |
| 2337 | .fh = fhandle, |
| 2338 | .bitmask = server->attr_bitmask, |
| 2339 | }; |
| 2340 | struct nfs4_getattr_res res = { |
| 2341 | .fattr = fattr, |
| 2342 | .server = server, |
| 2343 | }; |
| 2344 | struct rpc_message msg = { |
| 2345 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2346 | .rpc_argp = &args, |
| 2347 | .rpc_resp = &res, |
| 2348 | }; |
| 2349 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2350 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2351 | 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] | 2352 | } |
| 2353 | |
| 2354 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2355 | { |
| 2356 | struct nfs4_exception exception = { }; |
| 2357 | int err; |
| 2358 | do { |
| 2359 | err = nfs4_handle_exception(server, |
| 2360 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2361 | &exception); |
| 2362 | } while (exception.retry); |
| 2363 | return err; |
| 2364 | } |
| 2365 | |
| 2366 | /* |
| 2367 | * The file is not closed if it is opened due to the a request to change |
| 2368 | * the size of the file. The open call will not be needed once the |
| 2369 | * VFS layer lookup-intents are implemented. |
| 2370 | * |
| 2371 | * Close is called when the inode is destroyed. |
| 2372 | * If we haven't opened the file for O_WRONLY, we |
| 2373 | * need to in the size_change case to obtain a stateid. |
| 2374 | * |
| 2375 | * Got race? |
| 2376 | * Because OPEN is always done by name in nfsv4, it is |
| 2377 | * possible that we opened a different file by the same |
| 2378 | * name. We can recognize this race condition, but we |
| 2379 | * can't do anything about it besides returning an error. |
| 2380 | * |
| 2381 | * This will be fixed with VFS changes (lookup-intent). |
| 2382 | */ |
| 2383 | static int |
| 2384 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2385 | struct iattr *sattr) |
| 2386 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2387 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2388 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2389 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | int status; |
| 2391 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2392 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2393 | pnfs_return_layout(inode); |
| 2394 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2395 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2397 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2398 | if (sattr->ia_valid & ATTR_FILE) { |
| 2399 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2400 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2401 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2402 | if (ctx) { |
| 2403 | cred = ctx->cred; |
| 2404 | state = ctx->state; |
| 2405 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2409 | if (status == 0) |
| 2410 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | return status; |
| 2412 | } |
| 2413 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2414 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2415 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2416 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2417 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2418 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2419 | int status; |
| 2420 | struct nfs4_lookup_arg args = { |
| 2421 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2422 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2423 | .name = name, |
| 2424 | }; |
| 2425 | struct nfs4_lookup_res res = { |
| 2426 | .server = server, |
| 2427 | .fattr = fattr, |
| 2428 | .fh = fhandle, |
| 2429 | }; |
| 2430 | struct rpc_message msg = { |
| 2431 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2432 | .rpc_argp = &args, |
| 2433 | .rpc_resp = &res, |
| 2434 | }; |
| 2435 | |
| 2436 | nfs_fattr_init(fattr); |
| 2437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2439 | status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | dprintk("NFS reply lookup: %d\n", status); |
| 2441 | return status; |
| 2442 | } |
| 2443 | |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2444 | void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr, struct nfs_fh *fh) |
| 2445 | { |
| 2446 | memset(fh, 0, sizeof(struct nfs_fh)); |
| 2447 | fattr->fsid.major = 1; |
| 2448 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 2449 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_FSID | NFS_ATTR_FATTR_MOUNTPOINT; |
| 2450 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2451 | fattr->nlink = 2; |
| 2452 | } |
| 2453 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2454 | static int nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, struct qstr *name, |
| 2455 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | { |
| 2457 | struct nfs4_exception exception = { }; |
| 2458 | int err; |
| 2459 | do { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2460 | int status; |
| 2461 | |
| 2462 | status = _nfs4_proc_lookup(clnt, dir, name, fhandle, fattr); |
| 2463 | switch (status) { |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 2464 | case -NFS4ERR_BADNAME: |
| 2465 | return -ENOENT; |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2466 | case -NFS4ERR_MOVED: |
Trond Myklebust | a6f498a | 2011-11-07 15:50:32 -0500 | [diff] [blame] | 2467 | return nfs4_get_referral(dir, name, fattr, fhandle); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2468 | case -NFS4ERR_WRONGSEC: |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2469 | nfs_fixup_secinfo_attributes(fattr, fhandle); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2470 | } |
| 2471 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2472 | status, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | } while (exception.retry); |
| 2474 | return err; |
| 2475 | } |
| 2476 | |
| 2477 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2478 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2479 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | struct nfs4_accessargs args = { |
| 2481 | .fh = NFS_FH(inode), |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2482 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2484 | struct nfs4_accessres res = { |
| 2485 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2486 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | struct rpc_message msg = { |
| 2488 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2489 | .rpc_argp = &args, |
| 2490 | .rpc_resp = &res, |
| 2491 | .rpc_cred = entry->cred, |
| 2492 | }; |
| 2493 | int mode = entry->mask; |
| 2494 | int status; |
| 2495 | |
| 2496 | /* |
| 2497 | * Determine which access bits we want to ask for... |
| 2498 | */ |
| 2499 | if (mode & MAY_READ) |
| 2500 | args.access |= NFS4_ACCESS_READ; |
| 2501 | if (S_ISDIR(inode->i_mode)) { |
| 2502 | if (mode & MAY_WRITE) |
| 2503 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2504 | if (mode & MAY_EXEC) |
| 2505 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2506 | } else { |
| 2507 | if (mode & MAY_WRITE) |
| 2508 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2509 | if (mode & MAY_EXEC) |
| 2510 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2511 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2512 | |
| 2513 | res.fattr = nfs_alloc_fattr(); |
| 2514 | if (res.fattr == NULL) |
| 2515 | return -ENOMEM; |
| 2516 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2517 | 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] | 2518 | if (!status) { |
| 2519 | entry->mask = 0; |
| 2520 | if (res.access & NFS4_ACCESS_READ) |
| 2521 | entry->mask |= MAY_READ; |
| 2522 | if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE)) |
| 2523 | entry->mask |= MAY_WRITE; |
| 2524 | if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE)) |
| 2525 | entry->mask |= MAY_EXEC; |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2526 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2528 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | return status; |
| 2530 | } |
| 2531 | |
| 2532 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2533 | { |
| 2534 | struct nfs4_exception exception = { }; |
| 2535 | int err; |
| 2536 | do { |
| 2537 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2538 | _nfs4_proc_access(inode, entry), |
| 2539 | &exception); |
| 2540 | } while (exception.retry); |
| 2541 | return err; |
| 2542 | } |
| 2543 | |
| 2544 | /* |
| 2545 | * TODO: For the time being, we don't try to get any attributes |
| 2546 | * along with any of the zero-copy operations READ, READDIR, |
| 2547 | * READLINK, WRITE. |
| 2548 | * |
| 2549 | * In the case of the first three, we want to put the GETATTR |
| 2550 | * after the read-type operation -- this is because it is hard |
| 2551 | * to predict the length of a GETATTR response in v4, and thus |
| 2552 | * align the READ data correctly. This means that the GETATTR |
| 2553 | * may end up partially falling into the page cache, and we should |
| 2554 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2555 | * To do this efficiently, we need to know the total length |
| 2556 | * of data received, which doesn't seem to be available outside |
| 2557 | * of the RPC layer. |
| 2558 | * |
| 2559 | * In the case of WRITE, we also want to put the GETATTR after |
| 2560 | * the operation -- in this case because we want to make sure |
| 2561 | * we get the post-operation mtime and size. This means that |
| 2562 | * we can't use xdr_encode_pages() as written: we need a variant |
| 2563 | * of it which would leave room in the 'tail' iovec. |
| 2564 | * |
| 2565 | * Both of these changes to the XDR layer would in fact be quite |
| 2566 | * minor, but I decided to leave them for a subsequent patch. |
| 2567 | */ |
| 2568 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2569 | unsigned int pgbase, unsigned int pglen) |
| 2570 | { |
| 2571 | struct nfs4_readlink args = { |
| 2572 | .fh = NFS_FH(inode), |
| 2573 | .pgbase = pgbase, |
| 2574 | .pglen = pglen, |
| 2575 | .pages = &page, |
| 2576 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2577 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | struct rpc_message msg = { |
| 2579 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2580 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2581 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | }; |
| 2583 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2584 | 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] | 2585 | } |
| 2586 | |
| 2587 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2588 | unsigned int pgbase, unsigned int pglen) |
| 2589 | { |
| 2590 | struct nfs4_exception exception = { }; |
| 2591 | int err; |
| 2592 | do { |
| 2593 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2594 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2595 | &exception); |
| 2596 | } while (exception.retry); |
| 2597 | return err; |
| 2598 | } |
| 2599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | /* |
| 2601 | * Got race? |
| 2602 | * We will need to arrange for the VFS layer to provide an atomic open. |
| 2603 | * Until then, this create/open method is prone to inefficiency and race |
| 2604 | * conditions due to the lookup, create, and open VFS calls from sys_open() |
| 2605 | * placed on the wire. |
| 2606 | * |
| 2607 | * Given the above sorry state of affairs, I'm simply sending an OPEN. |
| 2608 | * The file will be opened again in the subsequent VFS open call |
| 2609 | * (nfs4_proc_file_open). |
| 2610 | * |
| 2611 | * The open for read will just hang around to be used by any process that |
| 2612 | * opens the file O_RDONLY. This will all be resolved with the VFS changes. |
| 2613 | */ |
| 2614 | |
| 2615 | static int |
| 2616 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2617 | int flags, struct nfs_open_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2619 | struct dentry *de = dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | struct nfs4_state *state; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2621 | struct rpc_cred *cred = NULL; |
| 2622 | fmode_t fmode = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | int status = 0; |
| 2624 | |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2625 | if (ctx != NULL) { |
| 2626 | cred = ctx->cred; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 2627 | de = ctx->dentry; |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2628 | fmode = ctx->mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | } |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2630 | sattr->ia_mode &= ~current_umask(); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 2631 | state = nfs4_do_open(dir, de, fmode, flags, sattr, cred); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2632 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | if (IS_ERR(state)) { |
| 2634 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2635 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2637 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2638 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2639 | if (ctx != NULL) |
| 2640 | ctx->state = state; |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 2641 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2642 | nfs4_close_sync(state, fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | out: |
| 2644 | return status; |
| 2645 | } |
| 2646 | |
| 2647 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2648 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2649 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2650 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | .fh = NFS_FH(dir), |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2652 | .name.len = name->len, |
| 2653 | .name.name = name->name, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2654 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2656 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2657 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2658 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2660 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2661 | .rpc_argp = &args, |
| 2662 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | }; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2664 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2666 | res.dir_attr = nfs_alloc_fattr(); |
| 2667 | if (res.dir_attr == NULL) |
| 2668 | goto out; |
| 2669 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2670 | 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] | 2671 | if (status == 0) { |
| 2672 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2673 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2674 | } |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2675 | nfs_free_fattr(res.dir_attr); |
| 2676 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | return status; |
| 2678 | } |
| 2679 | |
| 2680 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2681 | { |
| 2682 | struct nfs4_exception exception = { }; |
| 2683 | int err; |
| 2684 | do { |
| 2685 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2686 | _nfs4_proc_remove(dir, name), |
| 2687 | &exception); |
| 2688 | } while (exception.retry); |
| 2689 | return err; |
| 2690 | } |
| 2691 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2692 | 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] | 2693 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2694 | struct nfs_server *server = NFS_SERVER(dir); |
| 2695 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2696 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2698 | args->bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2699 | res->server = server; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 2700 | res->seq_res.sr_slot = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2704 | 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] | 2705 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2706 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2707 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2708 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2709 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2710 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2711 | return 0; |
| 2712 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2713 | nfs_post_op_update_inode(dir, res->dir_attr); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2714 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | } |
| 2716 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2717 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2718 | { |
| 2719 | struct nfs_server *server = NFS_SERVER(dir); |
| 2720 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2721 | struct nfs_renameres *res = msg->rpc_resp; |
| 2722 | |
| 2723 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
| 2724 | arg->bitmask = server->attr_bitmask; |
| 2725 | res->server = server; |
| 2726 | } |
| 2727 | |
| 2728 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 2729 | struct inode *new_dir) |
| 2730 | { |
| 2731 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 2732 | |
| 2733 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2734 | return 0; |
| 2735 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 2736 | return 0; |
| 2737 | |
| 2738 | update_changeattr(old_dir, &res->old_cinfo); |
| 2739 | nfs_post_op_update_inode(old_dir, res->old_fattr); |
| 2740 | update_changeattr(new_dir, &res->new_cinfo); |
| 2741 | nfs_post_op_update_inode(new_dir, res->new_fattr); |
| 2742 | return 1; |
| 2743 | } |
| 2744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2746 | struct inode *new_dir, struct qstr *new_name) |
| 2747 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2748 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 2749 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | .old_dir = NFS_FH(old_dir), |
| 2751 | .new_dir = NFS_FH(new_dir), |
| 2752 | .old_name = old_name, |
| 2753 | .new_name = new_name, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2754 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 2756 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2757 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2758 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | struct rpc_message msg = { |
| 2760 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 2761 | .rpc_argp = &arg, |
| 2762 | .rpc_resp = &res, |
| 2763 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2764 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2766 | res.old_fattr = nfs_alloc_fattr(); |
| 2767 | res.new_fattr = nfs_alloc_fattr(); |
| 2768 | if (res.old_fattr == NULL || res.new_fattr == NULL) |
| 2769 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2771 | 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] | 2772 | if (!status) { |
| 2773 | update_changeattr(old_dir, &res.old_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2774 | nfs_post_op_update_inode(old_dir, res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | update_changeattr(new_dir, &res.new_cinfo); |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 2776 | nfs_post_op_update_inode(new_dir, res.new_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | } |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2778 | out: |
| 2779 | nfs_free_fattr(res.new_fattr); |
| 2780 | nfs_free_fattr(res.old_fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | return status; |
| 2782 | } |
| 2783 | |
| 2784 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 2785 | struct inode *new_dir, struct qstr *new_name) |
| 2786 | { |
| 2787 | struct nfs4_exception exception = { }; |
| 2788 | int err; |
| 2789 | do { |
| 2790 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 2791 | _nfs4_proc_rename(old_dir, old_name, |
| 2792 | new_dir, new_name), |
| 2793 | &exception); |
| 2794 | } while (exception.retry); |
| 2795 | return err; |
| 2796 | } |
| 2797 | |
| 2798 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2799 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2800 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | struct nfs4_link_arg arg = { |
| 2802 | .fh = NFS_FH(inode), |
| 2803 | .dir_fh = NFS_FH(dir), |
| 2804 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2805 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2807 | struct nfs4_link_res res = { |
| 2808 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2809 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | struct rpc_message msg = { |
| 2811 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 2812 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2813 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2815 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2817 | res.fattr = nfs_alloc_fattr(); |
| 2818 | res.dir_attr = nfs_alloc_fattr(); |
| 2819 | if (res.fattr == NULL || res.dir_attr == NULL) |
| 2820 | goto out; |
| 2821 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2822 | 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] | 2823 | if (!status) { |
| 2824 | update_changeattr(dir, &res.cinfo); |
| 2825 | nfs_post_op_update_inode(dir, res.dir_attr); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 2826 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 2827 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 2828 | out: |
| 2829 | nfs_free_fattr(res.dir_attr); |
| 2830 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | return status; |
| 2832 | } |
| 2833 | |
| 2834 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 2835 | { |
| 2836 | struct nfs4_exception exception = { }; |
| 2837 | int err; |
| 2838 | do { |
| 2839 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2840 | _nfs4_proc_link(inode, dir, name), |
| 2841 | &exception); |
| 2842 | } while (exception.retry); |
| 2843 | return err; |
| 2844 | } |
| 2845 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2846 | struct nfs4_createdata { |
| 2847 | struct rpc_message msg; |
| 2848 | struct nfs4_create_arg arg; |
| 2849 | struct nfs4_create_res res; |
| 2850 | struct nfs_fh fh; |
| 2851 | struct nfs_fattr fattr; |
| 2852 | struct nfs_fattr dir_fattr; |
| 2853 | }; |
| 2854 | |
| 2855 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 2856 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 2857 | { |
| 2858 | struct nfs4_createdata *data; |
| 2859 | |
| 2860 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2861 | if (data != NULL) { |
| 2862 | struct nfs_server *server = NFS_SERVER(dir); |
| 2863 | |
| 2864 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 2865 | data->msg.rpc_argp = &data->arg; |
| 2866 | data->msg.rpc_resp = &data->res; |
| 2867 | data->arg.dir_fh = NFS_FH(dir); |
| 2868 | data->arg.server = server; |
| 2869 | data->arg.name = name; |
| 2870 | data->arg.attrs = sattr; |
| 2871 | data->arg.ftype = ftype; |
| 2872 | data->arg.bitmask = server->attr_bitmask; |
| 2873 | data->res.server = server; |
| 2874 | data->res.fh = &data->fh; |
| 2875 | data->res.fattr = &data->fattr; |
| 2876 | data->res.dir_fattr = &data->dir_fattr; |
| 2877 | nfs_fattr_init(data->res.fattr); |
| 2878 | nfs_fattr_init(data->res.dir_fattr); |
| 2879 | } |
| 2880 | return data; |
| 2881 | } |
| 2882 | |
| 2883 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 2884 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2885 | 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] | 2886 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2887 | if (status == 0) { |
| 2888 | update_changeattr(dir, &data->res.dir_cinfo); |
| 2889 | nfs_post_op_update_inode(dir, data->res.dir_fattr); |
| 2890 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 2891 | } |
| 2892 | return status; |
| 2893 | } |
| 2894 | |
| 2895 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 2896 | { |
| 2897 | kfree(data); |
| 2898 | } |
| 2899 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2900 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2901 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2903 | struct nfs4_createdata *data; |
| 2904 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2906 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2907 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2908 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2909 | status = -ENOMEM; |
| 2910 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 2911 | if (data == NULL) |
| 2912 | goto out; |
| 2913 | |
| 2914 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 2915 | data->arg.u.symlink.pages = &page; |
| 2916 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2918 | status = nfs4_do_create(dir, dentry, data); |
| 2919 | |
| 2920 | nfs4_free_createdata(data); |
| 2921 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | return status; |
| 2923 | } |
| 2924 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 2925 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2926 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | { |
| 2928 | struct nfs4_exception exception = { }; |
| 2929 | int err; |
| 2930 | do { |
| 2931 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 2932 | _nfs4_proc_symlink(dir, dentry, page, |
| 2933 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | &exception); |
| 2935 | } while (exception.retry); |
| 2936 | return err; |
| 2937 | } |
| 2938 | |
| 2939 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2940 | struct iattr *sattr) |
| 2941 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2942 | struct nfs4_createdata *data; |
| 2943 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 2945 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 2946 | if (data == NULL) |
| 2947 | goto out; |
| 2948 | |
| 2949 | status = nfs4_do_create(dir, dentry, data); |
| 2950 | |
| 2951 | nfs4_free_createdata(data); |
| 2952 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | return status; |
| 2954 | } |
| 2955 | |
| 2956 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 2957 | struct iattr *sattr) |
| 2958 | { |
| 2959 | struct nfs4_exception exception = { }; |
| 2960 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2961 | |
| 2962 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | do { |
| 2964 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2965 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 2966 | &exception); |
| 2967 | } while (exception.retry); |
| 2968 | return err; |
| 2969 | } |
| 2970 | |
| 2971 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2972 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | { |
| 2974 | struct inode *dir = dentry->d_inode; |
| 2975 | struct nfs4_readdir_arg args = { |
| 2976 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 2977 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | .pgbase = 0, |
| 2979 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 2980 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 2981 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | }; |
| 2983 | struct nfs4_readdir_res res; |
| 2984 | struct rpc_message msg = { |
| 2985 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 2986 | .rpc_argp = &args, |
| 2987 | .rpc_resp = &res, |
| 2988 | .rpc_cred = cred, |
| 2989 | }; |
| 2990 | int status; |
| 2991 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 2992 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 2993 | dentry->d_parent->d_name.name, |
| 2994 | dentry->d_name.name, |
| 2995 | (unsigned long long)cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args); |
| 2997 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2998 | 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] | 2999 | if (status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3000 | memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3001 | status += args.pgbase; |
| 3002 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3003 | |
| 3004 | nfs_invalidate_atime(dir); |
| 3005 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3006 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | return status; |
| 3008 | } |
| 3009 | |
| 3010 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3011 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | { |
| 3013 | struct nfs4_exception exception = { }; |
| 3014 | int err; |
| 3015 | do { |
| 3016 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3017 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3018 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | &exception); |
| 3020 | } while (exception.retry); |
| 3021 | return err; |
| 3022 | } |
| 3023 | |
| 3024 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3025 | struct iattr *sattr, dev_t rdev) |
| 3026 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3027 | struct nfs4_createdata *data; |
| 3028 | int mode = sattr->ia_mode; |
| 3029 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | |
| 3031 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3032 | 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] | 3033 | |
| 3034 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3035 | if (data == NULL) |
| 3036 | goto out; |
| 3037 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3039 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3041 | data->arg.ftype = NF4BLK; |
| 3042 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3043 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | } |
| 3045 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3046 | data->arg.ftype = NF4CHR; |
| 3047 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3048 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3051 | status = nfs4_do_create(dir, dentry, data); |
| 3052 | |
| 3053 | nfs4_free_createdata(data); |
| 3054 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | return status; |
| 3056 | } |
| 3057 | |
| 3058 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3059 | struct iattr *sattr, dev_t rdev) |
| 3060 | { |
| 3061 | struct nfs4_exception exception = { }; |
| 3062 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3063 | |
| 3064 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | do { |
| 3066 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3067 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3068 | &exception); |
| 3069 | } while (exception.retry); |
| 3070 | return err; |
| 3071 | } |
| 3072 | |
| 3073 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3074 | struct nfs_fsstat *fsstat) |
| 3075 | { |
| 3076 | struct nfs4_statfs_arg args = { |
| 3077 | .fh = fhandle, |
| 3078 | .bitmask = server->attr_bitmask, |
| 3079 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3080 | struct nfs4_statfs_res res = { |
| 3081 | .fsstat = fsstat, |
| 3082 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | struct rpc_message msg = { |
| 3084 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3085 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3086 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | }; |
| 3088 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3089 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3090 | 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] | 3091 | } |
| 3092 | |
| 3093 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3094 | { |
| 3095 | struct nfs4_exception exception = { }; |
| 3096 | int err; |
| 3097 | do { |
| 3098 | err = nfs4_handle_exception(server, |
| 3099 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3100 | &exception); |
| 3101 | } while (exception.retry); |
| 3102 | return err; |
| 3103 | } |
| 3104 | |
| 3105 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3106 | struct nfs_fsinfo *fsinfo) |
| 3107 | { |
| 3108 | struct nfs4_fsinfo_arg args = { |
| 3109 | .fh = fhandle, |
| 3110 | .bitmask = server->attr_bitmask, |
| 3111 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3112 | struct nfs4_fsinfo_res res = { |
| 3113 | .fsinfo = fsinfo, |
| 3114 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | struct rpc_message msg = { |
| 3116 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3117 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3118 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | }; |
| 3120 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3121 | 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] | 3122 | } |
| 3123 | |
| 3124 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3125 | { |
| 3126 | struct nfs4_exception exception = { }; |
| 3127 | int err; |
| 3128 | |
| 3129 | do { |
| 3130 | err = nfs4_handle_exception(server, |
| 3131 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3132 | &exception); |
| 3133 | } while (exception.retry); |
| 3134 | return err; |
| 3135 | } |
| 3136 | |
| 3137 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3138 | { |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3139 | nfs_fattr_init(fsinfo->fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | return nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3141 | } |
| 3142 | |
| 3143 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3144 | struct nfs_pathconf *pathconf) |
| 3145 | { |
| 3146 | struct nfs4_pathconf_arg args = { |
| 3147 | .fh = fhandle, |
| 3148 | .bitmask = server->attr_bitmask, |
| 3149 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3150 | struct nfs4_pathconf_res res = { |
| 3151 | .pathconf = pathconf, |
| 3152 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | struct rpc_message msg = { |
| 3154 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3155 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3156 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | }; |
| 3158 | |
| 3159 | /* None of the pathconf attributes are mandatory to implement */ |
| 3160 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3161 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3162 | return 0; |
| 3163 | } |
| 3164 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3165 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3166 | 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] | 3167 | } |
| 3168 | |
| 3169 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3170 | struct nfs_pathconf *pathconf) |
| 3171 | { |
| 3172 | struct nfs4_exception exception = { }; |
| 3173 | int err; |
| 3174 | |
| 3175 | do { |
| 3176 | err = nfs4_handle_exception(server, |
| 3177 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3178 | &exception); |
| 3179 | } while (exception.retry); |
| 3180 | return err; |
| 3181 | } |
| 3182 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3183 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3184 | { |
| 3185 | nfs_invalidate_atime(data->inode); |
| 3186 | } |
| 3187 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3188 | 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] | 3189 | { |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3190 | struct nfs_server *server = NFS_SERVER(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3192 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3193 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3194 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3196 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3197 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3199 | renew_lease(server, data->timestamp); |
| 3200 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | } |
| 3202 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3203 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3204 | { |
| 3205 | |
| 3206 | dprintk("--> %s\n", __func__); |
| 3207 | |
| 3208 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3209 | return -EAGAIN; |
| 3210 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3211 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3212 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3213 | } |
| 3214 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3215 | 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] | 3216 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3218 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3219 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
Andy Adamson | cbdabc7f | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3222 | /* Reset the the nfs_read_data to send the read to the MDS. */ |
| 3223 | void nfs4_reset_read(struct rpc_task *task, struct nfs_read_data *data) |
| 3224 | { |
| 3225 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3226 | put_lseg(data->lseg); |
| 3227 | data->lseg = NULL; |
| 3228 | /* offsets will differ in the dense stripe case */ |
| 3229 | data->args.offset = data->mds_offset; |
| 3230 | data->ds_clp = NULL; |
| 3231 | data->args.fh = NFS_FH(data->inode); |
| 3232 | data->read_done_cb = nfs4_read_done_cb; |
| 3233 | task->tk_ops = data->mds_ops; |
| 3234 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3235 | } |
| 3236 | EXPORT_SYMBOL_GPL(nfs4_reset_read); |
| 3237 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3238 | 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] | 3239 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | struct inode *inode = data->inode; |
| 3241 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3242 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3243 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3244 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3246 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 3248 | nfs_post_op_update_inode_force_wcc(inode, data->res.fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3249 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3250 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | } |
| 3252 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3253 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3254 | { |
| 3255 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3256 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3257 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3258 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3259 | } |
| 3260 | |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3261 | /* Reset the the nfs_write_data to send the write to the MDS. */ |
| 3262 | void nfs4_reset_write(struct rpc_task *task, struct nfs_write_data *data) |
| 3263 | { |
| 3264 | dprintk("%s Reset task for i/o through\n", __func__); |
| 3265 | put_lseg(data->lseg); |
| 3266 | data->lseg = NULL; |
| 3267 | data->ds_clp = NULL; |
| 3268 | data->write_done_cb = nfs4_write_done_cb; |
| 3269 | data->args.fh = NFS_FH(data->inode); |
| 3270 | data->args.bitmask = data->res.server->cache_consistency_bitmask; |
| 3271 | data->args.offset = data->mds_offset; |
| 3272 | data->res.fattr = &data->fattr; |
| 3273 | task->tk_ops = data->mds_ops; |
| 3274 | rpc_task_reset_client(task, NFS_CLIENT(data->inode)); |
| 3275 | } |
| 3276 | EXPORT_SYMBOL_GPL(nfs4_reset_write); |
| 3277 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3278 | 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] | 3279 | { |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3280 | struct nfs_server *server = NFS_SERVER(data->inode); |
| 3281 | |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3282 | if (data->lseg) { |
| 3283 | data->args.bitmask = NULL; |
| 3284 | data->res.fattr = NULL; |
| 3285 | } else |
| 3286 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3287 | if (!data->write_done_cb) |
| 3288 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3289 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | data->timestamp = jiffies; |
| 3291 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3292 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3295 | static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3298 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3299 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3300 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3301 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | } |
Trond Myklebust | 9e08a3c | 2007-10-08 14:10:31 -0400 | [diff] [blame] | 3303 | nfs_refresh_inode(inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3304 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | } |
| 3306 | |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3307 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3308 | { |
| 3309 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3310 | return -EAGAIN; |
| 3311 | return data->write_done_cb(task, data); |
| 3312 | } |
| 3313 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3314 | 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] | 3315 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3316 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3317 | |
| 3318 | if (data->lseg) { |
| 3319 | data->args.bitmask = NULL; |
| 3320 | data->res.fattr = NULL; |
| 3321 | } else |
| 3322 | data->args.bitmask = server->cache_consistency_bitmask; |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3323 | if (!data->write_done_cb) |
| 3324 | data->write_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3325 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3326 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | } |
| 3328 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3329 | struct nfs4_renewdata { |
| 3330 | struct nfs_client *client; |
| 3331 | unsigned long timestamp; |
| 3332 | }; |
| 3333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | /* |
| 3335 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3336 | * standalone procedure for queueing an asynchronous RENEW. |
| 3337 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3338 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3339 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3340 | struct nfs4_renewdata *data = calldata; |
| 3341 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3342 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3343 | if (atomic_read(&clp->cl_count) > 1) |
| 3344 | nfs4_schedule_state_renewal(clp); |
| 3345 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3346 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3347 | } |
| 3348 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3349 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3351 | struct nfs4_renewdata *data = calldata; |
| 3352 | struct nfs_client *clp = data->client; |
| 3353 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | |
| 3355 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3356 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3357 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3358 | return; |
| 3359 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3360 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3361 | return; |
| 3362 | } |
| 3363 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3365 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | } |
| 3367 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3368 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3369 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3370 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3371 | }; |
| 3372 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3373 | static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | { |
| 3375 | struct rpc_message msg = { |
| 3376 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3377 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3378 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3380 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3382 | if (renew_flags == 0) |
| 3383 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3384 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3385 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3386 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3387 | if (data == NULL) |
| 3388 | return -ENOMEM; |
| 3389 | data->client = clp; |
| 3390 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3392 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3395 | static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | { |
| 3397 | struct rpc_message msg = { |
| 3398 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3399 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3400 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | }; |
| 3402 | unsigned long now = jiffies; |
| 3403 | int status; |
| 3404 | |
| 3405 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3406 | if (status < 0) |
| 3407 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3408 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | return 0; |
| 3410 | } |
| 3411 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3412 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3413 | { |
| 3414 | return (server->caps & NFS_CAP_ACLS) |
| 3415 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3416 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3417 | } |
| 3418 | |
| 3419 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that |
| 3420 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on |
| 3421 | * the stack. |
| 3422 | */ |
| 3423 | #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT) |
| 3424 | |
| 3425 | static void buf_to_pages(const void *buf, size_t buflen, |
| 3426 | struct page **pages, unsigned int *pgbase) |
| 3427 | { |
| 3428 | const void *p = buf; |
| 3429 | |
| 3430 | *pgbase = offset_in_page(buf); |
| 3431 | p -= *pgbase; |
| 3432 | while (p < buf + buflen) { |
| 3433 | *(pages++) = virt_to_page(p); |
| 3434 | p += PAGE_CACHE_SIZE; |
| 3435 | } |
| 3436 | } |
| 3437 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3438 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3439 | struct page **pages, unsigned int *pgbase) |
| 3440 | { |
| 3441 | struct page *newpage, **spages; |
| 3442 | int rc = 0; |
| 3443 | size_t len; |
| 3444 | spages = pages; |
| 3445 | |
| 3446 | do { |
Jovi Zhang | 43b7c3f | 2011-03-02 23:19:37 +0000 | [diff] [blame] | 3447 | len = min_t(size_t, PAGE_CACHE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3448 | newpage = alloc_page(GFP_KERNEL); |
| 3449 | |
| 3450 | if (newpage == NULL) |
| 3451 | goto unwind; |
| 3452 | memcpy(page_address(newpage), buf, len); |
| 3453 | buf += len; |
| 3454 | buflen -= len; |
| 3455 | *pages++ = newpage; |
| 3456 | rc++; |
| 3457 | } while (buflen != 0); |
| 3458 | |
| 3459 | return rc; |
| 3460 | |
| 3461 | unwind: |
| 3462 | for(; rc > 0; rc--) |
| 3463 | __free_page(spages[rc-1]); |
| 3464 | return -ENOMEM; |
| 3465 | } |
| 3466 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3467 | struct nfs4_cached_acl { |
| 3468 | int cached; |
| 3469 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3470 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3471 | }; |
| 3472 | |
| 3473 | 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] | 3474 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3475 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3476 | |
| 3477 | spin_lock(&inode->i_lock); |
| 3478 | kfree(nfsi->nfs4_acl); |
| 3479 | nfsi->nfs4_acl = acl; |
| 3480 | spin_unlock(&inode->i_lock); |
| 3481 | } |
| 3482 | |
| 3483 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3484 | { |
| 3485 | nfs4_set_cached_acl(inode, NULL); |
| 3486 | } |
| 3487 | |
| 3488 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3489 | { |
| 3490 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3491 | struct nfs4_cached_acl *acl; |
| 3492 | int ret = -ENOENT; |
| 3493 | |
| 3494 | spin_lock(&inode->i_lock); |
| 3495 | acl = nfsi->nfs4_acl; |
| 3496 | if (acl == NULL) |
| 3497 | goto out; |
| 3498 | if (buf == NULL) /* user is just asking for length */ |
| 3499 | goto out_len; |
| 3500 | if (acl->cached == 0) |
| 3501 | goto out; |
| 3502 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3503 | if (acl->len > buflen) |
| 3504 | goto out; |
| 3505 | memcpy(buf, acl->data, acl->len); |
| 3506 | out_len: |
| 3507 | ret = acl->len; |
| 3508 | out: |
| 3509 | spin_unlock(&inode->i_lock); |
| 3510 | return ret; |
| 3511 | } |
| 3512 | |
| 3513 | static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len) |
| 3514 | { |
| 3515 | struct nfs4_cached_acl *acl; |
| 3516 | |
| 3517 | if (buf && acl_len <= PAGE_SIZE) { |
| 3518 | acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL); |
| 3519 | if (acl == NULL) |
| 3520 | goto out; |
| 3521 | acl->cached = 1; |
| 3522 | memcpy(acl->data, buf, acl_len); |
| 3523 | } else { |
| 3524 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3525 | if (acl == NULL) |
| 3526 | goto out; |
| 3527 | acl->cached = 0; |
| 3528 | } |
| 3529 | acl->len = acl_len; |
| 3530 | out: |
| 3531 | nfs4_set_cached_acl(inode, acl); |
| 3532 | } |
| 3533 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3534 | 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] | 3535 | { |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3536 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3537 | struct nfs_getaclargs args = { |
| 3538 | .fh = NFS_FH(inode), |
| 3539 | .acl_pages = pages, |
| 3540 | .acl_len = buflen, |
| 3541 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3542 | struct nfs_getaclres res = { |
| 3543 | .acl_len = buflen, |
| 3544 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3545 | void *resp_buf; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3546 | struct rpc_message msg = { |
| 3547 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3548 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3549 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3550 | }; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3551 | struct page *localpage = NULL; |
| 3552 | int ret; |
| 3553 | |
| 3554 | if (buflen < PAGE_SIZE) { |
| 3555 | /* As long as we're doing a round trip to the server anyway, |
| 3556 | * let's be prepared for a page of acl data. */ |
| 3557 | localpage = alloc_page(GFP_KERNEL); |
| 3558 | resp_buf = page_address(localpage); |
| 3559 | if (localpage == NULL) |
| 3560 | return -ENOMEM; |
| 3561 | args.acl_pages[0] = localpage; |
| 3562 | args.acl_pgbase = 0; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3563 | args.acl_len = PAGE_SIZE; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3564 | } else { |
| 3565 | resp_buf = buf; |
| 3566 | buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase); |
| 3567 | } |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3568 | 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] | 3569 | if (ret) |
| 3570 | goto out_free; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3571 | if (res.acl_len > args.acl_len) |
| 3572 | nfs4_write_cached_acl(inode, NULL, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3573 | else |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3574 | nfs4_write_cached_acl(inode, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3575 | if (buf) { |
| 3576 | ret = -ERANGE; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3577 | if (res.acl_len > buflen) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3578 | goto out_free; |
| 3579 | if (localpage) |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3580 | memcpy(buf, resp_buf, res.acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3581 | } |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3582 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3583 | out_free: |
| 3584 | if (localpage) |
| 3585 | __free_page(localpage); |
| 3586 | return ret; |
| 3587 | } |
| 3588 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3589 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3590 | { |
| 3591 | struct nfs4_exception exception = { }; |
| 3592 | ssize_t ret; |
| 3593 | do { |
| 3594 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3595 | if (ret >= 0) |
| 3596 | break; |
| 3597 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3598 | } while (exception.retry); |
| 3599 | return ret; |
| 3600 | } |
| 3601 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3602 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3603 | { |
| 3604 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3605 | int ret; |
| 3606 | |
| 3607 | if (!nfs4_server_supports_acls(server)) |
| 3608 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3609 | ret = nfs_revalidate_inode(server, inode); |
| 3610 | if (ret < 0) |
| 3611 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3612 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3613 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3614 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3615 | if (ret != -ENOENT) |
| 3616 | return ret; |
| 3617 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3618 | } |
| 3619 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3620 | 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] | 3621 | { |
| 3622 | struct nfs_server *server = NFS_SERVER(inode); |
| 3623 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3624 | struct nfs_setaclargs arg = { |
| 3625 | .fh = NFS_FH(inode), |
| 3626 | .acl_pages = pages, |
| 3627 | .acl_len = buflen, |
| 3628 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3629 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3630 | struct rpc_message msg = { |
| 3631 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3632 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3633 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3634 | }; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3635 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3636 | |
| 3637 | if (!nfs4_server_supports_acls(server)) |
| 3638 | return -EOPNOTSUPP; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3639 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3640 | if (i < 0) |
| 3641 | return i; |
Trond Myklebust | 642ac54 | 2005-10-18 14:20:19 -0700 | [diff] [blame] | 3642 | nfs_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3643 | 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] | 3644 | |
| 3645 | /* |
| 3646 | * Free each page after tx, so the only ref left is |
| 3647 | * held by the network stack |
| 3648 | */ |
| 3649 | for (; i > 0; i--) |
| 3650 | put_page(pages[i-1]); |
| 3651 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3652 | /* |
| 3653 | * Acl update can result in inode attribute update. |
| 3654 | * so mark the attribute cache invalid. |
| 3655 | */ |
| 3656 | spin_lock(&inode->i_lock); |
| 3657 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3658 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3659 | nfs_access_zap_cache(inode); |
| 3660 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3661 | return ret; |
| 3662 | } |
| 3663 | |
Trond Myklebust | 16b4289c | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3664 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3665 | { |
| 3666 | struct nfs4_exception exception = { }; |
| 3667 | int err; |
| 3668 | do { |
| 3669 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3670 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3671 | &exception); |
| 3672 | } while (exception.retry); |
| 3673 | return err; |
| 3674 | } |
| 3675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3676 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3677 | 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] | 3678 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3679 | struct nfs_client *clp = server->nfs_client; |
| 3680 | |
| 3681 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | return 0; |
| 3683 | switch(task->tk_status) { |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3684 | case -NFS4ERR_ADMIN_REVOKED: |
| 3685 | case -NFS4ERR_BAD_STATEID: |
| 3686 | case -NFS4ERR_OPENMODE: |
| 3687 | if (state == NULL) |
| 3688 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3689 | nfs4_schedule_stateid_recovery(server, state); |
| 3690 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3691 | case -NFS4ERR_EXPIRED: |
| 3692 | if (state != NULL) |
| 3693 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3695 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3696 | nfs4_schedule_lease_recovery(clp); |
| 3697 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3698 | #if defined(CONFIG_NFS_V4_1) |
| 3699 | case -NFS4ERR_BADSESSION: |
| 3700 | case -NFS4ERR_BADSLOT: |
| 3701 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 3702 | case -NFS4ERR_DEADSESSION: |
| 3703 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 3704 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 3705 | case -NFS4ERR_SEQ_MISORDERED: |
| 3706 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 3707 | task->tk_status); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3708 | nfs4_schedule_session_recovery(clp->cl_session); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3709 | task->tk_status = 0; |
| 3710 | return -EAGAIN; |
| 3711 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3713 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 3714 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 3715 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 3717 | task->tk_status = 0; |
| 3718 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 3719 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | case -NFS4ERR_OLD_STATEID: |
| 3721 | task->tk_status = 0; |
| 3722 | return -EAGAIN; |
| 3723 | } |
| 3724 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 3725 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3726 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3727 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3728 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 3729 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 3730 | task->tk_status = 0; |
| 3731 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3734 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 3735 | unsigned short port, struct rpc_cred *cred, |
| 3736 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3737 | { |
| 3738 | nfs4_verifier sc_verifier; |
| 3739 | struct nfs4_setclientid setclientid = { |
| 3740 | .sc_verifier = &sc_verifier, |
| 3741 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 3742 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | }; |
| 3744 | struct rpc_message msg = { |
| 3745 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 3746 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3747 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3748 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | }; |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3750 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | int loop = 0; |
| 3752 | int status; |
| 3753 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 3754 | p = (__be32*)sc_verifier.data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 3756 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 3757 | |
| 3758 | for(;;) { |
| 3759 | setclientid.sc_name_len = scnprintf(setclientid.sc_name, |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3760 | sizeof(setclientid.sc_name), "%s/%s %s %s %u", |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3761 | clp->cl_ipaddr, |
| 3762 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3763 | RPC_DISPLAY_ADDR), |
Trond Myklebust | 69dd716 | 2007-12-14 14:56:07 -0500 | [diff] [blame] | 3764 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3765 | RPC_DISPLAY_PROTO), |
Trond Myklebust | 78ea323 | 2008-04-07 20:49:28 -0400 | [diff] [blame] | 3766 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | clp->cl_id_uniquifier); |
| 3768 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3769 | sizeof(setclientid.sc_netid), |
| 3770 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 3771 | RPC_DISPLAY_NETID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 3773 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3774 | clp->cl_ipaddr, port >> 8, port & 255); |
| 3775 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3776 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | if (status != -NFS4ERR_CLID_INUSE) |
| 3778 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3779 | if (loop != 0) { |
| 3780 | ++clp->cl_id_uniquifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | break; |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3782 | } |
| 3783 | ++loop; |
| 3784 | ssleep(clp->cl_lease_time / HZ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | } |
| 3786 | return status; |
| 3787 | } |
| 3788 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 3789 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3790 | struct nfs4_setclientid_res *arg, |
| 3791 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | { |
| 3793 | struct nfs_fsinfo fsinfo; |
| 3794 | struct rpc_message msg = { |
| 3795 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 3796 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 3798 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | }; |
| 3800 | unsigned long now; |
| 3801 | int status; |
| 3802 | |
| 3803 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 3804 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | if (status == 0) { |
| 3806 | spin_lock(&clp->cl_lock); |
| 3807 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 3808 | clp->cl_last_renewal = now; |
| 3809 | spin_unlock(&clp->cl_lock); |
| 3810 | } |
| 3811 | return status; |
| 3812 | } |
| 3813 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3814 | struct nfs4_delegreturndata { |
| 3815 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3816 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3817 | struct nfs_fh fh; |
| 3818 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3819 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3820 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3821 | int rpc_status; |
| 3822 | }; |
| 3823 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3824 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 3825 | { |
| 3826 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3827 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3828 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3829 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3830 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3831 | switch (task->tk_status) { |
| 3832 | case -NFS4ERR_STALE_STATEID: |
| 3833 | case -NFS4ERR_EXPIRED: |
| 3834 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3835 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3836 | break; |
| 3837 | default: |
| 3838 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 3839 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3840 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 3841 | return; |
| 3842 | } |
| 3843 | } |
| 3844 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | static void nfs4_delegreturn_release(void *calldata) |
| 3848 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3849 | kfree(calldata); |
| 3850 | } |
| 3851 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3852 | #if defined(CONFIG_NFS_V4_1) |
| 3853 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 3854 | { |
| 3855 | struct nfs4_delegreturndata *d_data; |
| 3856 | |
| 3857 | d_data = (struct nfs4_delegreturndata *)data; |
| 3858 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 3859 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3860 | &d_data->args.seq_args, |
| 3861 | &d_data->res.seq_res, 1, task)) |
| 3862 | return; |
| 3863 | rpc_call_start(task); |
| 3864 | } |
| 3865 | #endif /* CONFIG_NFS_V4_1 */ |
| 3866 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 3867 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 3868 | #if defined(CONFIG_NFS_V4_1) |
| 3869 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 3870 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3871 | .rpc_call_done = nfs4_delegreturn_done, |
| 3872 | .rpc_release = nfs4_delegreturn_release, |
| 3873 | }; |
| 3874 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3875 | 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] | 3876 | { |
| 3877 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3878 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3879 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3880 | struct rpc_message msg = { |
| 3881 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 3882 | .rpc_cred = cred, |
| 3883 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3884 | struct rpc_task_setup task_setup_data = { |
| 3885 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3886 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3887 | .callback_ops = &nfs4_delegreturn_ops, |
| 3888 | .flags = RPC_TASK_ASYNC, |
| 3889 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3890 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3891 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 3892 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3893 | if (data == NULL) |
| 3894 | return -ENOMEM; |
| 3895 | data->args.fhandle = &data->fh; |
| 3896 | data->args.stateid = &data->stateid; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3897 | data->args.bitmask = server->attr_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3898 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
| 3899 | memcpy(&data->stateid, stateid, sizeof(data->stateid)); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 3900 | data->res.fattr = &data->fattr; |
| 3901 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 3902 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 3903 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3904 | data->rpc_status = 0; |
| 3905 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3906 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 3907 | msg.rpc_argp = &data->args; |
| 3908 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 3909 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 3910 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3911 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3912 | if (!issync) |
| 3913 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3914 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3915 | if (status != 0) |
| 3916 | goto out; |
| 3917 | status = data->rpc_status; |
| 3918 | if (status != 0) |
| 3919 | goto out; |
| 3920 | nfs_refresh_inode(inode, &data->fattr); |
| 3921 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 3922 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 3923 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | } |
| 3925 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3926 | 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] | 3927 | { |
| 3928 | struct nfs_server *server = NFS_SERVER(inode); |
| 3929 | struct nfs4_exception exception = { }; |
| 3930 | int err; |
| 3931 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 3932 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | switch (err) { |
| 3934 | case -NFS4ERR_STALE_STATEID: |
| 3935 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | case 0: |
| 3937 | return 0; |
| 3938 | } |
| 3939 | err = nfs4_handle_exception(server, err, &exception); |
| 3940 | } while (exception.retry); |
| 3941 | return err; |
| 3942 | } |
| 3943 | |
| 3944 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 3945 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 3946 | |
| 3947 | /* |
| 3948 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 3949 | */ |
| 3950 | static unsigned long |
| 3951 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 3952 | { |
Matthew Wilcox | 150030b | 2007-12-06 16:24:39 -0500 | [diff] [blame] | 3953 | schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | timeout <<= 1; |
| 3955 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 3956 | return NFS4_LOCK_MAXTIMEOUT; |
| 3957 | return timeout; |
| 3958 | } |
| 3959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 3961 | { |
| 3962 | struct inode *inode = state->inode; |
| 3963 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 3964 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3965 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3967 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3969 | struct nfs_lockt_res res = { |
| 3970 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | }; |
| 3972 | struct rpc_message msg = { |
| 3973 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 3974 | .rpc_argp = &arg, |
| 3975 | .rpc_resp = &res, |
| 3976 | .rpc_cred = state->owner->so_cred, |
| 3977 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | struct nfs4_lock_state *lsp; |
| 3979 | int status; |
| 3980 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 3981 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3982 | status = nfs4_set_lock_state(state, request); |
| 3983 | if (status != 0) |
| 3984 | goto out; |
| 3985 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 3986 | arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 3987 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3988 | 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] | 3989 | switch (status) { |
| 3990 | case 0: |
| 3991 | request->fl_type = F_UNLCK; |
| 3992 | break; |
| 3993 | case -NFS4ERR_DENIED: |
| 3994 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 3996 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 3997 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | return status; |
| 3999 | } |
| 4000 | |
| 4001 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4002 | { |
| 4003 | struct nfs4_exception exception = { }; |
| 4004 | int err; |
| 4005 | |
| 4006 | do { |
| 4007 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4008 | _nfs4_proc_getlk(state, cmd, request), |
| 4009 | &exception); |
| 4010 | } while (exception.retry); |
| 4011 | return err; |
| 4012 | } |
| 4013 | |
| 4014 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4015 | { |
| 4016 | int res = 0; |
| 4017 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4018 | case FL_POSIX: |
| 4019 | res = posix_lock_file_wait(file, fl); |
| 4020 | break; |
| 4021 | case FL_FLOCK: |
| 4022 | res = flock_lock_file_wait(file, fl); |
| 4023 | break; |
| 4024 | default: |
| 4025 | BUG(); |
| 4026 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | return res; |
| 4028 | } |
| 4029 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4030 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4031 | struct nfs_locku_args arg; |
| 4032 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4033 | struct nfs4_lock_state *lsp; |
| 4034 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4035 | struct file_lock fl; |
| 4036 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4037 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4038 | }; |
| 4039 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4040 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4041 | struct nfs_open_context *ctx, |
| 4042 | struct nfs4_lock_state *lsp, |
| 4043 | struct nfs_seqid *seqid) |
| 4044 | { |
| 4045 | struct nfs4_unlockdata *p; |
| 4046 | struct inode *inode = lsp->ls_state->inode; |
| 4047 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4048 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4049 | if (p == NULL) |
| 4050 | return NULL; |
| 4051 | p->arg.fh = NFS_FH(inode); |
| 4052 | p->arg.fl = &p->fl; |
| 4053 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4054 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4055 | p->arg.stateid = &lsp->ls_stateid; |
| 4056 | p->lsp = lsp; |
| 4057 | atomic_inc(&lsp->ls_count); |
| 4058 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4059 | p->ctx = get_nfs_open_context(ctx); |
| 4060 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4061 | p->server = NFS_SERVER(inode); |
| 4062 | return p; |
| 4063 | } |
| 4064 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4065 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4066 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4067 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4068 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4069 | nfs4_put_lock_state(calldata->lsp); |
| 4070 | put_nfs_open_context(calldata->ctx); |
| 4071 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4072 | } |
| 4073 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4074 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4075 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4076 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4077 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4078 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4079 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4080 | switch (task->tk_status) { |
| 4081 | case 0: |
| 4082 | memcpy(calldata->lsp->ls_stateid.data, |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4083 | calldata->res.stateid.data, |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4084 | sizeof(calldata->lsp->ls_stateid.data)); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4085 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4086 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4087 | case -NFS4ERR_BAD_STATEID: |
| 4088 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4089 | case -NFS4ERR_STALE_STATEID: |
| 4090 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4091 | break; |
| 4092 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4093 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4094 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4095 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4096 | } |
| 4097 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4098 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4099 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4100 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4102 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4103 | return; |
| 4104 | if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4105 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4106 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4107 | return; |
| 4108 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4109 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4110 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4111 | &calldata->arg.seq_args, |
| 4112 | &calldata->res.seq_res, 1, task)) |
| 4113 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4114 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | } |
| 4116 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4117 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4118 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4119 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4120 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4121 | }; |
| 4122 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4123 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4124 | struct nfs_open_context *ctx, |
| 4125 | struct nfs4_lock_state *lsp, |
| 4126 | struct nfs_seqid *seqid) |
| 4127 | { |
| 4128 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4129 | struct rpc_message msg = { |
| 4130 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4131 | .rpc_cred = ctx->cred, |
| 4132 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4133 | struct rpc_task_setup task_setup_data = { |
| 4134 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4135 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4136 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4137 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4138 | .flags = RPC_TASK_ASYNC, |
| 4139 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4140 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4141 | /* Ensure this is an unlock - when canceling a lock, the |
| 4142 | * canceled lock is passed in, and it won't be an unlock. |
| 4143 | */ |
| 4144 | fl->fl_type = F_UNLCK; |
| 4145 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4146 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4147 | if (data == NULL) { |
| 4148 | nfs_free_seqid(seqid); |
| 4149 | return ERR_PTR(-ENOMEM); |
| 4150 | } |
| 4151 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4152 | msg.rpc_argp = &data->arg; |
| 4153 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4154 | task_setup_data.callback_data = data; |
| 4155 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4156 | } |
| 4157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4159 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4160 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4161 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4162 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4163 | struct rpc_task *task; |
| 4164 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4165 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4167 | status = nfs4_set_lock_state(state, request); |
| 4168 | /* Unlock _before_ we do the RPC call */ |
| 4169 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4170 | down_read(&nfsi->rwsem); |
| 4171 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4172 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4173 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4174 | } |
| 4175 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4176 | if (status != 0) |
| 4177 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4178 | /* Is this a delegated lock? */ |
| 4179 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4180 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4181 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4182 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4183 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4184 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4185 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4186 | 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] | 4187 | status = PTR_ERR(task); |
| 4188 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4189 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4190 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4191 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4192 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4193 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4194 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4197 | struct nfs4_lockdata { |
| 4198 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4199 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4200 | struct nfs4_lock_state *lsp; |
| 4201 | struct nfs_open_context *ctx; |
| 4202 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4203 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4204 | int rpc_status; |
| 4205 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4206 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4207 | }; |
| 4208 | |
| 4209 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4210 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4211 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4212 | { |
| 4213 | struct nfs4_lockdata *p; |
| 4214 | struct inode *inode = lsp->ls_state->inode; |
| 4215 | struct nfs_server *server = NFS_SERVER(inode); |
| 4216 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4217 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4218 | if (p == NULL) |
| 4219 | return NULL; |
| 4220 | |
| 4221 | p->arg.fh = NFS_FH(inode); |
| 4222 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4223 | 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] | 4224 | if (p->arg.open_seqid == NULL) |
| 4225 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4226 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4227 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4228 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4229 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4230 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 9f958ab | 2007-07-02 13:58:33 -0400 | [diff] [blame] | 4231 | p->arg.lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4232 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4233 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4234 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4235 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4236 | atomic_inc(&lsp->ls_count); |
| 4237 | p->ctx = get_nfs_open_context(ctx); |
| 4238 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4239 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4240 | out_free_seqid: |
| 4241 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4242 | out_free: |
| 4243 | kfree(p); |
| 4244 | return NULL; |
| 4245 | } |
| 4246 | |
| 4247 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4248 | { |
| 4249 | struct nfs4_lockdata *data = calldata; |
| 4250 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4252 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4253 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4254 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4255 | /* Do we need to do an open_to_lock_owner? */ |
| 4256 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4257 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4258 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4259 | data->arg.open_stateid = &state->stateid; |
| 4260 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4261 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4262 | } else |
| 4263 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4264 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4265 | if (nfs4_setup_sequence(data->server, |
| 4266 | &data->arg.seq_args, |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4267 | &data->res.seq_res, 1, task)) |
| 4268 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4269 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4270 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4271 | } |
| 4272 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4273 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4274 | { |
| 4275 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4276 | nfs4_lock_prepare(task, calldata); |
| 4277 | } |
| 4278 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4279 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4280 | { |
| 4281 | struct nfs4_lockdata *data = calldata; |
| 4282 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4283 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4284 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4285 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4286 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4287 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4288 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4289 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4290 | if (data->rpc_status == 0) |
| 4291 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4292 | else |
| 4293 | goto out; |
| 4294 | } |
| 4295 | if (data->rpc_status == 0) { |
| 4296 | memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, |
| 4297 | sizeof(data->lsp->ls_stateid.data)); |
| 4298 | data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4299 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4300 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4301 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4302 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | static void nfs4_lock_release(void *calldata) |
| 4306 | { |
| 4307 | struct nfs4_lockdata *data = calldata; |
| 4308 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4309 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4310 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4311 | if (data->cancelled != 0) { |
| 4312 | struct rpc_task *task; |
| 4313 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4314 | data->arg.lock_seqid); |
| 4315 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4316 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4317 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4318 | } else |
| 4319 | nfs_free_seqid(data->arg.lock_seqid); |
| 4320 | nfs4_put_lock_state(data->lsp); |
| 4321 | put_nfs_open_context(data->ctx); |
| 4322 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4323 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4327 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4328 | .rpc_call_done = nfs4_lock_done, |
| 4329 | .rpc_release = nfs4_lock_release, |
| 4330 | }; |
| 4331 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4332 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4333 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4334 | .rpc_call_done = nfs4_lock_done, |
| 4335 | .rpc_release = nfs4_lock_release, |
| 4336 | }; |
| 4337 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4338 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4339 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4340 | switch (error) { |
| 4341 | case -NFS4ERR_ADMIN_REVOKED: |
| 4342 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4343 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4344 | if (new_lock_owner != 0 || |
| 4345 | (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4346 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4347 | break; |
| 4348 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4349 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4350 | case -NFS4ERR_EXPIRED: |
| 4351 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4352 | }; |
| 4353 | } |
| 4354 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4355 | 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] | 4356 | { |
| 4357 | struct nfs4_lockdata *data; |
| 4358 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4359 | struct rpc_message msg = { |
| 4360 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4361 | .rpc_cred = state->owner->so_cred, |
| 4362 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4363 | struct rpc_task_setup task_setup_data = { |
| 4364 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4365 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4366 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4367 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4368 | .flags = RPC_TASK_ASYNC, |
| 4369 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4370 | int ret; |
| 4371 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4372 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4373 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4374 | fl->fl_u.nfs4_fl.owner, |
| 4375 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4376 | if (data == NULL) |
| 4377 | return -ENOMEM; |
| 4378 | if (IS_SETLKW(cmd)) |
| 4379 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4380 | if (recovery_type > NFS_LOCK_NEW) { |
| 4381 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4382 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4383 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4384 | } |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4385 | msg.rpc_argp = &data->arg; |
| 4386 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4387 | task_setup_data.callback_data = data; |
| 4388 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4389 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4390 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4391 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4392 | if (ret == 0) { |
| 4393 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4394 | if (ret) |
| 4395 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4396 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4397 | } else |
| 4398 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4399 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4400 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4401 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | } |
| 4403 | |
| 4404 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4405 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4406 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4407 | struct nfs4_exception exception = { }; |
| 4408 | int err; |
| 4409 | |
| 4410 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4411 | /* Cache the lock if possible... */ |
| 4412 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4413 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4414 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4415 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4416 | break; |
| 4417 | nfs4_handle_exception(server, err, &exception); |
| 4418 | } while (exception.retry); |
| 4419 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4423 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4424 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4425 | struct nfs4_exception exception = { }; |
| 4426 | int err; |
| 4427 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4428 | err = nfs4_set_lock_state(state, request); |
| 4429 | if (err != 0) |
| 4430 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4431 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4432 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4433 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4434 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4435 | switch (err) { |
| 4436 | default: |
| 4437 | goto out; |
| 4438 | case -NFS4ERR_GRACE: |
| 4439 | case -NFS4ERR_DELAY: |
| 4440 | nfs4_handle_exception(server, err, &exception); |
| 4441 | err = 0; |
| 4442 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4443 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4444 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4445 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4446 | } |
| 4447 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4448 | #if defined(CONFIG_NFS_V4_1) |
| 4449 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4450 | { |
| 4451 | int status; |
| 4452 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4453 | |
| 4454 | status = nfs41_test_stateid(server, state); |
| 4455 | if (status == NFS_OK) |
| 4456 | return 0; |
| 4457 | nfs41_free_stateid(server, state); |
| 4458 | return nfs4_lock_expired(state, request); |
| 4459 | } |
| 4460 | #endif |
| 4461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4463 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4464 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4465 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4466 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4467 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4468 | if ((fl_flags & FL_POSIX) && |
| 4469 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4470 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4471 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4472 | status = nfs4_set_lock_state(state, request); |
| 4473 | if (status != 0) |
| 4474 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4475 | request->fl_flags |= FL_ACCESS; |
| 4476 | status = do_vfs_lock(request->fl_file, request); |
| 4477 | if (status < 0) |
| 4478 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4479 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4480 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4481 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4482 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4483 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4484 | status = do_vfs_lock(request->fl_file, request); |
| 4485 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4486 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4487 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4488 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4489 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4490 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4491 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4492 | if (do_vfs_lock(request->fl_file, request) < 0) |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4493 | 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] | 4494 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4495 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4496 | out: |
| 4497 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | return status; |
| 4499 | } |
| 4500 | |
| 4501 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4502 | { |
| 4503 | struct nfs4_exception exception = { }; |
| 4504 | int err; |
| 4505 | |
| 4506 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4507 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4508 | if (err == -NFS4ERR_DENIED) |
| 4509 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4511 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | } while (exception.retry); |
| 4513 | return err; |
| 4514 | } |
| 4515 | |
| 4516 | static int |
| 4517 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4518 | { |
| 4519 | struct nfs_open_context *ctx; |
| 4520 | struct nfs4_state *state; |
| 4521 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4522 | int status; |
| 4523 | |
| 4524 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4525 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4526 | state = ctx->state; |
| 4527 | |
| 4528 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4529 | return -EINVAL; |
| 4530 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4531 | if (IS_GETLK(cmd)) { |
| 4532 | if (state != NULL) |
| 4533 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4534 | return 0; |
| 4535 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | |
| 4537 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4538 | return -EINVAL; |
| 4539 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4540 | if (request->fl_type == F_UNLCK) { |
| 4541 | if (state != NULL) |
| 4542 | return nfs4_proc_unlck(state, cmd, request); |
| 4543 | return 0; |
| 4544 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4546 | if (state == NULL) |
| 4547 | return -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | do { |
| 4549 | status = nfs4_proc_setlk(state, cmd, request); |
| 4550 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4551 | break; |
| 4552 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4553 | status = -ERESTARTSYS; |
| 4554 | if (signalled()) |
| 4555 | break; |
| 4556 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | return status; |
| 4558 | } |
| 4559 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4560 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4561 | { |
| 4562 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4563 | struct nfs4_exception exception = { }; |
| 4564 | int err; |
| 4565 | |
| 4566 | err = nfs4_set_lock_state(state, fl); |
| 4567 | if (err != 0) |
| 4568 | goto out; |
| 4569 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4570 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4571 | switch (err) { |
| 4572 | default: |
| 4573 | printk(KERN_ERR "%s: unhandled error %d.\n", |
| 4574 | __func__, err); |
| 4575 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4576 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4577 | goto out; |
| 4578 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4579 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4580 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4581 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4582 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 4583 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 4584 | case -NFS4ERR_BADSESSION: |
| 4585 | case -NFS4ERR_BADSLOT: |
| 4586 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4587 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4588 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4589 | nfs4_schedule_session_recovery(server->nfs_client->cl_session); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4590 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4591 | case -ERESTARTSYS: |
| 4592 | /* |
| 4593 | * The show must go on: exit, but mark the |
| 4594 | * stateid as needing recovery. |
| 4595 | */ |
| 4596 | case -NFS4ERR_ADMIN_REVOKED: |
| 4597 | case -NFS4ERR_BAD_STATEID: |
| 4598 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4599 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4600 | err = 0; |
| 4601 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4602 | case -EKEYEXPIRED: |
| 4603 | /* |
| 4604 | * User RPCSEC_GSS context has expired. |
| 4605 | * We cannot recover this stateid now, so |
| 4606 | * skip it and allow recovery thread to |
| 4607 | * proceed. |
| 4608 | */ |
| 4609 | err = 0; |
| 4610 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4611 | case -ENOMEM: |
| 4612 | case -NFS4ERR_DENIED: |
| 4613 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 4614 | err = 0; |
| 4615 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4616 | case -NFS4ERR_DELAY: |
| 4617 | break; |
| 4618 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4619 | err = nfs4_handle_exception(server, err, &exception); |
| 4620 | } while (exception.retry); |
| 4621 | out: |
| 4622 | return err; |
| 4623 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4624 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4625 | static void nfs4_release_lockowner_release(void *calldata) |
| 4626 | { |
| 4627 | kfree(calldata); |
| 4628 | } |
| 4629 | |
| 4630 | const struct rpc_call_ops nfs4_release_lockowner_ops = { |
| 4631 | .rpc_release = nfs4_release_lockowner_release, |
| 4632 | }; |
| 4633 | |
| 4634 | void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) |
| 4635 | { |
| 4636 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
| 4637 | struct nfs_release_lockowner_args *args; |
| 4638 | struct rpc_message msg = { |
| 4639 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 4640 | }; |
| 4641 | |
| 4642 | if (server->nfs_client->cl_mvops->minor_version != 0) |
| 4643 | return; |
| 4644 | args = kmalloc(sizeof(*args), GFP_NOFS); |
| 4645 | if (!args) |
| 4646 | return; |
| 4647 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
| 4648 | args->lock_owner.id = lsp->ls_id.id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4649 | args->lock_owner.s_dev = server->s_dev; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 4650 | msg.rpc_argp = args; |
| 4651 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
| 4652 | } |
| 4653 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4654 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 4655 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4656 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 4657 | const void *buf, size_t buflen, |
| 4658 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4659 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4660 | if (strcmp(key, "") != 0) |
| 4661 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4662 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4663 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4664 | } |
| 4665 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4666 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 4667 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4668 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4669 | if (strcmp(key, "") != 0) |
| 4670 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4671 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4672 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4673 | } |
| 4674 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4675 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 4676 | size_t list_len, const char *name, |
| 4677 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4678 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4679 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4680 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 4681 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 4682 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 4683 | |
| 4684 | if (list && len <= list_len) |
| 4685 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4686 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 4687 | } |
| 4688 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4689 | /* |
| 4690 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 4691 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4692 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 4693 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4694 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 4695 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 4696 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
| 4697 | (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 4698 | return; |
| 4699 | |
| 4700 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
| 4701 | NFS_ATTR_FATTR_NLINK; |
| 4702 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 4703 | fattr->nlink = 2; |
| 4704 | } |
| 4705 | |
Trond Myklebust | 56659e9 | 2007-07-17 21:52:39 -0400 | [diff] [blame] | 4706 | int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
Manoj Naik | 7aaa0b3 | 2006-06-09 09:34:23 -0400 | [diff] [blame] | 4707 | struct nfs4_fs_locations *fs_locations, struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4708 | { |
| 4709 | struct nfs_server *server = NFS_SERVER(dir); |
| 4710 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 4711 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4712 | }; |
| 4713 | struct nfs4_fs_locations_arg args = { |
| 4714 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4715 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4716 | .page = page, |
| 4717 | .bitmask = bitmask, |
| 4718 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4719 | struct nfs4_fs_locations_res res = { |
| 4720 | .fs_locations = fs_locations, |
| 4721 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4722 | struct rpc_message msg = { |
| 4723 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 4724 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 4725 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4726 | }; |
| 4727 | int status; |
| 4728 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4729 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 4730 | |
| 4731 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 4732 | * is not supported */ |
| 4733 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 4734 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 4735 | else |
| 4736 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 4737 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 4738 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4739 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 4740 | fs_locations->nlocations = 0; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4741 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4742 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 4743 | return status; |
| 4744 | } |
| 4745 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 4746 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4747 | { |
| 4748 | int status; |
| 4749 | struct nfs4_secinfo_arg args = { |
| 4750 | .dir_fh = NFS_FH(dir), |
| 4751 | .name = name, |
| 4752 | }; |
| 4753 | struct nfs4_secinfo_res res = { |
| 4754 | .flavors = flavors, |
| 4755 | }; |
| 4756 | struct rpc_message msg = { |
| 4757 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 4758 | .rpc_argp = &args, |
| 4759 | .rpc_resp = &res, |
| 4760 | }; |
| 4761 | |
| 4762 | dprintk("NFS call secinfo %s\n", name->name); |
| 4763 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 4764 | dprintk("NFS reply secinfo: %d\n", status); |
| 4765 | return status; |
| 4766 | } |
| 4767 | |
| 4768 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 4769 | { |
| 4770 | struct nfs4_exception exception = { }; |
| 4771 | int err; |
| 4772 | do { |
| 4773 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 4774 | _nfs4_proc_secinfo(dir, name, flavors), |
| 4775 | &exception); |
| 4776 | } while (exception.retry); |
| 4777 | return err; |
| 4778 | } |
| 4779 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 4780 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4781 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4782 | * Check the exchange flags returned by the server for invalid flags, having |
| 4783 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 4784 | * DS flags set. |
| 4785 | */ |
| 4786 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 4787 | { |
| 4788 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 4789 | goto out_inval; |
| 4790 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 4791 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 4792 | goto out_inval; |
| 4793 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 4794 | goto out_inval; |
| 4795 | return NFS_OK; |
| 4796 | out_inval: |
| 4797 | return -NFS4ERR_INVAL; |
| 4798 | } |
| 4799 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4800 | static bool |
| 4801 | nfs41_same_server_scope(struct server_scope *a, struct server_scope *b) |
| 4802 | { |
| 4803 | if (a->server_scope_sz == b->server_scope_sz && |
| 4804 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 4805 | return true; |
| 4806 | |
| 4807 | return false; |
| 4808 | } |
| 4809 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4810 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4811 | * nfs4_proc_exchange_id() |
| 4812 | * |
| 4813 | * Since the clientid has expired, all compounds using sessions |
| 4814 | * associated with the stale clientid will be returning |
| 4815 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 4816 | * be in some phase of session reset. |
| 4817 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 4818 | 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] | 4819 | { |
| 4820 | nfs4_verifier verifier; |
| 4821 | struct nfs41_exchange_id_args args = { |
| 4822 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 4823 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4824 | }; |
| 4825 | struct nfs41_exchange_id_res res = { |
| 4826 | .client = clp, |
| 4827 | }; |
| 4828 | int status; |
| 4829 | struct rpc_message msg = { |
| 4830 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 4831 | .rpc_argp = &args, |
| 4832 | .rpc_resp = &res, |
| 4833 | .rpc_cred = cred, |
| 4834 | }; |
| 4835 | __be32 *p; |
| 4836 | |
| 4837 | dprintk("--> %s\n", __func__); |
| 4838 | BUG_ON(clp == NULL); |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 4839 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4840 | p = (u32 *)verifier.data; |
| 4841 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
| 4842 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
| 4843 | args.verifier = &verifier; |
| 4844 | |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4845 | args.id_len = scnprintf(args.id, sizeof(args.id), |
| 4846 | "%s/%s.%s/%u", |
| 4847 | clp->cl_ipaddr, |
| 4848 | init_utsname()->nodename, |
| 4849 | init_utsname()->domainname, |
| 4850 | clp->cl_rpcclient->cl_auth->au_flavor); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4851 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4852 | res.server_scope = kzalloc(sizeof(struct server_scope), GFP_KERNEL); |
| 4853 | if (unlikely(!res.server_scope)) |
| 4854 | return -ENOMEM; |
| 4855 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4856 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 4857 | if (!status) |
| 4858 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 4859 | |
| 4860 | if (!status) { |
| 4861 | if (clp->server_scope && |
| 4862 | !nfs41_same_server_scope(clp->server_scope, |
| 4863 | res.server_scope)) { |
| 4864 | dprintk("%s: server_scope mismatch detected\n", |
| 4865 | __func__); |
| 4866 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
| 4867 | kfree(clp->server_scope); |
| 4868 | clp->server_scope = NULL; |
| 4869 | } |
| 4870 | |
| 4871 | if (!clp->server_scope) |
| 4872 | clp->server_scope = res.server_scope; |
| 4873 | else |
| 4874 | kfree(res.server_scope); |
| 4875 | } |
| 4876 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 4877 | dprintk("<-- %s status= %d\n", __func__, status); |
| 4878 | return status; |
| 4879 | } |
| 4880 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4881 | struct nfs4_get_lease_time_data { |
| 4882 | struct nfs4_get_lease_time_args *args; |
| 4883 | struct nfs4_get_lease_time_res *res; |
| 4884 | struct nfs_client *clp; |
| 4885 | }; |
| 4886 | |
| 4887 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 4888 | void *calldata) |
| 4889 | { |
| 4890 | int ret; |
| 4891 | struct nfs4_get_lease_time_data *data = |
| 4892 | (struct nfs4_get_lease_time_data *)calldata; |
| 4893 | |
| 4894 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4895 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4896 | /* just setup sequence, do not trigger session recovery |
| 4897 | since we're invoked within one */ |
| 4898 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 4899 | &data->args->la_seq_args, |
| 4900 | &data->res->lr_seq_res, 0, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4901 | |
| 4902 | BUG_ON(ret == -EAGAIN); |
| 4903 | rpc_call_start(task); |
| 4904 | dprintk("<-- %s\n", __func__); |
| 4905 | } |
| 4906 | |
| 4907 | /* |
| 4908 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 4909 | * from sequence operation or clientid errors. |
| 4910 | */ |
| 4911 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 4912 | { |
| 4913 | struct nfs4_get_lease_time_data *data = |
| 4914 | (struct nfs4_get_lease_time_data *)calldata; |
| 4915 | |
| 4916 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4917 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 4918 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4919 | switch (task->tk_status) { |
| 4920 | case -NFS4ERR_DELAY: |
| 4921 | case -NFS4ERR_GRACE: |
| 4922 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 4923 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 4924 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4925 | /* fall through */ |
| 4926 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4927 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4928 | return; |
| 4929 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4930 | dprintk("<-- %s\n", __func__); |
| 4931 | } |
| 4932 | |
| 4933 | struct rpc_call_ops nfs4_get_lease_time_ops = { |
| 4934 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 4935 | .rpc_call_done = nfs4_get_lease_time_done, |
| 4936 | }; |
| 4937 | |
| 4938 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 4939 | { |
| 4940 | struct rpc_task *task; |
| 4941 | struct nfs4_get_lease_time_args args; |
| 4942 | struct nfs4_get_lease_time_res res = { |
| 4943 | .lr_fsinfo = fsinfo, |
| 4944 | }; |
| 4945 | struct nfs4_get_lease_time_data data = { |
| 4946 | .args = &args, |
| 4947 | .res = &res, |
| 4948 | .clp = clp, |
| 4949 | }; |
| 4950 | struct rpc_message msg = { |
| 4951 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 4952 | .rpc_argp = &args, |
| 4953 | .rpc_resp = &res, |
| 4954 | }; |
| 4955 | struct rpc_task_setup task_setup = { |
| 4956 | .rpc_client = clp->cl_rpcclient, |
| 4957 | .rpc_message = &msg, |
| 4958 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4959 | .callback_data = &data, |
| 4960 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4961 | }; |
| 4962 | int status; |
| 4963 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 4964 | dprintk("--> %s\n", __func__); |
| 4965 | task = rpc_run_task(&task_setup); |
| 4966 | |
| 4967 | if (IS_ERR(task)) |
| 4968 | status = PTR_ERR(task); |
| 4969 | else { |
| 4970 | status = task->tk_status; |
| 4971 | rpc_put_task(task); |
| 4972 | } |
| 4973 | dprintk("<-- %s return %d\n", __func__, status); |
| 4974 | |
| 4975 | return status; |
| 4976 | } |
| 4977 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4978 | /* |
| 4979 | * Reset a slot table |
| 4980 | */ |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4981 | static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 4982 | int ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4983 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4984 | struct nfs4_slot *new = NULL; |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 4985 | int i; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4986 | int ret = 0; |
| 4987 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4988 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 4989 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 4990 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4991 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 4992 | if (max_reqs != tbl->max_slots) { |
| 4993 | ret = -ENOMEM; |
| 4994 | new = kmalloc(max_reqs * sizeof(struct nfs4_slot), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4995 | GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 4996 | if (!new) |
| 4997 | goto out; |
| 4998 | ret = 0; |
| 4999 | kfree(tbl->slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5000 | } |
| 5001 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5002 | if (new) { |
| 5003 | tbl->slots = new; |
| 5004 | tbl->max_slots = max_reqs; |
| 5005 | } |
| 5006 | for (i = 0; i < tbl->max_slots; ++i) |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5007 | tbl->slots[i].seq_nr = ivalue; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5008 | spin_unlock(&tbl->slot_tbl_lock); |
| 5009 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5010 | tbl, tbl->slots, tbl->max_slots); |
| 5011 | out: |
| 5012 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5013 | return ret; |
| 5014 | } |
| 5015 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5016 | /* |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5017 | * Reset the forechannel and backchannel slot tables |
| 5018 | */ |
| 5019 | static int nfs4_reset_slot_tables(struct nfs4_session *session) |
| 5020 | { |
| 5021 | int status; |
| 5022 | |
| 5023 | status = nfs4_reset_slot_table(&session->fc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5024 | session->fc_attrs.max_reqs, 1); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5025 | if (status) |
| 5026 | return status; |
| 5027 | |
| 5028 | status = nfs4_reset_slot_table(&session->bc_slot_table, |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5029 | session->bc_attrs.max_reqs, 0); |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5030 | return status; |
| 5031 | } |
| 5032 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5033 | /* Destroy the slot table */ |
| 5034 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5035 | { |
| 5036 | if (session->fc_slot_table.slots != NULL) { |
| 5037 | kfree(session->fc_slot_table.slots); |
| 5038 | session->fc_slot_table.slots = NULL; |
| 5039 | } |
| 5040 | if (session->bc_slot_table.slots != NULL) { |
| 5041 | kfree(session->bc_slot_table.slots); |
| 5042 | session->bc_slot_table.slots = NULL; |
| 5043 | } |
| 5044 | return; |
| 5045 | } |
| 5046 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5047 | /* |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5048 | * Initialize slot table |
| 5049 | */ |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5050 | static int nfs4_init_slot_table(struct nfs4_slot_table *tbl, |
| 5051 | int max_slots, int ivalue) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5052 | { |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5053 | struct nfs4_slot *slot; |
| 5054 | int ret = -ENOMEM; |
| 5055 | |
| 5056 | BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE); |
| 5057 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5058 | dprintk("--> %s: max_reqs=%u\n", __func__, max_slots); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5059 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5060 | slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5061 | if (!slot) |
| 5062 | goto out; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5063 | ret = 0; |
| 5064 | |
| 5065 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5066 | tbl->max_slots = max_slots; |
| 5067 | tbl->slots = slot; |
| 5068 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5069 | spin_unlock(&tbl->slot_tbl_lock); |
| 5070 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5071 | tbl, tbl->slots, tbl->max_slots); |
| 5072 | out: |
| 5073 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5074 | return ret; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5075 | } |
| 5076 | |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5077 | /* |
| 5078 | * Initialize the forechannel and backchannel tables |
| 5079 | */ |
| 5080 | static int nfs4_init_slot_tables(struct nfs4_session *session) |
| 5081 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5082 | struct nfs4_slot_table *tbl; |
| 5083 | int status = 0; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5084 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5085 | tbl = &session->fc_slot_table; |
| 5086 | if (tbl->slots == NULL) { |
| 5087 | status = nfs4_init_slot_table(tbl, |
| 5088 | session->fc_attrs.max_reqs, 1); |
| 5089 | if (status) |
| 5090 | return status; |
| 5091 | } |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5092 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5093 | tbl = &session->bc_slot_table; |
| 5094 | if (tbl->slots == NULL) { |
| 5095 | status = nfs4_init_slot_table(tbl, |
| 5096 | session->bc_attrs.max_reqs, 0); |
| 5097 | if (status) |
| 5098 | nfs4_destroy_slot_tables(session); |
| 5099 | } |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5100 | |
| 5101 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5105 | { |
| 5106 | struct nfs4_session *session; |
| 5107 | struct nfs4_slot_table *tbl; |
| 5108 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5109 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5110 | if (!session) |
| 5111 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5112 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5113 | tbl = &session->fc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5114 | tbl->highest_used_slotid = -1; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5115 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5116 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5117 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5118 | |
| 5119 | tbl = &session->bc_slot_table; |
Ricardo Labiaga | 9dfdf40 | 2009-12-06 12:57:34 -0500 | [diff] [blame] | 5120 | tbl->highest_used_slotid = -1; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5121 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5122 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5123 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5124 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5125 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5126 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5127 | session->clp = clp; |
| 5128 | return session; |
| 5129 | } |
| 5130 | |
| 5131 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5132 | { |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5133 | nfs4_proc_destroy_session(session); |
| 5134 | dprintk("%s Destroy backchannel for xprt %p\n", |
| 5135 | __func__, session->clp->cl_rpcclient->cl_xprt); |
| 5136 | xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, |
| 5137 | NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5138 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5139 | kfree(session); |
| 5140 | } |
| 5141 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5142 | /* |
| 5143 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5144 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5145 | * use them. |
| 5146 | * |
| 5147 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5148 | * always set csa_cachethis to FALSE because the current implementation |
| 5149 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5150 | */ |
| 5151 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5152 | { |
| 5153 | struct nfs4_session *session = args->client->cl_session; |
| 5154 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5155 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5156 | |
| 5157 | if (mxrqst_sz == 0) |
| 5158 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5159 | if (mxresp_sz == 0) |
| 5160 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5161 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5162 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5163 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5164 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
| 5165 | args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; |
| 5166 | |
| 5167 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5168 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5169 | __func__, |
| 5170 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5171 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5172 | |
| 5173 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5174 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5175 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5176 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5177 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5178 | args->bc_attrs.max_reqs = 1; |
| 5179 | |
| 5180 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5181 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5182 | __func__, |
| 5183 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5184 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5185 | args->bc_attrs.max_reqs); |
| 5186 | } |
| 5187 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5188 | 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] | 5189 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5190 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5191 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5192 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5193 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5194 | return -EINVAL; |
| 5195 | /* |
| 5196 | * Our requested max_ops is the minimum we need; we're not |
| 5197 | * prepared to break up compounds into smaller pieces than that. |
| 5198 | * So, no point even trying to continue if the server won't |
| 5199 | * cooperate: |
| 5200 | */ |
| 5201 | if (rcvd->max_ops < sent->max_ops) |
| 5202 | return -EINVAL; |
| 5203 | if (rcvd->max_reqs == 0) |
| 5204 | return -EINVAL; |
| 5205 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5206 | } |
| 5207 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5208 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5209 | { |
| 5210 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5211 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5212 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5213 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5214 | return -EINVAL; |
| 5215 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5216 | return -EINVAL; |
| 5217 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5218 | return -EINVAL; |
| 5219 | /* These would render the backchannel useless: */ |
| 5220 | if (rcvd->max_ops == 0) |
| 5221 | return -EINVAL; |
| 5222 | if (rcvd->max_reqs == 0) |
| 5223 | return -EINVAL; |
| 5224 | return 0; |
| 5225 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5226 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5227 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5228 | struct nfs4_session *session) |
| 5229 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5230 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5231 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5232 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5233 | if (ret) |
| 5234 | return ret; |
| 5235 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5236 | } |
| 5237 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5238 | static int _nfs4_proc_create_session(struct nfs_client *clp) |
| 5239 | { |
| 5240 | struct nfs4_session *session = clp->cl_session; |
| 5241 | struct nfs41_create_session_args args = { |
| 5242 | .client = clp, |
| 5243 | .cb_program = NFS4_CALLBACK, |
| 5244 | }; |
| 5245 | struct nfs41_create_session_res res = { |
| 5246 | .client = clp, |
| 5247 | }; |
| 5248 | struct rpc_message msg = { |
| 5249 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5250 | .rpc_argp = &args, |
| 5251 | .rpc_resp = &res, |
| 5252 | }; |
| 5253 | int status; |
| 5254 | |
| 5255 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5256 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5257 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5258 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5259 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5260 | if (!status) |
| 5261 | /* Verify the session's negotiated channel_attrs values */ |
| 5262 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5263 | if (!status) { |
| 5264 | /* Increment the clientid slot sequence id */ |
| 5265 | clp->cl_seqid++; |
| 5266 | } |
| 5267 | |
| 5268 | return status; |
| 5269 | } |
| 5270 | |
| 5271 | /* |
| 5272 | * Issues a CREATE_SESSION operation to the server. |
| 5273 | * It is the responsibility of the caller to verify the session is |
| 5274 | * expired before calling this routine. |
| 5275 | */ |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5276 | int nfs4_proc_create_session(struct nfs_client *clp) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5277 | { |
| 5278 | int status; |
| 5279 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5280 | struct nfs4_session *session = clp->cl_session; |
| 5281 | |
| 5282 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5283 | |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 5284 | status = _nfs4_proc_create_session(clp); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5285 | if (status) |
| 5286 | goto out; |
| 5287 | |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5288 | /* Init and reset the fore channel */ |
| 5289 | status = nfs4_init_slot_tables(session); |
| 5290 | dprintk("slot table initialization returned %d\n", status); |
| 5291 | if (status) |
| 5292 | goto out; |
| 5293 | status = nfs4_reset_slot_tables(session); |
| 5294 | dprintk("slot table reset returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5295 | if (status) |
| 5296 | goto out; |
| 5297 | |
| 5298 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5299 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5300 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5301 | out: |
| 5302 | dprintk("<-- %s\n", __func__); |
| 5303 | return status; |
| 5304 | } |
| 5305 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5306 | /* |
| 5307 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5308 | * The caller must serialize access to this routine. |
| 5309 | */ |
| 5310 | int nfs4_proc_destroy_session(struct nfs4_session *session) |
| 5311 | { |
| 5312 | int status = 0; |
| 5313 | struct rpc_message msg; |
| 5314 | |
| 5315 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5316 | |
| 5317 | /* session is still being setup */ |
| 5318 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5319 | return status; |
| 5320 | |
| 5321 | msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION]; |
| 5322 | msg.rpc_argp = session; |
| 5323 | msg.rpc_resp = NULL; |
| 5324 | msg.rpc_cred = NULL; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5325 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5326 | |
| 5327 | if (status) |
| 5328 | printk(KERN_WARNING |
| 5329 | "Got error %d from the server on DESTROY_SESSION. " |
| 5330 | "Session has been destroyed regardless...\n", status); |
| 5331 | |
| 5332 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5333 | return status; |
| 5334 | } |
| 5335 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5336 | int nfs4_init_session(struct nfs_server *server) |
| 5337 | { |
| 5338 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5339 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5340 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5341 | int ret; |
| 5342 | |
| 5343 | if (!nfs4_has_session(clp)) |
| 5344 | return 0; |
| 5345 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5346 | session = clp->cl_session; |
| 5347 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5348 | return 0; |
| 5349 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5350 | rsize = server->rsize; |
| 5351 | if (rsize == 0) |
| 5352 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5353 | wsize = server->wsize; |
| 5354 | if (wsize == 0) |
| 5355 | wsize = NFS_MAX_FILE_IO_SIZE; |
| 5356 | |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5357 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5358 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5359 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5360 | ret = nfs4_recover_expired_lease(server); |
| 5361 | if (!ret) |
| 5362 | ret = nfs4_check_client_ready(clp); |
| 5363 | return ret; |
| 5364 | } |
| 5365 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5366 | int nfs4_init_ds_session(struct nfs_client *clp) |
| 5367 | { |
| 5368 | struct nfs4_session *session = clp->cl_session; |
| 5369 | int ret; |
| 5370 | |
| 5371 | if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) |
| 5372 | return 0; |
| 5373 | |
| 5374 | ret = nfs4_client_recover_expired_lease(clp); |
| 5375 | if (!ret) |
| 5376 | /* Test for the DS role */ |
| 5377 | if (!is_ds_client(clp)) |
| 5378 | ret = -ENODEV; |
| 5379 | if (!ret) |
| 5380 | ret = nfs4_check_client_ready(clp); |
| 5381 | return ret; |
| 5382 | |
| 5383 | } |
| 5384 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5385 | |
| 5386 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5387 | /* |
| 5388 | * Renew the cl_session lease. |
| 5389 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5390 | struct nfs4_sequence_data { |
| 5391 | struct nfs_client *clp; |
| 5392 | struct nfs4_sequence_args args; |
| 5393 | struct nfs4_sequence_res res; |
| 5394 | }; |
| 5395 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5396 | static void nfs41_sequence_release(void *data) |
| 5397 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5398 | struct nfs4_sequence_data *calldata = data; |
| 5399 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5400 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5401 | if (atomic_read(&clp->cl_count) > 1) |
| 5402 | nfs4_schedule_state_renewal(clp); |
| 5403 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5404 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5405 | } |
| 5406 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5407 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5408 | { |
| 5409 | switch(task->tk_status) { |
| 5410 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5411 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 5412 | return -EAGAIN; |
| 5413 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5414 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5415 | } |
| 5416 | return 0; |
| 5417 | } |
| 5418 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5419 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5420 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5421 | struct nfs4_sequence_data *calldata = data; |
| 5422 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5423 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5424 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 5425 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5426 | |
| 5427 | if (task->tk_status < 0) { |
| 5428 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5429 | if (atomic_read(&clp->cl_count) == 1) |
| 5430 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5431 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5432 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 5433 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5434 | return; |
| 5435 | } |
| 5436 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5437 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5438 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5439 | dprintk("<-- %s\n", __func__); |
| 5440 | } |
| 5441 | |
| 5442 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 5443 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5444 | struct nfs4_sequence_data *calldata = data; |
| 5445 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5446 | struct nfs4_sequence_args *args; |
| 5447 | struct nfs4_sequence_res *res; |
| 5448 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5449 | args = task->tk_msg.rpc_argp; |
| 5450 | res = task->tk_msg.rpc_resp; |
| 5451 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5452 | if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5453 | return; |
| 5454 | rpc_call_start(task); |
| 5455 | } |
| 5456 | |
| 5457 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 5458 | .rpc_call_done = nfs41_sequence_call_done, |
| 5459 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5460 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5461 | }; |
| 5462 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5463 | 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] | 5464 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5465 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5466 | struct rpc_message msg = { |
| 5467 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 5468 | .rpc_cred = cred, |
| 5469 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5470 | struct rpc_task_setup task_setup_data = { |
| 5471 | .rpc_client = clp->cl_rpcclient, |
| 5472 | .rpc_message = &msg, |
| 5473 | .callback_ops = &nfs41_sequence_ops, |
| 5474 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 5475 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5476 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5477 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5478 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 5479 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5480 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 5481 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5482 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5483 | } |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5484 | msg.rpc_argp = &calldata->args; |
| 5485 | msg.rpc_resp = &calldata->res; |
| 5486 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5487 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5488 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5489 | return rpc_run_task(&task_setup_data); |
| 5490 | } |
| 5491 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5492 | static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5493 | { |
| 5494 | struct rpc_task *task; |
| 5495 | int ret = 0; |
| 5496 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 5497 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 5498 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5499 | task = _nfs41_proc_sequence(clp, cred); |
| 5500 | if (IS_ERR(task)) |
| 5501 | ret = PTR_ERR(task); |
| 5502 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 5503 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5504 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5505 | return ret; |
| 5506 | } |
| 5507 | |
| 5508 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 5509 | { |
| 5510 | struct rpc_task *task; |
| 5511 | int ret; |
| 5512 | |
| 5513 | task = _nfs41_proc_sequence(clp, cred); |
| 5514 | if (IS_ERR(task)) { |
| 5515 | ret = PTR_ERR(task); |
| 5516 | goto out; |
| 5517 | } |
| 5518 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5519 | if (!ret) { |
| 5520 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 5521 | |
| 5522 | if (task->tk_status == 0) |
| 5523 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5524 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 5525 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5526 | rpc_put_task(task); |
| 5527 | out: |
| 5528 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 5529 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5530 | } |
| 5531 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5532 | struct nfs4_reclaim_complete_data { |
| 5533 | struct nfs_client *clp; |
| 5534 | struct nfs41_reclaim_complete_args arg; |
| 5535 | struct nfs41_reclaim_complete_res res; |
| 5536 | }; |
| 5537 | |
| 5538 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 5539 | { |
| 5540 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5541 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 5542 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 5543 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 5544 | &calldata->arg.seq_args, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5545 | &calldata->res.seq_res, 0, task)) |
| 5546 | return; |
| 5547 | |
| 5548 | rpc_call_start(task); |
| 5549 | } |
| 5550 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5551 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 5552 | { |
| 5553 | switch(task->tk_status) { |
| 5554 | case 0: |
| 5555 | case -NFS4ERR_COMPLETE_ALREADY: |
| 5556 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 5557 | break; |
| 5558 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5559 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5560 | /* fall through */ |
| 5561 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5562 | return -EAGAIN; |
| 5563 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5564 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5565 | } |
| 5566 | return 0; |
| 5567 | } |
| 5568 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5569 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 5570 | { |
| 5571 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5572 | struct nfs_client *clp = calldata->clp; |
| 5573 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 5574 | |
| 5575 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5576 | if (!nfs41_sequence_done(task, res)) |
| 5577 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5578 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5579 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 5580 | rpc_restart_call_prepare(task); |
| 5581 | return; |
| 5582 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5583 | dprintk("<-- %s\n", __func__); |
| 5584 | } |
| 5585 | |
| 5586 | static void nfs4_free_reclaim_complete_data(void *data) |
| 5587 | { |
| 5588 | struct nfs4_reclaim_complete_data *calldata = data; |
| 5589 | |
| 5590 | kfree(calldata); |
| 5591 | } |
| 5592 | |
| 5593 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 5594 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 5595 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 5596 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 5597 | }; |
| 5598 | |
| 5599 | /* |
| 5600 | * Issue a global reclaim complete. |
| 5601 | */ |
| 5602 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 5603 | { |
| 5604 | struct nfs4_reclaim_complete_data *calldata; |
| 5605 | struct rpc_task *task; |
| 5606 | struct rpc_message msg = { |
| 5607 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 5608 | }; |
| 5609 | struct rpc_task_setup task_setup_data = { |
| 5610 | .rpc_client = clp->cl_rpcclient, |
| 5611 | .rpc_message = &msg, |
| 5612 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 5613 | .flags = RPC_TASK_ASYNC, |
| 5614 | }; |
| 5615 | int status = -ENOMEM; |
| 5616 | |
| 5617 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5618 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5619 | if (calldata == NULL) |
| 5620 | goto out; |
| 5621 | calldata->clp = clp; |
| 5622 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5623 | |
| 5624 | msg.rpc_argp = &calldata->arg; |
| 5625 | msg.rpc_resp = &calldata->res; |
| 5626 | task_setup_data.callback_data = calldata; |
| 5627 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5628 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5629 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5630 | goto out; |
| 5631 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 5632 | status = nfs4_wait_for_completion_rpc_task(task); |
| 5633 | if (status == 0) |
| 5634 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5635 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 5636 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 5637 | out: |
| 5638 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5639 | return status; |
| 5640 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5641 | |
| 5642 | static void |
| 5643 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 5644 | { |
| 5645 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5646 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5647 | |
| 5648 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5649 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 5650 | * right now covering the LAYOUTGET we are about to send. |
| 5651 | * However, that is not so catastrophic, and there seems |
| 5652 | * to be no way to prevent it completely. |
| 5653 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5654 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
| 5655 | &lgp->res.seq_res, 0, task)) |
| 5656 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 5657 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 5658 | NFS_I(lgp->args.inode)->layout, |
| 5659 | lgp->args.ctx->state)) { |
| 5660 | rpc_exit(task, NFS4_OK); |
| 5661 | return; |
| 5662 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5663 | rpc_call_start(task); |
| 5664 | } |
| 5665 | |
| 5666 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 5667 | { |
| 5668 | struct nfs4_layoutget *lgp = calldata; |
| 5669 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5670 | |
| 5671 | dprintk("--> %s\n", __func__); |
| 5672 | |
| 5673 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 5674 | return; |
| 5675 | |
| 5676 | switch (task->tk_status) { |
| 5677 | case 0: |
| 5678 | break; |
| 5679 | case -NFS4ERR_LAYOUTTRYLATER: |
| 5680 | case -NFS4ERR_RECALLCONFLICT: |
| 5681 | task->tk_status = -NFS4ERR_DELAY; |
| 5682 | /* Fall through */ |
| 5683 | default: |
| 5684 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 5685 | rpc_restart_call_prepare(task); |
| 5686 | return; |
| 5687 | } |
| 5688 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5689 | dprintk("<-- %s\n", __func__); |
| 5690 | } |
| 5691 | |
| 5692 | static void nfs4_layoutget_release(void *calldata) |
| 5693 | { |
| 5694 | struct nfs4_layoutget *lgp = calldata; |
| 5695 | |
| 5696 | dprintk("--> %s\n", __func__); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5697 | put_nfs_open_context(lgp->args.ctx); |
| 5698 | kfree(calldata); |
| 5699 | dprintk("<-- %s\n", __func__); |
| 5700 | } |
| 5701 | |
| 5702 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 5703 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 5704 | .rpc_call_done = nfs4_layoutget_done, |
| 5705 | .rpc_release = nfs4_layoutget_release, |
| 5706 | }; |
| 5707 | |
| 5708 | int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) |
| 5709 | { |
| 5710 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 5711 | struct rpc_task *task; |
| 5712 | struct rpc_message msg = { |
| 5713 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 5714 | .rpc_argp = &lgp->args, |
| 5715 | .rpc_resp = &lgp->res, |
| 5716 | }; |
| 5717 | struct rpc_task_setup task_setup_data = { |
| 5718 | .rpc_client = server->client, |
| 5719 | .rpc_message = &msg, |
| 5720 | .callback_ops = &nfs4_layoutget_call_ops, |
| 5721 | .callback_data = lgp, |
| 5722 | .flags = RPC_TASK_ASYNC, |
| 5723 | }; |
| 5724 | int status = 0; |
| 5725 | |
| 5726 | dprintk("--> %s\n", __func__); |
| 5727 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 5728 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5729 | lgp->res.seq_res.sr_slot = NULL; |
| 5730 | task = rpc_run_task(&task_setup_data); |
| 5731 | if (IS_ERR(task)) |
| 5732 | return PTR_ERR(task); |
| 5733 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 5734 | if (status == 0) |
| 5735 | status = task->tk_status; |
| 5736 | if (status == 0) |
| 5737 | status = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5738 | rpc_put_task(task); |
| 5739 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5740 | return status; |
| 5741 | } |
| 5742 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5743 | static void |
| 5744 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 5745 | { |
| 5746 | struct nfs4_layoutreturn *lrp = calldata; |
| 5747 | |
| 5748 | dprintk("--> %s\n", __func__); |
| 5749 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
| 5750 | &lrp->res.seq_res, 0, task)) |
| 5751 | return; |
| 5752 | rpc_call_start(task); |
| 5753 | } |
| 5754 | |
| 5755 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 5756 | { |
| 5757 | struct nfs4_layoutreturn *lrp = calldata; |
| 5758 | struct nfs_server *server; |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5759 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5760 | |
| 5761 | dprintk("--> %s\n", __func__); |
| 5762 | |
| 5763 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 5764 | return; |
| 5765 | |
| 5766 | server = NFS_SERVER(lrp->args.inode); |
| 5767 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5768 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5769 | return; |
| 5770 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5771 | spin_lock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5772 | if (task->tk_status == 0) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5773 | if (lrp->res.lrs_present) { |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5774 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5775 | } else |
| 5776 | BUG_ON(!list_empty(&lo->plh_segs)); |
| 5777 | } |
Fred Isaman | a2e1d4f | 2011-06-13 18:54:53 -0400 | [diff] [blame] | 5778 | lo->plh_block_lgets--; |
| 5779 | spin_unlock(&lo->plh_inode->i_lock); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5780 | dprintk("<-- %s\n", __func__); |
| 5781 | } |
| 5782 | |
| 5783 | static void nfs4_layoutreturn_release(void *calldata) |
| 5784 | { |
| 5785 | struct nfs4_layoutreturn *lrp = calldata; |
| 5786 | |
| 5787 | dprintk("--> %s\n", __func__); |
Trond Myklebust | a56aaa0 | 2011-06-15 11:59:10 -0400 | [diff] [blame] | 5788 | put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 5789 | kfree(calldata); |
| 5790 | dprintk("<-- %s\n", __func__); |
| 5791 | } |
| 5792 | |
| 5793 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 5794 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 5795 | .rpc_call_done = nfs4_layoutreturn_done, |
| 5796 | .rpc_release = nfs4_layoutreturn_release, |
| 5797 | }; |
| 5798 | |
| 5799 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 5800 | { |
| 5801 | struct rpc_task *task; |
| 5802 | struct rpc_message msg = { |
| 5803 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 5804 | .rpc_argp = &lrp->args, |
| 5805 | .rpc_resp = &lrp->res, |
| 5806 | }; |
| 5807 | struct rpc_task_setup task_setup_data = { |
| 5808 | .rpc_client = lrp->clp->cl_rpcclient, |
| 5809 | .rpc_message = &msg, |
| 5810 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 5811 | .callback_data = lrp, |
| 5812 | }; |
| 5813 | int status; |
| 5814 | |
| 5815 | dprintk("--> %s\n", __func__); |
| 5816 | task = rpc_run_task(&task_setup_data); |
| 5817 | if (IS_ERR(task)) |
| 5818 | return PTR_ERR(task); |
| 5819 | status = task->tk_status; |
| 5820 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5821 | rpc_put_task(task); |
| 5822 | return status; |
| 5823 | } |
| 5824 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 5825 | /* |
| 5826 | * Retrieve the list of Data Server devices from the MDS. |
| 5827 | */ |
| 5828 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 5829 | const struct nfs_fh *fh, |
| 5830 | struct pnfs_devicelist *devlist) |
| 5831 | { |
| 5832 | struct nfs4_getdevicelist_args args = { |
| 5833 | .fh = fh, |
| 5834 | .layoutclass = server->pnfs_curr_ld->id, |
| 5835 | }; |
| 5836 | struct nfs4_getdevicelist_res res = { |
| 5837 | .devlist = devlist, |
| 5838 | }; |
| 5839 | struct rpc_message msg = { |
| 5840 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 5841 | .rpc_argp = &args, |
| 5842 | .rpc_resp = &res, |
| 5843 | }; |
| 5844 | int status; |
| 5845 | |
| 5846 | dprintk("--> %s\n", __func__); |
| 5847 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 5848 | &res.seq_res, 0); |
| 5849 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5850 | return status; |
| 5851 | } |
| 5852 | |
| 5853 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 5854 | const struct nfs_fh *fh, |
| 5855 | struct pnfs_devicelist *devlist) |
| 5856 | { |
| 5857 | struct nfs4_exception exception = { }; |
| 5858 | int err; |
| 5859 | |
| 5860 | do { |
| 5861 | err = nfs4_handle_exception(server, |
| 5862 | _nfs4_getdevicelist(server, fh, devlist), |
| 5863 | &exception); |
| 5864 | } while (exception.retry); |
| 5865 | |
| 5866 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 5867 | err, devlist->num_devs); |
| 5868 | |
| 5869 | return err; |
| 5870 | } |
| 5871 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 5872 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 5873 | static int |
| 5874 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5875 | { |
| 5876 | struct nfs4_getdeviceinfo_args args = { |
| 5877 | .pdev = pdev, |
| 5878 | }; |
| 5879 | struct nfs4_getdeviceinfo_res res = { |
| 5880 | .pdev = pdev, |
| 5881 | }; |
| 5882 | struct rpc_message msg = { |
| 5883 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 5884 | .rpc_argp = &args, |
| 5885 | .rpc_resp = &res, |
| 5886 | }; |
| 5887 | int status; |
| 5888 | |
| 5889 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 5890 | 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] | 5891 | dprintk("<-- %s status=%d\n", __func__, status); |
| 5892 | |
| 5893 | return status; |
| 5894 | } |
| 5895 | |
| 5896 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 5897 | { |
| 5898 | struct nfs4_exception exception = { }; |
| 5899 | int err; |
| 5900 | |
| 5901 | do { |
| 5902 | err = nfs4_handle_exception(server, |
| 5903 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 5904 | &exception); |
| 5905 | } while (exception.retry); |
| 5906 | return err; |
| 5907 | } |
| 5908 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 5909 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5910 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 5911 | { |
| 5912 | struct nfs4_layoutcommit_data *data = calldata; |
| 5913 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5914 | |
| 5915 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
| 5916 | &data->res.seq_res, 1, task)) |
| 5917 | return; |
| 5918 | rpc_call_start(task); |
| 5919 | } |
| 5920 | |
| 5921 | static void |
| 5922 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 5923 | { |
| 5924 | struct nfs4_layoutcommit_data *data = calldata; |
| 5925 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 5926 | |
| 5927 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 5928 | return; |
| 5929 | |
| 5930 | switch (task->tk_status) { /* Just ignore these failures */ |
| 5931 | case NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 5932 | case NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 5933 | case NFS4ERR_BADLAYOUT: /* no layout */ |
| 5934 | case NFS4ERR_GRACE: /* loca_recalim always false */ |
| 5935 | task->tk_status = 0; |
| 5936 | } |
| 5937 | |
| 5938 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5939 | rpc_restart_call_prepare(task); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5940 | return; |
| 5941 | } |
| 5942 | |
| 5943 | if (task->tk_status == 0) |
| 5944 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 5945 | data->res.fattr); |
| 5946 | } |
| 5947 | |
| 5948 | static void nfs4_layoutcommit_release(void *calldata) |
| 5949 | { |
| 5950 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 5951 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 5952 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5953 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 5954 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5955 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 5956 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 5957 | list_del_init(&lseg->pls_lc_list); |
| 5958 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 5959 | &lseg->pls_flags)) |
| 5960 | put_lseg(lseg); |
| 5961 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 5962 | |
| 5963 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 5964 | smp_mb__after_clear_bit(); |
| 5965 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 5966 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5967 | put_rpccred(data->cred); |
| 5968 | kfree(data); |
| 5969 | } |
| 5970 | |
| 5971 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 5972 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 5973 | .rpc_call_done = nfs4_layoutcommit_done, |
| 5974 | .rpc_release = nfs4_layoutcommit_release, |
| 5975 | }; |
| 5976 | |
| 5977 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 5978 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 5979 | { |
| 5980 | struct rpc_message msg = { |
| 5981 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 5982 | .rpc_argp = &data->args, |
| 5983 | .rpc_resp = &data->res, |
| 5984 | .rpc_cred = data->cred, |
| 5985 | }; |
| 5986 | struct rpc_task_setup task_setup_data = { |
| 5987 | .task = &data->task, |
| 5988 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 5989 | .rpc_message = &msg, |
| 5990 | .callback_ops = &nfs4_layoutcommit_ops, |
| 5991 | .callback_data = data, |
| 5992 | .flags = RPC_TASK_ASYNC, |
| 5993 | }; |
| 5994 | struct rpc_task *task; |
| 5995 | int status = 0; |
| 5996 | |
| 5997 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 5998 | "lbw: %llu inode %lu\n", |
| 5999 | data->task.tk_pid, sync, |
| 6000 | data->args.lastbytewritten, |
| 6001 | data->args.inode->i_ino); |
| 6002 | |
| 6003 | task = rpc_run_task(&task_setup_data); |
| 6004 | if (IS_ERR(task)) |
| 6005 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6006 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6007 | goto out; |
| 6008 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6009 | if (status != 0) |
| 6010 | goto out; |
| 6011 | status = task->tk_status; |
| 6012 | out: |
| 6013 | dprintk("%s: status %d\n", __func__, status); |
| 6014 | rpc_put_task(task); |
| 6015 | return status; |
| 6016 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6017 | |
| 6018 | static int |
| 6019 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6020 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6021 | { |
| 6022 | struct nfs41_secinfo_no_name_args args = { |
| 6023 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6024 | }; |
| 6025 | struct nfs4_secinfo_res res = { |
| 6026 | .flavors = flavors, |
| 6027 | }; |
| 6028 | struct rpc_message msg = { |
| 6029 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6030 | .rpc_argp = &args, |
| 6031 | .rpc_resp = &res, |
| 6032 | }; |
| 6033 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6034 | } |
| 6035 | |
| 6036 | static int |
| 6037 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6038 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6039 | { |
| 6040 | struct nfs4_exception exception = { }; |
| 6041 | int err; |
| 6042 | do { |
| 6043 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6044 | switch (err) { |
| 6045 | case 0: |
| 6046 | case -NFS4ERR_WRONGSEC: |
| 6047 | case -NFS4ERR_NOTSUPP: |
| 6048 | break; |
| 6049 | default: |
| 6050 | err = nfs4_handle_exception(server, err, &exception); |
| 6051 | } |
| 6052 | } while (exception.retry); |
| 6053 | return err; |
| 6054 | } |
| 6055 | |
| 6056 | static int |
| 6057 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6058 | struct nfs_fsinfo *info) |
| 6059 | { |
| 6060 | int err; |
| 6061 | struct page *page; |
| 6062 | rpc_authflavor_t flavor; |
| 6063 | struct nfs4_secinfo_flavors *flavors; |
| 6064 | |
| 6065 | page = alloc_page(GFP_KERNEL); |
| 6066 | if (!page) { |
| 6067 | err = -ENOMEM; |
| 6068 | goto out; |
| 6069 | } |
| 6070 | |
| 6071 | flavors = page_address(page); |
| 6072 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6073 | |
| 6074 | /* |
| 6075 | * Fall back on "guess and check" method if |
| 6076 | * the server doesn't support SECINFO_NO_NAME |
| 6077 | */ |
| 6078 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6079 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6080 | goto out_freepage; |
| 6081 | } |
| 6082 | if (err) |
| 6083 | goto out_freepage; |
| 6084 | |
| 6085 | flavor = nfs_find_best_sec(flavors); |
| 6086 | if (err == 0) |
| 6087 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6088 | |
| 6089 | out_freepage: |
| 6090 | put_page(page); |
| 6091 | if (err == -EACCES) |
| 6092 | return -EPERM; |
| 6093 | out: |
| 6094 | return err; |
| 6095 | } |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6096 | static int _nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6097 | { |
| 6098 | int status; |
| 6099 | struct nfs41_test_stateid_args args = { |
| 6100 | .stateid = &state->stateid, |
| 6101 | }; |
| 6102 | struct nfs41_test_stateid_res res; |
| 6103 | struct rpc_message msg = { |
| 6104 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6105 | .rpc_argp = &args, |
| 6106 | .rpc_resp = &res, |
| 6107 | }; |
| 6108 | args.seq_args.sa_session = res.seq_res.sr_session = NULL; |
| 6109 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); |
| 6110 | return status; |
| 6111 | } |
| 6112 | |
| 6113 | static int nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6114 | { |
| 6115 | struct nfs4_exception exception = { }; |
| 6116 | int err; |
| 6117 | do { |
| 6118 | err = nfs4_handle_exception(server, |
| 6119 | _nfs41_test_stateid(server, state), |
| 6120 | &exception); |
| 6121 | } while (exception.retry); |
| 6122 | return err; |
| 6123 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6124 | |
| 6125 | static int _nfs4_free_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6126 | { |
| 6127 | int status; |
| 6128 | struct nfs41_free_stateid_args args = { |
| 6129 | .stateid = &state->stateid, |
| 6130 | }; |
| 6131 | struct nfs41_free_stateid_res res; |
| 6132 | struct rpc_message msg = { |
| 6133 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6134 | .rpc_argp = &args, |
| 6135 | .rpc_resp = &res, |
| 6136 | }; |
| 6137 | |
| 6138 | args.seq_args.sa_session = res.seq_res.sr_session = NULL; |
| 6139 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); |
| 6140 | return status; |
| 6141 | } |
| 6142 | |
| 6143 | static int nfs41_free_stateid(struct nfs_server *server, struct nfs4_state *state) |
| 6144 | { |
| 6145 | struct nfs4_exception exception = { }; |
| 6146 | int err; |
| 6147 | do { |
| 6148 | err = nfs4_handle_exception(server, |
| 6149 | _nfs4_free_stateid(server, state), |
| 6150 | &exception); |
| 6151 | } while (exception.retry); |
| 6152 | return err; |
| 6153 | } |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6154 | #endif /* CONFIG_NFS_V4_1 */ |
| 6155 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6156 | struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6157 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6158 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6159 | .recover_open = nfs4_open_reclaim, |
| 6160 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6161 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6162 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6163 | }; |
| 6164 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6165 | #if defined(CONFIG_NFS_V4_1) |
| 6166 | struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
| 6167 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6168 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6169 | .recover_open = nfs4_open_reclaim, |
| 6170 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6171 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6172 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6173 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6174 | }; |
| 6175 | #endif /* CONFIG_NFS_V4_1 */ |
| 6176 | |
| 6177 | struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6178 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6179 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6180 | .recover_open = nfs4_open_expired, |
| 6181 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6182 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6183 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | }; |
| 6185 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6186 | #if defined(CONFIG_NFS_V4_1) |
| 6187 | struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
| 6188 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6189 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6190 | .recover_open = nfs41_open_expired, |
| 6191 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6192 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6193 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6194 | }; |
| 6195 | #endif /* CONFIG_NFS_V4_1 */ |
| 6196 | |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6197 | struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
| 6198 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6199 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6200 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6201 | }; |
| 6202 | |
| 6203 | #if defined(CONFIG_NFS_V4_1) |
| 6204 | struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
| 6205 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6206 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6207 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6208 | }; |
| 6209 | #endif |
| 6210 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6211 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6212 | .minor_version = 0, |
| 6213 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6214 | .validate_stateid = nfs4_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6215 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6216 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6217 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6218 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6219 | }; |
| 6220 | |
| 6221 | #if defined(CONFIG_NFS_V4_1) |
| 6222 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6223 | .minor_version = 1, |
| 6224 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | e047a10 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6225 | .validate_stateid = nfs41_validate_delegation_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6226 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6227 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6228 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6229 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6230 | }; |
| 6231 | #endif |
| 6232 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6233 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6234 | [0] = &nfs_v4_0_minor_ops, |
| 6235 | #if defined(CONFIG_NFS_V4_1) |
| 6236 | [1] = &nfs_v4_1_minor_ops, |
| 6237 | #endif |
| 6238 | }; |
| 6239 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6240 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6241 | .permission = nfs_permission, |
| 6242 | .getattr = nfs_getattr, |
| 6243 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6244 | .getxattr = generic_getxattr, |
| 6245 | .setxattr = generic_setxattr, |
| 6246 | .listxattr = generic_listxattr, |
| 6247 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6248 | }; |
| 6249 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6250 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6251 | .version = 4, /* protocol version */ |
| 6252 | .dentry_ops = &nfs4_dentry_operations, |
| 6253 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6254 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6255 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6256 | .getroot = nfs4_proc_get_root, |
| 6257 | .getattr = nfs4_proc_getattr, |
| 6258 | .setattr = nfs4_proc_setattr, |
| 6259 | .lookup = nfs4_proc_lookup, |
| 6260 | .access = nfs4_proc_access, |
| 6261 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6262 | .create = nfs4_proc_create, |
| 6263 | .remove = nfs4_proc_remove, |
| 6264 | .unlink_setup = nfs4_proc_unlink_setup, |
| 6265 | .unlink_done = nfs4_proc_unlink_done, |
| 6266 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 6267 | .rename_setup = nfs4_proc_rename_setup, |
| 6268 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | .link = nfs4_proc_link, |
| 6270 | .symlink = nfs4_proc_symlink, |
| 6271 | .mkdir = nfs4_proc_mkdir, |
| 6272 | .rmdir = nfs4_proc_remove, |
| 6273 | .readdir = nfs4_proc_readdir, |
| 6274 | .mknod = nfs4_proc_mknod, |
| 6275 | .statfs = nfs4_proc_statfs, |
| 6276 | .fsinfo = nfs4_proc_fsinfo, |
| 6277 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 6278 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6279 | .decode_dirent = nfs4_decode_dirent, |
| 6280 | .read_setup = nfs4_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6281 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6282 | .write_setup = nfs4_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6283 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6284 | .commit_setup = nfs4_proc_commit_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 6285 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6286 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 6287 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 6288 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 6289 | .open_context = nfs4_atomic_open, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 6290 | .init_client = nfs4_init_client, |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 6291 | .secinfo = nfs4_proc_secinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6292 | }; |
| 6293 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6294 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 6295 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 6296 | .list = nfs4_xattr_list_nfs4_acl, |
| 6297 | .get = nfs4_xattr_get_nfs4_acl, |
| 6298 | .set = nfs4_xattr_set_nfs4_acl, |
| 6299 | }; |
| 6300 | |
| 6301 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 6302 | &nfs4_xattr_nfs4_acl_handler, |
| 6303 | NULL |
| 6304 | }; |
| 6305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6306 | /* |
| 6307 | * Local variables: |
| 6308 | * c-basic-offset: 8 |
| 6309 | * End: |
| 6310 | */ |