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> |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 42 | #include <linux/ratelimit.h> |
| 43 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/sunrpc/clnt.h> |
| 46 | #include <linux/nfs.h> |
| 47 | #include <linux/nfs4.h> |
| 48 | #include <linux/nfs_fs.h> |
| 49 | #include <linux/nfs_page.h> |
Bryan Schumaker | 9b7160c | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 50 | #include <linux/nfs_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/namei.h> |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 52 | #include <linux/mount.h> |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 53 | #include <linux/module.h> |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 54 | #include <linux/nfs_idmap.h> |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 55 | #include <linux/sunrpc/bc_xprt.h> |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 56 | #include <linux/xattr.h> |
Andy Adamson | c7a360b | 2011-01-25 19:15:32 -0500 | [diff] [blame] | 57 | #include <linux/utsname.h> |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 58 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 60 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include "delegation.h" |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 62 | #include "internal.h" |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 63 | #include "iostat.h" |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 64 | #include "callback.h" |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 65 | #include "pnfs.h" |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 66 | #include "netns.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 69 | |
Trond Myklebust | 2066fe8 | 2006-09-15 08:30:46 -0400 | [diff] [blame] | 70 | #define NFS4_POLL_RETRY_MIN (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define NFS4_POLL_RETRY_MAX (15*HZ) |
| 72 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 73 | #define NFS4_MAX_LOOP_ON_RECOVER (10) |
| 74 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 75 | struct nfs4_opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 76 | static int _nfs4_proc_open(struct nfs4_opendata *data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 77 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | 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] | 79 | static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 80 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr); |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 81 | static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *); |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 82 | 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] | 83 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 84 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 85 | struct nfs4_state *state); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 86 | #ifdef CONFIG_NFS_V4_1 |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 87 | static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *); |
| 88 | static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *); |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 89 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /* Prevent leaks of NFSv4 errors into userland */ |
WANG Cong | 46f72f5 | 2008-12-30 16:35:55 -0500 | [diff] [blame] | 91 | static int nfs4_map_errors(int err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 93 | if (err >= -1000) |
| 94 | return err; |
| 95 | switch (err) { |
| 96 | case -NFS4ERR_RESOURCE: |
| 97 | return -EREMOTEIO; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 98 | case -NFS4ERR_WRONGSEC: |
| 99 | return -EPERM; |
Trond Myklebust | 3ddeb7c | 2011-02-22 15:44:31 -0800 | [diff] [blame] | 100 | case -NFS4ERR_BADOWNER: |
| 101 | case -NFS4ERR_BADNAME: |
| 102 | return -EINVAL; |
Trond Myklebust | fb13bfa | 2012-05-28 11:36:28 -0400 | [diff] [blame] | 103 | case -NFS4ERR_SHARE_DENIED: |
| 104 | return -EACCES; |
Steve Dickson | f25efd8 | 2012-06-06 14:12:07 -0400 | [diff] [blame] | 105 | case -NFS4ERR_MINOR_VERS_MISMATCH: |
| 106 | return -EPROTONOSUPPORT; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 107 | case -NFS4ERR_ACCESS: |
| 108 | return -EACCES; |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 109 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | dprintk("%s could not handle NFSv4 error %d\n", |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 111 | __func__, -err); |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 112 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
Trond Myklebust | 52567b0 | 2009-10-23 14:46:42 -0400 | [diff] [blame] | 114 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* |
| 118 | * This is our standard bitmap for GETATTR requests. |
| 119 | */ |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 120 | const u32 nfs4_fattr_bitmap[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | FATTR4_WORD0_TYPE |
| 122 | | FATTR4_WORD0_CHANGE |
| 123 | | FATTR4_WORD0_SIZE |
| 124 | | FATTR4_WORD0_FSID |
| 125 | | FATTR4_WORD0_FILEID, |
| 126 | FATTR4_WORD1_MODE |
| 127 | | FATTR4_WORD1_NUMLINKS |
| 128 | | FATTR4_WORD1_OWNER |
| 129 | | FATTR4_WORD1_OWNER_GROUP |
| 130 | | FATTR4_WORD1_RAWDEV |
| 131 | | FATTR4_WORD1_SPACE_USED |
| 132 | | FATTR4_WORD1_TIME_ACCESS |
| 133 | | FATTR4_WORD1_TIME_METADATA |
| 134 | | FATTR4_WORD1_TIME_MODIFY |
| 135 | }; |
| 136 | |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 137 | static const u32 nfs4_pnfs_open_bitmap[3] = { |
| 138 | FATTR4_WORD0_TYPE |
| 139 | | FATTR4_WORD0_CHANGE |
| 140 | | FATTR4_WORD0_SIZE |
| 141 | | FATTR4_WORD0_FSID |
| 142 | | FATTR4_WORD0_FILEID, |
| 143 | FATTR4_WORD1_MODE |
| 144 | | FATTR4_WORD1_NUMLINKS |
| 145 | | FATTR4_WORD1_OWNER |
| 146 | | FATTR4_WORD1_OWNER_GROUP |
| 147 | | FATTR4_WORD1_RAWDEV |
| 148 | | FATTR4_WORD1_SPACE_USED |
| 149 | | FATTR4_WORD1_TIME_ACCESS |
| 150 | | FATTR4_WORD1_TIME_METADATA |
| 151 | | FATTR4_WORD1_TIME_MODIFY, |
| 152 | FATTR4_WORD2_MDSTHRESHOLD |
| 153 | }; |
| 154 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 155 | static const u32 nfs4_open_noattr_bitmap[3] = { |
| 156 | FATTR4_WORD0_TYPE |
| 157 | | FATTR4_WORD0_CHANGE |
| 158 | | FATTR4_WORD0_FILEID, |
| 159 | }; |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | const u32 nfs4_statfs_bitmap[2] = { |
| 162 | FATTR4_WORD0_FILES_AVAIL |
| 163 | | FATTR4_WORD0_FILES_FREE |
| 164 | | FATTR4_WORD0_FILES_TOTAL, |
| 165 | FATTR4_WORD1_SPACE_AVAIL |
| 166 | | FATTR4_WORD1_SPACE_FREE |
| 167 | | FATTR4_WORD1_SPACE_TOTAL |
| 168 | }; |
| 169 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 170 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | FATTR4_WORD0_MAXLINK |
| 172 | | FATTR4_WORD0_MAXNAME, |
| 173 | 0 |
| 174 | }; |
| 175 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 176 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | | FATTR4_WORD0_MAXREAD |
| 178 | | FATTR4_WORD0_MAXWRITE |
| 179 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 180 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 181 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 182 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 185 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 186 | FATTR4_WORD0_TYPE |
| 187 | | FATTR4_WORD0_CHANGE |
| 188 | | FATTR4_WORD0_SIZE |
| 189 | | FATTR4_WORD0_FSID |
| 190 | | FATTR4_WORD0_FILEID |
| 191 | | FATTR4_WORD0_FS_LOCATIONS, |
| 192 | FATTR4_WORD1_MODE |
| 193 | | FATTR4_WORD1_NUMLINKS |
| 194 | | FATTR4_WORD1_OWNER |
| 195 | | FATTR4_WORD1_OWNER_GROUP |
| 196 | | FATTR4_WORD1_RAWDEV |
| 197 | | FATTR4_WORD1_SPACE_USED |
| 198 | | FATTR4_WORD1_TIME_ACCESS |
| 199 | | FATTR4_WORD1_TIME_METADATA |
| 200 | | FATTR4_WORD1_TIME_MODIFY |
| 201 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 202 | }; |
| 203 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 204 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | struct nfs4_readdir_arg *readdir) |
| 206 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 207 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | BUG_ON(readdir->count < 80); |
| 210 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 211 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | readdir->cookie = 0; |
| 217 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 218 | if (cookie == 2) |
| 219 | return; |
| 220 | |
| 221 | /* |
| 222 | * NFSv4 servers do not return entries for '.' and '..' |
| 223 | * Therefore, we fake these entries here. We let '.' |
| 224 | * have cookie 0 and '..' have cookie 1. Note that |
| 225 | * when talking to the server, we always send cookie 0 |
| 226 | * instead of 1 or 2. |
| 227 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 228 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | if (cookie == 0) { |
| 231 | *p++ = xdr_one; /* next */ |
| 232 | *p++ = xdr_zero; /* cookie, first word */ |
| 233 | *p++ = xdr_one; /* cookie, second word */ |
| 234 | *p++ = xdr_one; /* entry len */ |
| 235 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 236 | p++; |
| 237 | *p++ = xdr_one; /* bitmap length */ |
| 238 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 239 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 240 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | *p++ = xdr_one; /* next */ |
| 244 | *p++ = xdr_zero; /* cookie, first word */ |
| 245 | *p++ = xdr_two; /* cookie, second word */ |
| 246 | *p++ = xdr_two; /* entry len */ |
| 247 | memcpy(p, "..\0\0", 4); /* entry */ |
| 248 | p++; |
| 249 | *p++ = xdr_one; /* bitmap length */ |
| 250 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 251 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 252 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
| 254 | readdir->pgbase = (char *)p - (char *)start; |
| 255 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 256 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 259 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 260 | { |
| 261 | int res; |
| 262 | |
| 263 | might_sleep(); |
| 264 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 265 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 266 | nfs_wait_bit_killable, TASK_KILLABLE); |
Chuck Lever | 46a87b8 | 2012-07-11 16:30:41 -0400 | [diff] [blame] | 267 | if (res) |
| 268 | return res; |
| 269 | |
| 270 | if (clp->cl_cons_state < 0) |
| 271 | return clp->cl_cons_state; |
| 272 | return 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 276 | { |
| 277 | int res = 0; |
| 278 | |
| 279 | might_sleep(); |
| 280 | |
| 281 | if (*timeout <= 0) |
| 282 | *timeout = NFS4_POLL_RETRY_MIN; |
| 283 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 284 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 285 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 286 | if (fatal_signal_pending(current)) |
| 287 | res = -ERESTARTSYS; |
| 288 | *timeout <<= 1; |
| 289 | return res; |
| 290 | } |
| 291 | |
| 292 | /* This is the error handling routine for processes that are allowed |
| 293 | * to sleep. |
| 294 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 295 | 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] | 296 | { |
| 297 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 298 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 299 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 300 | int ret = errorcode; |
| 301 | |
| 302 | exception->retry = 0; |
| 303 | switch(errorcode) { |
| 304 | case 0: |
| 305 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 306 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 307 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 308 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 309 | exception->retry = 1; |
| 310 | return 0; |
| 311 | } |
| 312 | if (state == NULL) |
| 313 | break; |
| 314 | nfs4_schedule_stateid_recovery(server, state); |
| 315 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 316 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 317 | case -NFS4ERR_ADMIN_REVOKED: |
| 318 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 319 | if (state == NULL) |
| 320 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 321 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 322 | nfs4_schedule_stateid_recovery(server, state); |
| 323 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 324 | case -NFS4ERR_EXPIRED: |
| 325 | if (state != NULL) |
| 326 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 327 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 328 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 329 | nfs4_schedule_lease_recovery(clp); |
| 330 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 331 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 332 | case -NFS4ERR_BADSESSION: |
| 333 | case -NFS4ERR_BADSLOT: |
| 334 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 335 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 336 | case -NFS4ERR_DEADSESSION: |
| 337 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 338 | case -NFS4ERR_SEQ_MISORDERED: |
| 339 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 340 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 341 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 342 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 343 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 344 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 345 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 346 | if (exception->timeout > HZ) { |
| 347 | /* We have retried a decent amount, time to |
| 348 | * fail |
| 349 | */ |
| 350 | ret = -EBUSY; |
| 351 | break; |
| 352 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 353 | case -NFS4ERR_GRACE: |
| 354 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 355 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 356 | ret = nfs4_delay(server->client, &exception->timeout); |
| 357 | if (ret != 0) |
| 358 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 359 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 360 | case -NFS4ERR_OLD_STATEID: |
| 361 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 362 | break; |
| 363 | case -NFS4ERR_BADOWNER: |
| 364 | /* The following works around a Linux server bug! */ |
| 365 | case -NFS4ERR_BADNAME: |
| 366 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 367 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 368 | exception->retry = 1; |
| 369 | printk(KERN_WARNING "NFS: v4 server %s " |
| 370 | "does not accept raw " |
| 371 | "uid/gids. " |
| 372 | "Reenabling the idmapper.\n", |
| 373 | server->nfs_client->cl_hostname); |
| 374 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 375 | } |
| 376 | /* We failed to handle the error */ |
| 377 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 378 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 379 | ret = nfs4_wait_clnt_recover(clp); |
| 380 | if (ret == 0) |
| 381 | exception->retry = 1; |
| 382 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 386 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | spin_lock(&clp->cl_lock); |
| 389 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 390 | clp->cl_last_renewal = timestamp; |
| 391 | spin_unlock(&clp->cl_lock); |
| 392 | } |
| 393 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 394 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 395 | { |
| 396 | do_renew_lease(server->nfs_client, timestamp); |
| 397 | } |
| 398 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 399 | #if defined(CONFIG_NFS_V4_1) |
| 400 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 401 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 402 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 403 | * |
| 404 | * freeing a slot is trivially done by clearing its respective bit |
| 405 | * in the bitmap. |
| 406 | * If the freed slotid equals highest_used_slotid we want to update it |
| 407 | * so that the server would be able to size down the slot table if needed, |
| 408 | * otherwise we know that the highest_used_slotid is still in use. |
| 409 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 410 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 411 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 412 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 413 | * |
| 414 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 415 | */ |
| 416 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 417 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 418 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 419 | BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 420 | /* clear used bit in bitmap */ |
| 421 | __clear_bit(slotid, tbl->used_slots); |
| 422 | |
| 423 | /* update highest_used_slotid when it is freed */ |
| 424 | if (slotid == tbl->highest_used_slotid) { |
| 425 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 426 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 427 | tbl->highest_used_slotid = slotid; |
| 428 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 429 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 430 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 431 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 432 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 433 | } |
| 434 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 435 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 436 | { |
| 437 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 438 | return true; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 439 | } |
| 440 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 441 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 442 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 443 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 444 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 445 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 446 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 447 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 448 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 449 | return; |
| 450 | } |
| 451 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 452 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 453 | return; |
| 454 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 455 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 456 | complete(&ses->fc_slot_table.complete); |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * Signal state manager thread if session back channel is drained |
| 461 | */ |
| 462 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 463 | { |
| 464 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 465 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 466 | return; |
| 467 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 468 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 469 | } |
| 470 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 471 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 472 | { |
| 473 | struct nfs4_slot_table *tbl; |
| 474 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 475 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 476 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 477 | /* just wake up the next guy waiting since |
| 478 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 479 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 480 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 481 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 482 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 483 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 484 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 485 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 486 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 487 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 488 | } |
| 489 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 490 | 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] | 491 | { |
| 492 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 493 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 494 | |
| 495 | /* |
| 496 | * sr_status remains 1 if an RPC level error occurred. The server |
| 497 | * may or may not have processed the sequence operation.. |
| 498 | * Proceed as if the server received and processed the sequence |
| 499 | * operation. |
| 500 | */ |
| 501 | if (res->sr_status == 1) |
| 502 | res->sr_status = NFS_OK; |
| 503 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 504 | /* don't increment the sequence number if the task wasn't sent */ |
| 505 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 506 | goto out; |
| 507 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 508 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 509 | switch (res->sr_status) { |
| 510 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 511 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 512 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 513 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 514 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 515 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 516 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 517 | if (res->sr_status_flags != 0) |
| 518 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 519 | break; |
| 520 | case -NFS4ERR_DELAY: |
| 521 | /* The server detected a resend of the RPC call and |
| 522 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 523 | * of RFC5661. |
| 524 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 525 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 526 | __func__, |
| 527 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 528 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 529 | goto out_retry; |
| 530 | default: |
| 531 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 532 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 533 | } |
| 534 | out: |
| 535 | /* The session may be reset by one of the error handlers. */ |
| 536 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 537 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 538 | return 1; |
| 539 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 540 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 541 | goto out; |
| 542 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 543 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 544 | } |
| 545 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 546 | static int nfs4_sequence_done(struct rpc_task *task, |
| 547 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 548 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 549 | if (res->sr_session == NULL) |
| 550 | return 1; |
| 551 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 552 | } |
| 553 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 554 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 555 | * nfs4_find_slot - efficiently look for a free slot |
| 556 | * |
| 557 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 558 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 559 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 560 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 561 | * |
| 562 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 563 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 564 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 565 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 566 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 567 | u32 slotid; |
| 568 | u32 ret_id = NFS4_NO_SLOT; |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 569 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 570 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 571 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 572 | tbl->max_slots); |
| 573 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 574 | if (slotid >= tbl->max_slots) |
| 575 | goto out; |
| 576 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 577 | if (slotid > tbl->highest_used_slotid || |
| 578 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 579 | tbl->highest_used_slotid = slotid; |
| 580 | ret_id = slotid; |
| 581 | out: |
| 582 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 583 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 584 | return ret_id; |
| 585 | } |
| 586 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 587 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 588 | struct nfs4_sequence_res *res, int cache_reply) |
| 589 | { |
| 590 | args->sa_session = NULL; |
| 591 | args->sa_cache_this = 0; |
| 592 | if (cache_reply) |
| 593 | args->sa_cache_this = 1; |
| 594 | res->sr_session = NULL; |
| 595 | res->sr_slot = NULL; |
| 596 | } |
| 597 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 598 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 599 | struct nfs4_sequence_args *args, |
| 600 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 601 | struct rpc_task *task) |
| 602 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 603 | struct nfs4_slot *slot; |
| 604 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 605 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 606 | |
| 607 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 608 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 609 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 610 | return 0; |
| 611 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 612 | tbl = &session->fc_slot_table; |
| 613 | |
| 614 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 615 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 616 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 617 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 618 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 619 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 620 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 621 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 622 | } |
| 623 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 624 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 625 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 626 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 627 | spin_unlock(&tbl->slot_tbl_lock); |
| 628 | dprintk("%s enforce FIFO order\n", __func__); |
| 629 | return -EAGAIN; |
| 630 | } |
| 631 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 632 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 633 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 634 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 635 | spin_unlock(&tbl->slot_tbl_lock); |
| 636 | dprintk("<-- %s: no free slots\n", __func__); |
| 637 | return -EAGAIN; |
| 638 | } |
| 639 | spin_unlock(&tbl->slot_tbl_lock); |
| 640 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 641 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 642 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 643 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 644 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 645 | |
| 646 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 647 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 648 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 649 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 650 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 651 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 652 | /* |
| 653 | * sr_status is only set in decode_sequence, and so will remain |
| 654 | * set to 1 if an rpc level failure occurs. |
| 655 | */ |
| 656 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 657 | return 0; |
| 658 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 659 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 660 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 661 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 662 | struct nfs4_sequence_args *args, |
| 663 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 664 | struct rpc_task *task) |
| 665 | { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 666 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 667 | int ret = 0; |
| 668 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 669 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 670 | goto out; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 671 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 672 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 673 | __func__, session->clp, session, res->sr_slot ? |
| 674 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 675 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 676 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 677 | out: |
| 678 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 679 | return ret; |
| 680 | } |
| 681 | |
| 682 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 683 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 684 | struct nfs4_sequence_args *seq_args; |
| 685 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 686 | }; |
| 687 | |
| 688 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 689 | { |
| 690 | struct nfs41_call_sync_data *data = calldata; |
| 691 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 692 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 693 | |
| 694 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 695 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 696 | return; |
| 697 | rpc_call_start(task); |
| 698 | } |
| 699 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 700 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 701 | { |
| 702 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 703 | nfs41_call_sync_prepare(task, calldata); |
| 704 | } |
| 705 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 706 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 707 | { |
| 708 | struct nfs41_call_sync_data *data = calldata; |
| 709 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 710 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 711 | } |
| 712 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 713 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 714 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 715 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 716 | }; |
| 717 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 718 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 719 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 720 | .rpc_call_done = nfs41_call_sync_done, |
| 721 | }; |
| 722 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 723 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 724 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 725 | struct rpc_message *msg, |
| 726 | struct nfs4_sequence_args *args, |
| 727 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 728 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 729 | { |
| 730 | int ret; |
| 731 | struct rpc_task *task; |
| 732 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 733 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 734 | .seq_args = args, |
| 735 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 736 | }; |
| 737 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 738 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 739 | .rpc_message = msg, |
| 740 | .callback_ops = &nfs41_call_sync_ops, |
| 741 | .callback_data = &data |
| 742 | }; |
| 743 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 744 | if (privileged) |
| 745 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 746 | task = rpc_run_task(&task_setup); |
| 747 | if (IS_ERR(task)) |
| 748 | ret = PTR_ERR(task); |
| 749 | else { |
| 750 | ret = task->tk_status; |
| 751 | rpc_put_task(task); |
| 752 | } |
| 753 | return ret; |
| 754 | } |
| 755 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 756 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 757 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 758 | struct rpc_message *msg, |
| 759 | struct nfs4_sequence_args *args, |
| 760 | struct nfs4_sequence_res *res, |
| 761 | int cache_reply) |
| 762 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 763 | nfs41_init_sequence(args, res, cache_reply); |
| 764 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 765 | } |
| 766 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 767 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 768 | static inline |
| 769 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 770 | struct nfs4_sequence_res *res, int cache_reply) |
| 771 | { |
| 772 | } |
| 773 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 774 | static int nfs4_sequence_done(struct rpc_task *task, |
| 775 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 776 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 777 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 778 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 779 | #endif /* CONFIG_NFS_V4_1 */ |
| 780 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 781 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 782 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 783 | struct rpc_message *msg, |
| 784 | struct nfs4_sequence_args *args, |
| 785 | struct nfs4_sequence_res *res, |
| 786 | int cache_reply) |
| 787 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 788 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 789 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 790 | } |
| 791 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 792 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 793 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 794 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 795 | struct rpc_message *msg, |
| 796 | struct nfs4_sequence_args *args, |
| 797 | struct nfs4_sequence_res *res, |
| 798 | int cache_reply) |
| 799 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 800 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 801 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 802 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 803 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 804 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 806 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 808 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 809 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 810 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 811 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 812 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 813 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 816 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 817 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | struct nfs_openargs o_arg; |
| 819 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 820 | struct nfs_open_confirmargs c_arg; |
| 821 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 822 | struct nfs4_string owner_name; |
| 823 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 824 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 825 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 826 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 827 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 828 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 829 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 830 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 831 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 832 | int rpc_status; |
| 833 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 834 | }; |
| 835 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 836 | |
| 837 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 838 | { |
| 839 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 840 | p->o_res.seqid = p->o_arg.seqid; |
| 841 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 842 | p->o_res.server = p->o_arg.server; |
Andy Adamson | 5f65753 | 2012-10-03 02:39:34 -0400 | [diff] [blame] | 843 | p->o_res.access_request = p->o_arg.access; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 844 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 845 | nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 846 | } |
| 847 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 848 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 849 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 850 | const struct iattr *attrs, |
| 851 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 852 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 853 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 854 | struct inode *dir = parent->d_inode; |
| 855 | struct nfs_server *server = NFS_SERVER(dir); |
| 856 | struct nfs4_opendata *p; |
| 857 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 858 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 859 | if (p == NULL) |
| 860 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 861 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 862 | if (p->o_arg.seqid == NULL) |
| 863 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 864 | nfs_sb_active(dentry->d_sb); |
| 865 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 866 | p->dir = parent; |
| 867 | p->owner = sp; |
| 868 | atomic_inc(&sp->so_count); |
| 869 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 870 | p->o_arg.open_flags = flags; |
| 871 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 872 | /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS |
| 873 | * will return permission denied for all bits until close */ |
| 874 | if (!(flags & O_EXCL)) { |
| 875 | /* ask server to check for all possible rights as results |
| 876 | * are cached */ |
| 877 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 878 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
Weston Andros Adamson | ae2bb03 | 2012-10-02 14:49:52 -0700 | [diff] [blame] | 879 | } |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 880 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 881 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 882 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 883 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 884 | p->o_arg.server = server; |
| 885 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 886 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 887 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 888 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 889 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 890 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 891 | p->o_arg.u.attrs = &p->attrs; |
| 892 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 893 | |
| 894 | verf[0] = jiffies; |
| 895 | verf[1] = current->pid; |
| 896 | memcpy(p->o_arg.u.verifier.data, verf, |
| 897 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 898 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 899 | p->c_arg.fh = &p->o_res.fh; |
| 900 | p->c_arg.stateid = &p->o_res.stateid; |
| 901 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 902 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 903 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 904 | return p; |
| 905 | err_free: |
| 906 | kfree(p); |
| 907 | err: |
| 908 | dput(parent); |
| 909 | return NULL; |
| 910 | } |
| 911 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 912 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 913 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 914 | struct nfs4_opendata *p = container_of(kref, |
| 915 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 916 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 917 | |
| 918 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 919 | if (p->state != NULL) |
| 920 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 921 | nfs4_put_state_owner(p->owner); |
| 922 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 923 | dput(p->dentry); |
| 924 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 925 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 926 | kfree(p); |
| 927 | } |
| 928 | |
| 929 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 930 | { |
| 931 | if (p != NULL) |
| 932 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 933 | } |
| 934 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 935 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 936 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 937 | int ret; |
| 938 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 939 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 940 | return ret; |
| 941 | } |
| 942 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 943 | 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] | 944 | { |
| 945 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 946 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 947 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 948 | goto out; |
| 949 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 950 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 951 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 952 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 953 | break; |
| 954 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 955 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 956 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 957 | break; |
| 958 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 959 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 960 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 961 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 962 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 963 | return ret; |
| 964 | } |
| 965 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 966 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 967 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 968 | if (delegation == NULL) |
| 969 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 970 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 971 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 972 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 973 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 974 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 975 | return 1; |
| 976 | } |
| 977 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 978 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 979 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 980 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 981 | case FMODE_WRITE: |
| 982 | state->n_wronly++; |
| 983 | break; |
| 984 | case FMODE_READ: |
| 985 | state->n_rdonly++; |
| 986 | break; |
| 987 | case FMODE_READ|FMODE_WRITE: |
| 988 | state->n_rdwr++; |
| 989 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 990 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 991 | } |
| 992 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 993 | 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] | 994 | { |
| 995 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 996 | nfs4_stateid_copy(&state->stateid, stateid); |
| 997 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 998 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 999 | case FMODE_READ: |
| 1000 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1001 | break; |
| 1002 | case FMODE_WRITE: |
| 1003 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1004 | break; |
| 1005 | case FMODE_READ|FMODE_WRITE: |
| 1006 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 1007 | } |
| 1008 | } |
| 1009 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1010 | 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] | 1011 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1012 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1013 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1014 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | 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] | 1018 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1019 | /* |
| 1020 | * Protect the call to nfs4_state_set_mode_locked and |
| 1021 | * serialise the stateid update |
| 1022 | */ |
| 1023 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1024 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1025 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1026 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1027 | } |
| 1028 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1029 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1030 | write_sequnlock(&state->seqlock); |
| 1031 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1032 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1033 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1036 | 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] | 1037 | { |
| 1038 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1039 | struct nfs_delegation *deleg_cur; |
| 1040 | int ret = 0; |
| 1041 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1042 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1043 | |
| 1044 | rcu_read_lock(); |
| 1045 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1046 | if (deleg_cur == NULL) |
| 1047 | goto no_delegation; |
| 1048 | |
| 1049 | spin_lock(&deleg_cur->lock); |
| 1050 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1051 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1052 | goto no_delegation_unlock; |
| 1053 | |
| 1054 | if (delegation == NULL) |
| 1055 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1056 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1057 | goto no_delegation_unlock; |
| 1058 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1059 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1060 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1061 | ret = 1; |
| 1062 | no_delegation_unlock: |
| 1063 | spin_unlock(&deleg_cur->lock); |
| 1064 | no_delegation: |
| 1065 | rcu_read_unlock(); |
| 1066 | |
| 1067 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1068 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1069 | ret = 1; |
| 1070 | } |
| 1071 | |
| 1072 | return ret; |
| 1073 | } |
| 1074 | |
| 1075 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1076 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1077 | { |
| 1078 | struct nfs_delegation *delegation; |
| 1079 | |
| 1080 | rcu_read_lock(); |
| 1081 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1082 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1083 | rcu_read_unlock(); |
| 1084 | return; |
| 1085 | } |
| 1086 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1087 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1088 | } |
| 1089 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1090 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1091 | { |
| 1092 | struct nfs4_state *state = opendata->state; |
| 1093 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1094 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1095 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1096 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1097 | nfs4_stateid stateid; |
| 1098 | int ret = -EAGAIN; |
| 1099 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1100 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1101 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1102 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1103 | if (can_open_cached(state, fmode, open_mode)) { |
| 1104 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1105 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1106 | goto out_return_state; |
| 1107 | } |
| 1108 | spin_unlock(&state->owner->so_lock); |
| 1109 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1110 | rcu_read_lock(); |
| 1111 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1112 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1113 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1114 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1115 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1116 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1117 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1118 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1119 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1120 | if (ret != 0) |
| 1121 | goto out; |
| 1122 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1123 | |
| 1124 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1125 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1126 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1127 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1128 | out: |
| 1129 | return ERR_PTR(ret); |
| 1130 | out_return_state: |
| 1131 | atomic_inc(&state->count); |
| 1132 | return state; |
| 1133 | } |
| 1134 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1135 | static void |
| 1136 | nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state) |
| 1137 | { |
| 1138 | struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client; |
| 1139 | struct nfs_delegation *delegation; |
| 1140 | int delegation_flags = 0; |
| 1141 | |
| 1142 | rcu_read_lock(); |
| 1143 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
| 1144 | if (delegation) |
| 1145 | delegation_flags = delegation->flags; |
| 1146 | rcu_read_unlock(); |
| 1147 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1148 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1149 | "returning a delegation for " |
| 1150 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
| 1151 | clp->cl_hostname); |
| 1152 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
| 1153 | nfs_inode_set_delegation(state->inode, |
| 1154 | data->owner->so_cred, |
| 1155 | &data->o_res); |
| 1156 | else |
| 1157 | nfs_inode_reclaim_delegation(state->inode, |
| 1158 | data->owner->so_cred, |
| 1159 | &data->o_res); |
| 1160 | } |
| 1161 | |
| 1162 | /* |
| 1163 | * Check the inode attributes against the CLAIM_PREVIOUS returned attributes |
| 1164 | * and update the nfs4_state. |
| 1165 | */ |
| 1166 | static struct nfs4_state * |
| 1167 | _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data) |
| 1168 | { |
| 1169 | struct inode *inode = data->state->inode; |
| 1170 | struct nfs4_state *state = data->state; |
| 1171 | int ret; |
| 1172 | |
| 1173 | if (!data->rpc_done) { |
| 1174 | ret = data->rpc_status; |
| 1175 | goto err; |
| 1176 | } |
| 1177 | |
| 1178 | ret = -ESTALE; |
| 1179 | if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) || |
| 1180 | !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) || |
| 1181 | !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE)) |
| 1182 | goto err; |
| 1183 | |
| 1184 | ret = -ENOMEM; |
| 1185 | state = nfs4_get_open_state(inode, data->owner); |
| 1186 | if (state == NULL) |
| 1187 | goto err; |
| 1188 | |
| 1189 | ret = nfs_refresh_inode(inode, &data->f_attr); |
| 1190 | if (ret) |
| 1191 | goto err; |
| 1192 | |
| 1193 | if (data->o_res.delegation_type != 0) |
| 1194 | nfs4_opendata_check_deleg(data, state); |
| 1195 | update_open_stateid(state, &data->o_res.stateid, NULL, |
| 1196 | data->o_arg.fmode); |
| 1197 | |
| 1198 | return state; |
| 1199 | err: |
| 1200 | return ERR_PTR(ret); |
| 1201 | |
| 1202 | } |
| 1203 | |
| 1204 | static struct nfs4_state * |
| 1205 | _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1206 | { |
| 1207 | struct inode *inode; |
| 1208 | struct nfs4_state *state = NULL; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1209 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1210 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1211 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1212 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1213 | goto out; |
| 1214 | } |
| 1215 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1216 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1217 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1218 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1219 | 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] | 1220 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1221 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1222 | goto err; |
| 1223 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1224 | state = nfs4_get_open_state(inode, data->owner); |
| 1225 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1226 | goto err_put_inode; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1227 | if (data->o_res.delegation_type != 0) |
| 1228 | nfs4_opendata_check_deleg(data, state); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1229 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1230 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1231 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1232 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1233 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1234 | err_put_inode: |
| 1235 | iput(inode); |
| 1236 | err: |
| 1237 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1238 | } |
| 1239 | |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1240 | static struct nfs4_state * |
| 1241 | nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1242 | { |
| 1243 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) |
| 1244 | return _nfs4_opendata_reclaim_to_nfs4_state(data); |
| 1245 | return _nfs4_opendata_to_nfs4_state(data); |
| 1246 | } |
| 1247 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1248 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1249 | { |
| 1250 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1251 | struct nfs_open_context *ctx; |
| 1252 | |
| 1253 | spin_lock(&state->inode->i_lock); |
| 1254 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1255 | if (ctx->state != state) |
| 1256 | continue; |
| 1257 | get_nfs_open_context(ctx); |
| 1258 | spin_unlock(&state->inode->i_lock); |
| 1259 | return ctx; |
| 1260 | } |
| 1261 | spin_unlock(&state->inode->i_lock); |
| 1262 | return ERR_PTR(-ENOENT); |
| 1263 | } |
| 1264 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1265 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1266 | { |
| 1267 | struct nfs4_opendata *opendata; |
| 1268 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1269 | 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] | 1270 | if (opendata == NULL) |
| 1271 | return ERR_PTR(-ENOMEM); |
| 1272 | opendata->state = state; |
| 1273 | atomic_inc(&state->count); |
| 1274 | return opendata; |
| 1275 | } |
| 1276 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1277 | 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] | 1278 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1279 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1280 | int ret; |
| 1281 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1282 | opendata->o_arg.open_flags = 0; |
| 1283 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1284 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1285 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1286 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1287 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1288 | if (ret != 0) |
| 1289 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1290 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1291 | if (IS_ERR(newstate)) |
| 1292 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1293 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1294 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1295 | return 0; |
| 1296 | } |
| 1297 | |
| 1298 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1299 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1300 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1301 | int ret; |
| 1302 | |
| 1303 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1304 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1305 | smp_rmb(); |
| 1306 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1307 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1308 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1309 | if (ret != 0) |
| 1310 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1311 | if (newstate != state) |
| 1312 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1313 | } |
| 1314 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1315 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1316 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1317 | if (ret != 0) |
| 1318 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1319 | if (newstate != state) |
| 1320 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1321 | } |
| 1322 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1323 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1324 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1325 | if (ret != 0) |
| 1326 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1327 | if (newstate != state) |
| 1328 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1329 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1330 | /* |
| 1331 | * We may have performed cached opens for all three recoveries. |
| 1332 | * Check if we need to update the current stateid. |
| 1333 | */ |
| 1334 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1335 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1336 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1337 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1338 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1339 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1340 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1341 | return 0; |
| 1342 | } |
| 1343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | /* |
| 1345 | * OPEN_RECLAIM: |
| 1346 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1348 | 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] | 1349 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1350 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1351 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1352 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | int status; |
| 1354 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1355 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1356 | if (IS_ERR(opendata)) |
| 1357 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1358 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1359 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1360 | rcu_read_lock(); |
| 1361 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1362 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1363 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1364 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1365 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1366 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1367 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | return status; |
| 1369 | } |
| 1370 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1371 | 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] | 1372 | { |
| 1373 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1374 | struct nfs4_exception exception = { }; |
| 1375 | int err; |
| 1376 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1377 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1378 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1379 | break; |
| 1380 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | } while (exception.retry); |
| 1382 | return err; |
| 1383 | } |
| 1384 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1385 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1386 | { |
| 1387 | struct nfs_open_context *ctx; |
| 1388 | int ret; |
| 1389 | |
| 1390 | ctx = nfs4_state_find_open_context(state); |
| 1391 | if (IS_ERR(ctx)) |
| 1392 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1393 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1394 | put_nfs_open_context(ctx); |
| 1395 | return ret; |
| 1396 | } |
| 1397 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1398 | 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] | 1399 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1400 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1401 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1403 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1404 | if (IS_ERR(opendata)) |
| 1405 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1406 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1407 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1408 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1409 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1410 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1413 | 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] | 1414 | { |
| 1415 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1416 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | int err; |
| 1418 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1419 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | switch (err) { |
| 1421 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1422 | case -ENOENT: |
| 1423 | case -ESTALE: |
| 1424 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1425 | case -NFS4ERR_BADSESSION: |
| 1426 | case -NFS4ERR_BADSLOT: |
| 1427 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1428 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1429 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1430 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1431 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | case -NFS4ERR_STALE_CLIENTID: |
| 1433 | case -NFS4ERR_STALE_STATEID: |
| 1434 | case -NFS4ERR_EXPIRED: |
| 1435 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1436 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1437 | goto out; |
| 1438 | case -ERESTARTSYS: |
| 1439 | /* |
| 1440 | * The show must go on: exit, but mark the |
| 1441 | * stateid as needing recovery. |
| 1442 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1443 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1444 | case -NFS4ERR_ADMIN_REVOKED: |
| 1445 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1446 | nfs_inode_find_state_and_recover(state->inode, |
| 1447 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1448 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1449 | case -EKEYEXPIRED: |
| 1450 | /* |
| 1451 | * User RPCSEC_GSS context has expired. |
| 1452 | * We cannot recover this stateid now, so |
| 1453 | * skip it and allow recovery thread to |
| 1454 | * proceed. |
| 1455 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1456 | case -ENOMEM: |
| 1457 | err = 0; |
| 1458 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | } |
| 1460 | err = nfs4_handle_exception(server, err, &exception); |
| 1461 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1462 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | return err; |
| 1464 | } |
| 1465 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1466 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1467 | { |
| 1468 | struct nfs4_opendata *data = calldata; |
| 1469 | |
| 1470 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1471 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1472 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1473 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1474 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1475 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1476 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | static void nfs4_open_confirm_release(void *calldata) |
| 1480 | { |
| 1481 | struct nfs4_opendata *data = calldata; |
| 1482 | struct nfs4_state *state = NULL; |
| 1483 | |
| 1484 | /* If this request hasn't been cancelled, do nothing */ |
| 1485 | if (data->cancelled == 0) |
| 1486 | goto out_free; |
| 1487 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1488 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1489 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1490 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1491 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1492 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1493 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1494 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1498 | .rpc_call_done = nfs4_open_confirm_done, |
| 1499 | .rpc_release = nfs4_open_confirm_release, |
| 1500 | }; |
| 1501 | |
| 1502 | /* |
| 1503 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1504 | */ |
| 1505 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1506 | { |
| 1507 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1508 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1509 | struct rpc_message msg = { |
| 1510 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1511 | .rpc_argp = &data->c_arg, |
| 1512 | .rpc_resp = &data->c_res, |
| 1513 | .rpc_cred = data->owner->so_cred, |
| 1514 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1515 | struct rpc_task_setup task_setup_data = { |
| 1516 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1517 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1518 | .callback_ops = &nfs4_open_confirm_ops, |
| 1519 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1520 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1521 | .flags = RPC_TASK_ASYNC, |
| 1522 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | int status; |
| 1524 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1525 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1526 | data->rpc_done = 0; |
| 1527 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1528 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1529 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1530 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1531 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1532 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1533 | if (status != 0) { |
| 1534 | data->cancelled = 1; |
| 1535 | smp_wmb(); |
| 1536 | } else |
| 1537 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1538 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | return status; |
| 1540 | } |
| 1541 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1542 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1544 | struct nfs4_opendata *data = calldata; |
| 1545 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1546 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1547 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1548 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1549 | /* |
| 1550 | * Check if we still need to send an OPEN call, or if we can use |
| 1551 | * a delegation instead. |
| 1552 | */ |
| 1553 | if (data->state != NULL) { |
| 1554 | struct nfs_delegation *delegation; |
| 1555 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1556 | 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] | 1557 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1558 | rcu_read_lock(); |
| 1559 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1560 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1561 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1562 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1563 | rcu_read_unlock(); |
| 1564 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1565 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1566 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1567 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1568 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Andy Adamson | e23008e | 2012-10-02 21:07:32 -0400 | [diff] [blame] | 1569 | data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1570 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1571 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1572 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1573 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1574 | &data->o_arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1575 | &data->o_res.seq_res, task)) |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1576 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1577 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1578 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1579 | unlock_no_action: |
| 1580 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1581 | out_no_action: |
| 1582 | task->tk_action = NULL; |
| 1583 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1584 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1586 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1587 | { |
| 1588 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1589 | nfs4_open_prepare(task, calldata); |
| 1590 | } |
| 1591 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1592 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1593 | { |
| 1594 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1596 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1597 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1598 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1599 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1600 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1601 | if (task->tk_status == 0) { |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1602 | if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) { |
| 1603 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1604 | case S_IFREG: |
| 1605 | break; |
| 1606 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1607 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1608 | break; |
| 1609 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1610 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1611 | break; |
| 1612 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1613 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 807d66d8 | 2012-10-02 17:09:00 -0700 | [diff] [blame] | 1614 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1615 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1616 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1617 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1618 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1619 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1620 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1621 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1622 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1623 | static void nfs4_open_release(void *calldata) |
| 1624 | { |
| 1625 | struct nfs4_opendata *data = calldata; |
| 1626 | struct nfs4_state *state = NULL; |
| 1627 | |
| 1628 | /* If this request hasn't been cancelled, do nothing */ |
| 1629 | if (data->cancelled == 0) |
| 1630 | goto out_free; |
| 1631 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1632 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1633 | goto out_free; |
| 1634 | /* In case we need an open_confirm, no cleanup! */ |
| 1635 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1636 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1637 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1638 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1639 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1640 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1641 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1645 | .rpc_call_prepare = nfs4_open_prepare, |
| 1646 | .rpc_call_done = nfs4_open_done, |
| 1647 | .rpc_release = nfs4_open_release, |
| 1648 | }; |
| 1649 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1650 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1651 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1652 | .rpc_call_done = nfs4_open_done, |
| 1653 | .rpc_release = nfs4_open_release, |
| 1654 | }; |
| 1655 | |
| 1656 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1657 | { |
| 1658 | struct inode *dir = data->dir->d_inode; |
| 1659 | struct nfs_server *server = NFS_SERVER(dir); |
| 1660 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1661 | struct nfs_openres *o_res = &data->o_res; |
| 1662 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1663 | struct rpc_message msg = { |
| 1664 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1665 | .rpc_argp = o_arg, |
| 1666 | .rpc_resp = o_res, |
| 1667 | .rpc_cred = data->owner->so_cred, |
| 1668 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1669 | struct rpc_task_setup task_setup_data = { |
| 1670 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1671 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1672 | .callback_ops = &nfs4_open_ops, |
| 1673 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1674 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1675 | .flags = RPC_TASK_ASYNC, |
| 1676 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1677 | int status; |
| 1678 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1679 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1680 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1681 | data->rpc_done = 0; |
| 1682 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1683 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1684 | if (isrecover) |
| 1685 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1686 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1687 | if (IS_ERR(task)) |
| 1688 | return PTR_ERR(task); |
| 1689 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1690 | if (status != 0) { |
| 1691 | data->cancelled = 1; |
| 1692 | smp_wmb(); |
| 1693 | } else |
| 1694 | status = data->rpc_status; |
| 1695 | rpc_put_task(task); |
| 1696 | |
| 1697 | return status; |
| 1698 | } |
| 1699 | |
| 1700 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1701 | { |
| 1702 | struct inode *dir = data->dir->d_inode; |
| 1703 | struct nfs_openres *o_res = &data->o_res; |
| 1704 | int status; |
| 1705 | |
| 1706 | status = nfs4_run_open_task(data, 1); |
| 1707 | if (status != 0 || !data->rpc_done) |
| 1708 | return status; |
| 1709 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1710 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1711 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1712 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1713 | status = _nfs4_proc_open_confirm(data); |
| 1714 | if (status != 0) |
| 1715 | return status; |
| 1716 | } |
| 1717 | |
| 1718 | return status; |
| 1719 | } |
| 1720 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1721 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1722 | struct nfs4_opendata *opendata, |
| 1723 | struct nfs4_state *state, fmode_t fmode) |
| 1724 | { |
| 1725 | struct nfs_access_entry cache; |
| 1726 | u32 mask; |
| 1727 | |
| 1728 | /* access call failed or for some reason the server doesn't |
| 1729 | * support any access modes -- defer access call until later */ |
| 1730 | if (opendata->o_res.access_supported == 0) |
| 1731 | return 0; |
| 1732 | |
| 1733 | mask = 0; |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1734 | /* don't check MAY_WRITE - a newly created file may not have |
| 1735 | * write mode bits, but POSIX allows the creating process to write */ |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1736 | if (fmode & FMODE_READ) |
| 1737 | mask |= MAY_READ; |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1738 | if (fmode & FMODE_EXEC) |
| 1739 | mask |= MAY_EXEC; |
| 1740 | |
| 1741 | cache.cred = cred; |
| 1742 | cache.jiffies = jiffies; |
| 1743 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1744 | nfs_access_add_cache(state->inode, &cache); |
| 1745 | |
Weston Andros Adamson | bbd3a8e | 2012-10-02 14:49:51 -0700 | [diff] [blame] | 1746 | if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0) |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1747 | return 0; |
| 1748 | |
| 1749 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1750 | nfs4_close_state(state, fmode); |
| 1751 | return -NFS4ERR_ACCESS; |
| 1752 | } |
| 1753 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1754 | /* |
| 1755 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1756 | */ |
| 1757 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1758 | { |
| 1759 | struct inode *dir = data->dir->d_inode; |
| 1760 | struct nfs_server *server = NFS_SERVER(dir); |
| 1761 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1762 | struct nfs_openres *o_res = &data->o_res; |
| 1763 | int status; |
| 1764 | |
| 1765 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1766 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1767 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1768 | if (status != 0) { |
| 1769 | if (status == -NFS4ERR_BADNAME && |
| 1770 | !(o_arg->open_flags & O_CREAT)) |
| 1771 | return -ENOENT; |
| 1772 | return status; |
| 1773 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1774 | |
Trond Myklebust | 6926afd | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1775 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1776 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1777 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1778 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1779 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1780 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1782 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1784 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | } |
| 1786 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1787 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1788 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1791 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1792 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1793 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1794 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1795 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1796 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1797 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1798 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1799 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1800 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1801 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1802 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1803 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1804 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1805 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1806 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1807 | } |
| 1808 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1809 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1810 | { |
| 1811 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1812 | } |
| 1813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | /* |
| 1815 | * OPEN_EXPIRED: |
| 1816 | * reclaim state on the server after a network partition. |
| 1817 | * Assumes caller holds the appropriate lock |
| 1818 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1819 | 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] | 1820 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1821 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1822 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1824 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1825 | if (IS_ERR(opendata)) |
| 1826 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1827 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1828 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1829 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1830 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1831 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1834 | 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] | 1835 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1836 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1837 | struct nfs4_exception exception = { }; |
| 1838 | int err; |
| 1839 | |
| 1840 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1841 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1842 | switch (err) { |
| 1843 | default: |
| 1844 | goto out; |
| 1845 | case -NFS4ERR_GRACE: |
| 1846 | case -NFS4ERR_DELAY: |
| 1847 | nfs4_handle_exception(server, err, &exception); |
| 1848 | err = 0; |
| 1849 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1850 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1851 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1852 | return err; |
| 1853 | } |
| 1854 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1856 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1858 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1860 | ctx = nfs4_state_find_open_context(state); |
| 1861 | if (IS_ERR(ctx)) |
| 1862 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1863 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1864 | put_nfs_open_context(ctx); |
| 1865 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1868 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1869 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1870 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1871 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1872 | nfs4_stateid *stateid = &state->stateid; |
| 1873 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1874 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1875 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1876 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1877 | return; |
| 1878 | |
| 1879 | status = nfs41_test_stateid(server, stateid); |
| 1880 | if (status != NFS_OK) { |
| 1881 | /* Free the stateid unless the server explicitly |
| 1882 | * informs us the stateid is unrecognized. */ |
| 1883 | if (status != -NFS4ERR_BAD_STATEID) |
| 1884 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1885 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1886 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1887 | write_seqlock(&state->seqlock); |
| 1888 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1889 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1890 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | /** |
| 1895 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1896 | * |
| 1897 | * @state: NFSv4 state for an inode |
| 1898 | * |
| 1899 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1900 | * Otherwise a negative NFS4ERR value is returned. |
| 1901 | */ |
| 1902 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1903 | { |
| 1904 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1905 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1906 | int status; |
| 1907 | |
| 1908 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1909 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1910 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1911 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1912 | return -NFS4ERR_BAD_STATEID; |
| 1913 | |
| 1914 | status = nfs41_test_stateid(server, stateid); |
| 1915 | if (status != NFS_OK) { |
| 1916 | /* Free the stateid unless the server explicitly |
| 1917 | * informs us the stateid is unrecognized. */ |
| 1918 | if (status != -NFS4ERR_BAD_STATEID) |
| 1919 | nfs41_free_stateid(server, stateid); |
| 1920 | |
| 1921 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1922 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1923 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1924 | } |
| 1925 | return status; |
| 1926 | } |
| 1927 | |
| 1928 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1929 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1930 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1931 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1932 | nfs41_clear_delegation_stateid(state); |
| 1933 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1934 | if (status != NFS_OK) |
| 1935 | status = nfs4_open_expired(sp, state); |
| 1936 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1937 | } |
| 1938 | #endif |
| 1939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1941 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1942 | * fields corresponding to attributes that were used to store the verifier. |
| 1943 | * Make sure we clobber those fields in the later setattr call |
| 1944 | */ |
| 1945 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1946 | { |
| 1947 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1948 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1949 | sattr->ia_valid |= ATTR_ATIME; |
| 1950 | |
| 1951 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1952 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1953 | sattr->ia_valid |= ATTR_MTIME; |
| 1954 | } |
| 1955 | |
| 1956 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1957 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1959 | static int _nfs4_do_open(struct inode *dir, |
| 1960 | struct dentry *dentry, |
| 1961 | fmode_t fmode, |
| 1962 | int flags, |
| 1963 | struct iattr *sattr, |
| 1964 | struct rpc_cred *cred, |
| 1965 | struct nfs4_state **res, |
| 1966 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | { |
| 1968 | struct nfs4_state_owner *sp; |
| 1969 | struct nfs4_state *state = NULL; |
| 1970 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1971 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1972 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | |
| 1974 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1976 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1977 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1979 | goto out_err; |
| 1980 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1981 | status = nfs4_recover_expired_lease(server); |
| 1982 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1983 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1984 | if (dentry->d_inode != NULL) |
| 1985 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1986 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1987 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1988 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1989 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1991 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1992 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1993 | if (!opendata->f_attr.mdsthreshold) |
| 1994 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1995 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1996 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1997 | if (dentry->d_inode != NULL) |
| 1998 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1999 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2000 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2002 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 2004 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 2005 | status = PTR_ERR(state); |
| 2006 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2007 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 2008 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 2009 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2010 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2011 | status = nfs4_opendata_access(cred, opendata, state, fmode); |
| 2012 | if (status != 0) |
| 2013 | goto err_opendata_put; |
| 2014 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 2015 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 2016 | nfs4_exclusive_attrset(opendata, sattr); |
| 2017 | |
| 2018 | nfs_fattr_init(opendata->o_res.f_attr); |
| 2019 | status = nfs4_do_setattr(state->inode, cred, |
| 2020 | opendata->o_res.f_attr, sattr, |
| 2021 | state); |
| 2022 | if (status == 0) |
| 2023 | nfs_setattr_update_inode(state->inode, sattr); |
| 2024 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 2025 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2026 | |
| 2027 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 2028 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 2029 | else |
| 2030 | kfree(opendata->f_attr.mdsthreshold); |
| 2031 | opendata->f_attr.mdsthreshold = NULL; |
| 2032 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2033 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | *res = state; |
| 2036 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2037 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2038 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 2039 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 2040 | err_put_state_owner: |
| 2041 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | *res = NULL; |
| 2044 | return status; |
| 2045 | } |
| 2046 | |
| 2047 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2048 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 2049 | struct dentry *dentry, |
| 2050 | fmode_t fmode, |
| 2051 | int flags, |
| 2052 | struct iattr *sattr, |
| 2053 | struct rpc_cred *cred, |
| 2054 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | { |
| 2056 | struct nfs4_exception exception = { }; |
| 2057 | struct nfs4_state *res; |
| 2058 | int status; |
| 2059 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2060 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2062 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 2063 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | if (status == 0) |
| 2065 | break; |
| 2066 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 2067 | * book-keeping w.r.t. state-changing operations |
| 2068 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 2069 | * It is actually a sign of a bug on the client or on the server. |
| 2070 | * |
| 2071 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2072 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | * have unhashed the old state_owner for us, and that we can |
| 2074 | * therefore safely retry using a new one. We should still warn |
| 2075 | * the user though... |
| 2076 | */ |
| 2077 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2078 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2079 | " returned a bad sequence-id error!\n", |
| 2080 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | exception.retry = 1; |
| 2082 | continue; |
| 2083 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2084 | /* |
| 2085 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2086 | * state before it received the OPEN_CONFIRM. |
| 2087 | * Recover by retrying the request as per the discussion |
| 2088 | * on Page 181 of RFC3530. |
| 2089 | */ |
| 2090 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2091 | exception.retry = 1; |
| 2092 | continue; |
| 2093 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2094 | if (status == -EAGAIN) { |
| 2095 | /* We must have found a delegation */ |
| 2096 | exception.retry = 1; |
| 2097 | continue; |
| 2098 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 2100 | status, &exception)); |
| 2101 | } while (exception.retry); |
| 2102 | return res; |
| 2103 | } |
| 2104 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2105 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2106 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2107 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2109 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2111 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | .iap = sattr, |
| 2113 | .server = server, |
| 2114 | .bitmask = server->attr_bitmask, |
| 2115 | }; |
| 2116 | struct nfs_setattrres res = { |
| 2117 | .fattr = fattr, |
| 2118 | .server = server, |
| 2119 | }; |
| 2120 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2121 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2122 | .rpc_argp = &arg, |
| 2123 | .rpc_resp = &res, |
| 2124 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2126 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2127 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2129 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2131 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2132 | struct nfs_lockowner lockowner = { |
| 2133 | .l_owner = current->files, |
| 2134 | .l_pid = current->tgid, |
| 2135 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2136 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2137 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2138 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2139 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2140 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2141 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2142 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2144 | 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] | 2145 | if (status == 0 && state != NULL) |
| 2146 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2147 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2150 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2151 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2152 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2154 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2155 | struct nfs4_exception exception = { |
| 2156 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2157 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2158 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | int err; |
| 2160 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2161 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2162 | switch (err) { |
| 2163 | case -NFS4ERR_OPENMODE: |
| 2164 | if (state && !(state->state & FMODE_WRITE)) { |
| 2165 | err = -EBADF; |
| 2166 | if (sattr->ia_valid & ATTR_OPEN) |
| 2167 | err = -EACCES; |
| 2168 | goto out; |
| 2169 | } |
| 2170 | } |
| 2171 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2173 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | return err; |
| 2175 | } |
| 2176 | |
| 2177 | struct nfs4_closedata { |
| 2178 | struct inode *inode; |
| 2179 | struct nfs4_state *state; |
| 2180 | struct nfs_closeargs arg; |
| 2181 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2182 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2183 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2184 | bool roc; |
| 2185 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | }; |
| 2187 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2188 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2189 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2190 | struct nfs4_closedata *calldata = data; |
| 2191 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2192 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2193 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2194 | if (calldata->roc) |
| 2195 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2196 | nfs4_put_open_state(calldata->state); |
| 2197 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2198 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2199 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2200 | kfree(calldata); |
| 2201 | } |
| 2202 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2203 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2204 | fmode_t fmode) |
| 2205 | { |
| 2206 | spin_lock(&state->owner->so_lock); |
| 2207 | if (!(fmode & FMODE_READ)) |
| 2208 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2209 | if (!(fmode & FMODE_WRITE)) |
| 2210 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2211 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2212 | spin_unlock(&state->owner->so_lock); |
| 2213 | } |
| 2214 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2215 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2217 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2220 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2221 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2222 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2223 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | /* hmm. we are done with the inode, and in the process of freeing |
| 2225 | * the state_owner. we keep this around to process errors |
| 2226 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | switch (task->tk_status) { |
| 2228 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2229 | if (calldata->roc) |
| 2230 | pnfs_roc_set_barrier(state->inode, |
| 2231 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2232 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2233 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2234 | nfs4_close_clear_stateid_flags(state, |
| 2235 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | break; |
| 2237 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2238 | case -NFS4ERR_OLD_STATEID: |
| 2239 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2241 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2242 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2244 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2245 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2247 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2248 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2249 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | } |
| 2251 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2252 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2254 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2255 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2256 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2257 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2258 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2259 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2260 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2261 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2262 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2263 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2264 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2265 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2266 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2267 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2268 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2269 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2270 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2271 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2272 | } |
| 2273 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2274 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2275 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2276 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2277 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2278 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2279 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2280 | |
| 2281 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2282 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2283 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2284 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2285 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2286 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2287 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2288 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2289 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2290 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2291 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2292 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2293 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2294 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2295 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2296 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2297 | &calldata->arg.seq_args, |
| 2298 | &calldata->res.seq_res, |
| 2299 | task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2300 | goto out; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2301 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2302 | out: |
| 2303 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2306 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2307 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2308 | .rpc_call_done = nfs4_close_done, |
| 2309 | .rpc_release = nfs4_free_closedata, |
| 2310 | }; |
| 2311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | /* |
| 2313 | * It is possible for data to be read/written from a mem-mapped file |
| 2314 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2315 | * This means that we can't safely call nfsv4 close on a file until |
| 2316 | * the inode is cleared. This in turn means that we are not good |
| 2317 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2318 | * share state even when we are done with one of the three share |
| 2319 | * stateid's in the inode. |
| 2320 | * |
| 2321 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2322 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2323 | int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2325 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2327 | struct nfs4_state_owner *sp = state->owner; |
| 2328 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2329 | struct rpc_message msg = { |
| 2330 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2331 | .rpc_cred = state->owner->so_cred, |
| 2332 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2333 | struct rpc_task_setup task_setup_data = { |
| 2334 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2335 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2336 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2337 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2338 | .flags = RPC_TASK_ASYNC, |
| 2339 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2340 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2342 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2344 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2345 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2346 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2348 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2349 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2351 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2352 | if (calldata->arg.seqid == NULL) |
| 2353 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2354 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2355 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2356 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2357 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2358 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2359 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2360 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2361 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2362 | msg.rpc_argp = &calldata->arg; |
| 2363 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2364 | task_setup_data.callback_data = calldata; |
| 2365 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2366 | if (IS_ERR(task)) |
| 2367 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2368 | status = 0; |
| 2369 | if (wait) |
| 2370 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2371 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2372 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2373 | out_free_calldata: |
| 2374 | kfree(calldata); |
| 2375 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2376 | nfs4_put_open_state(state); |
| 2377 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2378 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2381 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2382 | 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] | 2383 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | struct nfs4_state *state; |
| 2385 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2386 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2387 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2388 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2389 | if (IS_ERR(state)) |
| 2390 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2391 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2392 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2395 | 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] | 2396 | { |
| 2397 | if (ctx->state == NULL) |
| 2398 | return; |
| 2399 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2400 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2401 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2402 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2403 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | |
| 2405 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2406 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2407 | struct nfs4_server_caps_arg args = { |
| 2408 | .fhandle = fhandle, |
| 2409 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | struct nfs4_server_caps_res res = {}; |
| 2411 | struct rpc_message msg = { |
| 2412 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2413 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | .rpc_resp = &res, |
| 2415 | }; |
| 2416 | int status; |
| 2417 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2418 | 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] | 2419 | if (status == 0) { |
| 2420 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2421 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2422 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2423 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2424 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2425 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2427 | server->caps |= NFS_CAP_ACLS; |
| 2428 | if (res.has_links != 0) |
| 2429 | server->caps |= NFS_CAP_HARDLINKS; |
| 2430 | if (res.has_symlinks != 0) |
| 2431 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2432 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2433 | server->caps |= NFS_CAP_FILEID; |
| 2434 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2435 | server->caps |= NFS_CAP_MODE; |
| 2436 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2437 | server->caps |= NFS_CAP_NLINK; |
| 2438 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2439 | server->caps |= NFS_CAP_OWNER; |
| 2440 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2441 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2442 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2443 | server->caps |= NFS_CAP_ATIME; |
| 2444 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2445 | server->caps |= NFS_CAP_CTIME; |
| 2446 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2447 | server->caps |= NFS_CAP_MTIME; |
| 2448 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2449 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2450 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2451 | 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] | 2452 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2453 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | return status; |
| 2457 | } |
| 2458 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2459 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | { |
| 2461 | struct nfs4_exception exception = { }; |
| 2462 | int err; |
| 2463 | do { |
| 2464 | err = nfs4_handle_exception(server, |
| 2465 | _nfs4_server_capabilities(server, fhandle), |
| 2466 | &exception); |
| 2467 | } while (exception.retry); |
| 2468 | return err; |
| 2469 | } |
| 2470 | |
| 2471 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2472 | struct nfs_fsinfo *info) |
| 2473 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | struct nfs4_lookup_root_arg args = { |
| 2475 | .bitmask = nfs4_fattr_bitmap, |
| 2476 | }; |
| 2477 | struct nfs4_lookup_res res = { |
| 2478 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2479 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | .fh = fhandle, |
| 2481 | }; |
| 2482 | struct rpc_message msg = { |
| 2483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2484 | .rpc_argp = &args, |
| 2485 | .rpc_resp = &res, |
| 2486 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2487 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2488 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2489 | 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] | 2490 | } |
| 2491 | |
| 2492 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2493 | struct nfs_fsinfo *info) |
| 2494 | { |
| 2495 | struct nfs4_exception exception = { }; |
| 2496 | int err; |
| 2497 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2498 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2499 | switch (err) { |
| 2500 | case 0: |
| 2501 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2502 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2503 | default: |
| 2504 | err = nfs4_handle_exception(server, err, &exception); |
| 2505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2507 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | return err; |
| 2509 | } |
| 2510 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2511 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2512 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2513 | { |
| 2514 | struct rpc_auth *auth; |
| 2515 | int ret; |
| 2516 | |
| 2517 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2518 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2519 | ret = -EIO; |
| 2520 | goto out; |
| 2521 | } |
| 2522 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2523 | out: |
| 2524 | return ret; |
| 2525 | } |
| 2526 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2527 | 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] | 2528 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2530 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2531 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2533 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
| 2534 | BUG_ON(len < 0); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2535 | |
| 2536 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2537 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2538 | * thus has already been tried. */ |
| 2539 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2540 | continue; |
| 2541 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2542 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2543 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2544 | continue; |
| 2545 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2546 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2547 | /* |
| 2548 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2549 | * to access the mount. It could also mean that we tried to mount |
| 2550 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2551 | * existing mount programs don't handle -EACCES very well so it should |
| 2552 | * be mapped to -EPERM instead. |
| 2553 | */ |
| 2554 | if (status == -EACCES) |
| 2555 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2556 | return status; |
| 2557 | } |
| 2558 | |
| 2559 | /* |
| 2560 | * get the file handle for the "/" directory on the server |
| 2561 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2562 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2563 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2564 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2565 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2566 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2567 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2568 | /* |
| 2569 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2570 | * by nfs4_map_errors() as this function exits. |
| 2571 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2572 | 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] | 2573 | if (status == 0) |
| 2574 | status = nfs4_server_capabilities(server, fhandle); |
| 2575 | if (status == 0) |
| 2576 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2577 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2580 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2581 | struct nfs_fsinfo *info) |
| 2582 | { |
| 2583 | int error; |
| 2584 | struct nfs_fattr *fattr = info->fattr; |
| 2585 | |
| 2586 | error = nfs4_server_capabilities(server, mntfh); |
| 2587 | if (error < 0) { |
| 2588 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2589 | return error; |
| 2590 | } |
| 2591 | |
| 2592 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2593 | if (error < 0) { |
| 2594 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2595 | return error; |
| 2596 | } |
| 2597 | |
| 2598 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2599 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2600 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2601 | |
| 2602 | return error; |
| 2603 | } |
| 2604 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2605 | /* |
| 2606 | * Get locations and (maybe) other attributes of a referral. |
| 2607 | * Note that we'll actually follow the referral later when |
| 2608 | * we detect fsid mismatch in inode revalidation |
| 2609 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2610 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2611 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2612 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2613 | { |
| 2614 | int status = -ENOMEM; |
| 2615 | struct page *page = NULL; |
| 2616 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2617 | |
| 2618 | page = alloc_page(GFP_KERNEL); |
| 2619 | if (page == NULL) |
| 2620 | goto out; |
| 2621 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2622 | if (locations == NULL) |
| 2623 | goto out; |
| 2624 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2625 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2626 | if (status != 0) |
| 2627 | goto out; |
| 2628 | /* Make sure server returned a different fsid for the referral */ |
| 2629 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2630 | dprintk("%s: server did not return a different fsid for" |
| 2631 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2632 | status = -EIO; |
| 2633 | goto out; |
| 2634 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2635 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2636 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2637 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2638 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2639 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2640 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2641 | out: |
| 2642 | if (page) |
| 2643 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2644 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2645 | return status; |
| 2646 | } |
| 2647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2649 | { |
| 2650 | struct nfs4_getattr_arg args = { |
| 2651 | .fh = fhandle, |
| 2652 | .bitmask = server->attr_bitmask, |
| 2653 | }; |
| 2654 | struct nfs4_getattr_res res = { |
| 2655 | .fattr = fattr, |
| 2656 | .server = server, |
| 2657 | }; |
| 2658 | struct rpc_message msg = { |
| 2659 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2660 | .rpc_argp = &args, |
| 2661 | .rpc_resp = &res, |
| 2662 | }; |
| 2663 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2664 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2665 | 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] | 2666 | } |
| 2667 | |
| 2668 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2669 | { |
| 2670 | struct nfs4_exception exception = { }; |
| 2671 | int err; |
| 2672 | do { |
| 2673 | err = nfs4_handle_exception(server, |
| 2674 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2675 | &exception); |
| 2676 | } while (exception.retry); |
| 2677 | return err; |
| 2678 | } |
| 2679 | |
| 2680 | /* |
| 2681 | * The file is not closed if it is opened due to the a request to change |
| 2682 | * the size of the file. The open call will not be needed once the |
| 2683 | * VFS layer lookup-intents are implemented. |
| 2684 | * |
| 2685 | * Close is called when the inode is destroyed. |
| 2686 | * If we haven't opened the file for O_WRONLY, we |
| 2687 | * need to in the size_change case to obtain a stateid. |
| 2688 | * |
| 2689 | * Got race? |
| 2690 | * Because OPEN is always done by name in nfsv4, it is |
| 2691 | * possible that we opened a different file by the same |
| 2692 | * name. We can recognize this race condition, but we |
| 2693 | * can't do anything about it besides returning an error. |
| 2694 | * |
| 2695 | * This will be fixed with VFS changes (lookup-intent). |
| 2696 | */ |
| 2697 | static int |
| 2698 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2699 | struct iattr *sattr) |
| 2700 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2701 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2702 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2703 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | int status; |
| 2705 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2706 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2707 | pnfs_return_layout(inode); |
| 2708 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2709 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2711 | /* Deal with open(O_TRUNC) */ |
| 2712 | if (sattr->ia_valid & ATTR_OPEN) |
| 2713 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2714 | |
| 2715 | /* Optimization: if the end result is no change, don't RPC */ |
| 2716 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2717 | return 0; |
| 2718 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2719 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2720 | if (sattr->ia_valid & ATTR_FILE) { |
| 2721 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2722 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2723 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2724 | if (ctx) { |
| 2725 | cred = ctx->cred; |
| 2726 | state = ctx->state; |
| 2727 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2731 | if (status == 0) |
| 2732 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | return status; |
| 2734 | } |
| 2735 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2736 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2737 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2738 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2739 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2740 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2741 | int status; |
| 2742 | struct nfs4_lookup_arg args = { |
| 2743 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2744 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2745 | .name = name, |
| 2746 | }; |
| 2747 | struct nfs4_lookup_res res = { |
| 2748 | .server = server, |
| 2749 | .fattr = fattr, |
| 2750 | .fh = fhandle, |
| 2751 | }; |
| 2752 | struct rpc_message msg = { |
| 2753 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2754 | .rpc_argp = &args, |
| 2755 | .rpc_resp = &res, |
| 2756 | }; |
| 2757 | |
| 2758 | nfs_fattr_init(fattr); |
| 2759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2761 | 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] | 2762 | dprintk("NFS reply lookup: %d\n", status); |
| 2763 | return status; |
| 2764 | } |
| 2765 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2766 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2767 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2768 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2769 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2770 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2771 | fattr->nlink = 2; |
| 2772 | } |
| 2773 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2774 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2775 | struct qstr *name, struct nfs_fh *fhandle, |
| 2776 | struct nfs_fattr *fattr) |
| 2777 | { |
| 2778 | struct nfs4_exception exception = { }; |
| 2779 | struct rpc_clnt *client = *clnt; |
| 2780 | int err; |
| 2781 | do { |
| 2782 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2783 | switch (err) { |
| 2784 | case -NFS4ERR_BADNAME: |
| 2785 | err = -ENOENT; |
| 2786 | goto out; |
| 2787 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2788 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2789 | goto out; |
| 2790 | case -NFS4ERR_WRONGSEC: |
| 2791 | err = -EPERM; |
| 2792 | if (client != *clnt) |
| 2793 | goto out; |
| 2794 | |
| 2795 | client = nfs4_create_sec_client(client, dir, name); |
| 2796 | if (IS_ERR(client)) |
| 2797 | return PTR_ERR(client); |
| 2798 | |
| 2799 | exception.retry = 1; |
| 2800 | break; |
| 2801 | default: |
| 2802 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2803 | } |
| 2804 | } while (exception.retry); |
| 2805 | |
| 2806 | out: |
| 2807 | if (err == 0) |
| 2808 | *clnt = client; |
| 2809 | else if (client != *clnt) |
| 2810 | rpc_shutdown_client(client); |
| 2811 | |
| 2812 | return err; |
| 2813 | } |
| 2814 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2815 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2816 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2818 | int status; |
| 2819 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2820 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2821 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2822 | if (client != NFS_CLIENT(dir)) { |
| 2823 | rpc_shutdown_client(client); |
| 2824 | nfs_fixup_secinfo_attributes(fattr); |
| 2825 | } |
| 2826 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | } |
| 2828 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2829 | struct rpc_clnt * |
| 2830 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2831 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2832 | { |
| 2833 | int status; |
| 2834 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2835 | |
| 2836 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2837 | if (status < 0) { |
| 2838 | rpc_shutdown_client(client); |
| 2839 | return ERR_PTR(status); |
| 2840 | } |
| 2841 | return client; |
| 2842 | } |
| 2843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2845 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2846 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | struct nfs4_accessargs args = { |
| 2848 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2849 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2851 | struct nfs4_accessres res = { |
| 2852 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2853 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | struct rpc_message msg = { |
| 2855 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2856 | .rpc_argp = &args, |
| 2857 | .rpc_resp = &res, |
| 2858 | .rpc_cred = entry->cred, |
| 2859 | }; |
| 2860 | int mode = entry->mask; |
| 2861 | int status; |
| 2862 | |
| 2863 | /* |
| 2864 | * Determine which access bits we want to ask for... |
| 2865 | */ |
| 2866 | if (mode & MAY_READ) |
| 2867 | args.access |= NFS4_ACCESS_READ; |
| 2868 | if (S_ISDIR(inode->i_mode)) { |
| 2869 | if (mode & MAY_WRITE) |
| 2870 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2871 | if (mode & MAY_EXEC) |
| 2872 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2873 | } else { |
| 2874 | if (mode & MAY_WRITE) |
| 2875 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2876 | if (mode & MAY_EXEC) |
| 2877 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2878 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2879 | |
| 2880 | res.fattr = nfs_alloc_fattr(); |
| 2881 | if (res.fattr == NULL) |
| 2882 | return -ENOMEM; |
| 2883 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2884 | 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] | 2885 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2886 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2887 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2889 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | return status; |
| 2891 | } |
| 2892 | |
| 2893 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2894 | { |
| 2895 | struct nfs4_exception exception = { }; |
| 2896 | int err; |
| 2897 | do { |
| 2898 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2899 | _nfs4_proc_access(inode, entry), |
| 2900 | &exception); |
| 2901 | } while (exception.retry); |
| 2902 | return err; |
| 2903 | } |
| 2904 | |
| 2905 | /* |
| 2906 | * TODO: For the time being, we don't try to get any attributes |
| 2907 | * along with any of the zero-copy operations READ, READDIR, |
| 2908 | * READLINK, WRITE. |
| 2909 | * |
| 2910 | * In the case of the first three, we want to put the GETATTR |
| 2911 | * after the read-type operation -- this is because it is hard |
| 2912 | * to predict the length of a GETATTR response in v4, and thus |
| 2913 | * align the READ data correctly. This means that the GETATTR |
| 2914 | * may end up partially falling into the page cache, and we should |
| 2915 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2916 | * To do this efficiently, we need to know the total length |
| 2917 | * of data received, which doesn't seem to be available outside |
| 2918 | * of the RPC layer. |
| 2919 | * |
| 2920 | * In the case of WRITE, we also want to put the GETATTR after |
| 2921 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2922 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | * |
| 2924 | * Both of these changes to the XDR layer would in fact be quite |
| 2925 | * minor, but I decided to leave them for a subsequent patch. |
| 2926 | */ |
| 2927 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2928 | unsigned int pgbase, unsigned int pglen) |
| 2929 | { |
| 2930 | struct nfs4_readlink args = { |
| 2931 | .fh = NFS_FH(inode), |
| 2932 | .pgbase = pgbase, |
| 2933 | .pglen = pglen, |
| 2934 | .pages = &page, |
| 2935 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2936 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | struct rpc_message msg = { |
| 2938 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2939 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2940 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | }; |
| 2942 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2943 | 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] | 2944 | } |
| 2945 | |
| 2946 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2947 | unsigned int pgbase, unsigned int pglen) |
| 2948 | { |
| 2949 | struct nfs4_exception exception = { }; |
| 2950 | int err; |
| 2951 | do { |
| 2952 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2953 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2954 | &exception); |
| 2955 | } while (exception.retry); |
| 2956 | return err; |
| 2957 | } |
| 2958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2960 | * This is just for mknod. open(O_CREAT) will always do ->open_context(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | static int |
| 2963 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2964 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2966 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | int status = 0; |
| 2969 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2970 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2971 | if (IS_ERR(ctx)) |
| 2972 | return PTR_ERR(ctx); |
| 2973 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2974 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2975 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2976 | flags, sattr, ctx->cred, |
| 2977 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2978 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | if (IS_ERR(state)) { |
| 2980 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2981 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2983 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2984 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2985 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2987 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | return status; |
| 2989 | } |
| 2990 | |
| 2991 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2992 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2993 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2994 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2996 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2998 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2999 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3000 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 3002 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 3003 | .rpc_argp = &args, |
| 3004 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3006 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 3007 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3008 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3009 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3010 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | return status; |
| 3012 | } |
| 3013 | |
| 3014 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 3015 | { |
| 3016 | struct nfs4_exception exception = { }; |
| 3017 | int err; |
| 3018 | do { |
| 3019 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3020 | _nfs4_proc_remove(dir, name), |
| 3021 | &exception); |
| 3022 | } while (exception.retry); |
| 3023 | return err; |
| 3024 | } |
| 3025 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3026 | 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] | 3027 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3028 | struct nfs_server *server = NFS_SERVER(dir); |
| 3029 | struct nfs_removeargs *args = msg->rpc_argp; |
| 3030 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3032 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3034 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | } |
| 3036 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 3037 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 3038 | { |
| 3039 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 3040 | &data->args.seq_args, |
| 3041 | &data->res.seq_res, |
| 3042 | task)) |
| 3043 | return; |
| 3044 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | } |
| 3046 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3047 | 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] | 3048 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3049 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 3050 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3051 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3052 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3053 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3054 | return 0; |
| 3055 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 3056 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | } |
| 3058 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3059 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 3060 | { |
| 3061 | struct nfs_server *server = NFS_SERVER(dir); |
| 3062 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 3063 | struct nfs_renameres *res = msg->rpc_resp; |
| 3064 | |
| 3065 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3066 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3067 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3068 | } |
| 3069 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3070 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3071 | { |
| 3072 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3073 | &data->args.seq_args, |
| 3074 | &data->res.seq_res, |
| 3075 | task)) |
| 3076 | return; |
| 3077 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3081 | struct inode *new_dir) |
| 3082 | { |
| 3083 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3084 | |
| 3085 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3086 | return 0; |
| 3087 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3088 | return 0; |
| 3089 | |
| 3090 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3091 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3092 | return 1; |
| 3093 | } |
| 3094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3096 | struct inode *new_dir, struct qstr *new_name) |
| 3097 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3098 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3099 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | .old_dir = NFS_FH(old_dir), |
| 3101 | .new_dir = NFS_FH(new_dir), |
| 3102 | .old_name = old_name, |
| 3103 | .new_name = new_name, |
| 3104 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3105 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3106 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3107 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | struct rpc_message msg = { |
| 3109 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3110 | .rpc_argp = &arg, |
| 3111 | .rpc_resp = &res, |
| 3112 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3113 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3115 | 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] | 3116 | if (!status) { |
| 3117 | update_changeattr(old_dir, &res.old_cinfo); |
| 3118 | update_changeattr(new_dir, &res.new_cinfo); |
| 3119 | } |
| 3120 | return status; |
| 3121 | } |
| 3122 | |
| 3123 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3124 | struct inode *new_dir, struct qstr *new_name) |
| 3125 | { |
| 3126 | struct nfs4_exception exception = { }; |
| 3127 | int err; |
| 3128 | do { |
| 3129 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3130 | _nfs4_proc_rename(old_dir, old_name, |
| 3131 | new_dir, new_name), |
| 3132 | &exception); |
| 3133 | } while (exception.retry); |
| 3134 | return err; |
| 3135 | } |
| 3136 | |
| 3137 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3138 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3139 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | struct nfs4_link_arg arg = { |
| 3141 | .fh = NFS_FH(inode), |
| 3142 | .dir_fh = NFS_FH(dir), |
| 3143 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3144 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3146 | struct nfs4_link_res res = { |
| 3147 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3148 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | struct rpc_message msg = { |
| 3150 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3151 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3152 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3154 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3156 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3157 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3158 | goto out; |
| 3159 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3160 | 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] | 3161 | if (!status) { |
| 3162 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3163 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3164 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3165 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3166 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | return status; |
| 3168 | } |
| 3169 | |
| 3170 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3171 | { |
| 3172 | struct nfs4_exception exception = { }; |
| 3173 | int err; |
| 3174 | do { |
| 3175 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3176 | _nfs4_proc_link(inode, dir, name), |
| 3177 | &exception); |
| 3178 | } while (exception.retry); |
| 3179 | return err; |
| 3180 | } |
| 3181 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3182 | struct nfs4_createdata { |
| 3183 | struct rpc_message msg; |
| 3184 | struct nfs4_create_arg arg; |
| 3185 | struct nfs4_create_res res; |
| 3186 | struct nfs_fh fh; |
| 3187 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3188 | }; |
| 3189 | |
| 3190 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3191 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3192 | { |
| 3193 | struct nfs4_createdata *data; |
| 3194 | |
| 3195 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3196 | if (data != NULL) { |
| 3197 | struct nfs_server *server = NFS_SERVER(dir); |
| 3198 | |
| 3199 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3200 | data->msg.rpc_argp = &data->arg; |
| 3201 | data->msg.rpc_resp = &data->res; |
| 3202 | data->arg.dir_fh = NFS_FH(dir); |
| 3203 | data->arg.server = server; |
| 3204 | data->arg.name = name; |
| 3205 | data->arg.attrs = sattr; |
| 3206 | data->arg.ftype = ftype; |
| 3207 | data->arg.bitmask = server->attr_bitmask; |
| 3208 | data->res.server = server; |
| 3209 | data->res.fh = &data->fh; |
| 3210 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3211 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3212 | } |
| 3213 | return data; |
| 3214 | } |
| 3215 | |
| 3216 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3217 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3218 | 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] | 3219 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3220 | if (status == 0) { |
| 3221 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3222 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3223 | } |
| 3224 | return status; |
| 3225 | } |
| 3226 | |
| 3227 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3228 | { |
| 3229 | kfree(data); |
| 3230 | } |
| 3231 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3232 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3233 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3235 | struct nfs4_createdata *data; |
| 3236 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3238 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3239 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3240 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3241 | status = -ENOMEM; |
| 3242 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3243 | if (data == NULL) |
| 3244 | goto out; |
| 3245 | |
| 3246 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3247 | data->arg.u.symlink.pages = &page; |
| 3248 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3250 | status = nfs4_do_create(dir, dentry, data); |
| 3251 | |
| 3252 | nfs4_free_createdata(data); |
| 3253 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | return status; |
| 3255 | } |
| 3256 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3257 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3258 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | { |
| 3260 | struct nfs4_exception exception = { }; |
| 3261 | int err; |
| 3262 | do { |
| 3263 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3264 | _nfs4_proc_symlink(dir, dentry, page, |
| 3265 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | &exception); |
| 3267 | } while (exception.retry); |
| 3268 | return err; |
| 3269 | } |
| 3270 | |
| 3271 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3272 | struct iattr *sattr) |
| 3273 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3274 | struct nfs4_createdata *data; |
| 3275 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3277 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3278 | if (data == NULL) |
| 3279 | goto out; |
| 3280 | |
| 3281 | status = nfs4_do_create(dir, dentry, data); |
| 3282 | |
| 3283 | nfs4_free_createdata(data); |
| 3284 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | return status; |
| 3286 | } |
| 3287 | |
| 3288 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3289 | struct iattr *sattr) |
| 3290 | { |
| 3291 | struct nfs4_exception exception = { }; |
| 3292 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3293 | |
| 3294 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | do { |
| 3296 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3297 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3298 | &exception); |
| 3299 | } while (exception.retry); |
| 3300 | return err; |
| 3301 | } |
| 3302 | |
| 3303 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3304 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | { |
| 3306 | struct inode *dir = dentry->d_inode; |
| 3307 | struct nfs4_readdir_arg args = { |
| 3308 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3309 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | .pgbase = 0, |
| 3311 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3312 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3313 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | }; |
| 3315 | struct nfs4_readdir_res res; |
| 3316 | struct rpc_message msg = { |
| 3317 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3318 | .rpc_argp = &args, |
| 3319 | .rpc_resp = &res, |
| 3320 | .rpc_cred = cred, |
| 3321 | }; |
| 3322 | int status; |
| 3323 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3324 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3325 | dentry->d_parent->d_name.name, |
| 3326 | dentry->d_name.name, |
| 3327 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3328 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3330 | 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] | 3331 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3332 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3333 | status += args.pgbase; |
| 3334 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3335 | |
| 3336 | nfs_invalidate_atime(dir); |
| 3337 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3338 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | return status; |
| 3340 | } |
| 3341 | |
| 3342 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3343 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | { |
| 3345 | struct nfs4_exception exception = { }; |
| 3346 | int err; |
| 3347 | do { |
| 3348 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3349 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3350 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | &exception); |
| 3352 | } while (exception.retry); |
| 3353 | return err; |
| 3354 | } |
| 3355 | |
| 3356 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3357 | struct iattr *sattr, dev_t rdev) |
| 3358 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3359 | struct nfs4_createdata *data; |
| 3360 | int mode = sattr->ia_mode; |
| 3361 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | |
| 3363 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3364 | 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] | 3365 | |
| 3366 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3367 | if (data == NULL) |
| 3368 | goto out; |
| 3369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3371 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3372 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3373 | data->arg.ftype = NF4BLK; |
| 3374 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3375 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | } |
| 3377 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3378 | data->arg.ftype = NF4CHR; |
| 3379 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3380 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3383 | status = nfs4_do_create(dir, dentry, data); |
| 3384 | |
| 3385 | nfs4_free_createdata(data); |
| 3386 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | return status; |
| 3388 | } |
| 3389 | |
| 3390 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3391 | struct iattr *sattr, dev_t rdev) |
| 3392 | { |
| 3393 | struct nfs4_exception exception = { }; |
| 3394 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3395 | |
| 3396 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | do { |
| 3398 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3399 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3400 | &exception); |
| 3401 | } while (exception.retry); |
| 3402 | return err; |
| 3403 | } |
| 3404 | |
| 3405 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3406 | struct nfs_fsstat *fsstat) |
| 3407 | { |
| 3408 | struct nfs4_statfs_arg args = { |
| 3409 | .fh = fhandle, |
| 3410 | .bitmask = server->attr_bitmask, |
| 3411 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3412 | struct nfs4_statfs_res res = { |
| 3413 | .fsstat = fsstat, |
| 3414 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | struct rpc_message msg = { |
| 3416 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3417 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3418 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | }; |
| 3420 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3421 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3422 | 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] | 3423 | } |
| 3424 | |
| 3425 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3426 | { |
| 3427 | struct nfs4_exception exception = { }; |
| 3428 | int err; |
| 3429 | do { |
| 3430 | err = nfs4_handle_exception(server, |
| 3431 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3432 | &exception); |
| 3433 | } while (exception.retry); |
| 3434 | return err; |
| 3435 | } |
| 3436 | |
| 3437 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3438 | struct nfs_fsinfo *fsinfo) |
| 3439 | { |
| 3440 | struct nfs4_fsinfo_arg args = { |
| 3441 | .fh = fhandle, |
| 3442 | .bitmask = server->attr_bitmask, |
| 3443 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3444 | struct nfs4_fsinfo_res res = { |
| 3445 | .fsinfo = fsinfo, |
| 3446 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | struct rpc_message msg = { |
| 3448 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3449 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3450 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | }; |
| 3452 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3453 | 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] | 3454 | } |
| 3455 | |
| 3456 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3457 | { |
| 3458 | struct nfs4_exception exception = { }; |
| 3459 | int err; |
| 3460 | |
| 3461 | do { |
| 3462 | err = nfs4_handle_exception(server, |
| 3463 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3464 | &exception); |
| 3465 | } while (exception.retry); |
| 3466 | return err; |
| 3467 | } |
| 3468 | |
| 3469 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3470 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3471 | int error; |
| 3472 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3473 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3474 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3475 | if (error == 0) { |
| 3476 | /* block layout checks this! */ |
| 3477 | server->pnfs_blksize = fsinfo->blksize; |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3478 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
Peng Tao | dc18254 | 2012-08-24 00:27:49 +0800 | [diff] [blame] | 3479 | } |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3480 | |
| 3481 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3485 | struct nfs_pathconf *pathconf) |
| 3486 | { |
| 3487 | struct nfs4_pathconf_arg args = { |
| 3488 | .fh = fhandle, |
| 3489 | .bitmask = server->attr_bitmask, |
| 3490 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3491 | struct nfs4_pathconf_res res = { |
| 3492 | .pathconf = pathconf, |
| 3493 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | struct rpc_message msg = { |
| 3495 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3496 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3497 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | }; |
| 3499 | |
| 3500 | /* None of the pathconf attributes are mandatory to implement */ |
| 3501 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3502 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3503 | return 0; |
| 3504 | } |
| 3505 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3506 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3507 | 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] | 3508 | } |
| 3509 | |
| 3510 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3511 | struct nfs_pathconf *pathconf) |
| 3512 | { |
| 3513 | struct nfs4_exception exception = { }; |
| 3514 | int err; |
| 3515 | |
| 3516 | do { |
| 3517 | err = nfs4_handle_exception(server, |
| 3518 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3519 | &exception); |
| 3520 | } while (exception.retry); |
| 3521 | return err; |
| 3522 | } |
| 3523 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3524 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3525 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3526 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3527 | } |
| 3528 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3529 | 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] | 3530 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3531 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3533 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3534 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3535 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3537 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3538 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3540 | renew_lease(server, data->timestamp); |
| 3541 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | } |
| 3543 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3544 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3545 | { |
| 3546 | |
| 3547 | dprintk("--> %s\n", __func__); |
| 3548 | |
| 3549 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3550 | return -EAGAIN; |
| 3551 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3552 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3553 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3554 | } |
| 3555 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3556 | 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] | 3557 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3559 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3560 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3561 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | } |
| 3563 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3564 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3565 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3566 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3567 | &data->args.seq_args, |
| 3568 | &data->res.seq_res, |
| 3569 | task)) |
| 3570 | return; |
| 3571 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3574 | 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] | 3575 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3576 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3578 | 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] | 3579 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3580 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3582 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3584 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3585 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3586 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | } |
| 3588 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3589 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3590 | { |
| 3591 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3592 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3593 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3594 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3597 | static |
| 3598 | bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data) |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3599 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3600 | const struct nfs_pgio_header *hdr = data->header; |
| 3601 | |
| 3602 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3603 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3604 | return false; |
| 3605 | /* Otherwise, request attributes if and only if we don't hold |
| 3606 | * a delegation |
| 3607 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3608 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3609 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3610 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3611 | 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] | 3612 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3613 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3614 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3615 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3616 | data->args.bitmask = NULL; |
| 3617 | data->res.fattr = NULL; |
| 3618 | } else |
| 3619 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3620 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3621 | if (!data->write_done_cb) |
| 3622 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3623 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | data->timestamp = jiffies; |
| 3625 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3626 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3627 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3630 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3631 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3632 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3633 | &data->args.seq_args, |
| 3634 | &data->res.seq_res, |
| 3635 | task)) |
| 3636 | return; |
| 3637 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3640 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3641 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3643 | &data->args.seq_args, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3644 | &data->res.seq_res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | return; |
| 3647 | rpc_call_start(task); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3648 | } |
| 3649 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3650 | static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_commit_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | { |
| 3652 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3653 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3654 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3655 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3656 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3658 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | } |
| 3660 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3661 | static int nfs4_commit_done(struct rpc_task *task, struct nfs_commit_data *data) |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3662 | { |
| 3663 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3664 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3665 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3666 | } |
| 3667 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3668 | static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3670 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3671 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3672 | if (data->commit_done_cb == NULL) |
| 3673 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3674 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3675 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3676 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3679 | struct nfs4_renewdata { |
| 3680 | struct nfs_client *client; |
| 3681 | unsigned long timestamp; |
| 3682 | }; |
| 3683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | /* |
| 3685 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3686 | * standalone procedure for queueing an asynchronous RENEW. |
| 3687 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3688 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3689 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3690 | struct nfs4_renewdata *data = calldata; |
| 3691 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3692 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3693 | if (atomic_read(&clp->cl_count) > 1) |
| 3694 | nfs4_schedule_state_renewal(clp); |
| 3695 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3696 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3697 | } |
| 3698 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3699 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3701 | struct nfs4_renewdata *data = calldata; |
| 3702 | struct nfs_client *clp = data->client; |
| 3703 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | |
| 3705 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3706 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3707 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3708 | return; |
| 3709 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3710 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3711 | return; |
| 3712 | } |
| 3713 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3715 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | } |
| 3717 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3718 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3719 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3720 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3721 | }; |
| 3722 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3723 | 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] | 3724 | { |
| 3725 | struct rpc_message msg = { |
| 3726 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3727 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3728 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3730 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3732 | if (renew_flags == 0) |
| 3733 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3734 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3735 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3736 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3737 | if (data == NULL) |
| 3738 | return -ENOMEM; |
| 3739 | data->client = clp; |
| 3740 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3742 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3745 | 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] | 3746 | { |
| 3747 | struct rpc_message msg = { |
| 3748 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3749 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3750 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | }; |
| 3752 | unsigned long now = jiffies; |
| 3753 | int status; |
| 3754 | |
| 3755 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3756 | if (status < 0) |
| 3757 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3758 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | return 0; |
| 3760 | } |
| 3761 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3762 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3763 | { |
| 3764 | return (server->caps & NFS_CAP_ACLS) |
| 3765 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3766 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3767 | } |
| 3768 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3769 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3770 | * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3771 | * the stack. |
| 3772 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3773 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3774 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3775 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3776 | struct page **pages, unsigned int *pgbase) |
| 3777 | { |
| 3778 | struct page *newpage, **spages; |
| 3779 | int rc = 0; |
| 3780 | size_t len; |
| 3781 | spages = pages; |
| 3782 | |
| 3783 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3784 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3785 | newpage = alloc_page(GFP_KERNEL); |
| 3786 | |
| 3787 | if (newpage == NULL) |
| 3788 | goto unwind; |
| 3789 | memcpy(page_address(newpage), buf, len); |
| 3790 | buf += len; |
| 3791 | buflen -= len; |
| 3792 | *pages++ = newpage; |
| 3793 | rc++; |
| 3794 | } while (buflen != 0); |
| 3795 | |
| 3796 | return rc; |
| 3797 | |
| 3798 | unwind: |
| 3799 | for(; rc > 0; rc--) |
| 3800 | __free_page(spages[rc-1]); |
| 3801 | return -ENOMEM; |
| 3802 | } |
| 3803 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3804 | struct nfs4_cached_acl { |
| 3805 | int cached; |
| 3806 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3807 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3808 | }; |
| 3809 | |
| 3810 | 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] | 3811 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3812 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3813 | |
| 3814 | spin_lock(&inode->i_lock); |
| 3815 | kfree(nfsi->nfs4_acl); |
| 3816 | nfsi->nfs4_acl = acl; |
| 3817 | spin_unlock(&inode->i_lock); |
| 3818 | } |
| 3819 | |
| 3820 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3821 | { |
| 3822 | nfs4_set_cached_acl(inode, NULL); |
| 3823 | } |
| 3824 | |
| 3825 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3826 | { |
| 3827 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3828 | struct nfs4_cached_acl *acl; |
| 3829 | int ret = -ENOENT; |
| 3830 | |
| 3831 | spin_lock(&inode->i_lock); |
| 3832 | acl = nfsi->nfs4_acl; |
| 3833 | if (acl == NULL) |
| 3834 | goto out; |
| 3835 | if (buf == NULL) /* user is just asking for length */ |
| 3836 | goto out_len; |
| 3837 | if (acl->cached == 0) |
| 3838 | goto out; |
| 3839 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3840 | if (acl->len > buflen) |
| 3841 | goto out; |
| 3842 | memcpy(buf, acl->data, acl->len); |
| 3843 | out_len: |
| 3844 | ret = acl->len; |
| 3845 | out: |
| 3846 | spin_unlock(&inode->i_lock); |
| 3847 | return ret; |
| 3848 | } |
| 3849 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3850 | static void nfs4_write_cached_acl(struct inode *inode, struct page **pages, size_t pgbase, size_t acl_len) |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3851 | { |
| 3852 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3853 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3854 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3855 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3856 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3857 | if (acl == NULL) |
| 3858 | goto out; |
| 3859 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3860 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3861 | } else { |
| 3862 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3863 | if (acl == NULL) |
| 3864 | goto out; |
| 3865 | acl->cached = 0; |
| 3866 | } |
| 3867 | acl->len = acl_len; |
| 3868 | out: |
| 3869 | nfs4_set_cached_acl(inode, acl); |
| 3870 | } |
| 3871 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3872 | /* |
| 3873 | * The getxattr API returns the required buffer length when called with a |
| 3874 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3875 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3876 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3877 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3878 | * the cache. If not so, we throw away the page, and cache the required |
| 3879 | * length. The next getxattr call will then produce another round trip to |
| 3880 | * the server, this time with the input buf of the required size. |
| 3881 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3882 | 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] | 3883 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3884 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3885 | struct nfs_getaclargs args = { |
| 3886 | .fh = NFS_FH(inode), |
| 3887 | .acl_pages = pages, |
| 3888 | .acl_len = buflen, |
| 3889 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3890 | struct nfs_getaclres res = { |
| 3891 | .acl_len = buflen, |
| 3892 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3893 | struct rpc_message msg = { |
| 3894 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3895 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3896 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3897 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3898 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3899 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3900 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3901 | /* As long as we're doing a round trip to the server anyway, |
| 3902 | * let's be prepared for a page of acl data. */ |
| 3903 | if (npages == 0) |
| 3904 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3905 | if (npages > ARRAY_SIZE(pages)) |
| 3906 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3907 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3908 | for (i = 0; i < npages; i++) { |
| 3909 | pages[i] = alloc_page(GFP_KERNEL); |
| 3910 | if (!pages[i]) |
| 3911 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3912 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3913 | |
| 3914 | /* for decoding across pages */ |
| 3915 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3916 | if (!res.acl_scratch) |
| 3917 | goto out_free; |
| 3918 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3919 | args.acl_len = npages * PAGE_SIZE; |
| 3920 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3921 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3922 | dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n", |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3923 | __func__, buf, buflen, npages, args.acl_len); |
| 3924 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3925 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3926 | if (ret) |
| 3927 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3928 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3929 | /* Handle the case where the passed-in buffer is too short */ |
| 3930 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3931 | /* Did the user only issue a request for the acl length? */ |
| 3932 | if (buf == NULL) |
| 3933 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3934 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3935 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3936 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3937 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); |
| 3938 | if (buf) |
| 3939 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
| 3940 | out_ok: |
| 3941 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3942 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3943 | for (i = 0; i < npages; i++) |
| 3944 | if (pages[i]) |
| 3945 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3946 | if (res.acl_scratch) |
| 3947 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3948 | return ret; |
| 3949 | } |
| 3950 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3951 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3952 | { |
| 3953 | struct nfs4_exception exception = { }; |
| 3954 | ssize_t ret; |
| 3955 | do { |
| 3956 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3957 | if (ret >= 0) |
| 3958 | break; |
| 3959 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3960 | } while (exception.retry); |
| 3961 | return ret; |
| 3962 | } |
| 3963 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3964 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3965 | { |
| 3966 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3967 | int ret; |
| 3968 | |
| 3969 | if (!nfs4_server_supports_acls(server)) |
| 3970 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3971 | ret = nfs_revalidate_inode(server, inode); |
| 3972 | if (ret < 0) |
| 3973 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3974 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3975 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3976 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3977 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3978 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3979 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3980 | return ret; |
| 3981 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3982 | } |
| 3983 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3984 | 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] | 3985 | { |
| 3986 | struct nfs_server *server = NFS_SERVER(inode); |
| 3987 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3988 | struct nfs_setaclargs arg = { |
| 3989 | .fh = NFS_FH(inode), |
| 3990 | .acl_pages = pages, |
| 3991 | .acl_len = buflen, |
| 3992 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3993 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3994 | struct rpc_message msg = { |
| 3995 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3996 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3997 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3998 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3999 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4000 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4001 | |
| 4002 | if (!nfs4_server_supports_acls(server)) |
| 4003 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 4004 | if (npages > ARRAY_SIZE(pages)) |
| 4005 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 4006 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 4007 | if (i < 0) |
| 4008 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 4009 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4010 | 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] | 4011 | |
| 4012 | /* |
| 4013 | * Free each page after tx, so the only ref left is |
| 4014 | * held by the network stack |
| 4015 | */ |
| 4016 | for (; i > 0; i--) |
| 4017 | put_page(pages[i-1]); |
| 4018 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 4019 | /* |
| 4020 | * Acl update can result in inode attribute update. |
| 4021 | * so mark the attribute cache invalid. |
| 4022 | */ |
| 4023 | spin_lock(&inode->i_lock); |
| 4024 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 4025 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 4026 | nfs_access_zap_cache(inode); |
| 4027 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 4028 | return ret; |
| 4029 | } |
| 4030 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 4031 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 4032 | { |
| 4033 | struct nfs4_exception exception = { }; |
| 4034 | int err; |
| 4035 | do { |
| 4036 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 4037 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 4038 | &exception); |
| 4039 | } while (exception.retry); |
| 4040 | return err; |
| 4041 | } |
| 4042 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4044 | 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] | 4045 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4046 | struct nfs_client *clp = server->nfs_client; |
| 4047 | |
| 4048 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | return 0; |
| 4050 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4051 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4052 | case -NFS4ERR_ADMIN_REVOKED: |
| 4053 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 4054 | if (state == NULL) |
| 4055 | break; |
| 4056 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4057 | case -NFS4ERR_OPENMODE: |
| 4058 | if (state == NULL) |
| 4059 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4060 | nfs4_schedule_stateid_recovery(server, state); |
| 4061 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4062 | case -NFS4ERR_EXPIRED: |
| 4063 | if (state != NULL) |
| 4064 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4066 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4067 | nfs4_schedule_lease_recovery(clp); |
| 4068 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4069 | #if defined(CONFIG_NFS_V4_1) |
| 4070 | case -NFS4ERR_BADSESSION: |
| 4071 | case -NFS4ERR_BADSLOT: |
| 4072 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4073 | case -NFS4ERR_DEADSESSION: |
| 4074 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4075 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4076 | case -NFS4ERR_SEQ_MISORDERED: |
| 4077 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4078 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4079 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4080 | task->tk_status = 0; |
| 4081 | return -EAGAIN; |
| 4082 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4084 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4085 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 4086 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4088 | task->tk_status = 0; |
| 4089 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4090 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | case -NFS4ERR_OLD_STATEID: |
| 4092 | task->tk_status = 0; |
| 4093 | return -EAGAIN; |
| 4094 | } |
| 4095 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4096 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4097 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4098 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4099 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4100 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4101 | task->tk_status = 0; |
| 4102 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | } |
| 4104 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4105 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4106 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4107 | { |
| 4108 | __be32 verf[2]; |
| 4109 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4110 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4111 | /* An impossible timestamp guarantees this value |
| 4112 | * will never match a generated boot time. */ |
| 4113 | verf[0] = 0; |
| 4114 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4115 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4116 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4117 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4118 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4119 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4120 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4121 | } |
| 4122 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4123 | static unsigned int |
| 4124 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4125 | char *buf, size_t len) |
| 4126 | { |
| 4127 | unsigned int result; |
| 4128 | |
| 4129 | rcu_read_lock(); |
| 4130 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4131 | clp->cl_ipaddr, |
| 4132 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4133 | RPC_DISPLAY_ADDR), |
| 4134 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4135 | RPC_DISPLAY_PROTO)); |
| 4136 | rcu_read_unlock(); |
| 4137 | return result; |
| 4138 | } |
| 4139 | |
| 4140 | static unsigned int |
| 4141 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4142 | char *buf, size_t len) |
| 4143 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4144 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4145 | |
| 4146 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4147 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4148 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4149 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame] | 4150 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4151 | } |
| 4152 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4153 | /** |
| 4154 | * nfs4_proc_setclientid - Negotiate client ID |
| 4155 | * @clp: state data structure |
| 4156 | * @program: RPC program for NFSv4 callback service |
| 4157 | * @port: IP port number for NFS4 callback service |
| 4158 | * @cred: RPC credential to use for this call |
| 4159 | * @res: where to place the result |
| 4160 | * |
| 4161 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4162 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4163 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4164 | unsigned short port, struct rpc_cred *cred, |
| 4165 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | { |
| 4167 | nfs4_verifier sc_verifier; |
| 4168 | struct nfs4_setclientid setclientid = { |
| 4169 | .sc_verifier = &sc_verifier, |
| 4170 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4171 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | }; |
| 4173 | struct rpc_message msg = { |
| 4174 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4175 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4176 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4177 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4178 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4179 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4181 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4182 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4183 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4184 | setclientid.sc_name_len = |
| 4185 | nfs4_init_uniform_client_string(clp, |
| 4186 | setclientid.sc_name, |
| 4187 | sizeof(setclientid.sc_name)); |
| 4188 | else |
| 4189 | setclientid.sc_name_len = |
| 4190 | nfs4_init_nonuniform_client_string(clp, |
| 4191 | setclientid.sc_name, |
| 4192 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4193 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4194 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4195 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4196 | sizeof(setclientid.sc_netid), |
| 4197 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4198 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4199 | rcu_read_unlock(); |
| 4200 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4201 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4202 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4203 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4204 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4205 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4206 | setclientid.sc_name_len, setclientid.sc_name); |
| 4207 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4208 | dprintk("NFS reply setclientid: %d\n", status); |
| 4209 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | } |
| 4211 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4212 | /** |
| 4213 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4214 | * @clp: state data structure |
| 4215 | * @res: result of a previous SETCLIENTID |
| 4216 | * @cred: RPC credential to use for this call |
| 4217 | * |
| 4218 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4219 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4220 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4221 | struct nfs4_setclientid_res *arg, |
| 4222 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | { |
| 4224 | struct nfs_fsinfo fsinfo; |
| 4225 | struct rpc_message msg = { |
| 4226 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4227 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4229 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | }; |
| 4231 | unsigned long now; |
| 4232 | int status; |
| 4233 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4234 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4235 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4236 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4238 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | if (status == 0) { |
| 4240 | spin_lock(&clp->cl_lock); |
| 4241 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4242 | clp->cl_last_renewal = now; |
| 4243 | spin_unlock(&clp->cl_lock); |
| 4244 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4245 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4246 | return status; |
| 4247 | } |
| 4248 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4249 | struct nfs4_delegreturndata { |
| 4250 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4251 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4252 | struct nfs_fh fh; |
| 4253 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4254 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4255 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4256 | int rpc_status; |
| 4257 | }; |
| 4258 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4259 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4260 | { |
| 4261 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4262 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4263 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4264 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4265 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4266 | switch (task->tk_status) { |
| 4267 | case -NFS4ERR_STALE_STATEID: |
| 4268 | case -NFS4ERR_EXPIRED: |
| 4269 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4270 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4271 | break; |
| 4272 | default: |
| 4273 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4274 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4275 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4276 | return; |
| 4277 | } |
| 4278 | } |
| 4279 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | static void nfs4_delegreturn_release(void *calldata) |
| 4283 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4284 | kfree(calldata); |
| 4285 | } |
| 4286 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4287 | #if defined(CONFIG_NFS_V4_1) |
| 4288 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4289 | { |
| 4290 | struct nfs4_delegreturndata *d_data; |
| 4291 | |
| 4292 | d_data = (struct nfs4_delegreturndata *)data; |
| 4293 | |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4294 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4295 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4296 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4297 | return; |
| 4298 | rpc_call_start(task); |
| 4299 | } |
| 4300 | #endif /* CONFIG_NFS_V4_1 */ |
| 4301 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4302 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4303 | #if defined(CONFIG_NFS_V4_1) |
| 4304 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4305 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4306 | .rpc_call_done = nfs4_delegreturn_done, |
| 4307 | .rpc_release = nfs4_delegreturn_release, |
| 4308 | }; |
| 4309 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4310 | 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] | 4311 | { |
| 4312 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4313 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4314 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4315 | struct rpc_message msg = { |
| 4316 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4317 | .rpc_cred = cred, |
| 4318 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4319 | struct rpc_task_setup task_setup_data = { |
| 4320 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4321 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4322 | .callback_ops = &nfs4_delegreturn_ops, |
| 4323 | .flags = RPC_TASK_ASYNC, |
| 4324 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4325 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4326 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4327 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4328 | if (data == NULL) |
| 4329 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4330 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4331 | data->args.fhandle = &data->fh; |
| 4332 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4333 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4334 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4335 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4336 | data->res.fattr = &data->fattr; |
| 4337 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4338 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4339 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4340 | data->rpc_status = 0; |
| 4341 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4342 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4343 | msg.rpc_argp = &data->args; |
| 4344 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4345 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4346 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4347 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4348 | if (!issync) |
| 4349 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4350 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4351 | if (status != 0) |
| 4352 | goto out; |
| 4353 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4354 | if (status == 0) |
| 4355 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4356 | else |
| 4357 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4358 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4359 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4360 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | } |
| 4362 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4363 | 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] | 4364 | { |
| 4365 | struct nfs_server *server = NFS_SERVER(inode); |
| 4366 | struct nfs4_exception exception = { }; |
| 4367 | int err; |
| 4368 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4369 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | switch (err) { |
| 4371 | case -NFS4ERR_STALE_STATEID: |
| 4372 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | case 0: |
| 4374 | return 0; |
| 4375 | } |
| 4376 | err = nfs4_handle_exception(server, err, &exception); |
| 4377 | } while (exception.retry); |
| 4378 | return err; |
| 4379 | } |
| 4380 | |
| 4381 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4382 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4383 | |
| 4384 | /* |
| 4385 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4386 | */ |
| 4387 | static unsigned long |
| 4388 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4389 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4390 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | timeout <<= 1; |
| 4392 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4393 | return NFS4_LOCK_MAXTIMEOUT; |
| 4394 | return timeout; |
| 4395 | } |
| 4396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4398 | { |
| 4399 | struct inode *inode = state->inode; |
| 4400 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4401 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4402 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4404 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4406 | struct nfs_lockt_res res = { |
| 4407 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | }; |
| 4409 | struct rpc_message msg = { |
| 4410 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4411 | .rpc_argp = &arg, |
| 4412 | .rpc_resp = &res, |
| 4413 | .rpc_cred = state->owner->so_cred, |
| 4414 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | struct nfs4_lock_state *lsp; |
| 4416 | int status; |
| 4417 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4418 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4419 | status = nfs4_set_lock_state(state, request); |
| 4420 | if (status != 0) |
| 4421 | goto out; |
| 4422 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4423 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4424 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4425 | 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] | 4426 | switch (status) { |
| 4427 | case 0: |
| 4428 | request->fl_type = F_UNLCK; |
| 4429 | break; |
| 4430 | case -NFS4ERR_DENIED: |
| 4431 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4432 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4433 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4434 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | return status; |
| 4436 | } |
| 4437 | |
| 4438 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4439 | { |
| 4440 | struct nfs4_exception exception = { }; |
| 4441 | int err; |
| 4442 | |
| 4443 | do { |
| 4444 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4445 | _nfs4_proc_getlk(state, cmd, request), |
| 4446 | &exception); |
| 4447 | } while (exception.retry); |
| 4448 | return err; |
| 4449 | } |
| 4450 | |
| 4451 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4452 | { |
| 4453 | int res = 0; |
| 4454 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4455 | case FL_POSIX: |
| 4456 | res = posix_lock_file_wait(file, fl); |
| 4457 | break; |
| 4458 | case FL_FLOCK: |
| 4459 | res = flock_lock_file_wait(file, fl); |
| 4460 | break; |
| 4461 | default: |
| 4462 | BUG(); |
| 4463 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | return res; |
| 4465 | } |
| 4466 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4467 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4468 | struct nfs_locku_args arg; |
| 4469 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4470 | struct nfs4_lock_state *lsp; |
| 4471 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4472 | struct file_lock fl; |
| 4473 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4474 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4475 | }; |
| 4476 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4477 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4478 | struct nfs_open_context *ctx, |
| 4479 | struct nfs4_lock_state *lsp, |
| 4480 | struct nfs_seqid *seqid) |
| 4481 | { |
| 4482 | struct nfs4_unlockdata *p; |
| 4483 | struct inode *inode = lsp->ls_state->inode; |
| 4484 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4485 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4486 | if (p == NULL) |
| 4487 | return NULL; |
| 4488 | p->arg.fh = NFS_FH(inode); |
| 4489 | p->arg.fl = &p->fl; |
| 4490 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4491 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4492 | p->arg.stateid = &lsp->ls_stateid; |
| 4493 | p->lsp = lsp; |
| 4494 | atomic_inc(&lsp->ls_count); |
| 4495 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4496 | p->ctx = get_nfs_open_context(ctx); |
| 4497 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4498 | p->server = NFS_SERVER(inode); |
| 4499 | return p; |
| 4500 | } |
| 4501 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4502 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4503 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4504 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4505 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4506 | nfs4_put_lock_state(calldata->lsp); |
| 4507 | put_nfs_open_context(calldata->ctx); |
| 4508 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4509 | } |
| 4510 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4511 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4512 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4513 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4514 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4515 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4516 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4517 | switch (task->tk_status) { |
| 4518 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4519 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4520 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4521 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4522 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4523 | case -NFS4ERR_BAD_STATEID: |
| 4524 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4525 | case -NFS4ERR_STALE_STATEID: |
| 4526 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4527 | break; |
| 4528 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4529 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4530 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4531 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4532 | } |
| 4533 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4534 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4535 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4536 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4538 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4539 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4540 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4541 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4542 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4543 | return; |
| 4544 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4545 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4546 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4547 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4548 | &calldata->res.seq_res, task)) |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4549 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4550 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4553 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4554 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4555 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4556 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4557 | }; |
| 4558 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4559 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4560 | struct nfs_open_context *ctx, |
| 4561 | struct nfs4_lock_state *lsp, |
| 4562 | struct nfs_seqid *seqid) |
| 4563 | { |
| 4564 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4565 | struct rpc_message msg = { |
| 4566 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4567 | .rpc_cred = ctx->cred, |
| 4568 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4569 | struct rpc_task_setup task_setup_data = { |
| 4570 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4571 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4572 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4573 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4574 | .flags = RPC_TASK_ASYNC, |
| 4575 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4576 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4577 | /* Ensure this is an unlock - when canceling a lock, the |
| 4578 | * canceled lock is passed in, and it won't be an unlock. |
| 4579 | */ |
| 4580 | fl->fl_type = F_UNLCK; |
| 4581 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4582 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4583 | if (data == NULL) { |
| 4584 | nfs_free_seqid(seqid); |
| 4585 | return ERR_PTR(-ENOMEM); |
| 4586 | } |
| 4587 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4588 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4589 | msg.rpc_argp = &data->arg; |
| 4590 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4591 | task_setup_data.callback_data = data; |
| 4592 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4593 | } |
| 4594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4596 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4597 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4598 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4599 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4600 | struct rpc_task *task; |
| 4601 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4602 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4604 | status = nfs4_set_lock_state(state, request); |
| 4605 | /* Unlock _before_ we do the RPC call */ |
| 4606 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4607 | down_read(&nfsi->rwsem); |
| 4608 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4609 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4610 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4611 | } |
| 4612 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4613 | if (status != 0) |
| 4614 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4615 | /* Is this a delegated lock? */ |
| 4616 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4617 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4618 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4619 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4620 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4621 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4622 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4623 | 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] | 4624 | status = PTR_ERR(task); |
| 4625 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4626 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4627 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4628 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4629 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4630 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4631 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | } |
| 4633 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4634 | struct nfs4_lockdata { |
| 4635 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4636 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4637 | struct nfs4_lock_state *lsp; |
| 4638 | struct nfs_open_context *ctx; |
| 4639 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4640 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4641 | int rpc_status; |
| 4642 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4643 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4644 | }; |
| 4645 | |
| 4646 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4647 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4648 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4649 | { |
| 4650 | struct nfs4_lockdata *p; |
| 4651 | struct inode *inode = lsp->ls_state->inode; |
| 4652 | struct nfs_server *server = NFS_SERVER(inode); |
| 4653 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4654 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4655 | if (p == NULL) |
| 4656 | return NULL; |
| 4657 | |
| 4658 | p->arg.fh = NFS_FH(inode); |
| 4659 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4660 | 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] | 4661 | if (p->arg.open_seqid == NULL) |
| 4662 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4663 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4664 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4665 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4666 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4667 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4668 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4669 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4670 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4671 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4672 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4673 | atomic_inc(&lsp->ls_count); |
| 4674 | p->ctx = get_nfs_open_context(ctx); |
| 4675 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4676 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4677 | out_free_seqid: |
| 4678 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4679 | out_free: |
| 4680 | kfree(p); |
| 4681 | return NULL; |
| 4682 | } |
| 4683 | |
| 4684 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4685 | { |
| 4686 | struct nfs4_lockdata *data = calldata; |
| 4687 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4688 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4689 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4690 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4691 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4692 | /* Do we need to do an open_to_lock_owner? */ |
| 4693 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4694 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4695 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4696 | data->arg.open_stateid = &state->stateid; |
| 4697 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4698 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4699 | } else |
| 4700 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4701 | data->timestamp = jiffies; |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4702 | if (nfs4_setup_sequence(data->server, |
| 4703 | &data->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4704 | &data->res.seq_res, task)) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4705 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4706 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4707 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4708 | } |
| 4709 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4710 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4711 | { |
| 4712 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4713 | nfs4_lock_prepare(task, calldata); |
| 4714 | } |
| 4715 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4716 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4717 | { |
| 4718 | struct nfs4_lockdata *data = calldata; |
| 4719 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4720 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4721 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4722 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4723 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4724 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4725 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4726 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4727 | if (data->rpc_status == 0) |
| 4728 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4729 | else |
| 4730 | goto out; |
| 4731 | } |
| 4732 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4733 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4734 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4735 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4736 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4737 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4738 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | static void nfs4_lock_release(void *calldata) |
| 4742 | { |
| 4743 | struct nfs4_lockdata *data = calldata; |
| 4744 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4745 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4746 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4747 | if (data->cancelled != 0) { |
| 4748 | struct rpc_task *task; |
| 4749 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4750 | data->arg.lock_seqid); |
| 4751 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4752 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4753 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4754 | } else |
| 4755 | nfs_free_seqid(data->arg.lock_seqid); |
| 4756 | nfs4_put_lock_state(data->lsp); |
| 4757 | put_nfs_open_context(data->ctx); |
| 4758 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4759 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4760 | } |
| 4761 | |
| 4762 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4763 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4764 | .rpc_call_done = nfs4_lock_done, |
| 4765 | .rpc_release = nfs4_lock_release, |
| 4766 | }; |
| 4767 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4768 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4769 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4770 | .rpc_call_done = nfs4_lock_done, |
| 4771 | .rpc_release = nfs4_lock_release, |
| 4772 | }; |
| 4773 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4774 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4775 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4776 | switch (error) { |
| 4777 | case -NFS4ERR_ADMIN_REVOKED: |
| 4778 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4779 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4780 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4781 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4782 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4783 | break; |
| 4784 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4785 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4786 | case -NFS4ERR_EXPIRED: |
| 4787 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4788 | }; |
| 4789 | } |
| 4790 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4791 | 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] | 4792 | { |
| 4793 | struct nfs4_lockdata *data; |
| 4794 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4795 | struct rpc_message msg = { |
| 4796 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4797 | .rpc_cred = state->owner->so_cred, |
| 4798 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4799 | struct rpc_task_setup task_setup_data = { |
| 4800 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4801 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4802 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4803 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4804 | .flags = RPC_TASK_ASYNC, |
| 4805 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4806 | int ret; |
| 4807 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4808 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4809 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4810 | fl->fl_u.nfs4_fl.owner, |
| 4811 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4812 | if (data == NULL) |
| 4813 | return -ENOMEM; |
| 4814 | if (IS_SETLKW(cmd)) |
| 4815 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4816 | if (recovery_type > NFS_LOCK_NEW) { |
| 4817 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4818 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4819 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4820 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4821 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4822 | msg.rpc_argp = &data->arg; |
| 4823 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4824 | task_setup_data.callback_data = data; |
| 4825 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4826 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4827 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4828 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4829 | if (ret == 0) { |
| 4830 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4831 | if (ret) |
| 4832 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4833 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4834 | } else |
| 4835 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4836 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4837 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4838 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | } |
| 4840 | |
| 4841 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4842 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4843 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4844 | struct nfs4_exception exception = { |
| 4845 | .inode = state->inode, |
| 4846 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4847 | int err; |
| 4848 | |
| 4849 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4850 | /* Cache the lock if possible... */ |
| 4851 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4852 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4853 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4854 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4855 | break; |
| 4856 | nfs4_handle_exception(server, err, &exception); |
| 4857 | } while (exception.retry); |
| 4858 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | } |
| 4860 | |
| 4861 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4862 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4863 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4864 | struct nfs4_exception exception = { |
| 4865 | .inode = state->inode, |
| 4866 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4867 | int err; |
| 4868 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4869 | err = nfs4_set_lock_state(state, request); |
| 4870 | if (err != 0) |
| 4871 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4872 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4873 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4874 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4875 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4876 | switch (err) { |
| 4877 | default: |
| 4878 | goto out; |
| 4879 | case -NFS4ERR_GRACE: |
| 4880 | case -NFS4ERR_DELAY: |
| 4881 | nfs4_handle_exception(server, err, &exception); |
| 4882 | err = 0; |
| 4883 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4884 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4885 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4886 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | } |
| 4888 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4889 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4890 | /** |
| 4891 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4892 | * |
| 4893 | * @state: NFSv4 state for an inode |
| 4894 | * |
| 4895 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4896 | * Otherwise a negative NFS4ERR value is returned. |
| 4897 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4898 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4899 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4900 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4901 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4902 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4903 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4904 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4905 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4906 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4907 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4908 | /* Free the stateid unless the server |
| 4909 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4910 | if (status != -NFS4ERR_BAD_STATEID) |
| 4911 | nfs41_free_stateid(server, |
| 4912 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4913 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4914 | ret = status; |
| 4915 | } |
| 4916 | } |
| 4917 | }; |
| 4918 | |
| 4919 | return ret; |
| 4920 | } |
| 4921 | |
| 4922 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4923 | { |
| 4924 | int status = NFS_OK; |
| 4925 | |
| 4926 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4927 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4928 | if (status != NFS_OK) |
| 4929 | status = nfs4_lock_expired(state, request); |
| 4930 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4931 | } |
| 4932 | #endif |
| 4933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4935 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4936 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4937 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4938 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4940 | if ((fl_flags & FL_POSIX) && |
| 4941 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4942 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4943 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4944 | status = nfs4_set_lock_state(state, request); |
| 4945 | if (status != 0) |
| 4946 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4947 | request->fl_flags |= FL_ACCESS; |
| 4948 | status = do_vfs_lock(request->fl_file, request); |
| 4949 | if (status < 0) |
| 4950 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4951 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4952 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4953 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4954 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4955 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4956 | status = do_vfs_lock(request->fl_file, request); |
| 4957 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4958 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4959 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4960 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4961 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4962 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4963 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4964 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4965 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4966 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4967 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4968 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4969 | out: |
| 4970 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4971 | return status; |
| 4972 | } |
| 4973 | |
| 4974 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4975 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4976 | struct nfs4_exception exception = { |
| 4977 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4978 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4979 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | int err; |
| 4981 | |
| 4982 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4983 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4984 | if (err == -NFS4ERR_DENIED) |
| 4985 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4986 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4987 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4988 | } while (exception.retry); |
| 4989 | return err; |
| 4990 | } |
| 4991 | |
| 4992 | static int |
| 4993 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4994 | { |
| 4995 | struct nfs_open_context *ctx; |
| 4996 | struct nfs4_state *state; |
| 4997 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4998 | int status; |
| 4999 | |
| 5000 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 5001 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | state = ctx->state; |
| 5003 | |
| 5004 | if (request->fl_start < 0 || request->fl_end < 0) |
| 5005 | return -EINVAL; |
| 5006 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5007 | if (IS_GETLK(cmd)) { |
| 5008 | if (state != NULL) |
| 5009 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 5010 | return 0; |
| 5011 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | |
| 5013 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 5014 | return -EINVAL; |
| 5015 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5016 | if (request->fl_type == F_UNLCK) { |
| 5017 | if (state != NULL) |
| 5018 | return nfs4_proc_unlck(state, cmd, request); |
| 5019 | return 0; |
| 5020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 5022 | if (state == NULL) |
| 5023 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5024 | /* |
| 5025 | * Don't rely on the VFS having checked the file open mode, |
| 5026 | * since it won't do this for flock() locks. |
| 5027 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 5028 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 5029 | case F_RDLCK: |
| 5030 | if (!(filp->f_mode & FMODE_READ)) |
| 5031 | return -EBADF; |
| 5032 | break; |
| 5033 | case F_WRLCK: |
| 5034 | if (!(filp->f_mode & FMODE_WRITE)) |
| 5035 | return -EBADF; |
| 5036 | } |
| 5037 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5038 | do { |
| 5039 | status = nfs4_proc_setlk(state, cmd, request); |
| 5040 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 5041 | break; |
| 5042 | timeout = nfs4_set_lock_task_retry(timeout); |
| 5043 | status = -ERESTARTSYS; |
| 5044 | if (signalled()) |
| 5045 | break; |
| 5046 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5047 | return status; |
| 5048 | } |
| 5049 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5050 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 5051 | { |
| 5052 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 5053 | struct nfs4_exception exception = { }; |
| 5054 | int err; |
| 5055 | |
| 5056 | err = nfs4_set_lock_state(state, fl); |
| 5057 | if (err != 0) |
| 5058 | goto out; |
| 5059 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 5060 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5061 | switch (err) { |
| 5062 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 5063 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 5064 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5065 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5066 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5067 | goto out; |
| 5068 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 5069 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5070 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5071 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5072 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 5073 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5074 | case -NFS4ERR_BADSESSION: |
| 5075 | case -NFS4ERR_BADSLOT: |
| 5076 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5077 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5078 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5079 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5080 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5081 | case -ERESTARTSYS: |
| 5082 | /* |
| 5083 | * The show must go on: exit, but mark the |
| 5084 | * stateid as needing recovery. |
| 5085 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5086 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5087 | case -NFS4ERR_ADMIN_REVOKED: |
| 5088 | case -NFS4ERR_BAD_STATEID: |
| 5089 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5090 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5091 | err = 0; |
| 5092 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5093 | case -EKEYEXPIRED: |
| 5094 | /* |
| 5095 | * User RPCSEC_GSS context has expired. |
| 5096 | * We cannot recover this stateid now, so |
| 5097 | * skip it and allow recovery thread to |
| 5098 | * proceed. |
| 5099 | */ |
| 5100 | err = 0; |
| 5101 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5102 | case -ENOMEM: |
| 5103 | case -NFS4ERR_DENIED: |
| 5104 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5105 | err = 0; |
| 5106 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5107 | case -NFS4ERR_DELAY: |
| 5108 | break; |
| 5109 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5110 | err = nfs4_handle_exception(server, err, &exception); |
| 5111 | } while (exception.retry); |
| 5112 | out: |
| 5113 | return err; |
| 5114 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5115 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5116 | struct nfs_release_lockowner_data { |
| 5117 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5118 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5119 | struct nfs_release_lockowner_args args; |
| 5120 | }; |
| 5121 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5122 | static void nfs4_release_lockowner_release(void *calldata) |
| 5123 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5124 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5125 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5126 | kfree(calldata); |
| 5127 | } |
| 5128 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5129 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5130 | .rpc_release = nfs4_release_lockowner_release, |
| 5131 | }; |
| 5132 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5133 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5134 | { |
| 5135 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5136 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5137 | struct rpc_message msg = { |
| 5138 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5139 | }; |
| 5140 | |
| 5141 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5142 | return -EINVAL; |
| 5143 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5144 | if (!data) |
| 5145 | return -ENOMEM; |
| 5146 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5147 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5148 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5149 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5150 | data->args.lock_owner.s_dev = server->s_dev; |
| 5151 | msg.rpc_argp = &data->args; |
| 5152 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5153 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5154 | } |
| 5155 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5156 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5157 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5158 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5159 | const void *buf, size_t buflen, |
| 5160 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5161 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5162 | if (strcmp(key, "") != 0) |
| 5163 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5164 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5165 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5166 | } |
| 5167 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5168 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5169 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5170 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5171 | if (strcmp(key, "") != 0) |
| 5172 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5173 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5174 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5175 | } |
| 5176 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5177 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5178 | size_t list_len, const char *name, |
| 5179 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5180 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5181 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5182 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5183 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5184 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5185 | |
| 5186 | if (list && len <= list_len) |
| 5187 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5188 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5189 | } |
| 5190 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5191 | /* |
| 5192 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5193 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5194 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5195 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5196 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5197 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5198 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5199 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5200 | return; |
| 5201 | |
| 5202 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5203 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5204 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5205 | fattr->nlink = 2; |
| 5206 | } |
| 5207 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5208 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5209 | const struct qstr *name, |
| 5210 | struct nfs4_fs_locations *fs_locations, |
| 5211 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5212 | { |
| 5213 | struct nfs_server *server = NFS_SERVER(dir); |
| 5214 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5215 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5216 | }; |
| 5217 | struct nfs4_fs_locations_arg args = { |
| 5218 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5219 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5220 | .page = page, |
| 5221 | .bitmask = bitmask, |
| 5222 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5223 | struct nfs4_fs_locations_res res = { |
| 5224 | .fs_locations = fs_locations, |
| 5225 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5226 | struct rpc_message msg = { |
| 5227 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5228 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5229 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5230 | }; |
| 5231 | int status; |
| 5232 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5233 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5234 | |
| 5235 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5236 | * is not supported */ |
| 5237 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5238 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5239 | else |
| 5240 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5241 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5242 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5243 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5244 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5245 | status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5246 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5247 | return status; |
| 5248 | } |
| 5249 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5250 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5251 | const struct qstr *name, |
| 5252 | struct nfs4_fs_locations *fs_locations, |
| 5253 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5254 | { |
| 5255 | struct nfs4_exception exception = { }; |
| 5256 | int err; |
| 5257 | do { |
| 5258 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5259 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5260 | &exception); |
| 5261 | } while (exception.retry); |
| 5262 | return err; |
| 5263 | } |
| 5264 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5265 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5266 | { |
| 5267 | int status; |
| 5268 | struct nfs4_secinfo_arg args = { |
| 5269 | .dir_fh = NFS_FH(dir), |
| 5270 | .name = name, |
| 5271 | }; |
| 5272 | struct nfs4_secinfo_res res = { |
| 5273 | .flavors = flavors, |
| 5274 | }; |
| 5275 | struct rpc_message msg = { |
| 5276 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5277 | .rpc_argp = &args, |
| 5278 | .rpc_resp = &res, |
| 5279 | }; |
| 5280 | |
| 5281 | dprintk("NFS call secinfo %s\n", name->name); |
| 5282 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5283 | dprintk("NFS reply secinfo: %d\n", status); |
| 5284 | return status; |
| 5285 | } |
| 5286 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5287 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5288 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5289 | { |
| 5290 | struct nfs4_exception exception = { }; |
| 5291 | int err; |
| 5292 | do { |
| 5293 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5294 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5295 | &exception); |
| 5296 | } while (exception.retry); |
| 5297 | return err; |
| 5298 | } |
| 5299 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5300 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5301 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5302 | * Check the exchange flags returned by the server for invalid flags, having |
| 5303 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5304 | * DS flags set. |
| 5305 | */ |
| 5306 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5307 | { |
| 5308 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5309 | goto out_inval; |
| 5310 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5311 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5312 | goto out_inval; |
| 5313 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5314 | goto out_inval; |
| 5315 | return NFS_OK; |
| 5316 | out_inval: |
| 5317 | return -NFS4ERR_INVAL; |
| 5318 | } |
| 5319 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5320 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5321 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5322 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5323 | { |
| 5324 | if (a->server_scope_sz == b->server_scope_sz && |
| 5325 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5326 | return true; |
| 5327 | |
| 5328 | return false; |
| 5329 | } |
| 5330 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5331 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5332 | * nfs4_proc_bind_conn_to_session() |
| 5333 | * |
| 5334 | * The 4.1 client currently uses the same TCP connection for the |
| 5335 | * fore and backchannel. |
| 5336 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5337 | int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred) |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5338 | { |
| 5339 | int status; |
| 5340 | struct nfs41_bind_conn_to_session_res res; |
| 5341 | struct rpc_message msg = { |
| 5342 | .rpc_proc = |
| 5343 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5344 | .rpc_argp = clp, |
| 5345 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5346 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5347 | }; |
| 5348 | |
| 5349 | dprintk("--> %s\n", __func__); |
| 5350 | BUG_ON(clp == NULL); |
| 5351 | |
| 5352 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5353 | if (unlikely(res.session == NULL)) { |
| 5354 | status = -ENOMEM; |
| 5355 | goto out; |
| 5356 | } |
| 5357 | |
| 5358 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5359 | if (status == 0) { |
| 5360 | if (memcmp(res.session->sess_id.data, |
| 5361 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5362 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5363 | status = -EIO; |
| 5364 | goto out_session; |
| 5365 | } |
| 5366 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5367 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5368 | __func__); |
| 5369 | status = -EIO; |
| 5370 | goto out_session; |
| 5371 | } |
| 5372 | if (res.use_conn_in_rdma_mode) { |
| 5373 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5374 | __func__); |
| 5375 | status = -EIO; |
| 5376 | goto out_session; |
| 5377 | } |
| 5378 | } |
| 5379 | out_session: |
| 5380 | kfree(res.session); |
| 5381 | out: |
| 5382 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5383 | return status; |
| 5384 | } |
| 5385 | |
| 5386 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5387 | * nfs4_proc_exchange_id() |
| 5388 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5389 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5390 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5391 | * Since the clientid has expired, all compounds using sessions |
| 5392 | * associated with the stale clientid will be returning |
| 5393 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5394 | * be in some phase of session reset. |
| 5395 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5396 | 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] | 5397 | { |
| 5398 | nfs4_verifier verifier; |
| 5399 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5400 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5401 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5402 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5403 | }; |
| 5404 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5405 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5406 | }; |
| 5407 | int status; |
| 5408 | struct rpc_message msg = { |
| 5409 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5410 | .rpc_argp = &args, |
| 5411 | .rpc_resp = &res, |
| 5412 | .rpc_cred = cred, |
| 5413 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5414 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5415 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5416 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5417 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5418 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5419 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5420 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5421 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5422 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5423 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5424 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5425 | status = -ENOMEM; |
| 5426 | goto out; |
| 5427 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5428 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5429 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5430 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5431 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5432 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5433 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5434 | } |
| 5435 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5436 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5437 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5438 | status = -ENOMEM; |
| 5439 | goto out_server_scope; |
| 5440 | } |
| 5441 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5442 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5443 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5444 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5445 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5446 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5447 | clp->cl_clientid = res.clientid; |
| 5448 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5449 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5450 | clp->cl_seqid = res.seqid; |
| 5451 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5452 | kfree(clp->cl_serverowner); |
| 5453 | clp->cl_serverowner = res.server_owner; |
| 5454 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5455 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5456 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5457 | kfree(clp->cl_implid); |
| 5458 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5459 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5460 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5461 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5462 | res.server_scope)) { |
| 5463 | dprintk("%s: server_scope mismatch detected\n", |
| 5464 | __func__); |
| 5465 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5466 | kfree(clp->cl_serverscope); |
| 5467 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5468 | } |
| 5469 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5470 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5471 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5472 | goto out; |
| 5473 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5474 | } else |
| 5475 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5476 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5477 | out_server_owner: |
| 5478 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5479 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5480 | kfree(res.server_scope); |
| 5481 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5482 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5483 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5484 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5485 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5486 | clp->cl_implid->date.seconds, |
| 5487 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5488 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5489 | return status; |
| 5490 | } |
| 5491 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5492 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5493 | struct rpc_cred *cred) |
| 5494 | { |
| 5495 | struct rpc_message msg = { |
| 5496 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5497 | .rpc_argp = clp, |
| 5498 | .rpc_cred = cred, |
| 5499 | }; |
| 5500 | int status; |
| 5501 | |
| 5502 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5503 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5504 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5505 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5506 | return status; |
| 5507 | } |
| 5508 | |
| 5509 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5510 | struct rpc_cred *cred) |
| 5511 | { |
| 5512 | unsigned int loop; |
| 5513 | int ret; |
| 5514 | |
| 5515 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5516 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5517 | switch (ret) { |
| 5518 | case -NFS4ERR_DELAY: |
| 5519 | case -NFS4ERR_CLIENTID_BUSY: |
| 5520 | ssleep(1); |
| 5521 | break; |
| 5522 | default: |
| 5523 | return ret; |
| 5524 | } |
| 5525 | } |
| 5526 | return 0; |
| 5527 | } |
| 5528 | |
| 5529 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5530 | { |
| 5531 | struct rpc_cred *cred; |
| 5532 | int ret = 0; |
| 5533 | |
| 5534 | if (clp->cl_mvops->minor_version < 1) |
| 5535 | goto out; |
| 5536 | if (clp->cl_exchange_flags == 0) |
| 5537 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5538 | if (clp->cl_preserve_clid) |
| 5539 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5540 | cred = nfs4_get_exchange_id_cred(clp); |
| 5541 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5542 | if (cred) |
| 5543 | put_rpccred(cred); |
| 5544 | switch (ret) { |
| 5545 | case 0: |
| 5546 | case -NFS4ERR_STALE_CLIENTID: |
| 5547 | clp->cl_exchange_flags = 0; |
| 5548 | } |
| 5549 | out: |
| 5550 | return ret; |
| 5551 | } |
| 5552 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5553 | struct nfs4_get_lease_time_data { |
| 5554 | struct nfs4_get_lease_time_args *args; |
| 5555 | struct nfs4_get_lease_time_res *res; |
| 5556 | struct nfs_client *clp; |
| 5557 | }; |
| 5558 | |
| 5559 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5560 | void *calldata) |
| 5561 | { |
| 5562 | int ret; |
| 5563 | struct nfs4_get_lease_time_data *data = |
| 5564 | (struct nfs4_get_lease_time_data *)calldata; |
| 5565 | |
| 5566 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5567 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5568 | /* just setup sequence, do not trigger session recovery |
| 5569 | since we're invoked within one */ |
| 5570 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5571 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5572 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5573 | |
| 5574 | BUG_ON(ret == -EAGAIN); |
| 5575 | rpc_call_start(task); |
| 5576 | dprintk("<-- %s\n", __func__); |
| 5577 | } |
| 5578 | |
| 5579 | /* |
| 5580 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5581 | * from sequence operation or clientid errors. |
| 5582 | */ |
| 5583 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5584 | { |
| 5585 | struct nfs4_get_lease_time_data *data = |
| 5586 | (struct nfs4_get_lease_time_data *)calldata; |
| 5587 | |
| 5588 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5589 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5590 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5591 | switch (task->tk_status) { |
| 5592 | case -NFS4ERR_DELAY: |
| 5593 | case -NFS4ERR_GRACE: |
| 5594 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5595 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5596 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5597 | /* fall through */ |
| 5598 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5599 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5600 | return; |
| 5601 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5602 | dprintk("<-- %s\n", __func__); |
| 5603 | } |
| 5604 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5605 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5606 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5607 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5608 | }; |
| 5609 | |
| 5610 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5611 | { |
| 5612 | struct rpc_task *task; |
| 5613 | struct nfs4_get_lease_time_args args; |
| 5614 | struct nfs4_get_lease_time_res res = { |
| 5615 | .lr_fsinfo = fsinfo, |
| 5616 | }; |
| 5617 | struct nfs4_get_lease_time_data data = { |
| 5618 | .args = &args, |
| 5619 | .res = &res, |
| 5620 | .clp = clp, |
| 5621 | }; |
| 5622 | struct rpc_message msg = { |
| 5623 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5624 | .rpc_argp = &args, |
| 5625 | .rpc_resp = &res, |
| 5626 | }; |
| 5627 | struct rpc_task_setup task_setup = { |
| 5628 | .rpc_client = clp->cl_rpcclient, |
| 5629 | .rpc_message = &msg, |
| 5630 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5631 | .callback_data = &data, |
| 5632 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5633 | }; |
| 5634 | int status; |
| 5635 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5636 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5637 | dprintk("--> %s\n", __func__); |
| 5638 | task = rpc_run_task(&task_setup); |
| 5639 | |
| 5640 | if (IS_ERR(task)) |
| 5641 | status = PTR_ERR(task); |
| 5642 | else { |
| 5643 | status = task->tk_status; |
| 5644 | rpc_put_task(task); |
| 5645 | } |
| 5646 | dprintk("<-- %s return %d\n", __func__, status); |
| 5647 | |
| 5648 | return status; |
| 5649 | } |
| 5650 | |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5651 | static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags) |
| 5652 | { |
| 5653 | return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags); |
| 5654 | } |
| 5655 | |
| 5656 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5657 | struct nfs4_slot *new, |
| 5658 | u32 max_slots, |
| 5659 | u32 ivalue) |
| 5660 | { |
| 5661 | struct nfs4_slot *old = NULL; |
| 5662 | u32 i; |
| 5663 | |
| 5664 | spin_lock(&tbl->slot_tbl_lock); |
| 5665 | if (new) { |
| 5666 | old = tbl->slots; |
| 5667 | tbl->slots = new; |
| 5668 | tbl->max_slots = max_slots; |
| 5669 | } |
| 5670 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5671 | for (i = 0; i < tbl->max_slots; i++) |
| 5672 | tbl->slots[i].seq_nr = ivalue; |
| 5673 | spin_unlock(&tbl->slot_tbl_lock); |
| 5674 | kfree(old); |
| 5675 | } |
| 5676 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5677 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5678 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5679 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5680 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5681 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5682 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5683 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5684 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5685 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5686 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5687 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5688 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5689 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5690 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5691 | new = nfs4_alloc_slots(max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5692 | if (!new) |
| 5693 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5694 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5695 | ret = 0; |
| 5696 | |
| 5697 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5698 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5699 | tbl, tbl->slots, tbl->max_slots); |
| 5700 | out: |
| 5701 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5702 | return ret; |
| 5703 | } |
| 5704 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5705 | /* Destroy the slot table */ |
| 5706 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5707 | { |
| 5708 | if (session->fc_slot_table.slots != NULL) { |
| 5709 | kfree(session->fc_slot_table.slots); |
| 5710 | session->fc_slot_table.slots = NULL; |
| 5711 | } |
| 5712 | if (session->bc_slot_table.slots != NULL) { |
| 5713 | kfree(session->bc_slot_table.slots); |
| 5714 | session->bc_slot_table.slots = NULL; |
| 5715 | } |
| 5716 | return; |
| 5717 | } |
| 5718 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5719 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5720 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5721 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5722 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5723 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5724 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5725 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5726 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5727 | dprintk("--> %s\n", __func__); |
| 5728 | /* Fore channel */ |
| 5729 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5730 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5731 | if (status) /* -ENOMEM */ |
| 5732 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5733 | /* Back channel */ |
| 5734 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5735 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5736 | if (status && tbl->slots == NULL) |
| 5737 | /* Fore and back channel share a connection so get |
| 5738 | * both slot tables or neither */ |
| 5739 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5740 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5744 | { |
| 5745 | struct nfs4_session *session; |
| 5746 | struct nfs4_slot_table *tbl; |
| 5747 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5748 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5749 | if (!session) |
| 5750 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5751 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5752 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5753 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5754 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5755 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5756 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5757 | |
| 5758 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5759 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5760 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5761 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5762 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5763 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5764 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5765 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5766 | session->clp = clp; |
| 5767 | return session; |
| 5768 | } |
| 5769 | |
| 5770 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5771 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5772 | struct rpc_xprt *xprt; |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5773 | struct rpc_cred *cred; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5774 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5775 | cred = nfs4_get_exchange_id_cred(session->clp); |
| 5776 | nfs4_proc_destroy_session(session, cred); |
| 5777 | if (cred) |
| 5778 | put_rpccred(cred); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5779 | |
| 5780 | rcu_read_lock(); |
| 5781 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5782 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5783 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5784 | __func__, xprt); |
| 5785 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5786 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5787 | kfree(session); |
| 5788 | } |
| 5789 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5790 | /* |
| 5791 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5792 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5793 | * use them. |
| 5794 | * |
| 5795 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5796 | * always set csa_cachethis to FALSE because the current implementation |
| 5797 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5798 | */ |
| 5799 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5800 | { |
| 5801 | struct nfs4_session *session = args->client->cl_session; |
| 5802 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5803 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5804 | |
| 5805 | if (mxrqst_sz == 0) |
| 5806 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5807 | if (mxresp_sz == 0) |
| 5808 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5809 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5810 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5811 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5812 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5813 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5814 | |
| 5815 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5816 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5817 | __func__, |
| 5818 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5819 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5820 | |
| 5821 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5822 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5823 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5824 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5825 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5826 | args->bc_attrs.max_reqs = 1; |
| 5827 | |
| 5828 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5829 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5830 | __func__, |
| 5831 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5832 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5833 | args->bc_attrs.max_reqs); |
| 5834 | } |
| 5835 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5836 | 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] | 5837 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5838 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5839 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5840 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5841 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5842 | return -EINVAL; |
| 5843 | /* |
| 5844 | * Our requested max_ops is the minimum we need; we're not |
| 5845 | * prepared to break up compounds into smaller pieces than that. |
| 5846 | * So, no point even trying to continue if the server won't |
| 5847 | * cooperate: |
| 5848 | */ |
| 5849 | if (rcvd->max_ops < sent->max_ops) |
| 5850 | return -EINVAL; |
| 5851 | if (rcvd->max_reqs == 0) |
| 5852 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5853 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5854 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5855 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5856 | } |
| 5857 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5858 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5859 | { |
| 5860 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5861 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5862 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5863 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5864 | return -EINVAL; |
| 5865 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5866 | return -EINVAL; |
| 5867 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5868 | return -EINVAL; |
| 5869 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5870 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5871 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5872 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5873 | return -EINVAL; |
| 5874 | return 0; |
| 5875 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5876 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5877 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5878 | struct nfs4_session *session) |
| 5879 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5880 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5881 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5882 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5883 | if (ret) |
| 5884 | return ret; |
| 5885 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5886 | } |
| 5887 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5888 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5889 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5890 | { |
| 5891 | struct nfs4_session *session = clp->cl_session; |
| 5892 | struct nfs41_create_session_args args = { |
| 5893 | .client = clp, |
| 5894 | .cb_program = NFS4_CALLBACK, |
| 5895 | }; |
| 5896 | struct nfs41_create_session_res res = { |
| 5897 | .client = clp, |
| 5898 | }; |
| 5899 | struct rpc_message msg = { |
| 5900 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5901 | .rpc_argp = &args, |
| 5902 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5903 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5904 | }; |
| 5905 | int status; |
| 5906 | |
| 5907 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5908 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5909 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5910 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5911 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5912 | if (!status) |
| 5913 | /* Verify the session's negotiated channel_attrs values */ |
| 5914 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5915 | if (!status) { |
| 5916 | /* Increment the clientid slot sequence id */ |
| 5917 | clp->cl_seqid++; |
| 5918 | } |
| 5919 | |
| 5920 | return status; |
| 5921 | } |
| 5922 | |
| 5923 | /* |
| 5924 | * Issues a CREATE_SESSION operation to the server. |
| 5925 | * It is the responsibility of the caller to verify the session is |
| 5926 | * expired before calling this routine. |
| 5927 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5928 | int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5929 | { |
| 5930 | int status; |
| 5931 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5932 | struct nfs4_session *session = clp->cl_session; |
| 5933 | |
| 5934 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5935 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5936 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5937 | if (status) |
| 5938 | goto out; |
| 5939 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5940 | /* Init or reset the session slot tables */ |
| 5941 | status = nfs4_setup_session_slot_tables(session); |
| 5942 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5943 | if (status) |
| 5944 | goto out; |
| 5945 | |
| 5946 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5947 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5948 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5949 | out: |
| 5950 | dprintk("<-- %s\n", __func__); |
| 5951 | return status; |
| 5952 | } |
| 5953 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5954 | /* |
| 5955 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5956 | * The caller must serialize access to this routine. |
| 5957 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5958 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5959 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5960 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5961 | struct rpc_message msg = { |
| 5962 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5963 | .rpc_argp = session, |
| 5964 | .rpc_cred = cred, |
| 5965 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5966 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5967 | |
| 5968 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5969 | |
| 5970 | /* session is still being setup */ |
| 5971 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5972 | return status; |
| 5973 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5974 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5975 | |
| 5976 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5977 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5978 | "Session has been destroyed regardless...\n", status); |
| 5979 | |
| 5980 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5981 | return status; |
| 5982 | } |
| 5983 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5984 | /* |
| 5985 | * With sessions, the client is not marked ready until after a |
| 5986 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 5987 | * |
| 5988 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 5989 | * other versions of NFS can be tried. |
| 5990 | */ |
| 5991 | static int nfs41_check_session_ready(struct nfs_client *clp) |
| 5992 | { |
| 5993 | int ret; |
| 5994 | |
| 5995 | if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { |
| 5996 | ret = nfs4_client_recover_expired_lease(clp); |
| 5997 | if (ret) |
| 5998 | return ret; |
| 5999 | } |
| 6000 | if (clp->cl_cons_state < NFS_CS_READY) |
| 6001 | return -EPROTONOSUPPORT; |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 6002 | smp_rmb(); |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6003 | return 0; |
| 6004 | } |
| 6005 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6006 | int nfs4_init_session(struct nfs_server *server) |
| 6007 | { |
| 6008 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 6009 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 6010 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6011 | |
| 6012 | if (!nfs4_has_session(clp)) |
| 6013 | return 0; |
| 6014 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6015 | session = clp->cl_session; |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6016 | spin_lock(&clp->cl_lock); |
| 6017 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6018 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6019 | rsize = server->rsize; |
| 6020 | if (rsize == 0) |
| 6021 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 6022 | wsize = server->wsize; |
| 6023 | if (wsize == 0) |
| 6024 | wsize = NFS_MAX_FILE_IO_SIZE; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 6025 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6026 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 6027 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
| 6028 | } |
| 6029 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 6030 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6031 | return nfs41_check_session_ready(clp); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 6032 | } |
| 6033 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6034 | int nfs4_init_ds_session(struct nfs_client *clp, unsigned long lease_time) |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6035 | { |
| 6036 | struct nfs4_session *session = clp->cl_session; |
| 6037 | int ret; |
| 6038 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6039 | spin_lock(&clp->cl_lock); |
| 6040 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
| 6041 | /* |
| 6042 | * Do not set NFS_CS_CHECK_LEASE_TIME instead set the |
| 6043 | * DS lease to be equal to the MDS lease. |
| 6044 | */ |
| 6045 | clp->cl_lease_time = lease_time; |
| 6046 | clp->cl_last_renewal = jiffies; |
| 6047 | } |
| 6048 | spin_unlock(&clp->cl_lock); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6049 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 6050 | ret = nfs41_check_session_ready(clp); |
| 6051 | if (ret) |
| 6052 | return ret; |
| 6053 | /* Test for the DS role */ |
| 6054 | if (!is_ds_client(clp)) |
| 6055 | return -ENODEV; |
| 6056 | return 0; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 6057 | } |
| 6058 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 6059 | |
| 6060 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6061 | /* |
| 6062 | * Renew the cl_session lease. |
| 6063 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6064 | struct nfs4_sequence_data { |
| 6065 | struct nfs_client *clp; |
| 6066 | struct nfs4_sequence_args args; |
| 6067 | struct nfs4_sequence_res res; |
| 6068 | }; |
| 6069 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6070 | static void nfs41_sequence_release(void *data) |
| 6071 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6072 | struct nfs4_sequence_data *calldata = data; |
| 6073 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6074 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6075 | if (atomic_read(&clp->cl_count) > 1) |
| 6076 | nfs4_schedule_state_renewal(clp); |
| 6077 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6078 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6079 | } |
| 6080 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6081 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6082 | { |
| 6083 | switch(task->tk_status) { |
| 6084 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6085 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6086 | return -EAGAIN; |
| 6087 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6088 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6089 | } |
| 6090 | return 0; |
| 6091 | } |
| 6092 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6093 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6094 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6095 | struct nfs4_sequence_data *calldata = data; |
| 6096 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6097 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6098 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6099 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6100 | |
| 6101 | if (task->tk_status < 0) { |
| 6102 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6103 | if (atomic_read(&clp->cl_count) == 1) |
| 6104 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6105 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6106 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6107 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6108 | return; |
| 6109 | } |
| 6110 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6111 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6112 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6113 | dprintk("<-- %s\n", __func__); |
| 6114 | } |
| 6115 | |
| 6116 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6117 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6118 | struct nfs4_sequence_data *calldata = data; |
| 6119 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6120 | struct nfs4_sequence_args *args; |
| 6121 | struct nfs4_sequence_res *res; |
| 6122 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6123 | args = task->tk_msg.rpc_argp; |
| 6124 | res = task->tk_msg.rpc_resp; |
| 6125 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6126 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6127 | return; |
| 6128 | rpc_call_start(task); |
| 6129 | } |
| 6130 | |
| 6131 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6132 | .rpc_call_done = nfs41_sequence_call_done, |
| 6133 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6134 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6135 | }; |
| 6136 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6137 | 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] | 6138 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6139 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6140 | struct rpc_message msg = { |
| 6141 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6142 | .rpc_cred = cred, |
| 6143 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6144 | struct rpc_task_setup task_setup_data = { |
| 6145 | .rpc_client = clp->cl_rpcclient, |
| 6146 | .rpc_message = &msg, |
| 6147 | .callback_ops = &nfs41_sequence_ops, |
| 6148 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 6149 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6150 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6151 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6152 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6153 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6154 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6155 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6156 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6157 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6158 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6159 | msg.rpc_argp = &calldata->args; |
| 6160 | msg.rpc_resp = &calldata->res; |
| 6161 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6162 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6163 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6164 | return rpc_run_task(&task_setup_data); |
| 6165 | } |
| 6166 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6167 | 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] | 6168 | { |
| 6169 | struct rpc_task *task; |
| 6170 | int ret = 0; |
| 6171 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6172 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6173 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6174 | task = _nfs41_proc_sequence(clp, cred); |
| 6175 | if (IS_ERR(task)) |
| 6176 | ret = PTR_ERR(task); |
| 6177 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6178 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6179 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6180 | return ret; |
| 6181 | } |
| 6182 | |
| 6183 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6184 | { |
| 6185 | struct rpc_task *task; |
| 6186 | int ret; |
| 6187 | |
| 6188 | task = _nfs41_proc_sequence(clp, cred); |
| 6189 | if (IS_ERR(task)) { |
| 6190 | ret = PTR_ERR(task); |
| 6191 | goto out; |
| 6192 | } |
| 6193 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6194 | if (!ret) { |
| 6195 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6196 | |
| 6197 | if (task->tk_status == 0) |
| 6198 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6199 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6200 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6201 | rpc_put_task(task); |
| 6202 | out: |
| 6203 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6204 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6205 | } |
| 6206 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6207 | struct nfs4_reclaim_complete_data { |
| 6208 | struct nfs_client *clp; |
| 6209 | struct nfs41_reclaim_complete_args arg; |
| 6210 | struct nfs41_reclaim_complete_res res; |
| 6211 | }; |
| 6212 | |
| 6213 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6214 | { |
| 6215 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6216 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6217 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168a | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6218 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 6219 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6220 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6221 | return; |
| 6222 | |
| 6223 | rpc_call_start(task); |
| 6224 | } |
| 6225 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6226 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6227 | { |
| 6228 | switch(task->tk_status) { |
| 6229 | case 0: |
| 6230 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6231 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6232 | break; |
| 6233 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6234 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6235 | /* fall through */ |
| 6236 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6237 | return -EAGAIN; |
| 6238 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6239 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6240 | } |
| 6241 | return 0; |
| 6242 | } |
| 6243 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6244 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6245 | { |
| 6246 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6247 | struct nfs_client *clp = calldata->clp; |
| 6248 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6249 | |
| 6250 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6251 | if (!nfs41_sequence_done(task, res)) |
| 6252 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6253 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6254 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6255 | rpc_restart_call_prepare(task); |
| 6256 | return; |
| 6257 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6258 | dprintk("<-- %s\n", __func__); |
| 6259 | } |
| 6260 | |
| 6261 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6262 | { |
| 6263 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6264 | |
| 6265 | kfree(calldata); |
| 6266 | } |
| 6267 | |
| 6268 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6269 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6270 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6271 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6272 | }; |
| 6273 | |
| 6274 | /* |
| 6275 | * Issue a global reclaim complete. |
| 6276 | */ |
| 6277 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6278 | { |
| 6279 | struct nfs4_reclaim_complete_data *calldata; |
| 6280 | struct rpc_task *task; |
| 6281 | struct rpc_message msg = { |
| 6282 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6283 | }; |
| 6284 | struct rpc_task_setup task_setup_data = { |
| 6285 | .rpc_client = clp->cl_rpcclient, |
| 6286 | .rpc_message = &msg, |
| 6287 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6288 | .flags = RPC_TASK_ASYNC, |
| 6289 | }; |
| 6290 | int status = -ENOMEM; |
| 6291 | |
| 6292 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6293 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6294 | if (calldata == NULL) |
| 6295 | goto out; |
| 6296 | calldata->clp = clp; |
| 6297 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6298 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6299 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6300 | msg.rpc_argp = &calldata->arg; |
| 6301 | msg.rpc_resp = &calldata->res; |
| 6302 | task_setup_data.callback_data = calldata; |
| 6303 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6304 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6305 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6306 | goto out; |
| 6307 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6308 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6309 | if (status == 0) |
| 6310 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6311 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6312 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6313 | out: |
| 6314 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6315 | return status; |
| 6316 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6317 | |
| 6318 | static void |
| 6319 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6320 | { |
| 6321 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6322 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6323 | |
| 6324 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6325 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6326 | * right now covering the LAYOUTGET we are about to send. |
| 6327 | * However, that is not so catastrophic, and there seems |
| 6328 | * to be no way to prevent it completely. |
| 6329 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6330 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6331 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6332 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6333 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6334 | NFS_I(lgp->args.inode)->layout, |
| 6335 | lgp->args.ctx->state)) { |
| 6336 | rpc_exit(task, NFS4_OK); |
| 6337 | return; |
| 6338 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6339 | rpc_call_start(task); |
| 6340 | } |
| 6341 | |
| 6342 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6343 | { |
| 6344 | struct nfs4_layoutget *lgp = calldata; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6345 | struct inode *inode = lgp->args.inode; |
| 6346 | struct nfs_server *server = NFS_SERVER(inode); |
| 6347 | struct pnfs_layout_hdr *lo; |
| 6348 | struct nfs4_state *state = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6349 | |
| 6350 | dprintk("--> %s\n", __func__); |
| 6351 | |
| 6352 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6353 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6354 | |
| 6355 | switch (task->tk_status) { |
| 6356 | case 0: |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6357 | goto out; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6358 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6359 | case -NFS4ERR_RECALLCONFLICT: |
| 6360 | task->tk_status = -NFS4ERR_DELAY; |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6361 | break; |
| 6362 | case -NFS4ERR_EXPIRED: |
| 6363 | case -NFS4ERR_BAD_STATEID: |
| 6364 | spin_lock(&inode->i_lock); |
| 6365 | lo = NFS_I(inode)->layout; |
| 6366 | if (!lo || list_empty(&lo->plh_segs)) { |
| 6367 | spin_unlock(&inode->i_lock); |
| 6368 | /* If the open stateid was bad, then recover it. */ |
| 6369 | state = lgp->args.ctx->state; |
| 6370 | } else { |
| 6371 | LIST_HEAD(head); |
| 6372 | |
| 6373 | pnfs_mark_matching_lsegs_invalid(lo, &head, NULL); |
| 6374 | spin_unlock(&inode->i_lock); |
| 6375 | /* Mark the bad layout state as invalid, then |
| 6376 | * retry using the open stateid. */ |
| 6377 | pnfs_free_lseg_list(&head); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6378 | } |
| 6379 | } |
Trond Myklebust | ee314c2 | 2012-10-01 17:25:48 -0700 | [diff] [blame] | 6380 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 6381 | rpc_restart_call_prepare(task); |
| 6382 | out: |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6383 | dprintk("<-- %s\n", __func__); |
| 6384 | } |
| 6385 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6386 | static size_t max_response_pages(struct nfs_server *server) |
| 6387 | { |
| 6388 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6389 | return nfs_page_array_len(0, max_resp_sz); |
| 6390 | } |
| 6391 | |
| 6392 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6393 | { |
| 6394 | int i; |
| 6395 | |
| 6396 | if (!pages) |
| 6397 | return; |
| 6398 | |
| 6399 | for (i = 0; i < size; i++) { |
| 6400 | if (!pages[i]) |
| 6401 | break; |
| 6402 | __free_page(pages[i]); |
| 6403 | } |
| 6404 | kfree(pages); |
| 6405 | } |
| 6406 | |
| 6407 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6408 | { |
| 6409 | struct page **pages; |
| 6410 | int i; |
| 6411 | |
| 6412 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6413 | if (!pages) { |
| 6414 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6415 | return NULL; |
| 6416 | } |
| 6417 | |
| 6418 | for (i = 0; i < size; i++) { |
| 6419 | pages[i] = alloc_page(gfp_flags); |
| 6420 | if (!pages[i]) { |
| 6421 | dprintk("%s: failed to allocate page\n", __func__); |
| 6422 | nfs4_free_pages(pages, size); |
| 6423 | return NULL; |
| 6424 | } |
| 6425 | } |
| 6426 | |
| 6427 | return pages; |
| 6428 | } |
| 6429 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6430 | static void nfs4_layoutget_release(void *calldata) |
| 6431 | { |
| 6432 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6433 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6434 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6435 | |
| 6436 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6437 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6438 | put_nfs_open_context(lgp->args.ctx); |
| 6439 | kfree(calldata); |
| 6440 | dprintk("<-- %s\n", __func__); |
| 6441 | } |
| 6442 | |
| 6443 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6444 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6445 | .rpc_call_done = nfs4_layoutget_done, |
| 6446 | .rpc_release = nfs4_layoutget_release, |
| 6447 | }; |
| 6448 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6449 | struct pnfs_layout_segment * |
| 6450 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6451 | { |
| 6452 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6453 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6454 | struct rpc_task *task; |
| 6455 | struct rpc_message msg = { |
| 6456 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6457 | .rpc_argp = &lgp->args, |
| 6458 | .rpc_resp = &lgp->res, |
| 6459 | }; |
| 6460 | struct rpc_task_setup task_setup_data = { |
| 6461 | .rpc_client = server->client, |
| 6462 | .rpc_message = &msg, |
| 6463 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6464 | .callback_data = lgp, |
| 6465 | .flags = RPC_TASK_ASYNC, |
| 6466 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6467 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6468 | int status = 0; |
| 6469 | |
| 6470 | dprintk("--> %s\n", __func__); |
| 6471 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6472 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6473 | if (!lgp->args.layout.pages) { |
| 6474 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6475 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6476 | } |
| 6477 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6478 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6479 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6480 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6481 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6482 | task = rpc_run_task(&task_setup_data); |
| 6483 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6484 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6485 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6486 | if (status == 0) |
| 6487 | status = task->tk_status; |
| 6488 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6489 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6490 | rpc_put_task(task); |
| 6491 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6492 | if (status) |
| 6493 | return ERR_PTR(status); |
| 6494 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6495 | } |
| 6496 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6497 | static void |
| 6498 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6499 | { |
| 6500 | struct nfs4_layoutreturn *lrp = calldata; |
| 6501 | |
| 6502 | dprintk("--> %s\n", __func__); |
| 6503 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6504 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6505 | return; |
| 6506 | rpc_call_start(task); |
| 6507 | } |
| 6508 | |
| 6509 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6510 | { |
| 6511 | struct nfs4_layoutreturn *lrp = calldata; |
| 6512 | struct nfs_server *server; |
| 6513 | |
| 6514 | dprintk("--> %s\n", __func__); |
| 6515 | |
| 6516 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6517 | return; |
| 6518 | |
| 6519 | server = NFS_SERVER(lrp->args.inode); |
| 6520 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6521 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6522 | return; |
| 6523 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6524 | dprintk("<-- %s\n", __func__); |
| 6525 | } |
| 6526 | |
| 6527 | static void nfs4_layoutreturn_release(void *calldata) |
| 6528 | { |
| 6529 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6530 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6531 | |
| 6532 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6533 | spin_lock(&lo->plh_inode->i_lock); |
| 6534 | if (lrp->res.lrs_present) |
| 6535 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6536 | lo->plh_block_lgets--; |
| 6537 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6538 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6539 | kfree(calldata); |
| 6540 | dprintk("<-- %s\n", __func__); |
| 6541 | } |
| 6542 | |
| 6543 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6544 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6545 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6546 | .rpc_release = nfs4_layoutreturn_release, |
| 6547 | }; |
| 6548 | |
| 6549 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6550 | { |
| 6551 | struct rpc_task *task; |
| 6552 | struct rpc_message msg = { |
| 6553 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6554 | .rpc_argp = &lrp->args, |
| 6555 | .rpc_resp = &lrp->res, |
| 6556 | }; |
| 6557 | struct rpc_task_setup task_setup_data = { |
| 6558 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6559 | .rpc_message = &msg, |
| 6560 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6561 | .callback_data = lrp, |
| 6562 | }; |
| 6563 | int status; |
| 6564 | |
| 6565 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6566 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6567 | task = rpc_run_task(&task_setup_data); |
| 6568 | if (IS_ERR(task)) |
| 6569 | return PTR_ERR(task); |
| 6570 | status = task->tk_status; |
| 6571 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6572 | rpc_put_task(task); |
| 6573 | return status; |
| 6574 | } |
| 6575 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6576 | /* |
| 6577 | * Retrieve the list of Data Server devices from the MDS. |
| 6578 | */ |
| 6579 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6580 | const struct nfs_fh *fh, |
| 6581 | struct pnfs_devicelist *devlist) |
| 6582 | { |
| 6583 | struct nfs4_getdevicelist_args args = { |
| 6584 | .fh = fh, |
| 6585 | .layoutclass = server->pnfs_curr_ld->id, |
| 6586 | }; |
| 6587 | struct nfs4_getdevicelist_res res = { |
| 6588 | .devlist = devlist, |
| 6589 | }; |
| 6590 | struct rpc_message msg = { |
| 6591 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6592 | .rpc_argp = &args, |
| 6593 | .rpc_resp = &res, |
| 6594 | }; |
| 6595 | int status; |
| 6596 | |
| 6597 | dprintk("--> %s\n", __func__); |
| 6598 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6599 | &res.seq_res, 0); |
| 6600 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6601 | return status; |
| 6602 | } |
| 6603 | |
| 6604 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6605 | const struct nfs_fh *fh, |
| 6606 | struct pnfs_devicelist *devlist) |
| 6607 | { |
| 6608 | struct nfs4_exception exception = { }; |
| 6609 | int err; |
| 6610 | |
| 6611 | do { |
| 6612 | err = nfs4_handle_exception(server, |
| 6613 | _nfs4_getdevicelist(server, fh, devlist), |
| 6614 | &exception); |
| 6615 | } while (exception.retry); |
| 6616 | |
| 6617 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6618 | err, devlist->num_devs); |
| 6619 | |
| 6620 | return err; |
| 6621 | } |
| 6622 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6623 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6624 | static int |
| 6625 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6626 | { |
| 6627 | struct nfs4_getdeviceinfo_args args = { |
| 6628 | .pdev = pdev, |
| 6629 | }; |
| 6630 | struct nfs4_getdeviceinfo_res res = { |
| 6631 | .pdev = pdev, |
| 6632 | }; |
| 6633 | struct rpc_message msg = { |
| 6634 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6635 | .rpc_argp = &args, |
| 6636 | .rpc_resp = &res, |
| 6637 | }; |
| 6638 | int status; |
| 6639 | |
| 6640 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6641 | 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] | 6642 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6643 | |
| 6644 | return status; |
| 6645 | } |
| 6646 | |
| 6647 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6648 | { |
| 6649 | struct nfs4_exception exception = { }; |
| 6650 | int err; |
| 6651 | |
| 6652 | do { |
| 6653 | err = nfs4_handle_exception(server, |
| 6654 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6655 | &exception); |
| 6656 | } while (exception.retry); |
| 6657 | return err; |
| 6658 | } |
| 6659 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6660 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6661 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6662 | { |
| 6663 | struct nfs4_layoutcommit_data *data = calldata; |
| 6664 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6665 | |
| 6666 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6667 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6668 | return; |
| 6669 | rpc_call_start(task); |
| 6670 | } |
| 6671 | |
| 6672 | static void |
| 6673 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6674 | { |
| 6675 | struct nfs4_layoutcommit_data *data = calldata; |
| 6676 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6677 | |
| 6678 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6679 | return; |
| 6680 | |
| 6681 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6682 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6683 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6684 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6685 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6686 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6687 | break; |
| 6688 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6689 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6690 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6691 | break; |
| 6692 | default: |
| 6693 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6694 | rpc_restart_call_prepare(task); |
| 6695 | return; |
| 6696 | } |
| 6697 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6698 | } |
| 6699 | |
| 6700 | static void nfs4_layoutcommit_release(void *calldata) |
| 6701 | { |
| 6702 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6703 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6704 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6705 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6706 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6707 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6708 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6709 | list_del_init(&lseg->pls_lc_list); |
| 6710 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6711 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6712 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6713 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6714 | |
| 6715 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6716 | smp_mb__after_clear_bit(); |
| 6717 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6718 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6719 | put_rpccred(data->cred); |
| 6720 | kfree(data); |
| 6721 | } |
| 6722 | |
| 6723 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6724 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6725 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6726 | .rpc_release = nfs4_layoutcommit_release, |
| 6727 | }; |
| 6728 | |
| 6729 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6730 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6731 | { |
| 6732 | struct rpc_message msg = { |
| 6733 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6734 | .rpc_argp = &data->args, |
| 6735 | .rpc_resp = &data->res, |
| 6736 | .rpc_cred = data->cred, |
| 6737 | }; |
| 6738 | struct rpc_task_setup task_setup_data = { |
| 6739 | .task = &data->task, |
| 6740 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6741 | .rpc_message = &msg, |
| 6742 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6743 | .callback_data = data, |
| 6744 | .flags = RPC_TASK_ASYNC, |
| 6745 | }; |
| 6746 | struct rpc_task *task; |
| 6747 | int status = 0; |
| 6748 | |
| 6749 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6750 | "lbw: %llu inode %lu\n", |
| 6751 | data->task.tk_pid, sync, |
| 6752 | data->args.lastbytewritten, |
| 6753 | data->args.inode->i_ino); |
| 6754 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6755 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6756 | task = rpc_run_task(&task_setup_data); |
| 6757 | if (IS_ERR(task)) |
| 6758 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6759 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6760 | goto out; |
| 6761 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6762 | if (status != 0) |
| 6763 | goto out; |
| 6764 | status = task->tk_status; |
| 6765 | out: |
| 6766 | dprintk("%s: status %d\n", __func__, status); |
| 6767 | rpc_put_task(task); |
| 6768 | return status; |
| 6769 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6770 | |
| 6771 | static int |
| 6772 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6773 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6774 | { |
| 6775 | struct nfs41_secinfo_no_name_args args = { |
| 6776 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6777 | }; |
| 6778 | struct nfs4_secinfo_res res = { |
| 6779 | .flavors = flavors, |
| 6780 | }; |
| 6781 | struct rpc_message msg = { |
| 6782 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6783 | .rpc_argp = &args, |
| 6784 | .rpc_resp = &res, |
| 6785 | }; |
| 6786 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6787 | } |
| 6788 | |
| 6789 | static int |
| 6790 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6791 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6792 | { |
| 6793 | struct nfs4_exception exception = { }; |
| 6794 | int err; |
| 6795 | do { |
| 6796 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6797 | switch (err) { |
| 6798 | case 0: |
| 6799 | case -NFS4ERR_WRONGSEC: |
| 6800 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6801 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6802 | default: |
| 6803 | err = nfs4_handle_exception(server, err, &exception); |
| 6804 | } |
| 6805 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6806 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6807 | return err; |
| 6808 | } |
| 6809 | |
| 6810 | static int |
| 6811 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6812 | struct nfs_fsinfo *info) |
| 6813 | { |
| 6814 | int err; |
| 6815 | struct page *page; |
| 6816 | rpc_authflavor_t flavor; |
| 6817 | struct nfs4_secinfo_flavors *flavors; |
| 6818 | |
| 6819 | page = alloc_page(GFP_KERNEL); |
| 6820 | if (!page) { |
| 6821 | err = -ENOMEM; |
| 6822 | goto out; |
| 6823 | } |
| 6824 | |
| 6825 | flavors = page_address(page); |
| 6826 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6827 | |
| 6828 | /* |
| 6829 | * Fall back on "guess and check" method if |
| 6830 | * the server doesn't support SECINFO_NO_NAME |
| 6831 | */ |
| 6832 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6833 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6834 | goto out_freepage; |
| 6835 | } |
| 6836 | if (err) |
| 6837 | goto out_freepage; |
| 6838 | |
| 6839 | flavor = nfs_find_best_sec(flavors); |
| 6840 | if (err == 0) |
| 6841 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6842 | |
| 6843 | out_freepage: |
| 6844 | put_page(page); |
| 6845 | if (err == -EACCES) |
| 6846 | return -EPERM; |
| 6847 | out: |
| 6848 | return err; |
| 6849 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6850 | |
| 6851 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6852 | { |
| 6853 | int status; |
| 6854 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6855 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6856 | }; |
| 6857 | struct nfs41_test_stateid_res res; |
| 6858 | struct rpc_message msg = { |
| 6859 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6860 | .rpc_argp = &args, |
| 6861 | .rpc_resp = &res, |
| 6862 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6863 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6864 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6865 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6866 | status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6867 | if (status != NFS_OK) { |
| 6868 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6869 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6870 | } |
| 6871 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6872 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6873 | } |
| 6874 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6875 | /** |
| 6876 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6877 | * |
| 6878 | * @server: server / transport on which to perform the operation |
| 6879 | * @stateid: state ID to test |
| 6880 | * |
| 6881 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6882 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6883 | * failed or the state ID is not currently valid. |
| 6884 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6885 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6886 | { |
| 6887 | struct nfs4_exception exception = { }; |
| 6888 | int err; |
| 6889 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6890 | err = _nfs41_test_stateid(server, stateid); |
| 6891 | if (err != -NFS4ERR_DELAY) |
| 6892 | break; |
| 6893 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6894 | } while (exception.retry); |
| 6895 | return err; |
| 6896 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6897 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6898 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6899 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6900 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6901 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6902 | }; |
| 6903 | struct nfs41_free_stateid_res res; |
| 6904 | struct rpc_message msg = { |
| 6905 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6906 | .rpc_argp = &args, |
| 6907 | .rpc_resp = &res, |
| 6908 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6909 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6910 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6911 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6912 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6913 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6914 | &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6915 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6916 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6917 | } |
| 6918 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6919 | /** |
| 6920 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6921 | * |
| 6922 | * @server: server / transport on which to perform the operation |
| 6923 | * @stateid: state ID to release |
| 6924 | * |
| 6925 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6926 | * negative NFS4ERR value is returned. |
| 6927 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6928 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6929 | { |
| 6930 | struct nfs4_exception exception = { }; |
| 6931 | int err; |
| 6932 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6933 | err = _nfs4_free_stateid(server, stateid); |
| 6934 | if (err != -NFS4ERR_DELAY) |
| 6935 | break; |
| 6936 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6937 | } while (exception.retry); |
| 6938 | return err; |
| 6939 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6940 | |
| 6941 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6942 | const nfs4_stateid *s2) |
| 6943 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6944 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6945 | return false; |
| 6946 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6947 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6948 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6949 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6950 | return true; |
| 6951 | |
| 6952 | return false; |
| 6953 | } |
| 6954 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6955 | #endif /* CONFIG_NFS_V4_1 */ |
| 6956 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6957 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6958 | const nfs4_stateid *s2) |
| 6959 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6960 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6961 | } |
| 6962 | |
| 6963 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6964 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6965 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6966 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6967 | .recover_open = nfs4_open_reclaim, |
| 6968 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6969 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6970 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6971 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6972 | }; |
| 6973 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6974 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6975 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6976 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6977 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6978 | .recover_open = nfs4_open_reclaim, |
| 6979 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6980 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6981 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6982 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6983 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6984 | }; |
| 6985 | #endif /* CONFIG_NFS_V4_1 */ |
| 6986 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6987 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6988 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6989 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6990 | .recover_open = nfs4_open_expired, |
| 6991 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6992 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6993 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6994 | }; |
| 6995 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6996 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6997 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6998 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6999 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 7000 | .recover_open = nfs41_open_expired, |
| 7001 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 7002 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 7003 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 7004 | }; |
| 7005 | #endif /* CONFIG_NFS_V4_1 */ |
| 7006 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7007 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7008 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7009 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7010 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7011 | }; |
| 7012 | |
| 7013 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 7014 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7015 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 7016 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 7017 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 7018 | }; |
| 7019 | #endif |
| 7020 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7021 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 7022 | .minor_version = 0, |
| 7023 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7024 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7025 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7026 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 7027 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 7028 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7029 | }; |
| 7030 | |
| 7031 | #if defined(CONFIG_NFS_V4_1) |
| 7032 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 7033 | .minor_version = 1, |
| 7034 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 7035 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 7036 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 7037 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 7038 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 7039 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7040 | }; |
| 7041 | #endif |
| 7042 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 7043 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 7044 | [0] = &nfs_v4_0_minor_ops, |
| 7045 | #if defined(CONFIG_NFS_V4_1) |
| 7046 | [1] = &nfs_v4_1_minor_ops, |
| 7047 | #endif |
| 7048 | }; |
| 7049 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 7050 | const struct inode_operations nfs4_dir_inode_operations = { |
| 7051 | .create = nfs_create, |
| 7052 | .lookup = nfs_lookup, |
| 7053 | .atomic_open = nfs_atomic_open, |
| 7054 | .link = nfs_link, |
| 7055 | .unlink = nfs_unlink, |
| 7056 | .symlink = nfs_symlink, |
| 7057 | .mkdir = nfs_mkdir, |
| 7058 | .rmdir = nfs_rmdir, |
| 7059 | .mknod = nfs_mknod, |
| 7060 | .rename = nfs_rename, |
| 7061 | .permission = nfs_permission, |
| 7062 | .getattr = nfs_getattr, |
| 7063 | .setattr = nfs_setattr, |
| 7064 | .getxattr = generic_getxattr, |
| 7065 | .setxattr = generic_setxattr, |
| 7066 | .listxattr = generic_listxattr, |
| 7067 | .removexattr = generic_removexattr, |
| 7068 | }; |
| 7069 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 7070 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7071 | .permission = nfs_permission, |
| 7072 | .getattr = nfs_getattr, |
| 7073 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7074 | .getxattr = generic_getxattr, |
| 7075 | .setxattr = generic_setxattr, |
| 7076 | .listxattr = generic_listxattr, |
| 7077 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7078 | }; |
| 7079 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 7080 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7081 | .version = 4, /* protocol version */ |
| 7082 | .dentry_ops = &nfs4_dentry_operations, |
| 7083 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 7084 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 7085 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7086 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 7087 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 7088 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7089 | .getattr = nfs4_proc_getattr, |
| 7090 | .setattr = nfs4_proc_setattr, |
| 7091 | .lookup = nfs4_proc_lookup, |
| 7092 | .access = nfs4_proc_access, |
| 7093 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7094 | .create = nfs4_proc_create, |
| 7095 | .remove = nfs4_proc_remove, |
| 7096 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7097 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7098 | .unlink_done = nfs4_proc_unlink_done, |
| 7099 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7100 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7101 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7102 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7103 | .link = nfs4_proc_link, |
| 7104 | .symlink = nfs4_proc_symlink, |
| 7105 | .mkdir = nfs4_proc_mkdir, |
| 7106 | .rmdir = nfs4_proc_remove, |
| 7107 | .readdir = nfs4_proc_readdir, |
| 7108 | .mknod = nfs4_proc_mknod, |
| 7109 | .statfs = nfs4_proc_statfs, |
| 7110 | .fsinfo = nfs4_proc_fsinfo, |
| 7111 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7112 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7113 | .decode_dirent = nfs4_decode_dirent, |
| 7114 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7115 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7116 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7117 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7118 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7119 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7120 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7121 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7122 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7123 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7124 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7125 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7126 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7127 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7128 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7129 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7130 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7131 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7132 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7133 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7134 | .create_server = nfs4_create_server, |
| 7135 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7136 | }; |
| 7137 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7138 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7139 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7140 | .list = nfs4_xattr_list_nfs4_acl, |
| 7141 | .get = nfs4_xattr_get_nfs4_acl, |
| 7142 | .set = nfs4_xattr_set_nfs4_acl, |
| 7143 | }; |
| 7144 | |
| 7145 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7146 | &nfs4_xattr_nfs4_acl_handler, |
| 7147 | NULL |
| 7148 | }; |
| 7149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7150 | /* |
| 7151 | * Local variables: |
| 7152 | * c-basic-offset: 8 |
| 7153 | * End: |
| 7154 | */ |