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 | 6926afd1 | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | const u32 nfs4_statfs_bitmap[2] = { |
| 156 | FATTR4_WORD0_FILES_AVAIL |
| 157 | | FATTR4_WORD0_FILES_FREE |
| 158 | | FATTR4_WORD0_FILES_TOTAL, |
| 159 | FATTR4_WORD1_SPACE_AVAIL |
| 160 | | FATTR4_WORD1_SPACE_FREE |
| 161 | | FATTR4_WORD1_SPACE_TOTAL |
| 162 | }; |
| 163 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 164 | const u32 nfs4_pathconf_bitmap[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | FATTR4_WORD0_MAXLINK |
| 166 | | FATTR4_WORD0_MAXNAME, |
| 167 | 0 |
| 168 | }; |
| 169 | |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 170 | const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | | FATTR4_WORD0_MAXREAD |
| 172 | | FATTR4_WORD0_MAXWRITE |
| 173 | | FATTR4_WORD0_LEASE_TIME, |
Ricardo Labiaga | 55b6e77 | 2010-10-12 16:30:06 -0700 | [diff] [blame] | 174 | FATTR4_WORD1_TIME_DELTA |
Fred Isaman | dae100c | 2011-07-30 20:52:37 -0400 | [diff] [blame] | 175 | | FATTR4_WORD1_FS_LAYOUT_TYPES, |
| 176 | FATTR4_WORD2_LAYOUT_BLKSIZE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | }; |
| 178 | |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 179 | const u32 nfs4_fs_locations_bitmap[2] = { |
| 180 | FATTR4_WORD0_TYPE |
| 181 | | FATTR4_WORD0_CHANGE |
| 182 | | FATTR4_WORD0_SIZE |
| 183 | | FATTR4_WORD0_FSID |
| 184 | | FATTR4_WORD0_FILEID |
| 185 | | FATTR4_WORD0_FS_LOCATIONS, |
| 186 | FATTR4_WORD1_MODE |
| 187 | | FATTR4_WORD1_NUMLINKS |
| 188 | | FATTR4_WORD1_OWNER |
| 189 | | FATTR4_WORD1_OWNER_GROUP |
| 190 | | FATTR4_WORD1_RAWDEV |
| 191 | | FATTR4_WORD1_SPACE_USED |
| 192 | | FATTR4_WORD1_TIME_ACCESS |
| 193 | | FATTR4_WORD1_TIME_METADATA |
| 194 | | FATTR4_WORD1_TIME_MODIFY |
| 195 | | FATTR4_WORD1_MOUNTED_ON_FILEID |
| 196 | }; |
| 197 | |
Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 198 | static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | struct nfs4_readdir_arg *readdir) |
| 200 | { |
Al Viro | 0dbb4c6 | 2006-10-19 23:28:49 -0700 | [diff] [blame] | 201 | __be32 *start, *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | BUG_ON(readdir->count < 80); |
| 204 | if (cookie > 2) { |
Adrian Bunk | b7ef195 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 205 | readdir->cookie = cookie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier)); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | readdir->cookie = 0; |
| 211 | memset(&readdir->verifier, 0, sizeof(readdir->verifier)); |
| 212 | if (cookie == 2) |
| 213 | return; |
| 214 | |
| 215 | /* |
| 216 | * NFSv4 servers do not return entries for '.' and '..' |
| 217 | * Therefore, we fake these entries here. We let '.' |
| 218 | * have cookie 0 and '..' have cookie 1. Note that |
| 219 | * when talking to the server, we always send cookie 0 |
| 220 | * instead of 1 or 2. |
| 221 | */ |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 222 | start = p = kmap_atomic(*readdir->pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | if (cookie == 0) { |
| 225 | *p++ = xdr_one; /* next */ |
| 226 | *p++ = xdr_zero; /* cookie, first word */ |
| 227 | *p++ = xdr_one; /* cookie, second word */ |
| 228 | *p++ = xdr_one; /* entry len */ |
| 229 | memcpy(p, ".\0\0\0", 4); /* entry */ |
| 230 | p++; |
| 231 | *p++ = xdr_one; /* bitmap length */ |
| 232 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 233 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 234 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | *p++ = xdr_one; /* next */ |
| 238 | *p++ = xdr_zero; /* cookie, first word */ |
| 239 | *p++ = xdr_two; /* cookie, second word */ |
| 240 | *p++ = xdr_two; /* entry len */ |
| 241 | memcpy(p, "..\0\0", 4); /* entry */ |
| 242 | p++; |
| 243 | *p++ = xdr_one; /* bitmap length */ |
| 244 | *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */ |
| 245 | *p++ = htonl(8); /* attribute buffer length */ |
Peter Staubach | 4e769b9 | 2007-08-03 15:07:10 -0400 | [diff] [blame] | 246 | p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | readdir->pgbase = (char *)p - (char *)start; |
| 249 | readdir->count -= readdir->pgbase; |
Cong Wang | 2b86ce2 | 2011-11-25 23:14:33 +0800 | [diff] [blame] | 250 | kunmap_atomic(start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 253 | static int nfs4_wait_clnt_recover(struct nfs_client *clp) |
| 254 | { |
| 255 | int res; |
| 256 | |
| 257 | might_sleep(); |
| 258 | |
Trond Myklebust | e005e80 | 2008-12-23 15:21:48 -0500 | [diff] [blame] | 259 | res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING, |
Trond Myklebust | 72cb77f | 2009-03-11 14:10:30 -0400 | [diff] [blame] | 260 | nfs_wait_bit_killable, TASK_KILLABLE); |
Chuck Lever | 46a87b8 | 2012-07-11 16:30:41 -0400 | [diff] [blame] | 261 | if (res) |
| 262 | return res; |
| 263 | |
| 264 | if (clp->cl_cons_state < 0) |
| 265 | return clp->cl_cons_state; |
| 266 | return 0; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) |
| 270 | { |
| 271 | int res = 0; |
| 272 | |
| 273 | might_sleep(); |
| 274 | |
| 275 | if (*timeout <= 0) |
| 276 | *timeout = NFS4_POLL_RETRY_MIN; |
| 277 | if (*timeout > NFS4_POLL_RETRY_MAX) |
| 278 | *timeout = NFS4_POLL_RETRY_MAX; |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 279 | freezable_schedule_timeout_killable(*timeout); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 280 | if (fatal_signal_pending(current)) |
| 281 | res = -ERESTARTSYS; |
| 282 | *timeout <<= 1; |
| 283 | return res; |
| 284 | } |
| 285 | |
| 286 | /* This is the error handling routine for processes that are allowed |
| 287 | * to sleep. |
| 288 | */ |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 289 | 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] | 290 | { |
| 291 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 292 | struct nfs4_state *state = exception->state; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 293 | struct inode *inode = exception->inode; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 294 | int ret = errorcode; |
| 295 | |
| 296 | exception->retry = 0; |
| 297 | switch(errorcode) { |
| 298 | case 0: |
| 299 | return 0; |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 300 | case -NFS4ERR_OPENMODE: |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 301 | if (inode && nfs4_have_delegation(inode, FMODE_READ)) { |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 302 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 303 | exception->retry = 1; |
| 304 | return 0; |
| 305 | } |
| 306 | if (state == NULL) |
| 307 | break; |
| 308 | nfs4_schedule_stateid_recovery(server, state); |
| 309 | goto wait_on_recovery; |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 310 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 311 | case -NFS4ERR_ADMIN_REVOKED: |
| 312 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 313 | if (state == NULL) |
| 314 | break; |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 315 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 316 | nfs4_schedule_stateid_recovery(server, state); |
| 317 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 318 | case -NFS4ERR_EXPIRED: |
| 319 | if (state != NULL) |
| 320 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 321 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 322 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 323 | nfs4_schedule_lease_recovery(clp); |
| 324 | goto wait_on_recovery; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 325 | #if defined(CONFIG_NFS_V4_1) |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 326 | case -NFS4ERR_BADSESSION: |
| 327 | case -NFS4ERR_BADSLOT: |
| 328 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 329 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 330 | case -NFS4ERR_DEADSESSION: |
| 331 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 332 | case -NFS4ERR_SEQ_MISORDERED: |
| 333 | dprintk("%s ERROR: %d Reset session\n", __func__, |
| 334 | errorcode); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 335 | nfs4_schedule_session_recovery(clp->cl_session, errorcode); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 336 | exception->retry = 1; |
Andy Adamson | b917923 | 2009-12-04 15:55:32 -0500 | [diff] [blame] | 337 | break; |
Trond Myklebust | 0339169 | 2010-01-26 15:42:38 -0500 | [diff] [blame] | 338 | #endif /* defined(CONFIG_NFS_V4_1) */ |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 339 | case -NFS4ERR_FILE_OPEN: |
NeilBrown | 44ed355 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 340 | if (exception->timeout > HZ) { |
| 341 | /* We have retried a decent amount, time to |
| 342 | * fail |
| 343 | */ |
| 344 | ret = -EBUSY; |
| 345 | break; |
| 346 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 347 | case -NFS4ERR_GRACE: |
| 348 | case -NFS4ERR_DELAY: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 349 | case -EKEYEXPIRED: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 350 | ret = nfs4_delay(server->client, &exception->timeout); |
| 351 | if (ret != 0) |
| 352 | break; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 353 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 354 | case -NFS4ERR_OLD_STATEID: |
| 355 | exception->retry = 1; |
Trond Myklebust | b064eca2 | 2011-02-22 15:44:32 -0800 | [diff] [blame] | 356 | break; |
| 357 | case -NFS4ERR_BADOWNER: |
| 358 | /* The following works around a Linux server bug! */ |
| 359 | case -NFS4ERR_BADNAME: |
| 360 | if (server->caps & NFS_CAP_UIDGID_NOMAP) { |
| 361 | server->caps &= ~NFS_CAP_UIDGID_NOMAP; |
| 362 | exception->retry = 1; |
| 363 | printk(KERN_WARNING "NFS: v4 server %s " |
| 364 | "does not accept raw " |
| 365 | "uid/gids. " |
| 366 | "Reenabling the idmapper.\n", |
| 367 | server->nfs_client->cl_hostname); |
| 368 | } |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 369 | } |
| 370 | /* We failed to handle the error */ |
| 371 | return nfs4_map_errors(ret); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 372 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 373 | ret = nfs4_wait_clnt_recover(clp); |
| 374 | if (ret == 0) |
| 375 | exception->retry = 1; |
| 376 | return ret; |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 380 | static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | spin_lock(&clp->cl_lock); |
| 383 | if (time_before(clp->cl_last_renewal,timestamp)) |
| 384 | clp->cl_last_renewal = timestamp; |
| 385 | spin_unlock(&clp->cl_lock); |
| 386 | } |
| 387 | |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 388 | static void renew_lease(const struct nfs_server *server, unsigned long timestamp) |
| 389 | { |
| 390 | do_renew_lease(server->nfs_client, timestamp); |
| 391 | } |
| 392 | |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 393 | #if defined(CONFIG_NFS_V4_1) |
| 394 | |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 395 | /* |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 396 | * nfs4_free_slot - free a slot and efficiently update slot table. |
| 397 | * |
| 398 | * freeing a slot is trivially done by clearing its respective bit |
| 399 | * in the bitmap. |
| 400 | * If the freed slotid equals highest_used_slotid we want to update it |
| 401 | * so that the server would be able to size down the slot table if needed, |
| 402 | * otherwise we know that the highest_used_slotid is still in use. |
| 403 | * When updating highest_used_slotid there may be "holes" in the bitmap |
| 404 | * so we need to scan down from highest_used_slotid to 0 looking for the now |
| 405 | * highest slotid in use. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 406 | * If none found, highest_used_slotid is set to NFS4_NO_SLOT. |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 407 | * |
| 408 | * Must be called while holding tbl->slot_tbl_lock |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 409 | */ |
| 410 | static void |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 411 | nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 412 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 413 | BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 414 | /* clear used bit in bitmap */ |
| 415 | __clear_bit(slotid, tbl->used_slots); |
| 416 | |
| 417 | /* update highest_used_slotid when it is freed */ |
| 418 | if (slotid == tbl->highest_used_slotid) { |
| 419 | slotid = find_last_bit(tbl->used_slots, tbl->max_slots); |
Trond Myklebust | bcb5616 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 420 | if (slotid < tbl->max_slots) |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 421 | tbl->highest_used_slotid = slotid; |
| 422 | else |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 423 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 424 | } |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 425 | dprintk("%s: slotid %u highest_used_slotid %d\n", __func__, |
| 426 | slotid, tbl->highest_used_slotid); |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 427 | } |
| 428 | |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 429 | bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy) |
| 430 | { |
| 431 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 432 | return true; |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 433 | } |
| 434 | |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 435 | /* |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 436 | * Signal state manager thread if session fore channel is drained |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 437 | */ |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 438 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 439 | { |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 440 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { |
Trond Myklebust | 961a828 | 2012-01-17 22:57:37 -0500 | [diff] [blame] | 441 | rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq, |
| 442 | nfs4_set_task_privileged, NULL); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 443 | return; |
| 444 | } |
| 445 | |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 446 | if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 447 | return; |
| 448 | |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 449 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
| 450 | complete(&ses->fc_slot_table.complete); |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * Signal state manager thread if session back channel is drained |
| 455 | */ |
| 456 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) |
| 457 | { |
| 458 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 459 | ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 460 | return; |
| 461 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); |
| 462 | complete(&ses->bc_slot_table.complete); |
Alexandros Batsakis | 3bfb0fc | 2009-12-09 01:50:11 -0800 | [diff] [blame] | 463 | } |
| 464 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 465 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 466 | { |
| 467 | struct nfs4_slot_table *tbl; |
| 468 | |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 469 | tbl = &res->sr_session->fc_slot_table; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 470 | if (!res->sr_slot) { |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 471 | /* just wake up the next guy waiting since |
| 472 | * we may have not consumed a slot after all */ |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 473 | dprintk("%s: No slot\n", __func__); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 474 | return; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 475 | } |
Andy Adamson | ea028ac | 2009-12-04 15:55:38 -0500 | [diff] [blame] | 476 | |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 477 | spin_lock(&tbl->slot_tbl_lock); |
Andy Adamson | aabd0b4 | 2011-11-09 13:58:22 -0500 | [diff] [blame] | 478 | nfs4_free_slot(tbl, res->sr_slot - tbl->slots); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 479 | nfs4_check_drain_fc_complete(res->sr_session); |
Trond Myklebust | 35dc1d7 | 2009-12-05 19:32:19 -0500 | [diff] [blame] | 480 | spin_unlock(&tbl->slot_tbl_lock); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 481 | res->sr_slot = NULL; |
Andy Adamson | 1361587 | 2009-04-01 09:22:17 -0400 | [diff] [blame] | 482 | } |
| 483 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 484 | 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] | 485 | { |
| 486 | unsigned long timestamp; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 487 | struct nfs_client *clp; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 488 | |
| 489 | /* |
| 490 | * sr_status remains 1 if an RPC level error occurred. The server |
| 491 | * may or may not have processed the sequence operation.. |
| 492 | * Proceed as if the server received and processed the sequence |
| 493 | * operation. |
| 494 | */ |
| 495 | if (res->sr_status == 1) |
| 496 | res->sr_status = NFS_OK; |
| 497 | |
Bryan Schumaker | 468f861 | 2011-04-18 15:57:32 -0400 | [diff] [blame] | 498 | /* don't increment the sequence number if the task wasn't sent */ |
| 499 | if (!RPC_WAS_SENT(task)) |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 500 | goto out; |
| 501 | |
Andy Adamson | 691daf3 | 2009-12-04 15:55:39 -0500 | [diff] [blame] | 502 | /* Check the SEQUENCE operation status */ |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 503 | switch (res->sr_status) { |
| 504 | case 0: |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 505 | /* Update the slot's sequence and clientid lease timer */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 506 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 507 | timestamp = res->sr_renewal_time; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 508 | clp = res->sr_session->clp; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 509 | do_renew_lease(clp, timestamp); |
Alexandros Batsakis | 0629e37 | 2009-12-05 13:46:14 -0500 | [diff] [blame] | 510 | /* Check sequence flags */ |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 511 | if (res->sr_status_flags != 0) |
| 512 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 513 | break; |
| 514 | case -NFS4ERR_DELAY: |
| 515 | /* The server detected a resend of the RPC call and |
| 516 | * returned NFS4ERR_DELAY as per Section 2.10.6.2 |
| 517 | * of RFC5661. |
| 518 | */ |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 519 | dprintk("%s: slot=%td seq=%d: Operation in progress\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 520 | __func__, |
| 521 | res->sr_slot - res->sr_session->fc_slot_table.slots, |
| 522 | res->sr_slot->seq_nr); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 523 | goto out_retry; |
| 524 | default: |
| 525 | /* Just update the slot sequence no. */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 526 | ++res->sr_slot->seq_nr; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 527 | } |
| 528 | out: |
| 529 | /* The session may be reset by one of the error handlers. */ |
| 530 | dprintk("%s: Error %d free the slot \n", __func__, res->sr_status); |
Trond Myklebust | d185a33 | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 531 | nfs41_sequence_free_slot(res); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 532 | return 1; |
| 533 | out_retry: |
Trond Myklebust | d05dd4e | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 534 | if (!rpc_restart_call(task)) |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 535 | goto out; |
| 536 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 537 | return 0; |
Andy Adamson | b0df806 | 2009-04-01 09:22:18 -0400 | [diff] [blame] | 538 | } |
| 539 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 540 | static int nfs4_sequence_done(struct rpc_task *task, |
| 541 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 542 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 543 | if (res->sr_session == NULL) |
| 544 | return 1; |
| 545 | return nfs41_sequence_done(task, res); |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 546 | } |
| 547 | |
Andy Adamson | e2c4ab3 | 2009-04-01 09:22:16 -0400 | [diff] [blame] | 548 | /* |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 549 | * nfs4_find_slot - efficiently look for a free slot |
| 550 | * |
| 551 | * nfs4_find_slot looks for an unset bit in the used_slots bitmap. |
| 552 | * If found, we mark the slot as used, update the highest_used_slotid, |
| 553 | * and respectively set up the sequence operation args. |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 554 | * The slot number is returned if found, or NFS4_NO_SLOT otherwise. |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 555 | * |
| 556 | * Note: must be called with under the slot_tbl_lock. |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 557 | */ |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 558 | static u32 |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 559 | nfs4_find_slot(struct nfs4_slot_table *tbl) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 560 | { |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 561 | u32 slotid; |
| 562 | u32 ret_id = NFS4_NO_SLOT; |
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 | dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n", |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 565 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, |
| 566 | tbl->max_slots); |
| 567 | slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); |
| 568 | if (slotid >= tbl->max_slots) |
| 569 | goto out; |
| 570 | __set_bit(slotid, tbl->used_slots); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 571 | if (slotid > tbl->highest_used_slotid || |
| 572 | tbl->highest_used_slotid == NFS4_NO_SLOT) |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 573 | tbl->highest_used_slotid = slotid; |
| 574 | ret_id = slotid; |
| 575 | out: |
| 576 | dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n", |
| 577 | __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id); |
Benny Halevy | 510b817 | 2009-04-01 09:22:14 -0400 | [diff] [blame] | 578 | return ret_id; |
| 579 | } |
| 580 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 581 | static void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 582 | struct nfs4_sequence_res *res, int cache_reply) |
| 583 | { |
| 584 | args->sa_session = NULL; |
| 585 | args->sa_cache_this = 0; |
| 586 | if (cache_reply) |
| 587 | args->sa_cache_this = 1; |
| 588 | res->sr_session = NULL; |
| 589 | res->sr_slot = NULL; |
| 590 | } |
| 591 | |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 592 | int nfs41_setup_sequence(struct nfs4_session *session, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 593 | struct nfs4_sequence_args *args, |
| 594 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 595 | struct rpc_task *task) |
| 596 | { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 597 | struct nfs4_slot *slot; |
| 598 | struct nfs4_slot_table *tbl; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 599 | u32 slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 600 | |
| 601 | dprintk("--> %s\n", __func__); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 602 | /* slot already allocated? */ |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 603 | if (res->sr_slot != NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 604 | return 0; |
| 605 | |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 606 | tbl = &session->fc_slot_table; |
| 607 | |
| 608 | spin_lock(&tbl->slot_tbl_lock); |
Trond Myklebust | a2118c3 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 609 | if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) && |
Alexandros Batsakis | 5601a00 | 2009-12-14 21:27:58 -0800 | [diff] [blame] | 610 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 611 | /* The state manager will wait until the slot table is empty */ |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 612 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 613 | spin_unlock(&tbl->slot_tbl_lock); |
Andy Adamson | 0b1c8fc | 2011-11-09 13:58:26 -0500 | [diff] [blame] | 614 | dprintk("%s session is draining\n", __func__); |
Andy Adamson | 05f0d23 | 2009-12-04 15:55:37 -0500 | [diff] [blame] | 615 | return -EAGAIN; |
Andy Adamson | b069d94 | 2009-04-01 09:22:43 -0400 | [diff] [blame] | 616 | } |
| 617 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 618 | if (!rpc_queue_empty(&tbl->slot_tbl_waitq) && |
| 619 | !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) { |
| 620 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 621 | spin_unlock(&tbl->slot_tbl_lock); |
| 622 | dprintk("%s enforce FIFO order\n", __func__); |
| 623 | return -EAGAIN; |
| 624 | } |
| 625 | |
Alexandros Batsakis | 40ead58 | 2009-12-14 21:27:54 -0800 | [diff] [blame] | 626 | slotid = nfs4_find_slot(tbl); |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 627 | if (slotid == NFS4_NO_SLOT) { |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 628 | rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); |
| 629 | spin_unlock(&tbl->slot_tbl_lock); |
| 630 | dprintk("<-- %s: no free slots\n", __func__); |
| 631 | return -EAGAIN; |
| 632 | } |
| 633 | spin_unlock(&tbl->slot_tbl_lock); |
| 634 | |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 635 | rpc_task_set_priority(task, RPC_PRIORITY_NORMAL); |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 636 | slot = tbl->slots + slotid; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 637 | args->sa_session = session; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 638 | args->sa_slotid = slotid; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 639 | |
| 640 | dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); |
| 641 | |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 642 | res->sr_session = session; |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 643 | res->sr_slot = slot; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 644 | res->sr_renewal_time = jiffies; |
Trond Myklebust | 2a6e26c | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 645 | res->sr_status_flags = 0; |
Andy Adamson | fbcd4ab | 2009-04-01 09:22:15 -0400 | [diff] [blame] | 646 | /* |
| 647 | * sr_status is only set in decode_sequence, and so will remain |
| 648 | * set to 1 if an rpc level failure occurs. |
| 649 | */ |
| 650 | res->sr_status = 1; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 651 | return 0; |
| 652 | } |
Andy Adamson | dc70d7b | 2011-03-01 01:34:19 +0000 | [diff] [blame] | 653 | EXPORT_SYMBOL_GPL(nfs41_setup_sequence); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 654 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 655 | int nfs4_setup_sequence(const struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 656 | struct nfs4_sequence_args *args, |
| 657 | struct nfs4_sequence_res *res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 658 | struct rpc_task *task) |
| 659 | { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 660 | struct nfs4_session *session = nfs4_get_session(server); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 661 | int ret = 0; |
| 662 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 663 | if (session == NULL) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 664 | goto out; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 665 | |
Geert Uytterhoeven | 12364a4 | 2010-10-28 20:06:19 +0200 | [diff] [blame] | 666 | dprintk("--> %s clp %p session %p sr_slot %td\n", |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 667 | __func__, session->clp, session, res->sr_slot ? |
| 668 | res->sr_slot - session->fc_slot_table.slots : -1); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 669 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 670 | ret = nfs41_setup_sequence(session, args, res, task); |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 671 | out: |
| 672 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 673 | return ret; |
| 674 | } |
| 675 | |
| 676 | struct nfs41_call_sync_data { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 677 | const struct nfs_server *seq_server; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 678 | struct nfs4_sequence_args *seq_args; |
| 679 | struct nfs4_sequence_res *seq_res; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 680 | }; |
| 681 | |
| 682 | static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) |
| 683 | { |
| 684 | struct nfs41_call_sync_data *data = calldata; |
| 685 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 686 | dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); |
| 687 | |
| 688 | if (nfs4_setup_sequence(data->seq_server, data->seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 689 | data->seq_res, task)) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 690 | return; |
| 691 | rpc_call_start(task); |
| 692 | } |
| 693 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 694 | static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata) |
| 695 | { |
| 696 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 697 | nfs41_call_sync_prepare(task, calldata); |
| 698 | } |
| 699 | |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 700 | static void nfs41_call_sync_done(struct rpc_task *task, void *calldata) |
| 701 | { |
| 702 | struct nfs41_call_sync_data *data = calldata; |
| 703 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 704 | nfs41_sequence_done(task, data->seq_res); |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 705 | } |
| 706 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 707 | static const struct rpc_call_ops nfs41_call_sync_ops = { |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 708 | .rpc_call_prepare = nfs41_call_sync_prepare, |
Andy Adamson | 69ab40c | 2009-04-01 09:22:19 -0400 | [diff] [blame] | 709 | .rpc_call_done = nfs41_call_sync_done, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 710 | }; |
| 711 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 712 | static const struct rpc_call_ops nfs41_call_priv_sync_ops = { |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 713 | .rpc_call_prepare = nfs41_call_priv_sync_prepare, |
| 714 | .rpc_call_done = nfs41_call_sync_done, |
| 715 | }; |
| 716 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 717 | static int nfs4_call_sync_sequence(struct rpc_clnt *clnt, |
| 718 | struct nfs_server *server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 719 | struct rpc_message *msg, |
| 720 | struct nfs4_sequence_args *args, |
| 721 | struct nfs4_sequence_res *res, |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 722 | int privileged) |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 723 | { |
| 724 | int ret; |
| 725 | struct rpc_task *task; |
| 726 | struct nfs41_call_sync_data data = { |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 727 | .seq_server = server, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 728 | .seq_args = args, |
| 729 | .seq_res = res, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 730 | }; |
| 731 | struct rpc_task_setup task_setup = { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 732 | .rpc_client = clnt, |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 733 | .rpc_message = msg, |
| 734 | .callback_ops = &nfs41_call_sync_ops, |
| 735 | .callback_data = &data |
| 736 | }; |
| 737 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 738 | if (privileged) |
| 739 | task_setup.callback_ops = &nfs41_call_priv_sync_ops; |
Andy Adamson | ce5039c | 2009-04-01 09:22:13 -0400 | [diff] [blame] | 740 | task = rpc_run_task(&task_setup); |
| 741 | if (IS_ERR(task)) |
| 742 | ret = PTR_ERR(task); |
| 743 | else { |
| 744 | ret = task->tk_status; |
| 745 | rpc_put_task(task); |
| 746 | } |
| 747 | return ret; |
| 748 | } |
| 749 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 750 | int _nfs4_call_sync_session(struct rpc_clnt *clnt, |
| 751 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 752 | struct rpc_message *msg, |
| 753 | struct nfs4_sequence_args *args, |
| 754 | struct nfs4_sequence_res *res, |
| 755 | int cache_reply) |
| 756 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 757 | nfs41_init_sequence(args, res, cache_reply); |
| 758 | return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 759 | } |
| 760 | |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 761 | #else |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 762 | static inline |
| 763 | void nfs41_init_sequence(struct nfs4_sequence_args *args, |
| 764 | struct nfs4_sequence_res *res, int cache_reply) |
| 765 | { |
| 766 | } |
| 767 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 768 | static int nfs4_sequence_done(struct rpc_task *task, |
| 769 | struct nfs4_sequence_res *res) |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 770 | { |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 771 | return 1; |
Trond Myklebust | df89645 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 772 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 773 | #endif /* CONFIG_NFS_V4_1 */ |
| 774 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 775 | int _nfs4_call_sync(struct rpc_clnt *clnt, |
| 776 | struct nfs_server *server, |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 777 | struct rpc_message *msg, |
| 778 | struct nfs4_sequence_args *args, |
| 779 | struct nfs4_sequence_res *res, |
| 780 | int cache_reply) |
| 781 | { |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 782 | nfs41_init_sequence(args, res, cache_reply); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 783 | return rpc_call_sync(clnt, msg, 0); |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 784 | } |
| 785 | |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 786 | static inline |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 787 | int nfs4_call_sync(struct rpc_clnt *clnt, |
| 788 | struct nfs_server *server, |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 789 | struct rpc_message *msg, |
| 790 | struct nfs4_sequence_args *args, |
| 791 | struct nfs4_sequence_res *res, |
| 792 | int cache_reply) |
| 793 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 794 | return server->nfs_client->cl_mvops->call_sync(clnt, server, msg, |
| 795 | args, res, cache_reply); |
Bryan Schumaker | e73b83f | 2011-03-24 17:12:23 +0000 | [diff] [blame] | 796 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 797 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 798 | static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | { |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 800 | struct nfs_inode *nfsi = NFS_I(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 802 | spin_lock(&dir->i_lock); |
Trond Myklebust | 359d7d1 | 2012-05-28 10:01:34 -0400 | [diff] [blame] | 803 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 804 | if (!cinfo->atomic || cinfo->before != dir->i_version) |
Trond Myklebust | bfc69a4 | 2007-10-15 18:18:29 -0400 | [diff] [blame] | 805 | nfs_force_lookup_revalidate(dir); |
Trond Myklebust | a9a4a87 | 2011-10-17 16:08:46 -0700 | [diff] [blame] | 806 | dir->i_version = cinfo->after; |
Trond Myklebust | 38478b2 | 2006-05-25 01:40:57 -0400 | [diff] [blame] | 807 | spin_unlock(&dir->i_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 810 | struct nfs4_opendata { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 811 | struct kref kref; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 812 | struct nfs_openargs o_arg; |
| 813 | struct nfs_openres o_res; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 814 | struct nfs_open_confirmargs c_arg; |
| 815 | struct nfs_open_confirmres c_res; |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 816 | struct nfs4_string owner_name; |
| 817 | struct nfs4_string group_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 818 | struct nfs_fattr f_attr; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 819 | struct dentry *dir; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 820 | struct dentry *dentry; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 821 | struct nfs4_state_owner *owner; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 822 | struct nfs4_state *state; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 823 | struct iattr attrs; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 824 | unsigned long timestamp; |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 825 | unsigned int rpc_done : 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 826 | int rpc_status; |
| 827 | int cancelled; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 828 | }; |
| 829 | |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 830 | |
| 831 | static void nfs4_init_opendata_res(struct nfs4_opendata *p) |
| 832 | { |
| 833 | p->o_res.f_attr = &p->f_attr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 834 | p->o_res.seqid = p->o_arg.seqid; |
| 835 | p->c_res.seqid = p->c_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 836 | p->o_res.server = p->o_arg.server; |
| 837 | nfs_fattr_init(&p->f_attr); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 838 | 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] | 839 | } |
| 840 | |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 841 | static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 842 | struct nfs4_state_owner *sp, fmode_t fmode, int flags, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 843 | const struct iattr *attrs, |
| 844 | gfp_t gfp_mask) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 845 | { |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 846 | struct dentry *parent = dget_parent(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 847 | struct inode *dir = parent->d_inode; |
| 848 | struct nfs_server *server = NFS_SERVER(dir); |
| 849 | struct nfs4_opendata *p; |
| 850 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 851 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 852 | if (p == NULL) |
| 853 | goto err; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 854 | p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 855 | if (p->o_arg.seqid == NULL) |
| 856 | goto err_free; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 857 | nfs_sb_active(dentry->d_sb); |
| 858 | p->dentry = dget(dentry); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 859 | p->dir = parent; |
| 860 | p->owner = sp; |
| 861 | atomic_inc(&sp->so_count); |
| 862 | p->o_arg.fh = NFS_FH(dir); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 863 | p->o_arg.open_flags = flags; |
| 864 | p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 865 | /* ask server to check for all possible rights as results are cached */ |
| 866 | p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY | |
| 867 | NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 868 | p->o_arg.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 869 | p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time); |
| 870 | p->o_arg.id.uniquifier = sp->so_seqid.owner_id; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 871 | p->o_arg.name = &dentry->d_name; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 872 | p->o_arg.server = server; |
| 873 | p->o_arg.bitmask = server->attr_bitmask; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 874 | p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0]; |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 875 | p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 876 | if (attrs != NULL && attrs->ia_valid != 0) { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 877 | __be32 verf[2]; |
Trond Myklebust | d77d76f | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 878 | |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 879 | p->o_arg.u.attrs = &p->attrs; |
| 880 | memcpy(&p->attrs, attrs, sizeof(p->attrs)); |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 881 | |
| 882 | verf[0] = jiffies; |
| 883 | verf[1] = current->pid; |
| 884 | memcpy(p->o_arg.u.verifier.data, verf, |
| 885 | sizeof(p->o_arg.u.verifier.data)); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 886 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 887 | p->c_arg.fh = &p->o_res.fh; |
| 888 | p->c_arg.stateid = &p->o_res.stateid; |
| 889 | p->c_arg.seqid = p->o_arg.seqid; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 890 | nfs4_init_opendata_res(p); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 891 | kref_init(&p->kref); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 892 | return p; |
| 893 | err_free: |
| 894 | kfree(p); |
| 895 | err: |
| 896 | dput(parent); |
| 897 | return NULL; |
| 898 | } |
| 899 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 900 | static void nfs4_opendata_free(struct kref *kref) |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 901 | { |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 902 | struct nfs4_opendata *p = container_of(kref, |
| 903 | struct nfs4_opendata, kref); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 904 | struct super_block *sb = p->dentry->d_sb; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 905 | |
| 906 | nfs_free_seqid(p->o_arg.seqid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 907 | if (p->state != NULL) |
| 908 | nfs4_put_open_state(p->state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 909 | nfs4_put_state_owner(p->owner); |
| 910 | dput(p->dir); |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 911 | dput(p->dentry); |
| 912 | nfs_sb_deactive(sb); |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 913 | nfs_fattr_free_names(&p->f_attr); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 914 | kfree(p); |
| 915 | } |
| 916 | |
| 917 | static void nfs4_opendata_put(struct nfs4_opendata *p) |
| 918 | { |
| 919 | if (p != NULL) |
| 920 | kref_put(&p->kref, nfs4_opendata_free); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 921 | } |
| 922 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 923 | static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task) |
| 924 | { |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 925 | int ret; |
| 926 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 927 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 928 | return ret; |
| 929 | } |
| 930 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 931 | 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] | 932 | { |
| 933 | int ret = 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 934 | |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 935 | if (open_mode & (O_EXCL|O_TRUNC)) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 936 | goto out; |
| 937 | switch (mode & (FMODE_READ|FMODE_WRITE)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 938 | case FMODE_READ: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 939 | ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0 |
| 940 | && state->n_rdonly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 941 | break; |
| 942 | case FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 943 | ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0 |
| 944 | && state->n_wronly != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 945 | break; |
| 946 | case FMODE_READ|FMODE_WRITE: |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 947 | ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0 |
| 948 | && state->n_rdwr != 0; |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 949 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 950 | out: |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 951 | return ret; |
| 952 | } |
| 953 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 954 | static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 955 | { |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 956 | if (delegation == NULL) |
| 957 | return 0; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 958 | if ((delegation->type & fmode) != fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 959 | return 0; |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 960 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags)) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 961 | return 0; |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 962 | nfs_mark_delegation_referenced(delegation); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 963 | return 1; |
| 964 | } |
| 965 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 966 | static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode) |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 967 | { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 968 | switch (fmode) { |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 969 | case FMODE_WRITE: |
| 970 | state->n_wronly++; |
| 971 | break; |
| 972 | case FMODE_READ: |
| 973 | state->n_rdonly++; |
| 974 | break; |
| 975 | case FMODE_READ|FMODE_WRITE: |
| 976 | state->n_rdwr++; |
| 977 | } |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 978 | nfs4_state_set_mode_locked(state, state->state | fmode); |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 979 | } |
| 980 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 981 | 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] | 982 | { |
| 983 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 984 | nfs4_stateid_copy(&state->stateid, stateid); |
| 985 | nfs4_stateid_copy(&state->open_stateid, stateid); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 986 | switch (fmode) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 987 | case FMODE_READ: |
| 988 | set_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 989 | break; |
| 990 | case FMODE_WRITE: |
| 991 | set_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 992 | break; |
| 993 | case FMODE_READ|FMODE_WRITE: |
| 994 | set_bit(NFS_O_RDWR_STATE, &state->flags); |
| 995 | } |
| 996 | } |
| 997 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 998 | 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] | 999 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1000 | write_seqlock(&state->seqlock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1001 | nfs_set_open_stateid_locked(state, stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1002 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1003 | } |
| 1004 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1005 | 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] | 1006 | { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1007 | /* |
| 1008 | * Protect the call to nfs4_state_set_mode_locked and |
| 1009 | * serialise the stateid update |
| 1010 | */ |
| 1011 | write_seqlock(&state->seqlock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1012 | if (deleg_stateid != NULL) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1013 | nfs4_stateid_copy(&state->stateid, deleg_stateid); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1014 | set_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1015 | } |
| 1016 | if (open_stateid != NULL) |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1017 | nfs_set_open_stateid_locked(state, open_stateid, fmode); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1018 | write_sequnlock(&state->seqlock); |
| 1019 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1020 | update_open_stateflags(state, fmode); |
Trond Myklebust | ec07342 | 2005-10-20 14:22:47 -0700 | [diff] [blame] | 1021 | spin_unlock(&state->owner->so_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1024 | 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] | 1025 | { |
| 1026 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1027 | struct nfs_delegation *deleg_cur; |
| 1028 | int ret = 0; |
| 1029 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1030 | fmode &= (FMODE_READ|FMODE_WRITE); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1031 | |
| 1032 | rcu_read_lock(); |
| 1033 | deleg_cur = rcu_dereference(nfsi->delegation); |
| 1034 | if (deleg_cur == NULL) |
| 1035 | goto no_delegation; |
| 1036 | |
| 1037 | spin_lock(&deleg_cur->lock); |
| 1038 | if (nfsi->delegation != deleg_cur || |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1039 | (deleg_cur->type & fmode) != fmode) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1040 | goto no_delegation_unlock; |
| 1041 | |
| 1042 | if (delegation == NULL) |
| 1043 | delegation = &deleg_cur->stateid; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1044 | else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1045 | goto no_delegation_unlock; |
| 1046 | |
Trond Myklebust | b7391f4 | 2008-12-23 15:21:52 -0500 | [diff] [blame] | 1047 | nfs_mark_delegation_referenced(deleg_cur); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1048 | __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1049 | ret = 1; |
| 1050 | no_delegation_unlock: |
| 1051 | spin_unlock(&deleg_cur->lock); |
| 1052 | no_delegation: |
| 1053 | rcu_read_unlock(); |
| 1054 | |
| 1055 | if (!ret && open_stateid != NULL) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1056 | __update_open_stateid(state, open_stateid, NULL, fmode); |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1057 | ret = 1; |
| 1058 | } |
| 1059 | |
| 1060 | return ret; |
| 1061 | } |
| 1062 | |
| 1063 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1064 | static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1065 | { |
| 1066 | struct nfs_delegation *delegation; |
| 1067 | |
| 1068 | rcu_read_lock(); |
| 1069 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1070 | if (delegation == NULL || (delegation->type & fmode) == fmode) { |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1071 | rcu_read_unlock(); |
| 1072 | return; |
| 1073 | } |
| 1074 | rcu_read_unlock(); |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 1075 | nfs4_inode_return_delegation(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1076 | } |
| 1077 | |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1078 | static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata) |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1079 | { |
| 1080 | struct nfs4_state *state = opendata->state; |
| 1081 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1082 | struct nfs_delegation *delegation; |
Trond Myklebust | 536e43d | 2012-01-17 22:04:26 -0500 | [diff] [blame] | 1083 | int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1084 | fmode_t fmode = opendata->o_arg.fmode; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1085 | nfs4_stateid stateid; |
| 1086 | int ret = -EAGAIN; |
| 1087 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1088 | for (;;) { |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1089 | if (can_open_cached(state, fmode, open_mode)) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1090 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1091 | if (can_open_cached(state, fmode, open_mode)) { |
| 1092 | update_open_stateflags(state, fmode); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1093 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1094 | goto out_return_state; |
| 1095 | } |
| 1096 | spin_unlock(&state->owner->so_lock); |
| 1097 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1098 | rcu_read_lock(); |
| 1099 | delegation = rcu_dereference(nfsi->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1100 | if (!can_open_delegated(delegation, fmode)) { |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1101 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1102 | break; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1103 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1104 | /* Save the delegation */ |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1105 | nfs4_stateid_copy(&stateid, &delegation->stateid); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1106 | rcu_read_unlock(); |
Trond Myklebust | af22f94 | 2007-08-10 17:45:10 -0400 | [diff] [blame] | 1107 | ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1108 | if (ret != 0) |
| 1109 | goto out; |
| 1110 | ret = -EAGAIN; |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1111 | |
| 1112 | /* Try to update the stateid using the delegation */ |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1113 | if (update_open_stateid(state, NULL, &stateid, fmode)) |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1114 | goto out_return_state; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1115 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1116 | out: |
| 1117 | return ERR_PTR(ret); |
| 1118 | out_return_state: |
| 1119 | atomic_inc(&state->count); |
| 1120 | return state; |
| 1121 | } |
| 1122 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1123 | static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data) |
| 1124 | { |
| 1125 | struct inode *inode; |
| 1126 | struct nfs4_state *state = NULL; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1127 | struct nfs_delegation *delegation; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1128 | int ret; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1129 | |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1130 | if (!data->rpc_done) { |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1131 | state = nfs4_try_open_cached(data); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1132 | goto out; |
| 1133 | } |
| 1134 | |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1135 | ret = -EAGAIN; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1136 | if (!(data->f_attr.valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1137 | goto err; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1138 | 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] | 1139 | ret = PTR_ERR(inode); |
Trond Myklebust | 03f28e3 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 1140 | if (IS_ERR(inode)) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1141 | goto err; |
| 1142 | ret = -ENOMEM; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1143 | state = nfs4_get_open_state(inode, data->owner); |
| 1144 | if (state == NULL) |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1145 | goto err_put_inode; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1146 | if (data->o_res.delegation_type != 0) { |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1147 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1148 | int delegation_flags = 0; |
| 1149 | |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 1150 | rcu_read_lock(); |
| 1151 | delegation = rcu_dereference(NFS_I(inode)->delegation); |
| 1152 | if (delegation) |
| 1153 | delegation_flags = delegation->flags; |
| 1154 | rcu_read_unlock(); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1155 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) { |
| 1156 | pr_err_ratelimited("NFS: Broken NFSv4 server %s is " |
| 1157 | "returning a delegation for " |
| 1158 | "OPEN(CLAIM_DELEGATE_CUR)\n", |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 1159 | clp->cl_hostname); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1160 | } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) |
Trond Myklebust | 549d6ed | 2007-07-03 16:42:45 -0400 | [diff] [blame] | 1161 | nfs_inode_set_delegation(state->inode, |
| 1162 | data->owner->so_cred, |
| 1163 | &data->o_res); |
| 1164 | else |
| 1165 | nfs_inode_reclaim_delegation(state->inode, |
| 1166 | data->owner->so_cred, |
| 1167 | &data->o_res); |
| 1168 | } |
Trond Myklebust | 3431043 | 2008-12-23 15:21:38 -0500 | [diff] [blame] | 1169 | |
| 1170 | update_open_stateid(state, &data->o_res.stateid, NULL, |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1171 | data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1172 | iput(inode); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1173 | out: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1174 | return state; |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1175 | err_put_inode: |
| 1176 | iput(inode); |
| 1177 | err: |
| 1178 | return ERR_PTR(ret); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1179 | } |
| 1180 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1181 | static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state) |
| 1182 | { |
| 1183 | struct nfs_inode *nfsi = NFS_I(state->inode); |
| 1184 | struct nfs_open_context *ctx; |
| 1185 | |
| 1186 | spin_lock(&state->inode->i_lock); |
| 1187 | list_for_each_entry(ctx, &nfsi->open_files, list) { |
| 1188 | if (ctx->state != state) |
| 1189 | continue; |
| 1190 | get_nfs_open_context(ctx); |
| 1191 | spin_unlock(&state->inode->i_lock); |
| 1192 | return ctx; |
| 1193 | } |
| 1194 | spin_unlock(&state->inode->i_lock); |
| 1195 | return ERR_PTR(-ENOENT); |
| 1196 | } |
| 1197 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1198 | static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state) |
| 1199 | { |
| 1200 | struct nfs4_opendata *opendata; |
| 1201 | |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1202 | 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] | 1203 | if (opendata == NULL) |
| 1204 | return ERR_PTR(-ENOMEM); |
| 1205 | opendata->state = state; |
| 1206 | atomic_inc(&state->count); |
| 1207 | return opendata; |
| 1208 | } |
| 1209 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1210 | 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] | 1211 | { |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1212 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1213 | int ret; |
| 1214 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1215 | opendata->o_arg.open_flags = 0; |
| 1216 | opendata->o_arg.fmode = fmode; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1217 | memset(&opendata->o_res, 0, sizeof(opendata->o_res)); |
| 1218 | memset(&opendata->c_res, 0, sizeof(opendata->c_res)); |
| 1219 | nfs4_init_opendata_res(opendata); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1220 | ret = _nfs4_recover_proc_open(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1221 | if (ret != 0) |
| 1222 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1223 | newstate = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1224 | if (IS_ERR(newstate)) |
| 1225 | return PTR_ERR(newstate); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1226 | nfs4_close_state(newstate, fmode); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1227 | *res = newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1228 | return 0; |
| 1229 | } |
| 1230 | |
| 1231 | static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state) |
| 1232 | { |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1233 | struct nfs4_state *newstate; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1234 | int ret; |
| 1235 | |
| 1236 | /* memory barrier prior to reading state->n_* */ |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1237 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1238 | smp_rmb(); |
| 1239 | if (state->n_rdwr != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1240 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1241 | ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1242 | if (ret != 0) |
| 1243 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1244 | if (newstate != state) |
| 1245 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1246 | } |
| 1247 | if (state->n_wronly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1248 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1249 | ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1250 | if (ret != 0) |
| 1251 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1252 | if (newstate != state) |
| 1253 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1254 | } |
| 1255 | if (state->n_rdonly != 0) { |
Trond Myklebust | b0ed9db | 2010-10-04 17:59:08 -0400 | [diff] [blame] | 1256 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1257 | ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1258 | if (ret != 0) |
| 1259 | return ret; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1260 | if (newstate != state) |
| 1261 | return -ESTALE; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1262 | } |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1263 | /* |
| 1264 | * We may have performed cached opens for all three recoveries. |
| 1265 | * Check if we need to update the current stateid. |
| 1266 | */ |
| 1267 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1268 | !nfs4_stateid_match(&state->stateid, &state->open_stateid)) { |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1269 | write_seqlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1270 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1271 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
Trond Myklebust | 8bda4e4 | 2007-07-09 10:45:42 -0400 | [diff] [blame] | 1272 | write_sequnlock(&state->seqlock); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1273 | } |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1274 | return 0; |
| 1275 | } |
| 1276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | /* |
| 1278 | * OPEN_RECLAIM: |
| 1279 | * reclaim state on the server after a reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1281 | 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] | 1282 | { |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1283 | struct nfs_delegation *delegation; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1284 | struct nfs4_opendata *opendata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1285 | fmode_t delegation_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | int status; |
| 1287 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1288 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1289 | if (IS_ERR(opendata)) |
| 1290 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1291 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS; |
| 1292 | opendata->o_arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1293 | rcu_read_lock(); |
| 1294 | delegation = rcu_dereference(NFS_I(state->inode)->delegation); |
Trond Myklebust | 15c831b | 2008-12-23 15:21:39 -0500 | [diff] [blame] | 1295 | if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0) |
Trond Myklebust | 65bbf6b | 2007-08-27 09:57:46 -0400 | [diff] [blame] | 1296 | delegation_type = delegation->type; |
Trond Myklebust | 1ac7e2f | 2007-07-08 21:04:15 -0400 | [diff] [blame] | 1297 | rcu_read_unlock(); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1298 | opendata->o_arg.u.delegation_type = delegation_type; |
| 1299 | status = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1300 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | return status; |
| 1302 | } |
| 1303 | |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1304 | 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] | 1305 | { |
| 1306 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 1307 | struct nfs4_exception exception = { }; |
| 1308 | int err; |
| 1309 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1310 | err = _nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1311 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1312 | break; |
| 1313 | nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | } while (exception.retry); |
| 1315 | return err; |
| 1316 | } |
| 1317 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1318 | static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1319 | { |
| 1320 | struct nfs_open_context *ctx; |
| 1321 | int ret; |
| 1322 | |
| 1323 | ctx = nfs4_state_find_open_context(state); |
| 1324 | if (IS_ERR(ctx)) |
| 1325 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1326 | ret = nfs4_do_open_reclaim(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1327 | put_nfs_open_context(ctx); |
| 1328 | return ret; |
| 1329 | } |
| 1330 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1331 | 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] | 1332 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1333 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1334 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1336 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1337 | if (IS_ERR(opendata)) |
| 1338 | return PTR_ERR(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1339 | opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1340 | nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1341 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1342 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1343 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1346 | 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] | 1347 | { |
| 1348 | struct nfs4_exception exception = { }; |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1349 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | int err; |
| 1351 | do { |
Trond Myklebust | 13437e1 | 2007-07-06 15:10:43 -0400 | [diff] [blame] | 1352 | err = _nfs4_open_delegation_recall(ctx, state, stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | switch (err) { |
| 1354 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1355 | case -ENOENT: |
| 1356 | case -ESTALE: |
| 1357 | goto out; |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1358 | case -NFS4ERR_BADSESSION: |
| 1359 | case -NFS4ERR_BADSLOT: |
| 1360 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 1361 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 1362 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 1363 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Ricardo Labiaga | bcfa49f | 2009-12-07 09:22:29 -0500 | [diff] [blame] | 1364 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | case -NFS4ERR_STALE_CLIENTID: |
| 1366 | case -NFS4ERR_STALE_STATEID: |
| 1367 | case -NFS4ERR_EXPIRED: |
| 1368 | /* Don't recall a delegation if it was lost */ |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1369 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1370 | goto out; |
| 1371 | case -ERESTARTSYS: |
| 1372 | /* |
| 1373 | * The show must go on: exit, but mark the |
| 1374 | * stateid as needing recovery. |
| 1375 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1376 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1377 | case -NFS4ERR_ADMIN_REVOKED: |
| 1378 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 1379 | nfs_inode_find_state_and_recover(state->inode, |
| 1380 | stateid); |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1381 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 1382 | case -EKEYEXPIRED: |
| 1383 | /* |
| 1384 | * User RPCSEC_GSS context has expired. |
| 1385 | * We cannot recover this stateid now, so |
| 1386 | * skip it and allow recovery thread to |
| 1387 | * proceed. |
| 1388 | */ |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1389 | case -ENOMEM: |
| 1390 | err = 0; |
| 1391 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | } |
| 1393 | err = nfs4_handle_exception(server, err, &exception); |
| 1394 | } while (exception.retry); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 1395 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | return err; |
| 1397 | } |
| 1398 | |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1399 | static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata) |
| 1400 | { |
| 1401 | struct nfs4_opendata *data = calldata; |
| 1402 | |
| 1403 | data->rpc_status = task->tk_status; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1404 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 1405 | nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid); |
Trond Myklebust | bb22629 | 2008-01-02 15:19:18 -0500 | [diff] [blame] | 1406 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1407 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1408 | data->rpc_done = 1; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1409 | } |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | static void nfs4_open_confirm_release(void *calldata) |
| 1413 | { |
| 1414 | struct nfs4_opendata *data = calldata; |
| 1415 | struct nfs4_state *state = NULL; |
| 1416 | |
| 1417 | /* If this request hasn't been cancelled, do nothing */ |
| 1418 | if (data->cancelled == 0) |
| 1419 | goto out_free; |
| 1420 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1421 | if (!data->rpc_done) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1422 | goto out_free; |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1423 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1424 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1425 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1426 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1427 | nfs4_opendata_put(data); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | static const struct rpc_call_ops nfs4_open_confirm_ops = { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1431 | .rpc_call_done = nfs4_open_confirm_done, |
| 1432 | .rpc_release = nfs4_open_confirm_release, |
| 1433 | }; |
| 1434 | |
| 1435 | /* |
| 1436 | * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata |
| 1437 | */ |
| 1438 | static int _nfs4_proc_open_confirm(struct nfs4_opendata *data) |
| 1439 | { |
| 1440 | struct nfs_server *server = NFS_SERVER(data->dir->d_inode); |
| 1441 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1442 | struct rpc_message msg = { |
| 1443 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM], |
| 1444 | .rpc_argp = &data->c_arg, |
| 1445 | .rpc_resp = &data->c_res, |
| 1446 | .rpc_cred = data->owner->so_cred, |
| 1447 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1448 | struct rpc_task_setup task_setup_data = { |
| 1449 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1450 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1451 | .callback_ops = &nfs4_open_confirm_ops, |
| 1452 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1453 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1454 | .flags = RPC_TASK_ASYNC, |
| 1455 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | int status; |
| 1457 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1458 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1459 | data->rpc_done = 0; |
| 1460 | data->rpc_status = 0; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1461 | data->timestamp = jiffies; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1462 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 1463 | if (IS_ERR(task)) |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1464 | return PTR_ERR(task); |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1465 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1466 | if (status != 0) { |
| 1467 | data->cancelled = 1; |
| 1468 | smp_wmb(); |
| 1469 | } else |
| 1470 | status = data->rpc_status; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 1471 | rpc_put_task(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | return status; |
| 1473 | } |
| 1474 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1475 | static void nfs4_open_prepare(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | { |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1477 | struct nfs4_opendata *data = calldata; |
| 1478 | struct nfs4_state_owner *sp = data->owner; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1479 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1480 | if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0) |
| 1481 | return; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1482 | /* |
| 1483 | * Check if we still need to send an OPEN call, or if we can use |
| 1484 | * a delegation instead. |
| 1485 | */ |
| 1486 | if (data->state != NULL) { |
| 1487 | struct nfs_delegation *delegation; |
| 1488 | |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 1489 | 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] | 1490 | goto out_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1491 | rcu_read_lock(); |
| 1492 | delegation = rcu_dereference(NFS_I(data->state->inode)->delegation); |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1493 | if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR && |
| 1494 | can_open_delegated(delegation, data->o_arg.fmode)) |
| 1495 | goto unlock_no_action; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1496 | rcu_read_unlock(); |
| 1497 | } |
Trond Myklebust | 95b72eb | 2012-04-20 19:24:51 -0400 | [diff] [blame] | 1498 | /* Update client id. */ |
Trond Myklebust | 1f0e890 | 2010-06-24 15:11:43 -0400 | [diff] [blame] | 1499 | data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1500 | if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1501 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1502 | nfs_copy_fh(&data->o_res.fh, data->o_arg.fh); |
| 1503 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1504 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 1505 | if (nfs4_setup_sequence(data->o_arg.server, |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1506 | &data->o_arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1507 | &data->o_res.seq_res, task)) |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1508 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1509 | rpc_call_start(task); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1510 | return; |
Trond Myklebust | 652f89f | 2011-12-09 19:05:58 -0500 | [diff] [blame] | 1511 | unlock_no_action: |
| 1512 | rcu_read_unlock(); |
Trond Myklebust | 6ee4126 | 2007-07-08 14:11:36 -0400 | [diff] [blame] | 1513 | out_no_action: |
| 1514 | task->tk_action = NULL; |
| 1515 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1518 | static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata) |
| 1519 | { |
| 1520 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 1521 | nfs4_open_prepare(task, calldata); |
| 1522 | } |
| 1523 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1524 | static void nfs4_open_done(struct rpc_task *task, void *calldata) |
| 1525 | { |
| 1526 | struct nfs4_opendata *data = calldata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1528 | data->rpc_status = task->tk_status; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1529 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 1530 | if (!nfs4_sequence_done(task, &data->o_res.seq_res)) |
| 1531 | return; |
Andy Adamson | d898528 | 2009-04-01 09:22:21 -0400 | [diff] [blame] | 1532 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1533 | if (task->tk_status == 0) { |
| 1534 | switch (data->o_res.f_attr->mode & S_IFMT) { |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1535 | case S_IFREG: |
| 1536 | break; |
| 1537 | case S_IFLNK: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1538 | data->rpc_status = -ELOOP; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1539 | break; |
| 1540 | case S_IFDIR: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1541 | data->rpc_status = -EISDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1542 | break; |
| 1543 | default: |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1544 | data->rpc_status = -ENOTDIR; |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1545 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 1546 | renew_lease(data->o_res.server, data->timestamp); |
Trond Myklebust | 0f9f95e | 2007-07-08 16:19:56 -0400 | [diff] [blame] | 1547 | if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) |
| 1548 | nfs_confirm_seqid(&data->owner->so_seqid, 0); |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1549 | } |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1550 | data->rpc_done = 1; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1551 | } |
Trond Myklebust | 6f926b5 | 2005-10-18 14:20:18 -0700 | [diff] [blame] | 1552 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1553 | static void nfs4_open_release(void *calldata) |
| 1554 | { |
| 1555 | struct nfs4_opendata *data = calldata; |
| 1556 | struct nfs4_state *state = NULL; |
| 1557 | |
| 1558 | /* If this request hasn't been cancelled, do nothing */ |
| 1559 | if (data->cancelled == 0) |
| 1560 | goto out_free; |
| 1561 | /* In case of error, no cleanup! */ |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1562 | if (data->rpc_status != 0 || !data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1563 | goto out_free; |
| 1564 | /* In case we need an open_confirm, no cleanup! */ |
| 1565 | if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) |
| 1566 | goto out_free; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1567 | state = nfs4_opendata_to_nfs4_state(data); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1568 | if (!IS_ERR(state)) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 1569 | nfs4_close_state(state, data->o_arg.fmode); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1570 | out_free: |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1571 | nfs4_opendata_put(data); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | static const struct rpc_call_ops nfs4_open_ops = { |
| 1575 | .rpc_call_prepare = nfs4_open_prepare, |
| 1576 | .rpc_call_done = nfs4_open_done, |
| 1577 | .rpc_release = nfs4_open_release, |
| 1578 | }; |
| 1579 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1580 | static const struct rpc_call_ops nfs4_recover_open_ops = { |
| 1581 | .rpc_call_prepare = nfs4_recover_open_prepare, |
| 1582 | .rpc_call_done = nfs4_open_done, |
| 1583 | .rpc_release = nfs4_open_release, |
| 1584 | }; |
| 1585 | |
| 1586 | static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1587 | { |
| 1588 | struct inode *dir = data->dir->d_inode; |
| 1589 | struct nfs_server *server = NFS_SERVER(dir); |
| 1590 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1591 | struct nfs_openres *o_res = &data->o_res; |
| 1592 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1593 | struct rpc_message msg = { |
| 1594 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN], |
| 1595 | .rpc_argp = o_arg, |
| 1596 | .rpc_resp = o_res, |
| 1597 | .rpc_cred = data->owner->so_cred, |
| 1598 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1599 | struct rpc_task_setup task_setup_data = { |
| 1600 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 1601 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1602 | .callback_ops = &nfs4_open_ops, |
| 1603 | .callback_data = data, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 1604 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1605 | .flags = RPC_TASK_ASYNC, |
| 1606 | }; |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1607 | int status; |
| 1608 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 1609 | nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1610 | kref_get(&data->kref); |
Trond Myklebust | 3e30991 | 2007-07-07 13:19:59 -0400 | [diff] [blame] | 1611 | data->rpc_done = 0; |
| 1612 | data->rpc_status = 0; |
Trond Myklebust | 2ced46c | 2007-07-03 23:48:13 -0400 | [diff] [blame] | 1613 | data->cancelled = 0; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1614 | if (isrecover) |
| 1615 | task_setup_data.callback_ops = &nfs4_recover_open_ops; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 1616 | task = rpc_run_task(&task_setup_data); |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1617 | if (IS_ERR(task)) |
| 1618 | return PTR_ERR(task); |
| 1619 | status = nfs4_wait_for_completion_rpc_task(task); |
| 1620 | if (status != 0) { |
| 1621 | data->cancelled = 1; |
| 1622 | smp_wmb(); |
| 1623 | } else |
| 1624 | status = data->rpc_status; |
| 1625 | rpc_put_task(task); |
| 1626 | |
| 1627 | return status; |
| 1628 | } |
| 1629 | |
| 1630 | static int _nfs4_recover_proc_open(struct nfs4_opendata *data) |
| 1631 | { |
| 1632 | struct inode *dir = data->dir->d_inode; |
| 1633 | struct nfs_openres *o_res = &data->o_res; |
| 1634 | int status; |
| 1635 | |
| 1636 | status = nfs4_run_open_task(data, 1); |
| 1637 | if (status != 0 || !data->rpc_done) |
| 1638 | return status; |
| 1639 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1640 | nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr); |
| 1641 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1642 | if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
| 1643 | status = _nfs4_proc_open_confirm(data); |
| 1644 | if (status != 0) |
| 1645 | return status; |
| 1646 | } |
| 1647 | |
| 1648 | return status; |
| 1649 | } |
| 1650 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1651 | static int nfs4_opendata_access(struct rpc_cred *cred, |
| 1652 | struct nfs4_opendata *opendata, |
| 1653 | struct nfs4_state *state, fmode_t fmode) |
| 1654 | { |
| 1655 | struct nfs_access_entry cache; |
| 1656 | u32 mask; |
| 1657 | |
| 1658 | /* access call failed or for some reason the server doesn't |
| 1659 | * support any access modes -- defer access call until later */ |
| 1660 | if (opendata->o_res.access_supported == 0) |
| 1661 | return 0; |
| 1662 | |
| 1663 | mask = 0; |
| 1664 | if (fmode & FMODE_READ) |
| 1665 | mask |= MAY_READ; |
| 1666 | if (fmode & FMODE_WRITE) |
| 1667 | mask |= MAY_WRITE; |
| 1668 | if (fmode & FMODE_EXEC) |
| 1669 | mask |= MAY_EXEC; |
| 1670 | |
| 1671 | cache.cred = cred; |
| 1672 | cache.jiffies = jiffies; |
| 1673 | nfs_access_set_mask(&cache, opendata->o_res.access_result); |
| 1674 | nfs_access_add_cache(state->inode, &cache); |
| 1675 | |
| 1676 | if ((mask & ~cache.mask & (MAY_READ | MAY_WRITE | MAY_EXEC)) == 0) |
| 1677 | return 0; |
| 1678 | |
| 1679 | /* even though OPEN succeeded, access is denied. Close the file */ |
| 1680 | nfs4_close_state(state, fmode); |
| 1681 | return -NFS4ERR_ACCESS; |
| 1682 | } |
| 1683 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 1684 | /* |
| 1685 | * Note: On error, nfs4_proc_open will free the struct nfs4_opendata |
| 1686 | */ |
| 1687 | static int _nfs4_proc_open(struct nfs4_opendata *data) |
| 1688 | { |
| 1689 | struct inode *dir = data->dir->d_inode; |
| 1690 | struct nfs_server *server = NFS_SERVER(dir); |
| 1691 | struct nfs_openargs *o_arg = &data->o_arg; |
| 1692 | struct nfs_openres *o_res = &data->o_res; |
| 1693 | int status; |
| 1694 | |
| 1695 | status = nfs4_run_open_task(data, 0); |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1696 | if (!data->rpc_done) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1697 | return status; |
Trond Myklebust | 08ef7bd | 2011-10-18 16:11:49 -0700 | [diff] [blame] | 1698 | if (status != 0) { |
| 1699 | if (status == -NFS4ERR_BADNAME && |
| 1700 | !(o_arg->open_flags & O_CREAT)) |
| 1701 | return -ENOENT; |
| 1702 | return status; |
| 1703 | } |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1704 | |
Trond Myklebust | 6926afd1 | 2012-01-07 13:22:46 -0500 | [diff] [blame] | 1705 | nfs_fattr_map_and_free_names(server, &data->f_attr); |
| 1706 | |
Trond Myklebust | 90ff0c5 | 2012-04-27 13:48:18 -0400 | [diff] [blame] | 1707 | if (o_arg->open_flags & O_CREAT) |
Trond Myklebust | 56ae19f | 2005-10-27 22:12:40 -0400 | [diff] [blame] | 1708 | update_changeattr(dir, &o_res->cinfo); |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1709 | if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0) |
| 1710 | server->caps &= ~NFS_CAP_POSIX_LOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) { |
Trond Myklebust | cdd4e68 | 2006-01-03 09:55:12 +0100 | [diff] [blame] | 1712 | status = _nfs4_proc_open_confirm(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | if (status != 0) |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1714 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } |
| 1716 | if (!(o_res->f_attr->valid & NFS_ATTR_FATTR)) |
Trond Myklebust | 9936781 | 2007-07-17 21:52:41 -0400 | [diff] [blame] | 1717 | _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr); |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1718 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1721 | static int nfs4_client_recover_expired_lease(struct nfs_client *clp) |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1722 | { |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1723 | unsigned int loop; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1724 | int ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1725 | |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1726 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
Trond Myklebust | 65de872 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 1727 | ret = nfs4_wait_clnt_recover(clp); |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1728 | if (ret != 0) |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1729 | break; |
Trond Myklebust | e598d84 | 2008-12-23 15:21:42 -0500 | [diff] [blame] | 1730 | if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) && |
| 1731 | !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state)) |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1732 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 1733 | nfs4_schedule_state_manager(clp); |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1734 | ret = -EIO; |
Trond Myklebust | 6b30954 | 2006-09-14 14:03:14 -0400 | [diff] [blame] | 1735 | } |
Trond Myklebust | a78cb57 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 1736 | return ret; |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1737 | } |
| 1738 | |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 1739 | static int nfs4_recover_expired_lease(struct nfs_server *server) |
| 1740 | { |
| 1741 | return nfs4_client_recover_expired_lease(server->nfs_client); |
| 1742 | } |
| 1743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | /* |
| 1745 | * OPEN_EXPIRED: |
| 1746 | * reclaim state on the server after a network partition. |
| 1747 | * Assumes caller holds the appropriate lock |
| 1748 | */ |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1749 | 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] | 1750 | { |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1751 | struct nfs4_opendata *opendata; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1752 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | |
Trond Myklebust | 6f220ed | 2007-07-17 21:50:45 -0400 | [diff] [blame] | 1754 | opendata = nfs4_open_recoverdata_alloc(ctx, state); |
| 1755 | if (IS_ERR(opendata)) |
| 1756 | return PTR_ERR(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1757 | ret = nfs4_open_recover(opendata, state); |
Trond Myklebust | 35d0577 | 2008-04-05 15:54:17 -0400 | [diff] [blame] | 1758 | if (ret == -ESTALE) |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 1759 | d_drop(ctx->dentry); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1760 | nfs4_opendata_put(opendata); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1761 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1764 | 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] | 1765 | { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1766 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1767 | struct nfs4_exception exception = { }; |
| 1768 | int err; |
| 1769 | |
| 1770 | do { |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1771 | err = _nfs4_open_expired(ctx, state); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1772 | switch (err) { |
| 1773 | default: |
| 1774 | goto out; |
| 1775 | case -NFS4ERR_GRACE: |
| 1776 | case -NFS4ERR_DELAY: |
| 1777 | nfs4_handle_exception(server, err, &exception); |
| 1778 | err = 0; |
| 1779 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1780 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 1781 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 1782 | return err; |
| 1783 | } |
| 1784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1786 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | struct nfs_open_context *ctx; |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1788 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1790 | ctx = nfs4_state_find_open_context(state); |
| 1791 | if (IS_ERR(ctx)) |
| 1792 | return PTR_ERR(ctx); |
Trond Myklebust | 539cd03 | 2007-06-05 11:46:42 -0400 | [diff] [blame] | 1793 | ret = nfs4_do_open_expired(ctx, state); |
Trond Myklebust | 864472e | 2006-01-03 09:55:15 +0100 | [diff] [blame] | 1794 | put_nfs_open_context(ctx); |
| 1795 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1798 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1799 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1800 | { |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1801 | struct nfs_server *server = NFS_SERVER(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1802 | nfs4_stateid *stateid = &state->stateid; |
| 1803 | int status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1804 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1805 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1806 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
| 1807 | return; |
| 1808 | |
| 1809 | status = nfs41_test_stateid(server, stateid); |
| 1810 | if (status != NFS_OK) { |
| 1811 | /* Free the stateid unless the server explicitly |
| 1812 | * informs us the stateid is unrecognized. */ |
| 1813 | if (status != -NFS4ERR_BAD_STATEID) |
| 1814 | nfs41_free_stateid(server, stateid); |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1815 | nfs_remove_bad_delegation(state->inode); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1816 | |
Bryan Schumaker | 6938867 | 2012-09-26 15:25:52 -0400 | [diff] [blame] | 1817 | write_seqlock(&state->seqlock); |
| 1818 | nfs4_stateid_copy(&state->stateid, &state->open_stateid); |
| 1819 | write_sequnlock(&state->seqlock); |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1820 | clear_bit(NFS_DELEGATED_STATE, &state->flags); |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | /** |
| 1825 | * nfs41_check_open_stateid - possibly free an open stateid |
| 1826 | * |
| 1827 | * @state: NFSv4 state for an inode |
| 1828 | * |
| 1829 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 1830 | * Otherwise a negative NFS4ERR value is returned. |
| 1831 | */ |
| 1832 | static int nfs41_check_open_stateid(struct nfs4_state *state) |
| 1833 | { |
| 1834 | struct nfs_server *server = NFS_SERVER(state->inode); |
Bryan Schumaker | fcb6d9c | 2012-09-26 15:25:53 -0400 | [diff] [blame] | 1835 | nfs4_stateid *stateid = &state->open_stateid; |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1836 | int status; |
| 1837 | |
| 1838 | /* If a state reset has been done, test_stateid is unneeded */ |
| 1839 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && |
| 1840 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && |
| 1841 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) |
| 1842 | return -NFS4ERR_BAD_STATEID; |
| 1843 | |
| 1844 | status = nfs41_test_stateid(server, stateid); |
| 1845 | if (status != NFS_OK) { |
| 1846 | /* Free the stateid unless the server explicitly |
| 1847 | * informs us the stateid is unrecognized. */ |
| 1848 | if (status != -NFS4ERR_BAD_STATEID) |
| 1849 | nfs41_free_stateid(server, stateid); |
| 1850 | |
| 1851 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 1852 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 1853 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1854 | } |
| 1855 | return status; |
| 1856 | } |
| 1857 | |
| 1858 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
| 1859 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1860 | int status; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 1861 | |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 1862 | nfs41_clear_delegation_stateid(state); |
| 1863 | status = nfs41_check_open_stateid(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 1864 | if (status != NFS_OK) |
| 1865 | status = nfs4_open_expired(sp, state); |
| 1866 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 1867 | } |
| 1868 | #endif |
| 1869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | /* |
Jeff Layton | aa53ed5 | 2007-06-05 14:49:03 -0400 | [diff] [blame] | 1871 | * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-* |
| 1872 | * fields corresponding to attributes that were used to store the verifier. |
| 1873 | * Make sure we clobber those fields in the later setattr call |
| 1874 | */ |
| 1875 | static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr) |
| 1876 | { |
| 1877 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) && |
| 1878 | !(sattr->ia_valid & ATTR_ATIME_SET)) |
| 1879 | sattr->ia_valid |= ATTR_ATIME; |
| 1880 | |
| 1881 | if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) && |
| 1882 | !(sattr->ia_valid & ATTR_MTIME_SET)) |
| 1883 | sattr->ia_valid |= ATTR_MTIME; |
| 1884 | } |
| 1885 | |
| 1886 | /* |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1887 | * Returns a referenced nfs4_state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1889 | static int _nfs4_do_open(struct inode *dir, |
| 1890 | struct dentry *dentry, |
| 1891 | fmode_t fmode, |
| 1892 | int flags, |
| 1893 | struct iattr *sattr, |
| 1894 | struct rpc_cred *cred, |
| 1895 | struct nfs4_state **res, |
| 1896 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | { |
| 1898 | struct nfs4_state_owner *sp; |
| 1899 | struct nfs4_state *state = NULL; |
| 1900 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1901 | struct nfs4_opendata *opendata; |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1902 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
| 1904 | /* Protect against reboot recovery conflicts */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | status = -ENOMEM; |
Trond Myklebust | d1e284d | 2012-01-17 22:04:24 -0500 | [diff] [blame] | 1906 | sp = nfs4_get_state_owner(server, cred, GFP_KERNEL); |
| 1907 | if (sp == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); |
| 1909 | goto out_err; |
| 1910 | } |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1911 | status = nfs4_recover_expired_lease(server); |
| 1912 | if (status != 0) |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 1913 | goto err_put_state_owner; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1914 | if (dentry->d_inode != NULL) |
| 1915 | nfs4_return_incompatible_delegation(dentry->d_inode, fmode); |
Trond Myklebust | 58d9714 | 2006-01-03 09:55:24 +0100 | [diff] [blame] | 1916 | status = -ENOMEM; |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1917 | opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1918 | if (opendata == NULL) |
Trond Myklebust | 95d35cb | 2008-12-23 15:21:45 -0500 | [diff] [blame] | 1919 | goto err_put_state_owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1921 | if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) { |
| 1922 | opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc(); |
| 1923 | if (!opendata->f_attr.mdsthreshold) |
| 1924 | goto err_opendata_put; |
Trond Myklebust | 1549210f | 2012-06-05 09:16:47 -0400 | [diff] [blame] | 1925 | opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0]; |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1926 | } |
Al Viro | 82a2c1b | 2011-06-22 18:30:55 -0400 | [diff] [blame] | 1927 | if (dentry->d_inode != NULL) |
| 1928 | opendata->state = nfs4_get_open_state(dentry->d_inode, sp); |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 1929 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1930 | status = _nfs4_proc_open(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | if (status != 0) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1932 | goto err_opendata_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | |
Trond Myklebust | 24ac23a | 2006-01-03 09:55:11 +0100 | [diff] [blame] | 1934 | state = nfs4_opendata_to_nfs4_state(opendata); |
Trond Myklebust | 1b370bc | 2007-07-07 08:04:47 -0400 | [diff] [blame] | 1935 | status = PTR_ERR(state); |
| 1936 | if (IS_ERR(state)) |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1937 | goto err_opendata_put; |
Trond Myklebust | 0df5dd4 | 2010-04-11 16:48:44 -0400 | [diff] [blame] | 1938 | if (server->caps & NFS_CAP_POSIX_LOCK) |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 1939 | set_bit(NFS_STATE_POSIX_LOCKS, &state->flags); |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1940 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1941 | status = nfs4_opendata_access(cred, opendata, state, fmode); |
| 1942 | if (status != 0) |
| 1943 | goto err_opendata_put; |
| 1944 | |
Trond Myklebust | 0ab64e0 | 2010-04-16 16:22:51 -0400 | [diff] [blame] | 1945 | if (opendata->o_arg.open_flags & O_EXCL) { |
| 1946 | nfs4_exclusive_attrset(opendata, sattr); |
| 1947 | |
| 1948 | nfs_fattr_init(opendata->o_res.f_attr); |
| 1949 | status = nfs4_do_setattr(state->inode, cred, |
| 1950 | opendata->o_res.f_attr, sattr, |
| 1951 | state); |
| 1952 | if (status == 0) |
| 1953 | nfs_setattr_update_inode(state->inode, sattr); |
| 1954 | nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr); |
| 1955 | } |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1956 | |
| 1957 | if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) |
| 1958 | *ctx_th = opendata->f_attr.mdsthreshold; |
| 1959 | else |
| 1960 | kfree(opendata->f_attr.mdsthreshold); |
| 1961 | opendata->f_attr.mdsthreshold = NULL; |
| 1962 | |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1963 | nfs4_opendata_put(opendata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | *res = state; |
| 1966 | return 0; |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1967 | err_opendata_put: |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1968 | kfree(opendata->f_attr.mdsthreshold); |
Trond Myklebust | c6d00e6 | 2007-06-17 16:02:44 -0400 | [diff] [blame] | 1969 | nfs4_opendata_put(opendata); |
Trond Myklebust | e56e0b78 | 2006-01-03 09:55:08 +0100 | [diff] [blame] | 1970 | err_put_state_owner: |
| 1971 | nfs4_put_state_owner(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | out_err: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | *res = NULL; |
| 1974 | return status; |
| 1975 | } |
| 1976 | |
| 1977 | |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1978 | static struct nfs4_state *nfs4_do_open(struct inode *dir, |
| 1979 | struct dentry *dentry, |
| 1980 | fmode_t fmode, |
| 1981 | int flags, |
| 1982 | struct iattr *sattr, |
| 1983 | struct rpc_cred *cred, |
| 1984 | struct nfs4_threshold **ctx_th) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | { |
| 1986 | struct nfs4_exception exception = { }; |
| 1987 | struct nfs4_state *res; |
| 1988 | int status; |
| 1989 | |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 1990 | fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | do { |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 1992 | status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred, |
| 1993 | &res, ctx_th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | if (status == 0) |
| 1995 | break; |
| 1996 | /* NOTE: BAD_SEQID means the server and client disagree about the |
| 1997 | * book-keeping w.r.t. state-changing operations |
| 1998 | * (OPEN/CLOSE/LOCK/LOCKU...) |
| 1999 | * It is actually a sign of a bug on the client or on the server. |
| 2000 | * |
| 2001 | * If we receive a BAD_SEQID error in the particular case of |
Trond Myklebust | cee54fc | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2002 | * doing an OPEN, we assume that nfs_increment_open_seqid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | * have unhashed the old state_owner for us, and that we can |
| 2004 | * therefore safely retry using a new one. We should still warn |
| 2005 | * the user though... |
| 2006 | */ |
| 2007 | if (status == -NFS4ERR_BAD_SEQID) { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 2008 | pr_warn_ratelimited("NFS: v4 server %s " |
Trond Myklebust | 6f43ddc | 2007-07-08 16:49:11 -0400 | [diff] [blame] | 2009 | " returned a bad sequence-id error!\n", |
| 2010 | NFS_SERVER(dir)->nfs_client->cl_hostname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | exception.retry = 1; |
| 2012 | continue; |
| 2013 | } |
Trond Myklebust | 550f574 | 2005-10-18 14:20:21 -0700 | [diff] [blame] | 2014 | /* |
| 2015 | * BAD_STATEID on OPEN means that the server cancelled our |
| 2016 | * state before it received the OPEN_CONFIRM. |
| 2017 | * Recover by retrying the request as per the discussion |
| 2018 | * on Page 181 of RFC3530. |
| 2019 | */ |
| 2020 | if (status == -NFS4ERR_BAD_STATEID) { |
| 2021 | exception.retry = 1; |
| 2022 | continue; |
| 2023 | } |
Trond Myklebust | aac00a8 | 2007-07-05 19:02:21 -0400 | [diff] [blame] | 2024 | if (status == -EAGAIN) { |
| 2025 | /* We must have found a delegation */ |
| 2026 | exception.retry = 1; |
| 2027 | continue; |
| 2028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir), |
| 2030 | status, &exception)); |
| 2031 | } while (exception.retry); |
| 2032 | return res; |
| 2033 | } |
| 2034 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2035 | static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2036 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2037 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2039 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | struct nfs_setattrargs arg = { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2041 | .fh = NFS_FH(inode), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | .iap = sattr, |
| 2043 | .server = server, |
| 2044 | .bitmask = server->attr_bitmask, |
| 2045 | }; |
| 2046 | struct nfs_setattrres res = { |
| 2047 | .fattr = fattr, |
| 2048 | .server = server, |
| 2049 | }; |
| 2050 | struct rpc_message msg = { |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2051 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR], |
| 2052 | .rpc_argp = &arg, |
| 2053 | .rpc_resp = &res, |
| 2054 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | }; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2056 | unsigned long timestamp = jiffies; |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2057 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2059 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2061 | if (state != NULL) { |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2062 | struct nfs_lockowner lockowner = { |
| 2063 | .l_owner = current->files, |
| 2064 | .l_pid = current->tgid, |
| 2065 | }; |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2066 | nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE, |
Trond Myklebust | 2a36915 | 2012-08-13 18:54:45 -0400 | [diff] [blame] | 2067 | &lockowner); |
Trond Myklebust | 4fc8796 | 2012-03-08 17:42:01 -0500 | [diff] [blame] | 2068 | } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode, |
| 2069 | FMODE_WRITE)) { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2070 | /* Use that stateid */ |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2071 | } else |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 2072 | nfs4_stateid_copy(&arg.stateid, &zero_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2074 | 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] | 2075 | if (status == 0 && state != NULL) |
| 2076 | renew_lease(server, timestamp); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2077 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2080 | static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, |
| 2081 | struct nfs_fattr *fattr, struct iattr *sattr, |
| 2082 | struct nfs4_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | { |
Trond Myklebust | 3e4f629 | 2006-03-20 13:44:46 -0500 | [diff] [blame] | 2084 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2085 | struct nfs4_exception exception = { |
| 2086 | .state = state, |
Trond Myklebust | 3114ea7 | 2012-03-07 16:39:06 -0500 | [diff] [blame] | 2087 | .inode = inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 2088 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | int err; |
| 2090 | do { |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2091 | err = _nfs4_do_setattr(inode, cred, fattr, sattr, state); |
| 2092 | switch (err) { |
| 2093 | case -NFS4ERR_OPENMODE: |
| 2094 | if (state && !(state->state & FMODE_WRITE)) { |
| 2095 | err = -EBADF; |
| 2096 | if (sattr->ia_valid & ATTR_OPEN) |
| 2097 | err = -EACCES; |
| 2098 | goto out; |
| 2099 | } |
| 2100 | } |
| 2101 | err = nfs4_handle_exception(server, err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | } while (exception.retry); |
Trond Myklebust | 451146b | 2012-04-18 16:29:11 -0400 | [diff] [blame] | 2103 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | return err; |
| 2105 | } |
| 2106 | |
| 2107 | struct nfs4_closedata { |
| 2108 | struct inode *inode; |
| 2109 | struct nfs4_state *state; |
| 2110 | struct nfs_closeargs arg; |
| 2111 | struct nfs_closeres res; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2112 | struct nfs_fattr fattr; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2113 | unsigned long timestamp; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2114 | bool roc; |
| 2115 | u32 roc_barrier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | }; |
| 2117 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2118 | static void nfs4_free_closedata(void *data) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2119 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2120 | struct nfs4_closedata *calldata = data; |
| 2121 | struct nfs4_state_owner *sp = calldata->state->owner; |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2122 | struct super_block *sb = calldata->state->inode->i_sb; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2123 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2124 | if (calldata->roc) |
| 2125 | pnfs_roc_release(calldata->state->inode); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2126 | nfs4_put_open_state(calldata->state); |
| 2127 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2128 | nfs4_put_state_owner(sp); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2129 | nfs_sb_deactive(sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2130 | kfree(calldata); |
| 2131 | } |
| 2132 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2133 | static void nfs4_close_clear_stateid_flags(struct nfs4_state *state, |
| 2134 | fmode_t fmode) |
| 2135 | { |
| 2136 | spin_lock(&state->owner->so_lock); |
| 2137 | if (!(fmode & FMODE_READ)) |
| 2138 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2139 | if (!(fmode & FMODE_WRITE)) |
| 2140 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2141 | clear_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2142 | spin_unlock(&state->owner->so_lock); |
| 2143 | } |
| 2144 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2145 | static void nfs4_close_done(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2147 | struct nfs4_closedata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | struct nfs4_state *state = calldata->state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | struct nfs_server *server = NFS_SERVER(calldata->inode); |
| 2150 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2151 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2152 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 2153 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | /* hmm. we are done with the inode, and in the process of freeing |
| 2155 | * the state_owner. we keep this around to process errors |
| 2156 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | switch (task->tk_status) { |
| 2158 | case 0: |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2159 | if (calldata->roc) |
| 2160 | pnfs_roc_set_barrier(state->inode, |
| 2161 | calldata->roc_barrier); |
Trond Myklebust | 45328c3 | 2007-07-26 17:47:34 -0400 | [diff] [blame] | 2162 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2163 | renew_lease(server, calldata->timestamp); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2164 | nfs4_close_clear_stateid_flags(state, |
| 2165 | calldata->arg.fmode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | break; |
| 2167 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2168 | case -NFS4ERR_OLD_STATEID: |
| 2169 | case -NFS4ERR_BAD_STATEID: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2171 | if (calldata->arg.fmode == 0) |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2172 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | default: |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2174 | if (nfs4_async_handle_error(task, server, state) == -EAGAIN) |
| 2175 | rpc_restart_call_prepare(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | } |
Trond Myklebust | 72211db | 2009-12-15 14:47:36 -0500 | [diff] [blame] | 2177 | nfs_release_seqid(calldata->arg.seqid); |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2178 | nfs_refresh_inode(calldata->inode, calldata->res.fattr); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2179 | dprintk("%s: done, ret = %d!\n", __func__, task->tk_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2182 | static void nfs4_close_prepare(struct rpc_task *task, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2184 | struct nfs4_closedata *calldata = data; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2185 | struct nfs4_state *state = calldata->state; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2186 | struct inode *inode = calldata->inode; |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2187 | int call_close = 0; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2188 | |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2189 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2190 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2191 | return; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2192 | |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2193 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE]; |
| 2194 | calldata->arg.fmode = FMODE_READ|FMODE_WRITE; |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2195 | spin_lock(&state->owner->so_lock); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2196 | /* Calculate the change in open mode */ |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2197 | if (state->n_rdwr == 0) { |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2198 | if (state->n_rdonly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2199 | call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags); |
| 2200 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2201 | calldata->arg.fmode &= ~FMODE_READ; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2202 | } |
| 2203 | if (state->n_wronly == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2204 | call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags); |
| 2205 | call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags); |
| 2206 | calldata->arg.fmode &= ~FMODE_WRITE; |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2207 | } |
Trond Myklebust | e761692 | 2006-01-03 09:55:13 +0100 | [diff] [blame] | 2208 | } |
Trond Myklebust | 4cecb76 | 2005-11-04 15:32:58 -0500 | [diff] [blame] | 2209 | spin_unlock(&state->owner->so_lock); |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2210 | |
| 2211 | if (!call_close) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2212 | /* Note: exit _without_ calling nfs4_close_done */ |
| 2213 | task->tk_action = NULL; |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2214 | goto out; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2215 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2216 | |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2217 | if (calldata->arg.fmode == 0) { |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2218 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2219 | if (calldata->roc && |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2220 | pnfs_roc_drain(inode, &calldata->roc_barrier, task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2221 | goto out; |
Fred Isaman | f7e8917 | 2011-01-06 11:36:32 +0000 | [diff] [blame] | 2222 | } |
Trond Myklebust | 88069f7 | 2009-12-08 08:33:16 -0500 | [diff] [blame] | 2223 | |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2224 | nfs_fattr_init(calldata->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 2225 | calldata->timestamp = jiffies; |
Trond Myklebust | 7fdab06 | 2012-09-20 20:15:57 -0400 | [diff] [blame] | 2226 | if (nfs4_setup_sequence(NFS_SERVER(inode), |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2227 | &calldata->arg.seq_args, |
| 2228 | &calldata->res.seq_res, |
| 2229 | task)) |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2230 | goto out; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2231 | rpc_call_start(task); |
Chuck Lever | a3ca565 | 2012-03-01 17:00:40 -0500 | [diff] [blame] | 2232 | out: |
| 2233 | dprintk("%s: done!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2236 | static const struct rpc_call_ops nfs4_close_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 2237 | .rpc_call_prepare = nfs4_close_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 2238 | .rpc_call_done = nfs4_close_done, |
| 2239 | .rpc_release = nfs4_free_closedata, |
| 2240 | }; |
| 2241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | /* |
| 2243 | * It is possible for data to be read/written from a mem-mapped file |
| 2244 | * after the sys_close call (which hits the vfs layer as a flush). |
| 2245 | * This means that we can't safely call nfsv4 close on a file until |
| 2246 | * the inode is cleared. This in turn means that we are not good |
| 2247 | * NFSv4 citizens - we do not indicate to the server to update the file's |
| 2248 | * share state even when we are done with one of the three share |
| 2249 | * stateid's in the inode. |
| 2250 | * |
| 2251 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
| 2252 | */ |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2253 | 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] | 2254 | { |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2255 | struct nfs_server *server = NFS_SERVER(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | struct nfs4_closedata *calldata; |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2257 | struct nfs4_state_owner *sp = state->owner; |
| 2258 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2259 | struct rpc_message msg = { |
| 2260 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE], |
| 2261 | .rpc_cred = state->owner->so_cred, |
| 2262 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2263 | struct rpc_task_setup task_setup_data = { |
| 2264 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 2265 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2266 | .callback_ops = &nfs4_close_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 2267 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2268 | .flags = RPC_TASK_ASYNC, |
| 2269 | }; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2270 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2272 | calldata = kzalloc(sizeof(*calldata), gfp_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | if (calldata == NULL) |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2274 | goto out; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2275 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1); |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2276 | calldata->inode = state->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | calldata->state = state; |
Trond Myklebust | 4a35bd4 | 2007-06-05 10:31:33 -0400 | [diff] [blame] | 2278 | calldata->arg.fh = NFS_FH(state->inode); |
Trond Myklebust | 003707c | 2007-07-05 18:07:55 -0400 | [diff] [blame] | 2279 | calldata->arg.stateid = &state->open_stateid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | /* Serialization for the sequence id */ |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 2281 | calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2282 | if (calldata->arg.seqid == NULL) |
| 2283 | goto out_free_calldata; |
Trond Myklebust | dc0b027 | 2008-12-23 15:21:56 -0500 | [diff] [blame] | 2284 | calldata->arg.fmode = 0; |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2285 | calldata->arg.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2286 | calldata->res.fattr = &calldata->fattr; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 2287 | calldata->res.seqid = calldata->arg.seqid; |
Trond Myklebust | 516a6af | 2005-10-27 22:12:41 -0400 | [diff] [blame] | 2288 | calldata->res.server = server; |
Trond Myklebust | 1f7977c | 2012-09-20 20:31:51 -0400 | [diff] [blame] | 2289 | calldata->roc = pnfs_roc(state->inode); |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2290 | nfs_sb_active(calldata->inode->i_sb); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2291 | |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 2292 | msg.rpc_argp = &calldata->arg; |
| 2293 | msg.rpc_resp = &calldata->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 2294 | task_setup_data.callback_data = calldata; |
| 2295 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2296 | if (IS_ERR(task)) |
| 2297 | return PTR_ERR(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2298 | status = 0; |
| 2299 | if (wait) |
| 2300 | status = rpc_wait_for_completion_task(task); |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2301 | rpc_put_task(task); |
Trond Myklebust | a49c3c7 | 2007-10-18 18:03:27 -0400 | [diff] [blame] | 2302 | return status; |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2303 | out_free_calldata: |
| 2304 | kfree(calldata); |
| 2305 | out: |
Trond Myklebust | b39e625 | 2007-06-11 23:05:07 -0400 | [diff] [blame] | 2306 | nfs4_put_open_state(state); |
| 2307 | nfs4_put_state_owner(sp); |
Trond Myklebust | 9512135 | 2005-10-18 14:20:12 -0700 | [diff] [blame] | 2308 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2311 | static struct inode * |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2312 | 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] | 2313 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | struct nfs4_state *state; |
| 2315 | |
Trond Myklebust | 565277f | 2007-10-15 18:17:53 -0400 | [diff] [blame] | 2316 | /* Protect against concurrent sillydeletes */ |
Andy Adamson | 82be417 | 2012-05-23 05:02:35 -0400 | [diff] [blame] | 2317 | state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr, |
| 2318 | ctx->cred, &ctx->mdsthreshold); |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2319 | if (IS_ERR(state)) |
| 2320 | return ERR_CAST(state); |
Trond Myklebust | cd9a1c0 | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2321 | ctx->state = state; |
Trond Myklebust | f46e0bd | 2010-09-17 10:56:50 -0400 | [diff] [blame] | 2322 | return igrab(state->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Trond Myklebust | 1185a55 | 2009-12-03 15:54:02 -0500 | [diff] [blame] | 2325 | 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] | 2326 | { |
| 2327 | if (ctx->state == NULL) |
| 2328 | return; |
| 2329 | if (is_sync) |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2330 | nfs4_close_sync(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2331 | else |
Al Viro | 643168c | 2011-06-22 18:20:23 -0400 | [diff] [blame] | 2332 | nfs4_close_state(ctx->state, ctx->mode); |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 2333 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | |
| 2335 | static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
| 2336 | { |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2337 | struct nfs4_server_caps_arg args = { |
| 2338 | .fhandle = fhandle, |
| 2339 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | struct nfs4_server_caps_res res = {}; |
| 2341 | struct rpc_message msg = { |
| 2342 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS], |
Benny Halevy | 43652ad | 2009-04-01 09:21:54 -0400 | [diff] [blame] | 2343 | .rpc_argp = &args, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | .rpc_resp = &res, |
| 2345 | }; |
| 2346 | int status; |
| 2347 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2348 | 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] | 2349 | if (status == 0) { |
| 2350 | memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask)); |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2351 | server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS| |
| 2352 | NFS_CAP_SYMLINKS|NFS_CAP_FILEID| |
| 2353 | NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER| |
| 2354 | NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME| |
| 2355 | NFS_CAP_CTIME|NFS_CAP_MTIME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | if (res.attr_bitmask[0] & FATTR4_WORD0_ACL) |
| 2357 | server->caps |= NFS_CAP_ACLS; |
| 2358 | if (res.has_links != 0) |
| 2359 | server->caps |= NFS_CAP_HARDLINKS; |
| 2360 | if (res.has_symlinks != 0) |
| 2361 | server->caps |= NFS_CAP_SYMLINKS; |
Trond Myklebust | 62ab460 | 2009-08-09 15:06:19 -0400 | [diff] [blame] | 2362 | if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID) |
| 2363 | server->caps |= NFS_CAP_FILEID; |
| 2364 | if (res.attr_bitmask[1] & FATTR4_WORD1_MODE) |
| 2365 | server->caps |= NFS_CAP_MODE; |
| 2366 | if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS) |
| 2367 | server->caps |= NFS_CAP_NLINK; |
| 2368 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER) |
| 2369 | server->caps |= NFS_CAP_OWNER; |
| 2370 | if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP) |
| 2371 | server->caps |= NFS_CAP_OWNER_GROUP; |
| 2372 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS) |
| 2373 | server->caps |= NFS_CAP_ATIME; |
| 2374 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA) |
| 2375 | server->caps |= NFS_CAP_CTIME; |
| 2376 | if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY) |
| 2377 | server->caps |= NFS_CAP_MTIME; |
| 2378 | |
Trond Myklebust | a65318b | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 2379 | memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask)); |
| 2380 | server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; |
| 2381 | 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] | 2382 | server->acl_bitmask = res.acl_bitmask; |
Chuck Lever | 264e635 | 2012-03-01 17:02:05 -0500 | [diff] [blame] | 2383 | server->fh_expire_type = res.fh_expire_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | } |
Andy Adamson | cccef3b | 2009-04-01 09:22:03 -0400 | [diff] [blame] | 2385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | return status; |
| 2387 | } |
| 2388 | |
Trond Myklebust | 55a9759 | 2006-06-09 09:34:19 -0400 | [diff] [blame] | 2389 | int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | { |
| 2391 | struct nfs4_exception exception = { }; |
| 2392 | int err; |
| 2393 | do { |
| 2394 | err = nfs4_handle_exception(server, |
| 2395 | _nfs4_server_capabilities(server, fhandle), |
| 2396 | &exception); |
| 2397 | } while (exception.retry); |
| 2398 | return err; |
| 2399 | } |
| 2400 | |
| 2401 | static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2402 | struct nfs_fsinfo *info) |
| 2403 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | struct nfs4_lookup_root_arg args = { |
| 2405 | .bitmask = nfs4_fattr_bitmap, |
| 2406 | }; |
| 2407 | struct nfs4_lookup_res res = { |
| 2408 | .server = server, |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2409 | .fattr = info->fattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | .fh = fhandle, |
| 2411 | }; |
| 2412 | struct rpc_message msg = { |
| 2413 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT], |
| 2414 | .rpc_argp = &args, |
| 2415 | .rpc_resp = &res, |
| 2416 | }; |
Benny Halevy | 008f55d | 2009-04-01 09:22:50 -0400 | [diff] [blame] | 2417 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2418 | nfs_fattr_init(info->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2419 | 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] | 2420 | } |
| 2421 | |
| 2422 | static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2423 | struct nfs_fsinfo *info) |
| 2424 | { |
| 2425 | struct nfs4_exception exception = { }; |
| 2426 | int err; |
| 2427 | do { |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2428 | err = _nfs4_lookup_root(server, fhandle, info); |
| 2429 | switch (err) { |
| 2430 | case 0: |
| 2431 | case -NFS4ERR_WRONGSEC: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2432 | goto out; |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2433 | default: |
| 2434 | err = nfs4_handle_exception(server, err, &exception); |
| 2435 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 2437 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | return err; |
| 2439 | } |
| 2440 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2441 | static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2442 | struct nfs_fsinfo *info, rpc_authflavor_t flavor) |
| 2443 | { |
| 2444 | struct rpc_auth *auth; |
| 2445 | int ret; |
| 2446 | |
| 2447 | auth = rpcauth_create(flavor, server->client); |
Wei Yongjun | e8d920c | 2012-09-21 12:27:41 +0800 | [diff] [blame] | 2448 | if (IS_ERR(auth)) { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2449 | ret = -EIO; |
| 2450 | goto out; |
| 2451 | } |
| 2452 | ret = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2453 | out: |
| 2454 | return ret; |
| 2455 | } |
| 2456 | |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2457 | 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] | 2458 | struct nfs_fsinfo *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | { |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2460 | int i, len, status = 0; |
Bryan Schumaker | 0fabee2 | 2011-04-13 14:31:29 -0400 | [diff] [blame] | 2461 | rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2463 | len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array)); |
| 2464 | BUG_ON(len < 0); |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2465 | |
| 2466 | for (i = 0; i < len; i++) { |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 2467 | /* AUTH_UNIX is the default flavor if none was specified, |
| 2468 | * thus has already been tried. */ |
| 2469 | if (flav_array[i] == RPC_AUTH_UNIX) |
| 2470 | continue; |
| 2471 | |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2472 | status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2473 | if (status == -NFS4ERR_WRONGSEC || status == -EACCES) |
Bryan Schumaker | d1a8016 | 2011-04-13 14:31:28 -0400 | [diff] [blame] | 2474 | continue; |
| 2475 | break; |
Bryan Schumaker | 8f70e95 | 2011-03-24 17:12:31 +0000 | [diff] [blame] | 2476 | } |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2477 | /* |
| 2478 | * -EACCESS could mean that the user doesn't have correct permissions |
| 2479 | * to access the mount. It could also mean that we tried to mount |
| 2480 | * with a gss auth flavor, but rpc.gssd isn't running. Either way, |
| 2481 | * existing mount programs don't handle -EACCES very well so it should |
| 2482 | * be mapped to -EPERM instead. |
| 2483 | */ |
| 2484 | if (status == -EACCES) |
| 2485 | status = -EPERM; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2486 | return status; |
| 2487 | } |
| 2488 | |
| 2489 | /* |
| 2490 | * get the file handle for the "/" directory on the server |
| 2491 | */ |
Bryan Schumaker | 3028eb2 | 2012-05-10 15:07:30 -0400 | [diff] [blame] | 2492 | int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle, |
| 2493 | struct nfs_fsinfo *info) |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2494 | { |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2495 | int minor_version = server->nfs_client->cl_minorversion; |
Bryan Schumaker | 801a16dc | 2011-04-13 14:31:30 -0400 | [diff] [blame] | 2496 | int status = nfs4_lookup_root(server, fhandle, info); |
Bryan Schumaker | fb8a5ba | 2011-04-18 16:52:25 -0400 | [diff] [blame] | 2497 | if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR)) |
| 2498 | /* |
| 2499 | * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM |
| 2500 | * by nfs4_map_errors() as this function exits. |
| 2501 | */ |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 2502 | 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] | 2503 | if (status == 0) |
| 2504 | status = nfs4_server_capabilities(server, fhandle); |
| 2505 | if (status == 0) |
| 2506 | status = nfs4_do_fsinfo(server, fhandle, info); |
Trond Myklebust | c12e87f | 2006-03-13 21:20:47 -0800 | [diff] [blame] | 2507 | return nfs4_map_errors(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | } |
| 2509 | |
Bryan Schumaker | bae3624 | 2012-05-10 15:07:31 -0400 | [diff] [blame] | 2510 | static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh, |
| 2511 | struct nfs_fsinfo *info) |
| 2512 | { |
| 2513 | int error; |
| 2514 | struct nfs_fattr *fattr = info->fattr; |
| 2515 | |
| 2516 | error = nfs4_server_capabilities(server, mntfh); |
| 2517 | if (error < 0) { |
| 2518 | dprintk("nfs4_get_root: getcaps error = %d\n", -error); |
| 2519 | return error; |
| 2520 | } |
| 2521 | |
| 2522 | error = nfs4_proc_getattr(server, mntfh, fattr); |
| 2523 | if (error < 0) { |
| 2524 | dprintk("nfs4_get_root: getattr error = %d\n", -error); |
| 2525 | return error; |
| 2526 | } |
| 2527 | |
| 2528 | if (fattr->valid & NFS_ATTR_FATTR_FSID && |
| 2529 | !nfs_fsid_equal(&server->fsid, &fattr->fsid)) |
| 2530 | memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid)); |
| 2531 | |
| 2532 | return error; |
| 2533 | } |
| 2534 | |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2535 | /* |
| 2536 | * Get locations and (maybe) other attributes of a referral. |
| 2537 | * Note that we'll actually follow the referral later when |
| 2538 | * we detect fsid mismatch in inode revalidation |
| 2539 | */ |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2540 | static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir, |
| 2541 | const struct qstr *name, struct nfs_fattr *fattr, |
| 2542 | struct nfs_fh *fhandle) |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2543 | { |
| 2544 | int status = -ENOMEM; |
| 2545 | struct page *page = NULL; |
| 2546 | struct nfs4_fs_locations *locations = NULL; |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2547 | |
| 2548 | page = alloc_page(GFP_KERNEL); |
| 2549 | if (page == NULL) |
| 2550 | goto out; |
| 2551 | locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL); |
| 2552 | if (locations == NULL) |
| 2553 | goto out; |
| 2554 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2555 | status = nfs4_proc_fs_locations(client, dir, name, locations, page); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2556 | if (status != 0) |
| 2557 | goto out; |
| 2558 | /* Make sure server returned a different fsid for the referral */ |
| 2559 | if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2560 | dprintk("%s: server did not return a different fsid for" |
| 2561 | " a referral at %s\n", __func__, name->name); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2562 | status = -EIO; |
| 2563 | goto out; |
| 2564 | } |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2565 | /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */ |
| 2566 | nfs_fixup_referral_attributes(&locations->fattr); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2567 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 2568 | /* replace the lookup nfs_fattr with the locations nfs_fattr */ |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2569 | memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr)); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2570 | memset(fhandle, 0, sizeof(struct nfs_fh)); |
| 2571 | out: |
| 2572 | if (page) |
| 2573 | __free_page(page); |
Davidlohr Bueso | 5d7ca35 | 2010-08-11 12:42:15 -0400 | [diff] [blame] | 2574 | kfree(locations); |
Manoj Naik | 6b97fd3 | 2006-06-09 09:34:29 -0400 | [diff] [blame] | 2575 | return status; |
| 2576 | } |
| 2577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2579 | { |
| 2580 | struct nfs4_getattr_arg args = { |
| 2581 | .fh = fhandle, |
| 2582 | .bitmask = server->attr_bitmask, |
| 2583 | }; |
| 2584 | struct nfs4_getattr_res res = { |
| 2585 | .fattr = fattr, |
| 2586 | .server = server, |
| 2587 | }; |
| 2588 | struct rpc_message msg = { |
| 2589 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR], |
| 2590 | .rpc_argp = &args, |
| 2591 | .rpc_resp = &res, |
| 2592 | }; |
| 2593 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2594 | nfs_fattr_init(fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2595 | 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] | 2596 | } |
| 2597 | |
| 2598 | static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2599 | { |
| 2600 | struct nfs4_exception exception = { }; |
| 2601 | int err; |
| 2602 | do { |
| 2603 | err = nfs4_handle_exception(server, |
| 2604 | _nfs4_proc_getattr(server, fhandle, fattr), |
| 2605 | &exception); |
| 2606 | } while (exception.retry); |
| 2607 | return err; |
| 2608 | } |
| 2609 | |
| 2610 | /* |
| 2611 | * The file is not closed if it is opened due to the a request to change |
| 2612 | * the size of the file. The open call will not be needed once the |
| 2613 | * VFS layer lookup-intents are implemented. |
| 2614 | * |
| 2615 | * Close is called when the inode is destroyed. |
| 2616 | * If we haven't opened the file for O_WRONLY, we |
| 2617 | * need to in the size_change case to obtain a stateid. |
| 2618 | * |
| 2619 | * Got race? |
| 2620 | * Because OPEN is always done by name in nfsv4, it is |
| 2621 | * possible that we opened a different file by the same |
| 2622 | * name. We can recognize this race condition, but we |
| 2623 | * can't do anything about it besides returning an error. |
| 2624 | * |
| 2625 | * This will be fixed with VFS changes (lookup-intent). |
| 2626 | */ |
| 2627 | static int |
| 2628 | nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 2629 | struct iattr *sattr) |
| 2630 | { |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2631 | struct inode *inode = dentry->d_inode; |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2632 | struct rpc_cred *cred = NULL; |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2633 | struct nfs4_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | int status; |
| 2635 | |
Benny Halevy | 8a1636c | 2010-07-14 15:43:57 -0400 | [diff] [blame] | 2636 | if (pnfs_ld_layoutret_on_setattr(inode)) |
| 2637 | pnfs_return_layout(inode); |
| 2638 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 2639 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | |
Andy Adamson | 2669940 | 2012-05-30 16:12:24 -0400 | [diff] [blame] | 2641 | /* Deal with open(O_TRUNC) */ |
| 2642 | if (sattr->ia_valid & ATTR_OPEN) |
| 2643 | sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); |
| 2644 | |
| 2645 | /* Optimization: if the end result is no change, don't RPC */ |
| 2646 | if ((sattr->ia_valid & ~(ATTR_FILE)) == 0) |
| 2647 | return 0; |
| 2648 | |
Trond Myklebust | d530838 | 2005-11-04 15:33:38 -0500 | [diff] [blame] | 2649 | /* Search for an existing open(O_WRITE) file */ |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2650 | if (sattr->ia_valid & ATTR_FILE) { |
| 2651 | struct nfs_open_context *ctx; |
Trond Myklebust | 08e9eac | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 2652 | |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2653 | ctx = nfs_file_open_context(sattr->ia_file); |
Neil Brown | 504e518 | 2008-10-16 14:15:16 +1100 | [diff] [blame] | 2654 | if (ctx) { |
| 2655 | cred = ctx->cred; |
| 2656 | state = ctx->state; |
| 2657 | } |
Trond Myklebust | 659bfcd | 2008-06-10 19:39:41 -0400 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | status = nfs4_do_setattr(inode, cred, fattr, sattr, state); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 2661 | if (status == 0) |
| 2662 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | return status; |
| 2664 | } |
| 2665 | |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2666 | static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir, |
| 2667 | const struct qstr *name, struct nfs_fh *fhandle, |
| 2668 | struct nfs_fattr *fattr) |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2669 | { |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2670 | struct nfs_server *server = NFS_SERVER(dir); |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2671 | int status; |
| 2672 | struct nfs4_lookup_arg args = { |
| 2673 | .bitmask = server->attr_bitmask, |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2674 | .dir_fh = NFS_FH(dir), |
David Howells | 2b3de44 | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 2675 | .name = name, |
| 2676 | }; |
| 2677 | struct nfs4_lookup_res res = { |
| 2678 | .server = server, |
| 2679 | .fattr = fattr, |
| 2680 | .fh = fhandle, |
| 2681 | }; |
| 2682 | struct rpc_message msg = { |
| 2683 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP], |
| 2684 | .rpc_argp = &args, |
| 2685 | .rpc_resp = &res, |
| 2686 | }; |
| 2687 | |
| 2688 | nfs_fattr_init(fattr); |
| 2689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2691 | 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] | 2692 | dprintk("NFS reply lookup: %d\n", status); |
| 2693 | return status; |
| 2694 | } |
| 2695 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2696 | static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr) |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2697 | { |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2698 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2699 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT; |
Bryan Schumaker | 7ebb931 | 2011-03-24 17:12:30 +0000 | [diff] [blame] | 2700 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 2701 | fattr->nlink = 2; |
| 2702 | } |
| 2703 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2704 | static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, |
| 2705 | struct qstr *name, struct nfs_fh *fhandle, |
| 2706 | struct nfs_fattr *fattr) |
| 2707 | { |
| 2708 | struct nfs4_exception exception = { }; |
| 2709 | struct rpc_clnt *client = *clnt; |
| 2710 | int err; |
| 2711 | do { |
| 2712 | err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr); |
| 2713 | switch (err) { |
| 2714 | case -NFS4ERR_BADNAME: |
| 2715 | err = -ENOENT; |
| 2716 | goto out; |
| 2717 | case -NFS4ERR_MOVED: |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2718 | err = nfs4_get_referral(client, dir, name, fattr, fhandle); |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2719 | goto out; |
| 2720 | case -NFS4ERR_WRONGSEC: |
| 2721 | err = -EPERM; |
| 2722 | if (client != *clnt) |
| 2723 | goto out; |
| 2724 | |
| 2725 | client = nfs4_create_sec_client(client, dir, name); |
| 2726 | if (IS_ERR(client)) |
| 2727 | return PTR_ERR(client); |
| 2728 | |
| 2729 | exception.retry = 1; |
| 2730 | break; |
| 2731 | default: |
| 2732 | err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception); |
| 2733 | } |
| 2734 | } while (exception.retry); |
| 2735 | |
| 2736 | out: |
| 2737 | if (err == 0) |
| 2738 | *clnt = client; |
| 2739 | else if (client != *clnt) |
| 2740 | rpc_shutdown_client(client); |
| 2741 | |
| 2742 | return err; |
| 2743 | } |
| 2744 | |
Bryan Schumaker | 80a16b2 | 2012-04-27 13:27:46 -0400 | [diff] [blame] | 2745 | static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2746 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | { |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2748 | int status; |
| 2749 | struct rpc_clnt *client = NFS_CLIENT(dir); |
Trond Myklebust | 0c2e53f | 2011-10-18 16:11:22 -0700 | [diff] [blame] | 2750 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 2751 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2752 | if (client != NFS_CLIENT(dir)) { |
| 2753 | rpc_shutdown_client(client); |
| 2754 | nfs_fixup_secinfo_attributes(fattr); |
| 2755 | } |
| 2756 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 2759 | struct rpc_clnt * |
| 2760 | nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name, |
| 2761 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 2762 | { |
| 2763 | int status; |
| 2764 | struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir)); |
| 2765 | |
| 2766 | status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr); |
| 2767 | if (status < 0) { |
| 2768 | rpc_shutdown_client(client); |
| 2769 | return ERR_PTR(status); |
| 2770 | } |
| 2771 | return client; |
| 2772 | } |
| 2773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2775 | { |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2776 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | struct nfs4_accessargs args = { |
| 2778 | .fh = NFS_FH(inode), |
Trond Myklebust | a4980e7 | 2012-01-30 15:43:56 -0500 | [diff] [blame] | 2779 | .bitmask = server->cache_consistency_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | }; |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2781 | struct nfs4_accessres res = { |
| 2782 | .server = server, |
Trond Myklebust | 76b3299 | 2007-08-10 17:45:11 -0400 | [diff] [blame] | 2783 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | struct rpc_message msg = { |
| 2785 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS], |
| 2786 | .rpc_argp = &args, |
| 2787 | .rpc_resp = &res, |
| 2788 | .rpc_cred = entry->cred, |
| 2789 | }; |
| 2790 | int mode = entry->mask; |
| 2791 | int status; |
| 2792 | |
| 2793 | /* |
| 2794 | * Determine which access bits we want to ask for... |
| 2795 | */ |
| 2796 | if (mode & MAY_READ) |
| 2797 | args.access |= NFS4_ACCESS_READ; |
| 2798 | if (S_ISDIR(inode->i_mode)) { |
| 2799 | if (mode & MAY_WRITE) |
| 2800 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE; |
| 2801 | if (mode & MAY_EXEC) |
| 2802 | args.access |= NFS4_ACCESS_LOOKUP; |
| 2803 | } else { |
| 2804 | if (mode & MAY_WRITE) |
| 2805 | args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND; |
| 2806 | if (mode & MAY_EXEC) |
| 2807 | args.access |= NFS4_ACCESS_EXECUTE; |
| 2808 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2809 | |
| 2810 | res.fattr = nfs_alloc_fattr(); |
| 2811 | if (res.fattr == NULL) |
| 2812 | return -ENOMEM; |
| 2813 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2814 | 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] | 2815 | if (!status) { |
Weston Andros Adamson | 6168f62 | 2012-09-10 14:00:46 -0400 | [diff] [blame] | 2816 | nfs_access_set_mask(entry, res.access); |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2817 | nfs_refresh_inode(inode, res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | } |
Trond Myklebust | c407d41 | 2010-04-16 16:22:48 -0400 | [diff] [blame] | 2819 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | return status; |
| 2821 | } |
| 2822 | |
| 2823 | static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry) |
| 2824 | { |
| 2825 | struct nfs4_exception exception = { }; |
| 2826 | int err; |
| 2827 | do { |
| 2828 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2829 | _nfs4_proc_access(inode, entry), |
| 2830 | &exception); |
| 2831 | } while (exception.retry); |
| 2832 | return err; |
| 2833 | } |
| 2834 | |
| 2835 | /* |
| 2836 | * TODO: For the time being, we don't try to get any attributes |
| 2837 | * along with any of the zero-copy operations READ, READDIR, |
| 2838 | * READLINK, WRITE. |
| 2839 | * |
| 2840 | * In the case of the first three, we want to put the GETATTR |
| 2841 | * after the read-type operation -- this is because it is hard |
| 2842 | * to predict the length of a GETATTR response in v4, and thus |
| 2843 | * align the READ data correctly. This means that the GETATTR |
| 2844 | * may end up partially falling into the page cache, and we should |
| 2845 | * shift it into the 'tail' of the xdr_buf before processing. |
| 2846 | * To do this efficiently, we need to know the total length |
| 2847 | * of data received, which doesn't seem to be available outside |
| 2848 | * of the RPC layer. |
| 2849 | * |
| 2850 | * In the case of WRITE, we also want to put the GETATTR after |
| 2851 | * the operation -- in this case because we want to make sure |
Trond Myklebust | 140150d | 2012-06-05 15:20:25 -0400 | [diff] [blame] | 2852 | * we get the post-operation mtime and size. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | * |
| 2854 | * Both of these changes to the XDR layer would in fact be quite |
| 2855 | * minor, but I decided to leave them for a subsequent patch. |
| 2856 | */ |
| 2857 | static int _nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2858 | unsigned int pgbase, unsigned int pglen) |
| 2859 | { |
| 2860 | struct nfs4_readlink args = { |
| 2861 | .fh = NFS_FH(inode), |
| 2862 | .pgbase = pgbase, |
| 2863 | .pglen = pglen, |
| 2864 | .pages = &page, |
| 2865 | }; |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2866 | struct nfs4_readlink_res res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | struct rpc_message msg = { |
| 2868 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK], |
| 2869 | .rpc_argp = &args, |
Benny Halevy | f50c700 | 2009-04-01 09:21:55 -0400 | [diff] [blame] | 2870 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | }; |
| 2872 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2873 | 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] | 2874 | } |
| 2875 | |
| 2876 | static int nfs4_proc_readlink(struct inode *inode, struct page *page, |
| 2877 | unsigned int pgbase, unsigned int pglen) |
| 2878 | { |
| 2879 | struct nfs4_exception exception = { }; |
| 2880 | int err; |
| 2881 | do { |
| 2882 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 2883 | _nfs4_proc_readlink(inode, page, pgbase, pglen), |
| 2884 | &exception); |
| 2885 | } while (exception.retry); |
| 2886 | return err; |
| 2887 | } |
| 2888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | /* |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2890 | * 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] | 2891 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | static int |
| 2893 | nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2894 | int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | { |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2896 | struct nfs_open_context *ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | struct nfs4_state *state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | int status = 0; |
| 2899 | |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2900 | ctx = alloc_nfs_open_context(dentry, FMODE_READ); |
| 2901 | if (IS_ERR(ctx)) |
| 2902 | return PTR_ERR(ctx); |
| 2903 | |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 2904 | sattr->ia_mode &= ~current_umask(); |
Trond Myklebust | 8626e4a | 2012-07-16 12:01:42 -0400 | [diff] [blame] | 2905 | state = nfs4_do_open(dir, dentry, ctx->mode, |
| 2906 | flags, sattr, ctx->cred, |
| 2907 | &ctx->mdsthreshold); |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2908 | d_drop(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | if (IS_ERR(state)) { |
| 2910 | status = PTR_ERR(state); |
Trond Myklebust | c0204fd | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 2911 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | } |
Trond Myklebust | d4d9cdc | 2007-10-02 18:38:53 -0400 | [diff] [blame] | 2913 | d_add(dentry, igrab(state->inode)); |
Trond Myklebust | d75340c | 2007-10-01 21:42:01 -0400 | [diff] [blame] | 2914 | nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2915 | ctx->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | out: |
Miklos Szeredi | 8867fe5 | 2012-06-05 15:10:19 +0200 | [diff] [blame] | 2917 | put_nfs_open_context(ctx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | return status; |
| 2919 | } |
| 2920 | |
| 2921 | static int _nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2922 | { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2923 | struct nfs_server *server = NFS_SERVER(dir); |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2924 | struct nfs_removeargs args = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | .fh = NFS_FH(dir), |
Linus Torvalds | 26fe575 | 2012-05-10 13:14:12 -0700 | [diff] [blame] | 2926 | .name = *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2928 | struct nfs_removeres res = { |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2929 | .server = server, |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2930 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | struct rpc_message msg = { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 2932 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE], |
| 2933 | .rpc_argp = &args, |
| 2934 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | }; |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 2936 | int status; |
Trond Myklebust | d346890 | 2010-04-16 16:22:50 -0400 | [diff] [blame] | 2937 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 2938 | 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] | 2939 | if (status == 0) |
Trond Myklebust | 16e4295 | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 2940 | update_changeattr(dir, &res.cinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | return status; |
| 2942 | } |
| 2943 | |
| 2944 | static int nfs4_proc_remove(struct inode *dir, struct qstr *name) |
| 2945 | { |
| 2946 | struct nfs4_exception exception = { }; |
| 2947 | int err; |
| 2948 | do { |
| 2949 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 2950 | _nfs4_proc_remove(dir, name), |
| 2951 | &exception); |
| 2952 | } while (exception.retry); |
| 2953 | return err; |
| 2954 | } |
| 2955 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2956 | 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] | 2957 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2958 | struct nfs_server *server = NFS_SERVER(dir); |
| 2959 | struct nfs_removeargs *args = msg->rpc_argp; |
| 2960 | struct nfs_removeres *res = msg->rpc_resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2962 | res->server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2964 | nfs41_init_sequence(&args->seq_args, &res->seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 2967 | static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) |
| 2968 | { |
| 2969 | if (nfs4_setup_sequence(NFS_SERVER(data->dir), |
| 2970 | &data->args.seq_args, |
| 2971 | &data->res.seq_res, |
| 2972 | task)) |
| 2973 | return; |
| 2974 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | } |
| 2976 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2977 | 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] | 2978 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2979 | struct nfs_removeres *res = task->tk_msg.rpc_resp; |
| 2980 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 2981 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 2982 | return 0; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 2983 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2984 | return 0; |
| 2985 | update_changeattr(dir, &res->cinfo); |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 2986 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | } |
| 2988 | |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2989 | static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir) |
| 2990 | { |
| 2991 | struct nfs_server *server = NFS_SERVER(dir); |
| 2992 | struct nfs_renameargs *arg = msg->rpc_argp; |
| 2993 | struct nfs_renameres *res = msg->rpc_resp; |
| 2994 | |
| 2995 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2996 | res->server = server; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 2997 | nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 2998 | } |
| 2999 | |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 3000 | static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) |
| 3001 | { |
| 3002 | if (nfs4_setup_sequence(NFS_SERVER(data->old_dir), |
| 3003 | &data->args.seq_args, |
| 3004 | &data->res.seq_res, |
| 3005 | task)) |
| 3006 | return; |
| 3007 | rpc_call_start(task); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, |
| 3011 | struct inode *new_dir) |
| 3012 | { |
| 3013 | struct nfs_renameres *res = task->tk_msg.rpc_resp; |
| 3014 | |
| 3015 | if (!nfs4_sequence_done(task, &res->seq_res)) |
| 3016 | return 0; |
| 3017 | if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN) |
| 3018 | return 0; |
| 3019 | |
| 3020 | update_changeattr(old_dir, &res->old_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3021 | update_changeattr(new_dir, &res->new_cinfo); |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 3022 | return 1; |
| 3023 | } |
| 3024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3026 | struct inode *new_dir, struct qstr *new_name) |
| 3027 | { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3028 | struct nfs_server *server = NFS_SERVER(old_dir); |
Jeff Layton | 920769f | 2010-09-17 17:30:25 -0400 | [diff] [blame] | 3029 | struct nfs_renameargs arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | .old_dir = NFS_FH(old_dir), |
| 3031 | .new_dir = NFS_FH(new_dir), |
| 3032 | .old_name = old_name, |
| 3033 | .new_name = new_name, |
| 3034 | }; |
Jeff Layton | e8582a8 | 2010-09-17 17:31:06 -0400 | [diff] [blame] | 3035 | struct nfs_renameres res = { |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3036 | .server = server, |
Trond Myklebust | 6caf2c8 | 2005-10-27 22:12:43 -0400 | [diff] [blame] | 3037 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | struct rpc_message msg = { |
| 3039 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME], |
| 3040 | .rpc_argp = &arg, |
| 3041 | .rpc_resp = &res, |
| 3042 | }; |
Trond Myklebust | 011fff7 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3043 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3045 | 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] | 3046 | if (!status) { |
| 3047 | update_changeattr(old_dir, &res.old_cinfo); |
| 3048 | update_changeattr(new_dir, &res.new_cinfo); |
| 3049 | } |
| 3050 | return status; |
| 3051 | } |
| 3052 | |
| 3053 | static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 3054 | struct inode *new_dir, struct qstr *new_name) |
| 3055 | { |
| 3056 | struct nfs4_exception exception = { }; |
| 3057 | int err; |
| 3058 | do { |
| 3059 | err = nfs4_handle_exception(NFS_SERVER(old_dir), |
| 3060 | _nfs4_proc_rename(old_dir, old_name, |
| 3061 | new_dir, new_name), |
| 3062 | &exception); |
| 3063 | } while (exception.retry); |
| 3064 | return err; |
| 3065 | } |
| 3066 | |
| 3067 | static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3068 | { |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3069 | struct nfs_server *server = NFS_SERVER(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | struct nfs4_link_arg arg = { |
| 3071 | .fh = NFS_FH(inode), |
| 3072 | .dir_fh = NFS_FH(dir), |
| 3073 | .name = name, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3074 | .bitmask = server->attr_bitmask, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | }; |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3076 | struct nfs4_link_res res = { |
| 3077 | .server = server, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3078 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | struct rpc_message msg = { |
| 3080 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK], |
| 3081 | .rpc_argp = &arg, |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3082 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | }; |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3084 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3085 | |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3086 | res.fattr = nfs_alloc_fattr(); |
Trond Myklebust | 778d281 | 2012-04-27 13:48:19 -0400 | [diff] [blame] | 3087 | if (res.fattr == NULL) |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3088 | goto out; |
| 3089 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3090 | 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] | 3091 | if (!status) { |
| 3092 | update_changeattr(dir, &res.cinfo); |
Trond Myklebust | 73a3d07 | 2006-05-25 01:40:47 -0400 | [diff] [blame] | 3093 | nfs_post_op_update_inode(inode, res.fattr); |
Trond Myklebust | 91ba2ee | 2005-10-27 22:12:42 -0400 | [diff] [blame] | 3094 | } |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3095 | out: |
Trond Myklebust | 136f262 | 2010-04-16 16:22:49 -0400 | [diff] [blame] | 3096 | nfs_free_fattr(res.fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | return status; |
| 3098 | } |
| 3099 | |
| 3100 | static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 3101 | { |
| 3102 | struct nfs4_exception exception = { }; |
| 3103 | int err; |
| 3104 | do { |
| 3105 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3106 | _nfs4_proc_link(inode, dir, name), |
| 3107 | &exception); |
| 3108 | } while (exception.retry); |
| 3109 | return err; |
| 3110 | } |
| 3111 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3112 | struct nfs4_createdata { |
| 3113 | struct rpc_message msg; |
| 3114 | struct nfs4_create_arg arg; |
| 3115 | struct nfs4_create_res res; |
| 3116 | struct nfs_fh fh; |
| 3117 | struct nfs_fattr fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3118 | }; |
| 3119 | |
| 3120 | static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir, |
| 3121 | struct qstr *name, struct iattr *sattr, u32 ftype) |
| 3122 | { |
| 3123 | struct nfs4_createdata *data; |
| 3124 | |
| 3125 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 3126 | if (data != NULL) { |
| 3127 | struct nfs_server *server = NFS_SERVER(dir); |
| 3128 | |
| 3129 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE]; |
| 3130 | data->msg.rpc_argp = &data->arg; |
| 3131 | data->msg.rpc_resp = &data->res; |
| 3132 | data->arg.dir_fh = NFS_FH(dir); |
| 3133 | data->arg.server = server; |
| 3134 | data->arg.name = name; |
| 3135 | data->arg.attrs = sattr; |
| 3136 | data->arg.ftype = ftype; |
| 3137 | data->arg.bitmask = server->attr_bitmask; |
| 3138 | data->res.server = server; |
| 3139 | data->res.fh = &data->fh; |
| 3140 | data->res.fattr = &data->fattr; |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3141 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3142 | } |
| 3143 | return data; |
| 3144 | } |
| 3145 | |
| 3146 | static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data) |
| 3147 | { |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3148 | 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] | 3149 | &data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3150 | if (status == 0) { |
| 3151 | update_changeattr(dir, &data->res.dir_cinfo); |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3152 | status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); |
| 3153 | } |
| 3154 | return status; |
| 3155 | } |
| 3156 | |
| 3157 | static void nfs4_free_createdata(struct nfs4_createdata *data) |
| 3158 | { |
| 3159 | kfree(data); |
| 3160 | } |
| 3161 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3162 | static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3163 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3165 | struct nfs4_createdata *data; |
| 3166 | int status = -ENAMETOOLONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3168 | if (len > NFS4_MAXPATHLEN) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3169 | goto out; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3170 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3171 | status = -ENOMEM; |
| 3172 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK); |
| 3173 | if (data == NULL) |
| 3174 | goto out; |
| 3175 | |
| 3176 | data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK]; |
| 3177 | data->arg.u.symlink.pages = &page; |
| 3178 | data->arg.u.symlink.len = len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3180 | status = nfs4_do_create(dir, dentry, data); |
| 3181 | |
| 3182 | nfs4_free_createdata(data); |
| 3183 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | return status; |
| 3185 | } |
| 3186 | |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 3187 | static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3188 | struct page *page, unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | { |
| 3190 | struct nfs4_exception exception = { }; |
| 3191 | int err; |
| 3192 | do { |
| 3193 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 3194 | _nfs4_proc_symlink(dir, dentry, page, |
| 3195 | len, sattr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | &exception); |
| 3197 | } while (exception.retry); |
| 3198 | return err; |
| 3199 | } |
| 3200 | |
| 3201 | static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3202 | struct iattr *sattr) |
| 3203 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3204 | struct nfs4_createdata *data; |
| 3205 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3207 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); |
| 3208 | if (data == NULL) |
| 3209 | goto out; |
| 3210 | |
| 3211 | status = nfs4_do_create(dir, dentry, data); |
| 3212 | |
| 3213 | nfs4_free_createdata(data); |
| 3214 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3215 | return status; |
| 3216 | } |
| 3217 | |
| 3218 | static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, |
| 3219 | struct iattr *sattr) |
| 3220 | { |
| 3221 | struct nfs4_exception exception = { }; |
| 3222 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3223 | |
| 3224 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | do { |
| 3226 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3227 | _nfs4_proc_mkdir(dir, dentry, sattr), |
| 3228 | &exception); |
| 3229 | } while (exception.retry); |
| 3230 | return err; |
| 3231 | } |
| 3232 | |
| 3233 | static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3234 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | { |
| 3236 | struct inode *dir = dentry->d_inode; |
| 3237 | struct nfs4_readdir_arg args = { |
| 3238 | .fh = NFS_FH(dir), |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3239 | .pages = pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | .pgbase = 0, |
| 3241 | .count = count, |
Trond Myklebust | 96d25e5 | 2009-11-11 16:15:42 +0900 | [diff] [blame] | 3242 | .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask, |
Bryan Schumaker | 82f2e54 | 2010-10-21 16:33:18 -0400 | [diff] [blame] | 3243 | .plus = plus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | }; |
| 3245 | struct nfs4_readdir_res res; |
| 3246 | struct rpc_message msg = { |
| 3247 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR], |
| 3248 | .rpc_argp = &args, |
| 3249 | .rpc_resp = &res, |
| 3250 | .rpc_cred = cred, |
| 3251 | }; |
| 3252 | int status; |
| 3253 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3254 | dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__, |
Trond Myklebust | eadf459 | 2005-06-22 17:16:39 +0000 | [diff] [blame] | 3255 | dentry->d_parent->d_name.name, |
| 3256 | dentry->d_name.name, |
| 3257 | (unsigned long long)cookie); |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3258 | nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | res.pgbase = args.pgbase; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3260 | 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] | 3261 | if (status >= 0) { |
Trond Myklebust | c3f52af | 2012-09-03 14:56:02 -0400 | [diff] [blame] | 3262 | memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE); |
Trond Myklebust | ac39612 | 2010-11-15 20:26:22 -0500 | [diff] [blame] | 3263 | status += args.pgbase; |
| 3264 | } |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 3265 | |
| 3266 | nfs_invalidate_atime(dir); |
| 3267 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 3268 | dprintk("%s: returns %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | return status; |
| 3270 | } |
| 3271 | |
| 3272 | static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3273 | u64 cookie, struct page **pages, unsigned int count, int plus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | { |
| 3275 | struct nfs4_exception exception = { }; |
| 3276 | int err; |
| 3277 | do { |
| 3278 | err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), |
| 3279 | _nfs4_proc_readdir(dentry, cred, cookie, |
Bryan Schumaker | 56e4ebf | 2010-10-20 15:44:37 -0400 | [diff] [blame] | 3280 | pages, count, plus), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | &exception); |
| 3282 | } while (exception.retry); |
| 3283 | return err; |
| 3284 | } |
| 3285 | |
| 3286 | static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3287 | struct iattr *sattr, dev_t rdev) |
| 3288 | { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3289 | struct nfs4_createdata *data; |
| 3290 | int mode = sattr->ia_mode; |
| 3291 | int status = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | |
| 3293 | BUG_ON(!(sattr->ia_valid & ATTR_MODE)); |
| 3294 | 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] | 3295 | |
| 3296 | data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK); |
| 3297 | if (data == NULL) |
| 3298 | goto out; |
| 3299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3300 | if (S_ISFIFO(mode)) |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3301 | data->arg.ftype = NF4FIFO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | else if (S_ISBLK(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3303 | data->arg.ftype = NF4BLK; |
| 3304 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3305 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | } |
| 3307 | else if (S_ISCHR(mode)) { |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3308 | data->arg.ftype = NF4CHR; |
| 3309 | data->arg.u.device.specdata1 = MAJOR(rdev); |
| 3310 | data->arg.u.device.specdata2 = MINOR(rdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | |
Trond Myklebust | 57dc9a5 | 2008-06-20 15:35:32 -0400 | [diff] [blame] | 3313 | status = nfs4_do_create(dir, dentry, data); |
| 3314 | |
| 3315 | nfs4_free_createdata(data); |
| 3316 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3317 | return status; |
| 3318 | } |
| 3319 | |
| 3320 | static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, |
| 3321 | struct iattr *sattr, dev_t rdev) |
| 3322 | { |
| 3323 | struct nfs4_exception exception = { }; |
| 3324 | int err; |
Aneesh Kumar K.V | a8a5da9 | 2010-12-09 11:35:14 +0000 | [diff] [blame] | 3325 | |
| 3326 | sattr->ia_mode &= ~current_umask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | do { |
| 3328 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 3329 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
| 3330 | &exception); |
| 3331 | } while (exception.retry); |
| 3332 | return err; |
| 3333 | } |
| 3334 | |
| 3335 | static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3336 | struct nfs_fsstat *fsstat) |
| 3337 | { |
| 3338 | struct nfs4_statfs_arg args = { |
| 3339 | .fh = fhandle, |
| 3340 | .bitmask = server->attr_bitmask, |
| 3341 | }; |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3342 | struct nfs4_statfs_res res = { |
| 3343 | .fsstat = fsstat, |
| 3344 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | struct rpc_message msg = { |
| 3346 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS], |
| 3347 | .rpc_argp = &args, |
Benny Halevy | 24ad148 | 2009-04-01 09:21:56 -0400 | [diff] [blame] | 3348 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | }; |
| 3350 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3351 | nfs_fattr_init(fsstat->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3352 | 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] | 3353 | } |
| 3354 | |
| 3355 | static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat) |
| 3356 | { |
| 3357 | struct nfs4_exception exception = { }; |
| 3358 | int err; |
| 3359 | do { |
| 3360 | err = nfs4_handle_exception(server, |
| 3361 | _nfs4_proc_statfs(server, fhandle, fsstat), |
| 3362 | &exception); |
| 3363 | } while (exception.retry); |
| 3364 | return err; |
| 3365 | } |
| 3366 | |
| 3367 | static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3368 | struct nfs_fsinfo *fsinfo) |
| 3369 | { |
| 3370 | struct nfs4_fsinfo_arg args = { |
| 3371 | .fh = fhandle, |
| 3372 | .bitmask = server->attr_bitmask, |
| 3373 | }; |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3374 | struct nfs4_fsinfo_res res = { |
| 3375 | .fsinfo = fsinfo, |
| 3376 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | struct rpc_message msg = { |
| 3378 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO], |
| 3379 | .rpc_argp = &args, |
Benny Halevy | 3dda5e4 | 2009-04-01 09:21:57 -0400 | [diff] [blame] | 3380 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | }; |
| 3382 | |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3383 | 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] | 3384 | } |
| 3385 | |
| 3386 | static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3387 | { |
| 3388 | struct nfs4_exception exception = { }; |
| 3389 | int err; |
| 3390 | |
| 3391 | do { |
| 3392 | err = nfs4_handle_exception(server, |
| 3393 | _nfs4_do_fsinfo(server, fhandle, fsinfo), |
| 3394 | &exception); |
| 3395 | } while (exception.retry); |
| 3396 | return err; |
| 3397 | } |
| 3398 | |
| 3399 | static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo) |
| 3400 | { |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3401 | int error; |
| 3402 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3403 | nfs_fattr_init(fsinfo->fattr); |
Bryan Schumaker | e38eb65 | 2012-06-20 15:53:40 -0400 | [diff] [blame] | 3404 | error = nfs4_do_fsinfo(server, fhandle, fsinfo); |
| 3405 | if (error == 0) |
| 3406 | set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype); |
| 3407 | |
| 3408 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3412 | struct nfs_pathconf *pathconf) |
| 3413 | { |
| 3414 | struct nfs4_pathconf_arg args = { |
| 3415 | .fh = fhandle, |
| 3416 | .bitmask = server->attr_bitmask, |
| 3417 | }; |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3418 | struct nfs4_pathconf_res res = { |
| 3419 | .pathconf = pathconf, |
| 3420 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | struct rpc_message msg = { |
| 3422 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF], |
| 3423 | .rpc_argp = &args, |
Benny Halevy | d45b298 | 2009-04-01 09:21:58 -0400 | [diff] [blame] | 3424 | .rpc_resp = &res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | }; |
| 3426 | |
| 3427 | /* None of the pathconf attributes are mandatory to implement */ |
| 3428 | if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) { |
| 3429 | memset(pathconf, 0, sizeof(*pathconf)); |
| 3430 | return 0; |
| 3431 | } |
| 3432 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 3433 | nfs_fattr_init(pathconf->fattr); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3434 | 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] | 3435 | } |
| 3436 | |
| 3437 | static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 3438 | struct nfs_pathconf *pathconf) |
| 3439 | { |
| 3440 | struct nfs4_exception exception = { }; |
| 3441 | int err; |
| 3442 | |
| 3443 | do { |
| 3444 | err = nfs4_handle_exception(server, |
| 3445 | _nfs4_proc_pathconf(server, fhandle, pathconf), |
| 3446 | &exception); |
| 3447 | } while (exception.retry); |
| 3448 | return err; |
| 3449 | } |
| 3450 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3451 | void __nfs4_read_done_cb(struct nfs_read_data *data) |
| 3452 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3453 | nfs_invalidate_atime(data->header->inode); |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3454 | } |
| 3455 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3456 | 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] | 3457 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3458 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3460 | if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3461 | rpc_restart_call_prepare(task); |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3462 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | } |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 3464 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3465 | __nfs4_read_done_cb(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | if (task->tk_status > 0) |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3467 | renew_lease(server, data->timestamp); |
| 3468 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | } |
| 3470 | |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3471 | static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data) |
| 3472 | { |
| 3473 | |
| 3474 | dprintk("--> %s\n", __func__); |
| 3475 | |
| 3476 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3477 | return -EAGAIN; |
| 3478 | |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3479 | return data->read_done_cb ? data->read_done_cb(task, data) : |
| 3480 | nfs4_read_done_cb(task, data); |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3481 | } |
| 3482 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3483 | 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] | 3484 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | data->timestamp = jiffies; |
Andy Adamson | cbdabc7 | 2011-03-01 01:34:20 +0000 | [diff] [blame] | 3486 | data->read_done_cb = nfs4_read_done_cb; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3487 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3488 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | } |
| 3490 | |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3491 | static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data) |
| 3492 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3493 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 3494 | &data->args.seq_args, |
| 3495 | &data->res.seq_res, |
| 3496 | task)) |
| 3497 | return; |
| 3498 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | } |
| 3500 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3501 | 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] | 3502 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3503 | struct inode *inode = data->header->inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3505 | 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] | 3506 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3507 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | } |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3509 | if (task->tk_status >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | renew_lease(NFS_SERVER(inode), data->timestamp); |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3511 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3512 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3513 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | } |
| 3515 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3516 | static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data) |
| 3517 | { |
| 3518 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3519 | return -EAGAIN; |
Benny Halevy | d20581a | 2011-05-22 19:52:03 +0300 | [diff] [blame] | 3520 | return data->write_done_cb ? data->write_done_cb(task, data) : |
| 3521 | nfs4_write_done_cb(task, data); |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3524 | static |
| 3525 | 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] | 3526 | { |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3527 | const struct nfs_pgio_header *hdr = data->header; |
| 3528 | |
| 3529 | /* Don't request attributes for pNFS or O_DIRECT writes */ |
| 3530 | if (data->ds_clp != NULL || hdr->dreq != NULL) |
| 3531 | return false; |
| 3532 | /* Otherwise, request attributes if and only if we don't hold |
| 3533 | * a delegation |
| 3534 | */ |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 3535 | return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0; |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3536 | } |
Fred Isaman | a69aef1 | 2011-03-03 15:13:47 +0000 | [diff] [blame] | 3537 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3538 | 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] | 3539 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3540 | struct nfs_server *server = NFS_SERVER(data->header->inode); |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3541 | |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3542 | if (!nfs4_write_need_cache_consistency_data(data)) { |
Fred Isaman | 7ffd106 | 2011-03-03 15:13:46 +0000 | [diff] [blame] | 3543 | data->args.bitmask = NULL; |
| 3544 | data->res.fattr = NULL; |
| 3545 | } else |
| 3546 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | 5a37f85 | 2012-04-28 14:55:16 -0400 | [diff] [blame] | 3547 | |
Fred Isaman | b029bc9 | 2011-03-03 15:13:42 +0000 | [diff] [blame] | 3548 | if (!data->write_done_cb) |
| 3549 | data->write_done_cb = nfs4_write_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3550 | data->res.server = server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | data->timestamp = jiffies; |
| 3552 | |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3553 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3554 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3557 | static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data) |
| 3558 | { |
Fred Isaman | cd84160 | 2012-04-20 14:47:44 -0400 | [diff] [blame] | 3559 | if (nfs4_setup_sequence(NFS_SERVER(data->header->inode), |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 3560 | &data->args.seq_args, |
| 3561 | &data->res.seq_res, |
| 3562 | task)) |
| 3563 | return; |
| 3564 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | } |
| 3566 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3567 | static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) |
| 3568 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | if (nfs4_setup_sequence(NFS_SERVER(data->inode), |
| 3570 | &data->args.seq_args, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3571 | &data->res.seq_res, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | task)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | return; |
| 3574 | rpc_call_start(task); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3575 | } |
| 3576 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3577 | 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] | 3578 | { |
| 3579 | struct inode *inode = data->inode; |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3580 | |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3581 | if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 3582 | rpc_restart_call_prepare(task); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3583 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | } |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3585 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3588 | 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] | 3589 | { |
| 3590 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 3591 | return -EAGAIN; |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3592 | return data->commit_done_cb(task, data); |
Fred Isaman | 5f45243 | 2011-03-23 13:27:46 +0000 | [diff] [blame] | 3593 | } |
| 3594 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3595 | 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] | 3596 | { |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 3597 | struct nfs_server *server = NFS_SERVER(data->inode); |
Fred Isaman | 988b6dc | 2011-03-23 13:27:52 +0000 | [diff] [blame] | 3598 | |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 3599 | if (data->commit_done_cb == NULL) |
| 3600 | data->commit_done_cb = nfs4_commit_done_cb; |
Trond Myklebust | 4f9838c | 2005-10-27 22:12:44 -0400 | [diff] [blame] | 3601 | data->res.server = server; |
Trond Myklebust | bdc7f02 | 2007-07-14 15:40:00 -0400 | [diff] [blame] | 3602 | msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 3603 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | } |
| 3605 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3606 | struct nfs4_renewdata { |
| 3607 | struct nfs_client *client; |
| 3608 | unsigned long timestamp; |
| 3609 | }; |
| 3610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | /* |
| 3612 | * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special |
| 3613 | * standalone procedure for queueing an asynchronous RENEW. |
| 3614 | */ |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3615 | static void nfs4_renew_release(void *calldata) |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3616 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3617 | struct nfs4_renewdata *data = calldata; |
| 3618 | struct nfs_client *clp = data->client; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3619 | |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3620 | if (atomic_read(&clp->cl_count) > 1) |
| 3621 | nfs4_schedule_state_renewal(clp); |
| 3622 | nfs_put_client(clp); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3623 | kfree(data); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3624 | } |
| 3625 | |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3626 | static void nfs4_renew_done(struct rpc_task *task, void *calldata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | { |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3628 | struct nfs4_renewdata *data = calldata; |
| 3629 | struct nfs_client *clp = data->client; |
| 3630 | unsigned long timestamp = data->timestamp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | |
| 3632 | if (task->tk_status < 0) { |
Trond Myklebust | 95baa25 | 2009-05-26 14:51:00 -0400 | [diff] [blame] | 3633 | /* Unless we're shutting down, schedule state recovery! */ |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3634 | if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0) |
| 3635 | return; |
| 3636 | if (task->tk_status != NFS4ERR_CB_PATH_DOWN) { |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3637 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | 042b60b | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3638 | return; |
| 3639 | } |
| 3640 | nfs4_schedule_path_down_recovery(clp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | } |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3642 | do_renew_lease(clp, timestamp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3645 | static const struct rpc_call_ops nfs4_renew_ops = { |
| 3646 | .rpc_call_done = nfs4_renew_done, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 3647 | .rpc_release = nfs4_renew_release, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 3648 | }; |
| 3649 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3650 | 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] | 3651 | { |
| 3652 | struct rpc_message msg = { |
| 3653 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3654 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3655 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | }; |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3657 | struct nfs4_renewdata *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3659 | if (renew_flags == 0) |
| 3660 | return 0; |
Alexandros Batsakis | 0851de06 | 2010-02-05 03:45:06 -0800 | [diff] [blame] | 3661 | if (!atomic_inc_not_zero(&clp->cl_count)) |
| 3662 | return -EIO; |
Trond Myklebust | b569ad3 | 2011-08-24 15:07:35 -0400 | [diff] [blame] | 3663 | data = kmalloc(sizeof(*data), GFP_NOFS); |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3664 | if (data == NULL) |
| 3665 | return -ENOMEM; |
| 3666 | data->client = clp; |
| 3667 | data->timestamp = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT, |
Chuck Lever | 9bc4e3c | 2010-05-07 13:34:17 -0400 | [diff] [blame] | 3669 | &nfs4_renew_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3670 | } |
| 3671 | |
Trond Myklebust | 8534d4e | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 3672 | 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] | 3673 | { |
| 3674 | struct rpc_message msg = { |
| 3675 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW], |
| 3676 | .rpc_argp = clp, |
Trond Myklebust | b4454fe | 2006-01-03 09:55:25 +0100 | [diff] [blame] | 3677 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | }; |
| 3679 | unsigned long now = jiffies; |
| 3680 | int status; |
| 3681 | |
| 3682 | status = rpc_call_sync(clp->cl_rpcclient, &msg, 0); |
| 3683 | if (status < 0) |
| 3684 | return status; |
Trond Myklebust | 452e935 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 3685 | do_renew_lease(clp, now); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | return 0; |
| 3687 | } |
| 3688 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3689 | static inline int nfs4_server_supports_acls(struct nfs_server *server) |
| 3690 | { |
| 3691 | return (server->caps & NFS_CAP_ACLS) |
| 3692 | && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL) |
| 3693 | && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL); |
| 3694 | } |
| 3695 | |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3696 | /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that |
| 3697 | * 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] | 3698 | * the stack. |
| 3699 | */ |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3700 | #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE) |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3701 | |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3702 | static int buf_to_pages_noslab(const void *buf, size_t buflen, |
| 3703 | struct page **pages, unsigned int *pgbase) |
| 3704 | { |
| 3705 | struct page *newpage, **spages; |
| 3706 | int rc = 0; |
| 3707 | size_t len; |
| 3708 | spages = pages; |
| 3709 | |
| 3710 | do { |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3711 | len = min_t(size_t, PAGE_SIZE, buflen); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3712 | newpage = alloc_page(GFP_KERNEL); |
| 3713 | |
| 3714 | if (newpage == NULL) |
| 3715 | goto unwind; |
| 3716 | memcpy(page_address(newpage), buf, len); |
| 3717 | buf += len; |
| 3718 | buflen -= len; |
| 3719 | *pages++ = newpage; |
| 3720 | rc++; |
| 3721 | } while (buflen != 0); |
| 3722 | |
| 3723 | return rc; |
| 3724 | |
| 3725 | unwind: |
| 3726 | for(; rc > 0; rc--) |
| 3727 | __free_page(spages[rc-1]); |
| 3728 | return -ENOMEM; |
| 3729 | } |
| 3730 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3731 | struct nfs4_cached_acl { |
| 3732 | int cached; |
| 3733 | size_t len; |
Andrew Morton | 3e9d415 | 2005-06-22 17:16:28 +0000 | [diff] [blame] | 3734 | char data[0]; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3735 | }; |
| 3736 | |
| 3737 | 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] | 3738 | { |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3739 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3740 | |
| 3741 | spin_lock(&inode->i_lock); |
| 3742 | kfree(nfsi->nfs4_acl); |
| 3743 | nfsi->nfs4_acl = acl; |
| 3744 | spin_unlock(&inode->i_lock); |
| 3745 | } |
| 3746 | |
| 3747 | static void nfs4_zap_acl_attr(struct inode *inode) |
| 3748 | { |
| 3749 | nfs4_set_cached_acl(inode, NULL); |
| 3750 | } |
| 3751 | |
| 3752 | static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen) |
| 3753 | { |
| 3754 | struct nfs_inode *nfsi = NFS_I(inode); |
| 3755 | struct nfs4_cached_acl *acl; |
| 3756 | int ret = -ENOENT; |
| 3757 | |
| 3758 | spin_lock(&inode->i_lock); |
| 3759 | acl = nfsi->nfs4_acl; |
| 3760 | if (acl == NULL) |
| 3761 | goto out; |
| 3762 | if (buf == NULL) /* user is just asking for length */ |
| 3763 | goto out_len; |
| 3764 | if (acl->cached == 0) |
| 3765 | goto out; |
| 3766 | ret = -ERANGE; /* see getxattr(2) man page */ |
| 3767 | if (acl->len > buflen) |
| 3768 | goto out; |
| 3769 | memcpy(buf, acl->data, acl->len); |
| 3770 | out_len: |
| 3771 | ret = acl->len; |
| 3772 | out: |
| 3773 | spin_unlock(&inode->i_lock); |
| 3774 | return ret; |
| 3775 | } |
| 3776 | |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3777 | 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] | 3778 | { |
| 3779 | struct nfs4_cached_acl *acl; |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3780 | size_t buflen = sizeof(*acl) + acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3781 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3782 | if (buflen <= PAGE_SIZE) { |
Trond Myklebust | b291f1b | 2012-08-14 18:30:41 -0400 | [diff] [blame] | 3783 | acl = kmalloc(buflen, GFP_KERNEL); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3784 | if (acl == NULL) |
| 3785 | goto out; |
| 3786 | acl->cached = 1; |
Sachin Prabhu | 5794d21 | 2012-04-17 14:36:40 +0100 | [diff] [blame] | 3787 | _copy_from_pages(acl->data, pages, pgbase, acl_len); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3788 | } else { |
| 3789 | acl = kmalloc(sizeof(*acl), GFP_KERNEL); |
| 3790 | if (acl == NULL) |
| 3791 | goto out; |
| 3792 | acl->cached = 0; |
| 3793 | } |
| 3794 | acl->len = acl_len; |
| 3795 | out: |
| 3796 | nfs4_set_cached_acl(inode, acl); |
| 3797 | } |
| 3798 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3799 | /* |
| 3800 | * The getxattr API returns the required buffer length when called with a |
| 3801 | * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating |
| 3802 | * the required buf. On a NULL buf, we send a page of data to the server |
| 3803 | * guessing that the ACL request can be serviced by a page. If so, we cache |
| 3804 | * up to the page of ACL data, and the 2nd call to getxattr is serviced by |
| 3805 | * the cache. If not so, we throw away the page, and cache the required |
| 3806 | * length. The next getxattr call will then produce another round trip to |
| 3807 | * the server, this time with the input buf of the required size. |
| 3808 | */ |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3809 | 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] | 3810 | { |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3811 | struct page *pages[NFS4ACL_MAXPAGES] = {NULL, }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3812 | struct nfs_getaclargs args = { |
| 3813 | .fh = NFS_FH(inode), |
| 3814 | .acl_pages = pages, |
| 3815 | .acl_len = buflen, |
| 3816 | }; |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3817 | struct nfs_getaclres res = { |
| 3818 | .acl_len = buflen, |
| 3819 | }; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3820 | struct rpc_message msg = { |
| 3821 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL], |
| 3822 | .rpc_argp = &args, |
Benny Halevy | 663c79b | 2009-04-01 09:21:59 -0400 | [diff] [blame] | 3823 | .rpc_resp = &res, |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3824 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3825 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
| 3826 | int ret = -ENOMEM, i; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3827 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3828 | /* As long as we're doing a round trip to the server anyway, |
| 3829 | * let's be prepared for a page of acl data. */ |
| 3830 | if (npages == 0) |
| 3831 | npages = 1; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3832 | if (npages > ARRAY_SIZE(pages)) |
| 3833 | return -ERANGE; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3834 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3835 | for (i = 0; i < npages; i++) { |
| 3836 | pages[i] = alloc_page(GFP_KERNEL); |
| 3837 | if (!pages[i]) |
| 3838 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3839 | } |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3840 | |
| 3841 | /* for decoding across pages */ |
| 3842 | res.acl_scratch = alloc_page(GFP_KERNEL); |
| 3843 | if (!res.acl_scratch) |
| 3844 | goto out_free; |
| 3845 | |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3846 | args.acl_len = npages * PAGE_SIZE; |
| 3847 | args.acl_pgbase = 0; |
Sachin Prabhu | 5a00689 | 2012-04-17 14:35:39 +0100 | [diff] [blame] | 3848 | |
Peng Tao | de040be | 2012-01-10 22:42:47 +0800 | [diff] [blame] | 3849 | 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] | 3850 | __func__, buf, buflen, npages, args.acl_len); |
| 3851 | ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), |
| 3852 | &msg, &args.seq_args, &res.seq_res, 0); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3853 | if (ret) |
| 3854 | goto out_free; |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3855 | |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3856 | /* Handle the case where the passed-in buffer is too short */ |
| 3857 | if (res.acl_flags & NFS4_ACL_TRUNC) { |
| 3858 | /* Did the user only issue a request for the acl length? */ |
| 3859 | if (buf == NULL) |
| 3860 | goto out_ok; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3861 | ret = -ERANGE; |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3862 | goto out_free; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3863 | } |
Trond Myklebust | 1f1ea6c | 2012-08-26 11:44:43 -0700 | [diff] [blame] | 3864 | nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len); |
| 3865 | if (buf) |
| 3866 | _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len); |
| 3867 | out_ok: |
| 3868 | ret = res.acl_len; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3869 | out_free: |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3870 | for (i = 0; i < npages; i++) |
| 3871 | if (pages[i]) |
| 3872 | __free_page(pages[i]); |
Trond Myklebust | 331818f | 2012-02-03 18:30:53 -0500 | [diff] [blame] | 3873 | if (res.acl_scratch) |
| 3874 | __free_page(res.acl_scratch); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3875 | return ret; |
| 3876 | } |
| 3877 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3878 | static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen) |
| 3879 | { |
| 3880 | struct nfs4_exception exception = { }; |
| 3881 | ssize_t ret; |
| 3882 | do { |
| 3883 | ret = __nfs4_get_acl_uncached(inode, buf, buflen); |
| 3884 | if (ret >= 0) |
| 3885 | break; |
| 3886 | ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception); |
| 3887 | } while (exception.retry); |
| 3888 | return ret; |
| 3889 | } |
| 3890 | |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3891 | static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen) |
| 3892 | { |
| 3893 | struct nfs_server *server = NFS_SERVER(inode); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3894 | int ret; |
| 3895 | |
| 3896 | if (!nfs4_server_supports_acls(server)) |
| 3897 | return -EOPNOTSUPP; |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3898 | ret = nfs_revalidate_inode(server, inode); |
| 3899 | if (ret < 0) |
| 3900 | return ret; |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3901 | if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) |
| 3902 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3903 | ret = nfs4_read_cached_acl(inode, buf, buflen); |
| 3904 | if (ret != -ENOENT) |
Andy Adamson | bf118a3 | 2011-12-07 11:55:27 -0500 | [diff] [blame] | 3905 | /* -ENOENT is returned if there is no ACL or if there is an ACL |
| 3906 | * but no cached acl data, just the acl length */ |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3907 | return ret; |
| 3908 | return nfs4_get_acl_uncached(inode, buf, buflen); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 3909 | } |
| 3910 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3911 | 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] | 3912 | { |
| 3913 | struct nfs_server *server = NFS_SERVER(inode); |
| 3914 | struct page *pages[NFS4ACL_MAXPAGES]; |
| 3915 | struct nfs_setaclargs arg = { |
| 3916 | .fh = NFS_FH(inode), |
| 3917 | .acl_pages = pages, |
| 3918 | .acl_len = buflen, |
| 3919 | }; |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3920 | struct nfs_setaclres res; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3921 | struct rpc_message msg = { |
| 3922 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL], |
| 3923 | .rpc_argp = &arg, |
Benny Halevy | 73c403a | 2009-04-01 09:22:01 -0400 | [diff] [blame] | 3924 | .rpc_resp = &res, |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3925 | }; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3926 | unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE); |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3927 | int ret, i; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3928 | |
| 3929 | if (!nfs4_server_supports_acls(server)) |
| 3930 | return -EOPNOTSUPP; |
Trond Myklebust | 21f498c | 2012-08-24 10:59:25 -0400 | [diff] [blame] | 3931 | if (npages > ARRAY_SIZE(pages)) |
| 3932 | return -ERANGE; |
Neil Horman | e9e3d72 | 2011-03-04 19:26:03 -0500 | [diff] [blame] | 3933 | i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase); |
| 3934 | if (i < 0) |
| 3935 | return i; |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 3936 | nfs4_inode_return_delegation(inode); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 3937 | 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] | 3938 | |
| 3939 | /* |
| 3940 | * Free each page after tx, so the only ref left is |
| 3941 | * held by the network stack |
| 3942 | */ |
| 3943 | for (; i > 0; i--) |
| 3944 | put_page(pages[i-1]); |
| 3945 | |
Aneesh Kumar K.V | 08a22b3 | 2010-12-01 10:42:16 +0000 | [diff] [blame] | 3946 | /* |
| 3947 | * Acl update can result in inode attribute update. |
| 3948 | * so mark the attribute cache invalid. |
| 3949 | */ |
| 3950 | spin_lock(&inode->i_lock); |
| 3951 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR; |
| 3952 | spin_unlock(&inode->i_lock); |
Trond Myklebust | f41f741 | 2008-06-11 17:39:04 -0400 | [diff] [blame] | 3953 | nfs_access_zap_cache(inode); |
| 3954 | nfs_zap_acl_cache(inode); |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 3955 | return ret; |
| 3956 | } |
| 3957 | |
Trond Myklebust | 16b4289 | 2006-08-24 12:27:15 -0400 | [diff] [blame] | 3958 | static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen) |
| 3959 | { |
| 3960 | struct nfs4_exception exception = { }; |
| 3961 | int err; |
| 3962 | do { |
| 3963 | err = nfs4_handle_exception(NFS_SERVER(inode), |
| 3964 | __nfs4_proc_set_acl(inode, buf, buflen), |
| 3965 | &exception); |
| 3966 | } while (exception.retry); |
| 3967 | return err; |
| 3968 | } |
| 3969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | static int |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3971 | 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] | 3972 | { |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 3973 | struct nfs_client *clp = server->nfs_client; |
| 3974 | |
| 3975 | if (task->tk_status >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | return 0; |
| 3977 | switch(task->tk_status) { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 3978 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3979 | case -NFS4ERR_ADMIN_REVOKED: |
| 3980 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | 1497748 | 2012-03-27 18:31:25 -0400 | [diff] [blame] | 3981 | if (state == NULL) |
| 3982 | break; |
| 3983 | nfs_remove_bad_delegation(state->inode); |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 3984 | case -NFS4ERR_OPENMODE: |
| 3985 | if (state == NULL) |
| 3986 | break; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3987 | nfs4_schedule_stateid_recovery(server, state); |
| 3988 | goto wait_on_recovery; |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 3989 | case -NFS4ERR_EXPIRED: |
| 3990 | if (state != NULL) |
| 3991 | nfs4_schedule_stateid_recovery(server, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3992 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 3993 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 3994 | nfs4_schedule_lease_recovery(clp); |
| 3995 | goto wait_on_recovery; |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 3996 | #if defined(CONFIG_NFS_V4_1) |
| 3997 | case -NFS4ERR_BADSESSION: |
| 3998 | case -NFS4ERR_BADSLOT: |
| 3999 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 4000 | case -NFS4ERR_DEADSESSION: |
| 4001 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 4002 | case -NFS4ERR_SEQ_FALSE_RETRY: |
| 4003 | case -NFS4ERR_SEQ_MISORDERED: |
| 4004 | dprintk("%s ERROR %d, Reset session\n", __func__, |
| 4005 | task->tk_status); |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 4006 | nfs4_schedule_session_recovery(clp->cl_session, task->tk_status); |
Andy Adamson | 4745e31 | 2009-04-01 09:22:42 -0400 | [diff] [blame] | 4007 | task->tk_status = 0; |
| 4008 | return -EAGAIN; |
| 4009 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 4011 | nfs_inc_server_stats(server, NFSIOS_DELAY); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 4012 | case -NFS4ERR_GRACE: |
Jeff Layton | 2c64348 | 2010-01-07 09:42:03 -0500 | [diff] [blame] | 4013 | case -EKEYEXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4014 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 4015 | task->tk_status = 0; |
| 4016 | return -EAGAIN; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 4017 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | case -NFS4ERR_OLD_STATEID: |
| 4019 | task->tk_status = 0; |
| 4020 | return -EAGAIN; |
| 4021 | } |
| 4022 | task->tk_status = nfs4_map_errors(task->tk_status); |
| 4023 | return 0; |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4024 | wait_on_recovery: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4025 | rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4026 | if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) |
| 4027 | rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task); |
| 4028 | task->tk_status = 0; |
| 4029 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | } |
| 4031 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4032 | static void nfs4_init_boot_verifier(const struct nfs_client *clp, |
| 4033 | nfs4_verifier *bootverf) |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4034 | { |
| 4035 | __be32 verf[2]; |
| 4036 | |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4037 | if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) { |
| 4038 | /* An impossible timestamp guarantees this value |
| 4039 | * will never match a generated boot time. */ |
| 4040 | verf[0] = 0; |
| 4041 | verf[1] = (__be32)(NSEC_PER_SEC + 1); |
| 4042 | } else { |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4043 | struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id); |
| 4044 | verf[0] = (__be32)nn->boot_time.tv_sec; |
| 4045 | verf[1] = (__be32)nn->boot_time.tv_nsec; |
Chuck Lever | 2c820d9 | 2012-05-21 22:45:33 -0400 | [diff] [blame] | 4046 | } |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 4047 | memcpy(bootverf->data, verf, sizeof(bootverf->data)); |
| 4048 | } |
| 4049 | |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4050 | static unsigned int |
| 4051 | nfs4_init_nonuniform_client_string(const struct nfs_client *clp, |
| 4052 | char *buf, size_t len) |
| 4053 | { |
| 4054 | unsigned int result; |
| 4055 | |
| 4056 | rcu_read_lock(); |
| 4057 | result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s", |
| 4058 | clp->cl_ipaddr, |
| 4059 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4060 | RPC_DISPLAY_ADDR), |
| 4061 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4062 | RPC_DISPLAY_PROTO)); |
| 4063 | rcu_read_unlock(); |
| 4064 | return result; |
| 4065 | } |
| 4066 | |
| 4067 | static unsigned int |
| 4068 | nfs4_init_uniform_client_string(const struct nfs_client *clp, |
| 4069 | char *buf, size_t len) |
| 4070 | { |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame^] | 4071 | char *nodename = clp->cl_rpcclient->cl_nodename; |
| 4072 | |
| 4073 | if (nfs4_client_id_uniquifier[0] != '\0') |
| 4074 | nodename = nfs4_client_id_uniquifier; |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4075 | return scnprintf(buf, len, "Linux NFSv%u.%u %s", |
| 4076 | clp->rpc_ops->version, clp->cl_minorversion, |
Chuck Lever | 6f2ea7f | 2012-09-14 17:24:41 -0400 | [diff] [blame^] | 4077 | nodename); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4078 | } |
| 4079 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4080 | /** |
| 4081 | * nfs4_proc_setclientid - Negotiate client ID |
| 4082 | * @clp: state data structure |
| 4083 | * @program: RPC program for NFSv4 callback service |
| 4084 | * @port: IP port number for NFS4 callback service |
| 4085 | * @cred: RPC credential to use for this call |
| 4086 | * @res: where to place the result |
| 4087 | * |
| 4088 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4089 | */ |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4090 | int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, |
| 4091 | unsigned short port, struct rpc_cred *cred, |
| 4092 | struct nfs4_setclientid_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | { |
| 4094 | nfs4_verifier sc_verifier; |
| 4095 | struct nfs4_setclientid setclientid = { |
| 4096 | .sc_verifier = &sc_verifier, |
| 4097 | .sc_prog = program, |
Andy Adamson | f4eecd5 | 2011-01-06 02:04:30 +0000 | [diff] [blame] | 4098 | .sc_cb_ident = clp->cl_cb_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4099 | }; |
| 4100 | struct rpc_message msg = { |
| 4101 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
| 4102 | .rpc_argp = &setclientid, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4103 | .rpc_resp = res, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4104 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | }; |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4106 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4108 | /* nfs_client_id4 */ |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 4109 | nfs4_init_boot_verifier(clp, &sc_verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4110 | if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags)) |
| 4111 | setclientid.sc_name_len = |
| 4112 | nfs4_init_uniform_client_string(clp, |
| 4113 | setclientid.sc_name, |
| 4114 | sizeof(setclientid.sc_name)); |
| 4115 | else |
| 4116 | setclientid.sc_name_len = |
| 4117 | nfs4_init_nonuniform_client_string(clp, |
| 4118 | setclientid.sc_name, |
| 4119 | sizeof(setclientid.sc_name)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4120 | /* cb_client4 */ |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 4121 | rcu_read_lock(); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4122 | setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4123 | sizeof(setclientid.sc_netid), |
| 4124 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 4125 | RPC_DISPLAY_NETID)); |
Chuck Lever | de73483 | 2012-07-11 16:30:50 -0400 | [diff] [blame] | 4126 | rcu_read_unlock(); |
| 4127 | setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, |
Chuck Lever | d4d3c50 | 2007-12-10 14:57:09 -0500 | [diff] [blame] | 4128 | sizeof(setclientid.sc_uaddr), "%s.%u.%u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4129 | clp->cl_ipaddr, port >> 8, port & 255); |
| 4130 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4131 | dprintk("NFS call setclientid auth=%s, '%.*s'\n", |
| 4132 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4133 | setclientid.sc_name_len, setclientid.sc_name); |
| 4134 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 4135 | dprintk("NFS reply setclientid: %d\n", status); |
| 4136 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | } |
| 4138 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4139 | /** |
| 4140 | * nfs4_proc_setclientid_confirm - Confirm client ID |
| 4141 | * @clp: state data structure |
| 4142 | * @res: result of a previous SETCLIENTID |
| 4143 | * @cred: RPC credential to use for this call |
| 4144 | * |
| 4145 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 4146 | */ |
Trond Myklebust | fd954ae | 2011-04-24 14:28:18 -0400 | [diff] [blame] | 4147 | int nfs4_proc_setclientid_confirm(struct nfs_client *clp, |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4148 | struct nfs4_setclientid_res *arg, |
| 4149 | struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | { |
| 4151 | struct nfs_fsinfo fsinfo; |
| 4152 | struct rpc_message msg = { |
| 4153 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM], |
Trond Myklebust | bb8b27e | 2010-04-16 16:43:06 -0400 | [diff] [blame] | 4154 | .rpc_argp = arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4155 | .rpc_resp = &fsinfo, |
Trond Myklebust | 286d7d6 | 2006-01-03 09:55:26 +0100 | [diff] [blame] | 4156 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | }; |
| 4158 | unsigned long now; |
| 4159 | int status; |
| 4160 | |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4161 | dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n", |
| 4162 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 4163 | clp->cl_clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | now = jiffies; |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 4165 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | if (status == 0) { |
| 4167 | spin_lock(&clp->cl_lock); |
| 4168 | clp->cl_lease_time = fsinfo.lease_time * HZ; |
| 4169 | clp->cl_last_renewal = now; |
| 4170 | spin_unlock(&clp->cl_lock); |
| 4171 | } |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 4172 | dprintk("NFS reply setclientid_confirm: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | return status; |
| 4174 | } |
| 4175 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4176 | struct nfs4_delegreturndata { |
| 4177 | struct nfs4_delegreturnargs args; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4178 | struct nfs4_delegreturnres res; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4179 | struct nfs_fh fh; |
| 4180 | nfs4_stateid stateid; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4181 | unsigned long timestamp; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4182 | struct nfs_fattr fattr; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4183 | int rpc_status; |
| 4184 | }; |
| 4185 | |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4186 | static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata) |
| 4187 | { |
| 4188 | struct nfs4_delegreturndata *data = calldata; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4189 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4190 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4191 | return; |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4192 | |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4193 | switch (task->tk_status) { |
| 4194 | case -NFS4ERR_STALE_STATEID: |
| 4195 | case -NFS4ERR_EXPIRED: |
| 4196 | case 0: |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4197 | renew_lease(data->res.server, data->timestamp); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4198 | break; |
| 4199 | default: |
| 4200 | if (nfs4_async_handle_error(task, data->res.server, NULL) == |
| 4201 | -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4202 | rpc_restart_call_prepare(task); |
Ricardo Labiaga | 7970886 | 2009-12-07 09:23:21 -0500 | [diff] [blame] | 4203 | return; |
| 4204 | } |
| 4205 | } |
| 4206 | data->rpc_status = task->tk_status; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | static void nfs4_delegreturn_release(void *calldata) |
| 4210 | { |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4211 | kfree(calldata); |
| 4212 | } |
| 4213 | |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4214 | #if defined(CONFIG_NFS_V4_1) |
| 4215 | static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data) |
| 4216 | { |
| 4217 | struct nfs4_delegreturndata *d_data; |
| 4218 | |
| 4219 | d_data = (struct nfs4_delegreturndata *)data; |
| 4220 | |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4221 | if (nfs4_setup_sequence(d_data->res.server, |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4222 | &d_data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4223 | &d_data->res.seq_res, task)) |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4224 | return; |
| 4225 | rpc_call_start(task); |
| 4226 | } |
| 4227 | #endif /* CONFIG_NFS_V4_1 */ |
| 4228 | |
Jesper Juhl | c8d149f | 2006-03-20 13:44:07 -0500 | [diff] [blame] | 4229 | static const struct rpc_call_ops nfs4_delegreturn_ops = { |
Andy Adamson | 938e101 | 2009-04-01 09:22:28 -0400 | [diff] [blame] | 4230 | #if defined(CONFIG_NFS_V4_1) |
| 4231 | .rpc_call_prepare = nfs4_delegreturn_prepare, |
| 4232 | #endif /* CONFIG_NFS_V4_1 */ |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4233 | .rpc_call_done = nfs4_delegreturn_done, |
| 4234 | .rpc_release = nfs4_delegreturn_release, |
| 4235 | }; |
| 4236 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4237 | 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] | 4238 | { |
| 4239 | struct nfs4_delegreturndata *data; |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4240 | struct nfs_server *server = NFS_SERVER(inode); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4241 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4242 | struct rpc_message msg = { |
| 4243 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN], |
| 4244 | .rpc_cred = cred, |
| 4245 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4246 | struct rpc_task_setup task_setup_data = { |
| 4247 | .rpc_client = server->client, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4248 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4249 | .callback_ops = &nfs4_delegreturn_ops, |
| 4250 | .flags = RPC_TASK_ASYNC, |
| 4251 | }; |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4252 | int status = 0; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4253 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4254 | data = kzalloc(sizeof(*data), GFP_NOFS); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4255 | if (data == NULL) |
| 4256 | return -ENOMEM; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4257 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4258 | data->args.fhandle = &data->fh; |
| 4259 | data->args.stateid = &data->stateid; |
Trond Myklebust | 9e907fe | 2012-04-27 13:48:17 -0400 | [diff] [blame] | 4260 | data->args.bitmask = server->cache_consistency_bitmask; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4261 | nfs_copy_fh(&data->fh, NFS_FH(inode)); |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4262 | nfs4_stateid_copy(&data->stateid, stateid); |
Trond Myklebust | fa178f2 | 2006-01-03 09:55:38 +0100 | [diff] [blame] | 4263 | data->res.fattr = &data->fattr; |
| 4264 | data->res.server = server; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4265 | nfs_fattr_init(data->res.fattr); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4266 | data->timestamp = jiffies; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4267 | data->rpc_status = 0; |
| 4268 | |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4269 | task_setup_data.callback_data = data; |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4270 | msg.rpc_argp = &data->args; |
| 4271 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4272 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4273 | if (IS_ERR(task)) |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4274 | return PTR_ERR(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4275 | if (!issync) |
| 4276 | goto out; |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4277 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4278 | if (status != 0) |
| 4279 | goto out; |
| 4280 | status = data->rpc_status; |
Trond Myklebust | e144cbc | 2012-04-28 16:05:03 -0400 | [diff] [blame] | 4281 | if (status == 0) |
| 4282 | nfs_post_op_update_inode_force_wcc(inode, &data->fattr); |
| 4283 | else |
| 4284 | nfs_refresh_inode(inode, &data->fattr); |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4285 | out: |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4286 | rpc_put_task(task); |
Trond Myklebust | fe65040 | 2006-01-03 09:55:18 +0100 | [diff] [blame] | 4287 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | } |
| 4289 | |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4290 | 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] | 4291 | { |
| 4292 | struct nfs_server *server = NFS_SERVER(inode); |
| 4293 | struct nfs4_exception exception = { }; |
| 4294 | int err; |
| 4295 | do { |
Trond Myklebust | e6f8107 | 2008-01-24 18:14:34 -0500 | [diff] [blame] | 4296 | err = _nfs4_proc_delegreturn(inode, cred, stateid, issync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | switch (err) { |
| 4298 | case -NFS4ERR_STALE_STATEID: |
| 4299 | case -NFS4ERR_EXPIRED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | case 0: |
| 4301 | return 0; |
| 4302 | } |
| 4303 | err = nfs4_handle_exception(server, err, &exception); |
| 4304 | } while (exception.retry); |
| 4305 | return err; |
| 4306 | } |
| 4307 | |
| 4308 | #define NFS4_LOCK_MINTIMEOUT (1 * HZ) |
| 4309 | #define NFS4_LOCK_MAXTIMEOUT (30 * HZ) |
| 4310 | |
| 4311 | /* |
| 4312 | * sleep, with exponential backoff, and retry the LOCK operation. |
| 4313 | */ |
| 4314 | static unsigned long |
| 4315 | nfs4_set_lock_task_retry(unsigned long timeout) |
| 4316 | { |
Jeff Layton | d310310 | 2011-12-01 22:44:39 +0100 | [diff] [blame] | 4317 | freezable_schedule_timeout_killable(timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | timeout <<= 1; |
| 4319 | if (timeout > NFS4_LOCK_MAXTIMEOUT) |
| 4320 | return NFS4_LOCK_MAXTIMEOUT; |
| 4321 | return timeout; |
| 4322 | } |
| 4323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4325 | { |
| 4326 | struct inode *inode = state->inode; |
| 4327 | struct nfs_server *server = NFS_SERVER(inode); |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4328 | struct nfs_client *clp = server->nfs_client; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4329 | struct nfs_lockt_args arg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | .fh = NFS_FH(inode), |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4331 | .fl = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4332 | }; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4333 | struct nfs_lockt_res res = { |
| 4334 | .denied = request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | }; |
| 4336 | struct rpc_message msg = { |
| 4337 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT], |
| 4338 | .rpc_argp = &arg, |
| 4339 | .rpc_resp = &res, |
| 4340 | .rpc_cred = state->owner->so_cred, |
| 4341 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | struct nfs4_lock_state *lsp; |
| 4343 | int status; |
| 4344 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4345 | arg.lock_owner.clientid = clp->cl_clientid; |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4346 | status = nfs4_set_lock_state(state, request); |
| 4347 | if (status != 0) |
| 4348 | goto out; |
| 4349 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4350 | arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4351 | arg.lock_owner.s_dev = server->s_dev; |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 4352 | 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] | 4353 | switch (status) { |
| 4354 | case 0: |
| 4355 | request->fl_type = F_UNLCK; |
| 4356 | break; |
| 4357 | case -NFS4ERR_DENIED: |
| 4358 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4359 | } |
J. Bruce Fields | 70cc648 | 2007-02-22 18:48:53 -0500 | [diff] [blame] | 4360 | request->fl_ops->fl_release_private(request); |
Trond Myklebust | 8d0a8a9 | 2005-06-22 17:16:32 +0000 | [diff] [blame] | 4361 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4362 | return status; |
| 4363 | } |
| 4364 | |
| 4365 | static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4366 | { |
| 4367 | struct nfs4_exception exception = { }; |
| 4368 | int err; |
| 4369 | |
| 4370 | do { |
| 4371 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
| 4372 | _nfs4_proc_getlk(state, cmd, request), |
| 4373 | &exception); |
| 4374 | } while (exception.retry); |
| 4375 | return err; |
| 4376 | } |
| 4377 | |
| 4378 | static int do_vfs_lock(struct file *file, struct file_lock *fl) |
| 4379 | { |
| 4380 | int res = 0; |
| 4381 | switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) { |
| 4382 | case FL_POSIX: |
| 4383 | res = posix_lock_file_wait(file, fl); |
| 4384 | break; |
| 4385 | case FL_FLOCK: |
| 4386 | res = flock_lock_file_wait(file, fl); |
| 4387 | break; |
| 4388 | default: |
| 4389 | BUG(); |
| 4390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | return res; |
| 4392 | } |
| 4393 | |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4394 | struct nfs4_unlockdata { |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4395 | struct nfs_locku_args arg; |
| 4396 | struct nfs_locku_res res; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4397 | struct nfs4_lock_state *lsp; |
| 4398 | struct nfs_open_context *ctx; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4399 | struct file_lock fl; |
| 4400 | const struct nfs_server *server; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4401 | unsigned long timestamp; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4402 | }; |
| 4403 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4404 | static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl, |
| 4405 | struct nfs_open_context *ctx, |
| 4406 | struct nfs4_lock_state *lsp, |
| 4407 | struct nfs_seqid *seqid) |
| 4408 | { |
| 4409 | struct nfs4_unlockdata *p; |
| 4410 | struct inode *inode = lsp->ls_state->inode; |
| 4411 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4412 | p = kzalloc(sizeof(*p), GFP_NOFS); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4413 | if (p == NULL) |
| 4414 | return NULL; |
| 4415 | p->arg.fh = NFS_FH(inode); |
| 4416 | p->arg.fl = &p->fl; |
| 4417 | p->arg.seqid = seqid; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4418 | p->res.seqid = seqid; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4419 | p->arg.stateid = &lsp->ls_stateid; |
| 4420 | p->lsp = lsp; |
| 4421 | atomic_inc(&lsp->ls_count); |
| 4422 | /* Ensure we don't close file until we're done freeing locks! */ |
| 4423 | p->ctx = get_nfs_open_context(ctx); |
| 4424 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4425 | p->server = NFS_SERVER(inode); |
| 4426 | return p; |
| 4427 | } |
| 4428 | |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4429 | static void nfs4_locku_release_calldata(void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4430 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4431 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4432 | nfs_free_seqid(calldata->arg.seqid); |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4433 | nfs4_put_lock_state(calldata->lsp); |
| 4434 | put_nfs_open_context(calldata->ctx); |
| 4435 | kfree(calldata); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4436 | } |
| 4437 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4438 | static void nfs4_locku_done(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4439 | { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4440 | struct nfs4_unlockdata *calldata = data; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4441 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4442 | if (!nfs4_sequence_done(task, &calldata->res.seq_res)) |
| 4443 | return; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4444 | switch (task->tk_status) { |
| 4445 | case 0: |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4446 | nfs4_stateid_copy(&calldata->lsp->ls_stateid, |
| 4447 | &calldata->res.stateid); |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4448 | renew_lease(calldata->server, calldata->timestamp); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4449 | break; |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4450 | case -NFS4ERR_BAD_STATEID: |
| 4451 | case -NFS4ERR_OLD_STATEID: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4452 | case -NFS4ERR_STALE_STATEID: |
| 4453 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4454 | break; |
| 4455 | default: |
Trond Myklebust | 9e33bed | 2008-12-23 15:21:46 -0500 | [diff] [blame] | 4456 | if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN) |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 4457 | rpc_restart_call_prepare(task); |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4458 | } |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4459 | } |
| 4460 | |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4461 | static void nfs4_locku_prepare(struct rpc_task *task, void *data) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4462 | { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4463 | struct nfs4_unlockdata *calldata = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4465 | if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4466 | return; |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4467 | if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) { |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4468 | /* Note: exit _without_ running nfs4_locku_done */ |
| 4469 | task->tk_action = NULL; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4470 | return; |
| 4471 | } |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4472 | calldata->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4473 | if (nfs4_setup_sequence(calldata->server, |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4474 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4475 | &calldata->res.seq_res, task)) |
Andy Adamson | a893693 | 2009-04-01 09:22:23 -0400 | [diff] [blame] | 4476 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4477 | rpc_call_start(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | } |
| 4479 | |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4480 | static const struct rpc_call_ops nfs4_locku_ops = { |
Trond Myklebust | 4ce70ad | 2006-01-03 09:55:05 +0100 | [diff] [blame] | 4481 | .rpc_call_prepare = nfs4_locku_prepare, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4482 | .rpc_call_done = nfs4_locku_done, |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4483 | .rpc_release = nfs4_locku_release_calldata, |
Trond Myklebust | 963d8fe | 2006-01-03 09:55:04 +0100 | [diff] [blame] | 4484 | }; |
| 4485 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4486 | static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, |
| 4487 | struct nfs_open_context *ctx, |
| 4488 | struct nfs4_lock_state *lsp, |
| 4489 | struct nfs_seqid *seqid) |
| 4490 | { |
| 4491 | struct nfs4_unlockdata *data; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4492 | struct rpc_message msg = { |
| 4493 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU], |
| 4494 | .rpc_cred = ctx->cred, |
| 4495 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4496 | struct rpc_task_setup task_setup_data = { |
| 4497 | .rpc_client = NFS_CLIENT(lsp->ls_state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4498 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4499 | .callback_ops = &nfs4_locku_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4500 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4501 | .flags = RPC_TASK_ASYNC, |
| 4502 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4503 | |
Frank Filz | 137d6ac | 2007-07-09 15:32:29 -0700 | [diff] [blame] | 4504 | /* Ensure this is an unlock - when canceling a lock, the |
| 4505 | * canceled lock is passed in, and it won't be an unlock. |
| 4506 | */ |
| 4507 | fl->fl_type = F_UNLCK; |
| 4508 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4509 | data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid); |
| 4510 | if (data == NULL) { |
| 4511 | nfs_free_seqid(seqid); |
| 4512 | return ERR_PTR(-ENOMEM); |
| 4513 | } |
| 4514 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4515 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4516 | msg.rpc_argp = &data->arg; |
| 4517 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4518 | task_setup_data.callback_data = data; |
| 4519 | return rpc_run_task(&task_setup_data); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4520 | } |
| 4521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4523 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4524 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4525 | struct nfs_seqid *seqid; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4526 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 06f814a | 2006-01-03 09:55:07 +0100 | [diff] [blame] | 4527 | struct rpc_task *task; |
| 4528 | int status = 0; |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4529 | unsigned char fl_flags = request->fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4531 | status = nfs4_set_lock_state(state, request); |
| 4532 | /* Unlock _before_ we do the RPC call */ |
| 4533 | request->fl_flags |= FL_EXISTS; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4534 | down_read(&nfsi->rwsem); |
| 4535 | if (do_vfs_lock(request->fl_file, request) == -ENOENT) { |
| 4536 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4537 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4538 | } |
| 4539 | up_read(&nfsi->rwsem); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4540 | if (status != 0) |
| 4541 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4542 | /* Is this a delegated lock? */ |
| 4543 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4544 | goto out; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4545 | lsp = request->fl_u.nfs4_fl.owner; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4546 | seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4547 | status = -ENOMEM; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4548 | if (seqid == NULL) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4549 | goto out; |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4550 | 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] | 4551 | status = PTR_ERR(task); |
| 4552 | if (IS_ERR(task)) |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4553 | goto out; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4554 | status = nfs4_wait_for_completion_rpc_task(task); |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4555 | rpc_put_task(task); |
Trond Myklebust | 9b07357 | 2006-06-29 16:38:34 -0400 | [diff] [blame] | 4556 | out: |
Trond Myklebust | 536ff0f | 2008-04-04 15:08:02 -0400 | [diff] [blame] | 4557 | request->fl_flags = fl_flags; |
Trond Myklebust | faf5f49 | 2005-10-18 14:20:15 -0700 | [diff] [blame] | 4558 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | } |
| 4560 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4561 | struct nfs4_lockdata { |
| 4562 | struct nfs_lock_args arg; |
Trond Myklebust | 911d1aa | 2006-01-03 09:55:16 +0100 | [diff] [blame] | 4563 | struct nfs_lock_res res; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4564 | struct nfs4_lock_state *lsp; |
| 4565 | struct nfs_open_context *ctx; |
| 4566 | struct file_lock fl; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4567 | unsigned long timestamp; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4568 | int rpc_status; |
| 4569 | int cancelled; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4570 | struct nfs_server *server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4571 | }; |
| 4572 | |
| 4573 | static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4574 | struct nfs_open_context *ctx, struct nfs4_lock_state *lsp, |
| 4575 | gfp_t gfp_mask) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4576 | { |
| 4577 | struct nfs4_lockdata *p; |
| 4578 | struct inode *inode = lsp->ls_state->inode; |
| 4579 | struct nfs_server *server = NFS_SERVER(inode); |
| 4580 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4581 | p = kzalloc(sizeof(*p), gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4582 | if (p == NULL) |
| 4583 | return NULL; |
| 4584 | |
| 4585 | p->arg.fh = NFS_FH(inode); |
| 4586 | p->arg.fl = &p->fl; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4587 | 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] | 4588 | if (p->arg.open_seqid == NULL) |
| 4589 | goto out_free; |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4590 | p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4591 | if (p->arg.lock_seqid == NULL) |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4592 | goto out_free_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4593 | p->arg.lock_stateid = &lsp->ls_stateid; |
David Howells | 7539bba | 2006-08-22 20:06:09 -0400 | [diff] [blame] | 4594 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
Trond Myklebust | 48c22eb | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4595 | p->arg.lock_owner.id = lsp->ls_seqid.owner_id; |
Trond Myklebust | d035c36 | 2010-12-21 10:45:27 -0500 | [diff] [blame] | 4596 | p->arg.lock_owner.s_dev = server->s_dev; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4597 | p->res.lock_seqid = p->arg.lock_seqid; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4598 | p->lsp = lsp; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4599 | p->server = server; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4600 | atomic_inc(&lsp->ls_count); |
| 4601 | p->ctx = get_nfs_open_context(ctx); |
| 4602 | memcpy(&p->fl, fl, sizeof(p->fl)); |
| 4603 | return p; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4604 | out_free_seqid: |
| 4605 | nfs_free_seqid(p->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4606 | out_free: |
| 4607 | kfree(p); |
| 4608 | return NULL; |
| 4609 | } |
| 4610 | |
| 4611 | static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) |
| 4612 | { |
| 4613 | struct nfs4_lockdata *data = calldata; |
| 4614 | struct nfs4_state *state = data->lsp->ls_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4616 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4617 | if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0) |
| 4618 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4619 | /* Do we need to do an open_to_lock_owner? */ |
| 4620 | if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { |
Trond Myklebust | e6e2197 | 2008-01-02 16:27:16 -0500 | [diff] [blame] | 4621 | if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) |
| 4622 | return; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4623 | data->arg.open_stateid = &state->stateid; |
| 4624 | data->arg.new_lock_owner = 1; |
Trond Myklebust | c1d5193 | 2008-04-07 13:20:54 -0400 | [diff] [blame] | 4625 | data->res.open_seqid = data->arg.open_seqid; |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4626 | } else |
| 4627 | data->arg.new_lock_owner = 0; |
Trond Myklebust | 26e976a | 2006-01-03 09:55:21 +0100 | [diff] [blame] | 4628 | data->timestamp = jiffies; |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 4629 | if (nfs4_setup_sequence(data->server, |
| 4630 | &data->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4631 | &data->res.seq_res, task)) |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4632 | return; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4633 | rpc_call_start(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4634 | dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4635 | } |
| 4636 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4637 | static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata) |
| 4638 | { |
| 4639 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
| 4640 | nfs4_lock_prepare(task, calldata); |
| 4641 | } |
| 4642 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4643 | static void nfs4_lock_done(struct rpc_task *task, void *calldata) |
| 4644 | { |
| 4645 | struct nfs4_lockdata *data = calldata; |
| 4646 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4647 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4648 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 4649 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 4650 | return; |
Andy Adamson | 66179ef | 2009-04-01 09:22:22 -0400 | [diff] [blame] | 4651 | |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4652 | data->rpc_status = task->tk_status; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4653 | if (data->arg.new_lock_owner != 0) { |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4654 | if (data->rpc_status == 0) |
| 4655 | nfs_confirm_seqid(&data->lsp->ls_seqid, 0); |
| 4656 | else |
| 4657 | goto out; |
| 4658 | } |
| 4659 | if (data->rpc_status == 0) { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 4660 | nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4661 | set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags); |
Al Viro | 3d4ff43 | 2011-06-22 18:40:12 -0400 | [diff] [blame] | 4662 | renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4663 | } |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4664 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4665 | dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | static void nfs4_lock_release(void *calldata) |
| 4669 | { |
| 4670 | struct nfs4_lockdata *data = calldata; |
| 4671 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4672 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | 2f74c0a | 2008-01-08 17:56:07 -0500 | [diff] [blame] | 4673 | nfs_free_seqid(data->arg.open_seqid); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4674 | if (data->cancelled != 0) { |
| 4675 | struct rpc_task *task; |
| 4676 | task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, |
| 4677 | data->arg.lock_seqid); |
| 4678 | if (!IS_ERR(task)) |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 4679 | rpc_put_task_async(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4680 | dprintk("%s: cancelling lock!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4681 | } else |
| 4682 | nfs_free_seqid(data->arg.lock_seqid); |
| 4683 | nfs4_put_lock_state(data->lsp); |
| 4684 | put_nfs_open_context(data->ctx); |
| 4685 | kfree(data); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4686 | dprintk("%s: done!\n", __func__); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | static const struct rpc_call_ops nfs4_lock_ops = { |
| 4690 | .rpc_call_prepare = nfs4_lock_prepare, |
| 4691 | .rpc_call_done = nfs4_lock_done, |
| 4692 | .rpc_release = nfs4_lock_release, |
| 4693 | }; |
| 4694 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4695 | static const struct rpc_call_ops nfs4_recover_lock_ops = { |
| 4696 | .rpc_call_prepare = nfs4_recover_lock_prepare, |
| 4697 | .rpc_call_done = nfs4_lock_done, |
| 4698 | .rpc_release = nfs4_lock_release, |
| 4699 | }; |
| 4700 | |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4701 | static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error) |
| 4702 | { |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4703 | switch (error) { |
| 4704 | case -NFS4ERR_ADMIN_REVOKED: |
| 4705 | case -NFS4ERR_BAD_STATEID: |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4706 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4707 | if (new_lock_owner != 0 || |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4708 | test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4709 | nfs4_schedule_stateid_recovery(server, lsp->ls_state); |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4710 | break; |
| 4711 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | a2c0b9e | 2010-01-26 15:42:47 -0500 | [diff] [blame] | 4712 | lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED; |
Trond Myklebust | ecac799 | 2011-03-09 16:00:56 -0500 | [diff] [blame] | 4713 | case -NFS4ERR_EXPIRED: |
| 4714 | nfs4_schedule_lease_recovery(server->nfs_client); |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4715 | }; |
| 4716 | } |
| 4717 | |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4718 | 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] | 4719 | { |
| 4720 | struct nfs4_lockdata *data; |
| 4721 | struct rpc_task *task; |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4722 | struct rpc_message msg = { |
| 4723 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK], |
| 4724 | .rpc_cred = state->owner->so_cred, |
| 4725 | }; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4726 | struct rpc_task_setup task_setup_data = { |
| 4727 | .rpc_client = NFS_CLIENT(state->inode), |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 4728 | .rpc_message = &msg, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4729 | .callback_ops = &nfs4_lock_ops, |
Trond Myklebust | 101070c | 2008-02-19 20:04:23 -0500 | [diff] [blame] | 4730 | .workqueue = nfsiod_workqueue, |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4731 | .flags = RPC_TASK_ASYNC, |
| 4732 | }; |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4733 | int ret; |
| 4734 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4735 | dprintk("%s: begin!\n", __func__); |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4736 | data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file), |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 4737 | fl->fl_u.nfs4_fl.owner, |
| 4738 | recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4739 | if (data == NULL) |
| 4740 | return -ENOMEM; |
| 4741 | if (IS_SETLKW(cmd)) |
| 4742 | data->arg.block = 1; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4743 | if (recovery_type > NFS_LOCK_NEW) { |
| 4744 | if (recovery_type == NFS_LOCK_RECLAIM) |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4745 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 4746 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
| 4747 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 4748 | nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1); |
Trond Myklebust | 1174dd1 | 2010-12-21 10:52:24 -0500 | [diff] [blame] | 4749 | msg.rpc_argp = &data->arg; |
| 4750 | msg.rpc_resp = &data->res; |
Trond Myklebust | c970aa8 | 2007-07-14 15:39:59 -0400 | [diff] [blame] | 4751 | task_setup_data.callback_data = data; |
| 4752 | task = rpc_run_task(&task_setup_data); |
Trond Myklebust | 7a1218a | 2006-03-20 18:11:10 -0500 | [diff] [blame] | 4753 | if (IS_ERR(task)) |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4754 | return PTR_ERR(task); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4755 | ret = nfs4_wait_for_completion_rpc_task(task); |
| 4756 | if (ret == 0) { |
| 4757 | ret = data->rpc_status; |
Trond Myklebust | 2bee72a | 2010-01-26 15:42:21 -0500 | [diff] [blame] | 4758 | if (ret) |
| 4759 | nfs4_handle_setlk_error(data->server, data->lsp, |
| 4760 | data->arg.new_lock_owner, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4761 | } else |
| 4762 | data->cancelled = 1; |
Trond Myklebust | e6b3c4d | 2006-11-11 22:18:03 -0500 | [diff] [blame] | 4763 | rpc_put_task(task); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 4764 | dprintk("%s: done, ret = %d!\n", __func__, ret); |
Trond Myklebust | a5d16a4 | 2006-01-03 09:55:17 +0100 | [diff] [blame] | 4765 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4766 | } |
| 4767 | |
| 4768 | static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request) |
| 4769 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4770 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4771 | struct nfs4_exception exception = { |
| 4772 | .inode = state->inode, |
| 4773 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4774 | int err; |
| 4775 | |
| 4776 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4777 | /* Cache the lock if possible... */ |
| 4778 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4779 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4780 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM); |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 4781 | if (err != -NFS4ERR_DELAY) |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4782 | break; |
| 4783 | nfs4_handle_exception(server, err, &exception); |
| 4784 | } while (exception.retry); |
| 4785 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4789 | { |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4790 | struct nfs_server *server = NFS_SERVER(state->inode); |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4791 | struct nfs4_exception exception = { |
| 4792 | .inode = state->inode, |
| 4793 | }; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4794 | int err; |
| 4795 | |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4796 | err = nfs4_set_lock_state(state, request); |
| 4797 | if (err != 0) |
| 4798 | return err; |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4799 | do { |
Trond Myklebust | 42a2d13 | 2006-06-29 16:38:36 -0400 | [diff] [blame] | 4800 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0) |
| 4801 | return 0; |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4802 | err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4803 | switch (err) { |
| 4804 | default: |
| 4805 | goto out; |
| 4806 | case -NFS4ERR_GRACE: |
| 4807 | case -NFS4ERR_DELAY: |
| 4808 | nfs4_handle_exception(server, err, &exception); |
| 4809 | err = 0; |
| 4810 | } |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4811 | } while (exception.retry); |
Trond Myklebust | a9ed2e2 | 2009-12-03 15:53:21 -0500 | [diff] [blame] | 4812 | out: |
Trond Myklebust | 202b50d | 2005-06-22 17:16:29 +0000 | [diff] [blame] | 4813 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | } |
| 4815 | |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4816 | #if defined(CONFIG_NFS_V4_1) |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4817 | /** |
| 4818 | * nfs41_check_expired_locks - possibly free a lock stateid |
| 4819 | * |
| 4820 | * @state: NFSv4 state for an inode |
| 4821 | * |
| 4822 | * Returns NFS_OK if recovery for this stateid is now finished. |
| 4823 | * Otherwise a negative NFS4ERR value is returned. |
| 4824 | */ |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4825 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4826 | { |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4827 | int status, ret = -NFS4ERR_BAD_STATEID; |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4828 | struct nfs4_lock_state *lsp; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4829 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4830 | |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4831 | list_for_each_entry(lsp, &state->lock_states, ls_locks) { |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4832 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4833 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
| 4834 | if (status != NFS_OK) { |
Chuck Lever | 3e60ffd | 2012-07-11 16:30:14 -0400 | [diff] [blame] | 4835 | /* Free the stateid unless the server |
| 4836 | * informs us the stateid is unrecognized. */ |
Chuck Lever | 89af273 | 2012-07-11 16:29:56 -0400 | [diff] [blame] | 4837 | if (status != -NFS4ERR_BAD_STATEID) |
| 4838 | nfs41_free_stateid(server, |
| 4839 | &lsp->ls_stateid); |
Trond Myklebust | 795a88c | 2012-09-10 13:26:49 -0400 | [diff] [blame] | 4840 | clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags); |
Bryan Schumaker | b01dd1d | 2012-01-31 10:39:30 -0500 | [diff] [blame] | 4841 | ret = status; |
| 4842 | } |
| 4843 | } |
| 4844 | }; |
| 4845 | |
| 4846 | return ret; |
| 4847 | } |
| 4848 | |
| 4849 | static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) |
| 4850 | { |
| 4851 | int status = NFS_OK; |
| 4852 | |
| 4853 | if (test_bit(LK_STATE_IN_USE, &state->flags)) |
| 4854 | status = nfs41_check_expired_locks(state); |
Chuck Lever | eb64cf9 | 2012-07-11 16:30:05 -0400 | [diff] [blame] | 4855 | if (status != NFS_OK) |
| 4856 | status = nfs4_lock_expired(state, request); |
| 4857 | return status; |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 4858 | } |
| 4859 | #endif |
| 4860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4861 | static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4862 | { |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4863 | struct nfs_inode *nfsi = NFS_I(state->inode); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4864 | unsigned char fl_flags = request->fl_flags; |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4865 | int status = -ENOLCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | |
Trond Myklebust | 8e469eb | 2010-01-26 15:42:30 -0500 | [diff] [blame] | 4867 | if ((fl_flags & FL_POSIX) && |
| 4868 | !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) |
| 4869 | goto out; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4870 | /* Is this a delegated open? */ |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4871 | status = nfs4_set_lock_state(state, request); |
| 4872 | if (status != 0) |
| 4873 | goto out; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4874 | request->fl_flags |= FL_ACCESS; |
| 4875 | status = do_vfs_lock(request->fl_file, request); |
| 4876 | if (status < 0) |
| 4877 | goto out; |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4878 | down_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4879 | if (test_bit(NFS_DELEGATED_STATE, &state->flags)) { |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4880 | /* Yes: cache locks! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4881 | /* ...but avoid races with delegation recall... */ |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4882 | request->fl_flags = fl_flags & ~FL_SLEEP; |
| 4883 | status = do_vfs_lock(request->fl_file, request); |
| 4884 | goto out_unlock; |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4885 | } |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4886 | status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW); |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4887 | if (status != 0) |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4888 | goto out_unlock; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4889 | /* Note: we always want to sleep here! */ |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4890 | request->fl_flags = fl_flags | FL_SLEEP; |
Trond Myklebust | 6bfc93e | 2005-11-04 15:39:36 -0500 | [diff] [blame] | 4891 | if (do_vfs_lock(request->fl_file, request) < 0) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4892 | printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock " |
| 4893 | "manager!\n", __func__); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4894 | out_unlock: |
Trond Myklebust | 19e03c5 | 2008-12-23 15:21:44 -0500 | [diff] [blame] | 4895 | up_read(&nfsi->rwsem); |
Trond Myklebust | 01c3b86 | 2006-06-29 16:38:39 -0400 | [diff] [blame] | 4896 | out: |
| 4897 | request->fl_flags = fl_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4898 | return status; |
| 4899 | } |
| 4900 | |
| 4901 | static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) |
| 4902 | { |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4903 | struct nfs4_exception exception = { |
| 4904 | .state = state, |
Trond Myklebust | 05ffe24 | 2012-04-18 12:20:10 -0400 | [diff] [blame] | 4905 | .inode = state->inode, |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 4906 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | int err; |
| 4908 | |
| 4909 | do { |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4910 | err = _nfs4_proc_setlk(state, cmd, request); |
| 4911 | if (err == -NFS4ERR_DENIED) |
| 4912 | err = -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4913 | err = nfs4_handle_exception(NFS_SERVER(state->inode), |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4914 | err, &exception); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4915 | } while (exception.retry); |
| 4916 | return err; |
| 4917 | } |
| 4918 | |
| 4919 | static int |
| 4920 | nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request) |
| 4921 | { |
| 4922 | struct nfs_open_context *ctx; |
| 4923 | struct nfs4_state *state; |
| 4924 | unsigned long timeout = NFS4_LOCK_MINTIMEOUT; |
| 4925 | int status; |
| 4926 | |
| 4927 | /* verify open state */ |
Trond Myklebust | cd3758e | 2007-08-10 17:44:32 -0400 | [diff] [blame] | 4928 | ctx = nfs_file_open_context(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4929 | state = ctx->state; |
| 4930 | |
| 4931 | if (request->fl_start < 0 || request->fl_end < 0) |
| 4932 | return -EINVAL; |
| 4933 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4934 | if (IS_GETLK(cmd)) { |
| 4935 | if (state != NULL) |
| 4936 | return nfs4_proc_getlk(state, F_GETLK, request); |
| 4937 | return 0; |
| 4938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | |
| 4940 | if (!(IS_SETLK(cmd) || IS_SETLKW(cmd))) |
| 4941 | return -EINVAL; |
| 4942 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4943 | if (request->fl_type == F_UNLCK) { |
| 4944 | if (state != NULL) |
| 4945 | return nfs4_proc_unlck(state, cmd, request); |
| 4946 | return 0; |
| 4947 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4948 | |
Trond Myklebust | d953126 | 2009-07-21 19:22:38 -0400 | [diff] [blame] | 4949 | if (state == NULL) |
| 4950 | return -ENOLCK; |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4951 | /* |
| 4952 | * Don't rely on the VFS having checked the file open mode, |
| 4953 | * since it won't do this for flock() locks. |
| 4954 | */ |
Jeff Layton | f44106e | 2012-07-23 15:49:56 -0400 | [diff] [blame] | 4955 | switch (request->fl_type) { |
Trond Myklebust | 5572551 | 2012-04-18 12:48:35 -0400 | [diff] [blame] | 4956 | case F_RDLCK: |
| 4957 | if (!(filp->f_mode & FMODE_READ)) |
| 4958 | return -EBADF; |
| 4959 | break; |
| 4960 | case F_WRLCK: |
| 4961 | if (!(filp->f_mode & FMODE_WRITE)) |
| 4962 | return -EBADF; |
| 4963 | } |
| 4964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4965 | do { |
| 4966 | status = nfs4_proc_setlk(state, cmd, request); |
| 4967 | if ((status != -EAGAIN) || IS_SETLK(cmd)) |
| 4968 | break; |
| 4969 | timeout = nfs4_set_lock_task_retry(timeout); |
| 4970 | status = -ERESTARTSYS; |
| 4971 | if (signalled()) |
| 4972 | break; |
| 4973 | } while(status < 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4974 | return status; |
| 4975 | } |
| 4976 | |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 4977 | int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl) |
| 4978 | { |
| 4979 | struct nfs_server *server = NFS_SERVER(state->inode); |
| 4980 | struct nfs4_exception exception = { }; |
| 4981 | int err; |
| 4982 | |
| 4983 | err = nfs4_set_lock_state(state, fl); |
| 4984 | if (err != 0) |
| 4985 | goto out; |
| 4986 | do { |
Alexandros Batsakis | afe6c27 | 2009-12-09 01:50:14 -0800 | [diff] [blame] | 4987 | err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4988 | switch (err) { |
| 4989 | default: |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 4990 | printk(KERN_ERR "NFS: %s: unhandled error " |
| 4991 | "%d.\n", __func__, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4992 | case 0: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4993 | case -ESTALE: |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4994 | goto out; |
| 4995 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 0ced63d | 2011-05-26 14:26:35 -0400 | [diff] [blame] | 4996 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 4997 | case -NFS4ERR_STALE_CLIENTID: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 4998 | case -NFS4ERR_STALE_STATEID: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 4999 | nfs4_schedule_lease_recovery(server->nfs_client); |
| 5000 | goto out; |
Ricardo Labiaga | 74e7bb7 | 2009-12-07 09:48:30 -0500 | [diff] [blame] | 5001 | case -NFS4ERR_BADSESSION: |
| 5002 | case -NFS4ERR_BADSLOT: |
| 5003 | case -NFS4ERR_BAD_HIGH_SLOT: |
| 5004 | case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: |
| 5005 | case -NFS4ERR_DEADSESSION: |
Trond Myklebust | 9f59479 | 2012-05-27 13:02:53 -0400 | [diff] [blame] | 5006 | nfs4_schedule_session_recovery(server->nfs_client->cl_session, err); |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5007 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5008 | case -ERESTARTSYS: |
| 5009 | /* |
| 5010 | * The show must go on: exit, but mark the |
| 5011 | * stateid as needing recovery. |
| 5012 | */ |
Trond Myklebust | a1d0b5e | 2012-03-05 19:56:44 -0500 | [diff] [blame] | 5013 | case -NFS4ERR_DELEG_REVOKED: |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5014 | case -NFS4ERR_ADMIN_REVOKED: |
| 5015 | case -NFS4ERR_BAD_STATEID: |
| 5016 | case -NFS4ERR_OPENMODE: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 5017 | nfs4_schedule_stateid_recovery(server, state); |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5018 | err = 0; |
| 5019 | goto out; |
Trond Myklebust | 168667c | 2010-10-19 19:47:49 -0400 | [diff] [blame] | 5020 | case -EKEYEXPIRED: |
| 5021 | /* |
| 5022 | * User RPCSEC_GSS context has expired. |
| 5023 | * We cannot recover this stateid now, so |
| 5024 | * skip it and allow recovery thread to |
| 5025 | * proceed. |
| 5026 | */ |
| 5027 | err = 0; |
| 5028 | goto out; |
Trond Myklebust | 965b5d6 | 2009-06-17 13:22:59 -0700 | [diff] [blame] | 5029 | case -ENOMEM: |
| 5030 | case -NFS4ERR_DENIED: |
| 5031 | /* kill_proc(fl->fl_pid, SIGLOST, 1); */ |
| 5032 | err = 0; |
| 5033 | goto out; |
Trond Myklebust | d512220 | 2009-06-17 13:22:58 -0700 | [diff] [blame] | 5034 | case -NFS4ERR_DELAY: |
| 5035 | break; |
| 5036 | } |
Trond Myklebust | 888e694 | 2005-11-04 15:38:11 -0500 | [diff] [blame] | 5037 | err = nfs4_handle_exception(server, err, &exception); |
| 5038 | } while (exception.retry); |
| 5039 | out: |
| 5040 | return err; |
| 5041 | } |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5042 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5043 | struct nfs_release_lockowner_data { |
| 5044 | struct nfs4_lock_state *lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5045 | struct nfs_server *server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5046 | struct nfs_release_lockowner_args args; |
| 5047 | }; |
| 5048 | |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5049 | static void nfs4_release_lockowner_release(void *calldata) |
| 5050 | { |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5051 | struct nfs_release_lockowner_data *data = calldata; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5052 | nfs4_free_lock_state(data->server, data->lsp); |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5053 | kfree(calldata); |
| 5054 | } |
| 5055 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5056 | static const struct rpc_call_ops nfs4_release_lockowner_ops = { |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5057 | .rpc_release = nfs4_release_lockowner_release, |
| 5058 | }; |
| 5059 | |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5060 | int nfs4_release_lockowner(struct nfs4_lock_state *lsp) |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5061 | { |
| 5062 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5063 | struct nfs_release_lockowner_data *data; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5064 | struct rpc_message msg = { |
| 5065 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], |
| 5066 | }; |
| 5067 | |
| 5068 | if (server->nfs_client->cl_mvops->minor_version != 0) |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5069 | return -EINVAL; |
| 5070 | data = kmalloc(sizeof(*data), GFP_NOFS); |
| 5071 | if (!data) |
| 5072 | return -ENOMEM; |
| 5073 | data->lsp = lsp; |
Trond Myklebust | 5ae67c4 | 2012-03-19 16:17:18 -0400 | [diff] [blame] | 5074 | data->server = server; |
Trond Myklebust | cf470c3 | 2012-03-07 13:49:12 -0500 | [diff] [blame] | 5075 | data->args.lock_owner.clientid = server->nfs_client->cl_clientid; |
| 5076 | data->args.lock_owner.id = lsp->ls_seqid.owner_id; |
| 5077 | data->args.lock_owner.s_dev = server->s_dev; |
| 5078 | msg.rpc_argp = &data->args; |
| 5079 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data); |
| 5080 | return 0; |
Trond Myklebust | d3c7b7c | 2010-07-01 12:49:01 -0400 | [diff] [blame] | 5081 | } |
| 5082 | |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5083 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
| 5084 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5085 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
| 5086 | const void *buf, size_t buflen, |
| 5087 | int flags, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5088 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5089 | if (strcmp(key, "") != 0) |
| 5090 | return -EINVAL; |
J. Bruce Fields | 4b580ee | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 5091 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5092 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5093 | } |
| 5094 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5095 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
| 5096 | void *buf, size_t buflen, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5097 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5098 | if (strcmp(key, "") != 0) |
| 5099 | return -EINVAL; |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5100 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5101 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5102 | } |
| 5103 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5104 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
| 5105 | size_t list_len, const char *name, |
| 5106 | size_t name_len, int type) |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5107 | { |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5108 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5109 | |
J. Bruce Fields | 096455a | 2006-03-20 23:23:42 -0500 | [diff] [blame] | 5110 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
| 5111 | return 0; |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 5112 | |
| 5113 | if (list && len <= list_len) |
| 5114 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
J. Bruce Fields | aa1870a | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5115 | return len; |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 5116 | } |
| 5117 | |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5118 | /* |
| 5119 | * nfs_fhget will use either the mounted_on_fileid or the fileid |
| 5120 | */ |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5121 | static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr) |
| 5122 | { |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5123 | if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || |
| 5124 | (fattr->valid & NFS_ATTR_FATTR_FILEID)) && |
| 5125 | (fattr->valid & NFS_ATTR_FATTR_FSID) && |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5126 | (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS))) |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5127 | return; |
| 5128 | |
| 5129 | fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | |
Chuck Lever | 81934dd | 2012-03-01 17:01:57 -0500 | [diff] [blame] | 5130 | NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL; |
Trond Myklebust | 69aaaae | 2009-03-11 14:10:28 -0400 | [diff] [blame] | 5131 | fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 5132 | fattr->nlink = 2; |
| 5133 | } |
| 5134 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5135 | static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5136 | const struct qstr *name, |
| 5137 | struct nfs4_fs_locations *fs_locations, |
| 5138 | struct page *page) |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5139 | { |
| 5140 | struct nfs_server *server = NFS_SERVER(dir); |
| 5141 | u32 bitmask[2] = { |
Manoj Naik | 361e624 | 2006-06-09 09:34:24 -0400 | [diff] [blame] | 5142 | [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5143 | }; |
| 5144 | struct nfs4_fs_locations_arg args = { |
| 5145 | .dir_fh = NFS_FH(dir), |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5146 | .name = name, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5147 | .page = page, |
| 5148 | .bitmask = bitmask, |
| 5149 | }; |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5150 | struct nfs4_fs_locations_res res = { |
| 5151 | .fs_locations = fs_locations, |
| 5152 | }; |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5153 | struct rpc_message msg = { |
| 5154 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS], |
| 5155 | .rpc_argp = &args, |
Benny Halevy | 2295846 | 2009-04-01 09:22:02 -0400 | [diff] [blame] | 5156 | .rpc_resp = &res, |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5157 | }; |
| 5158 | int status; |
| 5159 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 5160 | dprintk("%s: start\n", __func__); |
Andy Adamson | 533eb46 | 2011-06-13 18:25:56 -0400 | [diff] [blame] | 5161 | |
| 5162 | /* Ask for the fileid of the absent filesystem if mounted_on_fileid |
| 5163 | * is not supported */ |
| 5164 | if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 5165 | bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID; |
| 5166 | else |
| 5167 | bitmask[0] |= FATTR4_WORD0_FILEID; |
| 5168 | |
Trond Myklebust | c228fd3 | 2007-01-13 02:28:11 -0500 | [diff] [blame] | 5169 | nfs_fattr_init(&fs_locations->fattr); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5170 | fs_locations->server = server; |
Manoj Naik | 830b8e3 | 2006-06-09 09:34:25 -0400 | [diff] [blame] | 5171 | fs_locations->nlocations = 0; |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5172 | 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] | 5173 | dprintk("%s: returned status = %d\n", __func__, status); |
Trond Myklebust | 683b57b | 2006-06-09 09:34:22 -0400 | [diff] [blame] | 5174 | return status; |
| 5175 | } |
| 5176 | |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5177 | int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir, |
| 5178 | const struct qstr *name, |
| 5179 | struct nfs4_fs_locations *fs_locations, |
| 5180 | struct page *page) |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5181 | { |
| 5182 | struct nfs4_exception exception = { }; |
| 5183 | int err; |
| 5184 | do { |
| 5185 | err = nfs4_handle_exception(NFS_SERVER(dir), |
Bryan Schumaker | f05d147 | 2012-04-27 13:27:41 -0400 | [diff] [blame] | 5186 | _nfs4_proc_fs_locations(client, dir, name, fs_locations, page), |
Bryan Schumaker | db0a959 | 2012-04-27 13:27:39 -0400 | [diff] [blame] | 5187 | &exception); |
| 5188 | } while (exception.retry); |
| 5189 | return err; |
| 5190 | } |
| 5191 | |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5192 | static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) |
| 5193 | { |
| 5194 | int status; |
| 5195 | struct nfs4_secinfo_arg args = { |
| 5196 | .dir_fh = NFS_FH(dir), |
| 5197 | .name = name, |
| 5198 | }; |
| 5199 | struct nfs4_secinfo_res res = { |
| 5200 | .flavors = flavors, |
| 5201 | }; |
| 5202 | struct rpc_message msg = { |
| 5203 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO], |
| 5204 | .rpc_argp = &args, |
| 5205 | .rpc_resp = &res, |
| 5206 | }; |
| 5207 | |
| 5208 | dprintk("NFS call secinfo %s\n", name->name); |
| 5209 | status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0); |
| 5210 | dprintk("NFS reply secinfo: %d\n", status); |
| 5211 | return status; |
| 5212 | } |
| 5213 | |
Bryan Schumaker | 72de53e | 2012-04-27 13:27:40 -0400 | [diff] [blame] | 5214 | int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, |
| 5215 | struct nfs4_secinfo_flavors *flavors) |
Bryan Schumaker | 5a5ea0d | 2011-03-24 17:12:29 +0000 | [diff] [blame] | 5216 | { |
| 5217 | struct nfs4_exception exception = { }; |
| 5218 | int err; |
| 5219 | do { |
| 5220 | err = nfs4_handle_exception(NFS_SERVER(dir), |
| 5221 | _nfs4_proc_secinfo(dir, name, flavors), |
| 5222 | &exception); |
| 5223 | } while (exception.retry); |
| 5224 | return err; |
| 5225 | } |
| 5226 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5227 | #ifdef CONFIG_NFS_V4_1 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5228 | /* |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5229 | * Check the exchange flags returned by the server for invalid flags, having |
| 5230 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or |
| 5231 | * DS flags set. |
| 5232 | */ |
| 5233 | static int nfs4_check_cl_exchange_flags(u32 flags) |
| 5234 | { |
| 5235 | if (flags & ~EXCHGID4_FLAG_MASK_R) |
| 5236 | goto out_inval; |
| 5237 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && |
| 5238 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) |
| 5239 | goto out_inval; |
| 5240 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) |
| 5241 | goto out_inval; |
| 5242 | return NFS_OK; |
| 5243 | out_inval: |
| 5244 | return -NFS4ERR_INVAL; |
| 5245 | } |
| 5246 | |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5247 | static bool |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5248 | nfs41_same_server_scope(struct nfs41_server_scope *a, |
| 5249 | struct nfs41_server_scope *b) |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5250 | { |
| 5251 | if (a->server_scope_sz == b->server_scope_sz && |
| 5252 | memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0) |
| 5253 | return true; |
| 5254 | |
| 5255 | return false; |
| 5256 | } |
| 5257 | |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5258 | /* |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5259 | * nfs4_proc_bind_conn_to_session() |
| 5260 | * |
| 5261 | * The 4.1 client currently uses the same TCP connection for the |
| 5262 | * fore and backchannel. |
| 5263 | */ |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5264 | 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] | 5265 | { |
| 5266 | int status; |
| 5267 | struct nfs41_bind_conn_to_session_res res; |
| 5268 | struct rpc_message msg = { |
| 5269 | .rpc_proc = |
| 5270 | &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION], |
| 5271 | .rpc_argp = clp, |
| 5272 | .rpc_resp = &res, |
Trond Myklebust | 2cf047c | 2012-05-25 17:57:41 -0400 | [diff] [blame] | 5273 | .rpc_cred = cred, |
Weston Andros Adamson | 7c44f1ae | 2012-05-24 13:22:50 -0400 | [diff] [blame] | 5274 | }; |
| 5275 | |
| 5276 | dprintk("--> %s\n", __func__); |
| 5277 | BUG_ON(clp == NULL); |
| 5278 | |
| 5279 | res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
| 5280 | if (unlikely(res.session == NULL)) { |
| 5281 | status = -ENOMEM; |
| 5282 | goto out; |
| 5283 | } |
| 5284 | |
| 5285 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5286 | if (status == 0) { |
| 5287 | if (memcmp(res.session->sess_id.data, |
| 5288 | clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) { |
| 5289 | dprintk("NFS: %s: Session ID mismatch\n", __func__); |
| 5290 | status = -EIO; |
| 5291 | goto out_session; |
| 5292 | } |
| 5293 | if (res.dir != NFS4_CDFS4_BOTH) { |
| 5294 | dprintk("NFS: %s: Unexpected direction from server\n", |
| 5295 | __func__); |
| 5296 | status = -EIO; |
| 5297 | goto out_session; |
| 5298 | } |
| 5299 | if (res.use_conn_in_rdma_mode) { |
| 5300 | dprintk("NFS: %s: Server returned RDMA mode = true\n", |
| 5301 | __func__); |
| 5302 | status = -EIO; |
| 5303 | goto out_session; |
| 5304 | } |
| 5305 | } |
| 5306 | out_session: |
| 5307 | kfree(res.session); |
| 5308 | out: |
| 5309 | dprintk("<-- %s status= %d\n", __func__, status); |
| 5310 | return status; |
| 5311 | } |
| 5312 | |
| 5313 | /* |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5314 | * nfs4_proc_exchange_id() |
| 5315 | * |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5316 | * Returns zero, a negative errno, or a negative NFS4ERR status code. |
| 5317 | * |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5318 | * Since the clientid has expired, all compounds using sessions |
| 5319 | * associated with the stale clientid will be returning |
| 5320 | * NFS4ERR_BADSESSION in the sequence operation, and will therefore |
| 5321 | * be in some phase of session reset. |
| 5322 | */ |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 5323 | 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] | 5324 | { |
| 5325 | nfs4_verifier verifier; |
| 5326 | struct nfs41_exchange_id_args args = { |
Chuck Lever | cd93710 | 2012-03-02 17:14:31 -0500 | [diff] [blame] | 5327 | .verifier = &verifier, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5328 | .client = clp, |
Andy Adamson | 357f54d | 2010-12-14 10:11:57 -0500 | [diff] [blame] | 5329 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5330 | }; |
| 5331 | struct nfs41_exchange_id_res res = { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5332 | 0 |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5333 | }; |
| 5334 | int status; |
| 5335 | struct rpc_message msg = { |
| 5336 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID], |
| 5337 | .rpc_argp = &args, |
| 5338 | .rpc_resp = &res, |
| 5339 | .rpc_cred = cred, |
| 5340 | }; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5341 | |
Chuck Lever | f092075 | 2012-05-21 22:45:41 -0400 | [diff] [blame] | 5342 | nfs4_init_boot_verifier(clp, &verifier); |
Chuck Lever | e984a55 | 2012-09-14 17:24:21 -0400 | [diff] [blame] | 5343 | args.id_len = nfs4_init_uniform_client_string(clp, args.id, |
| 5344 | sizeof(args.id)); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5345 | dprintk("NFS call exchange_id auth=%s, '%.*s'\n", |
| 5346 | clp->cl_rpcclient->cl_auth->au_ops->au_name, |
| 5347 | args.id_len, args.id); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5348 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5349 | res.server_owner = kzalloc(sizeof(struct nfs41_server_owner), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5350 | GFP_NOFS); |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5351 | if (unlikely(res.server_owner == NULL)) { |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5352 | status = -ENOMEM; |
| 5353 | goto out; |
| 5354 | } |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5355 | |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5356 | res.server_scope = kzalloc(sizeof(struct nfs41_server_scope), |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5357 | GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5358 | if (unlikely(res.server_scope == NULL)) { |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5359 | status = -ENOMEM; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5360 | goto out_server_owner; |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5361 | } |
| 5362 | |
Trond Myklebust | bbafffd | 2012-05-24 16:31:39 -0400 | [diff] [blame] | 5363 | res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5364 | if (unlikely(res.impl_id == NULL)) { |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5365 | status = -ENOMEM; |
| 5366 | goto out_server_scope; |
| 5367 | } |
| 5368 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5369 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5370 | if (status == 0) |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5371 | status = nfs4_check_cl_exchange_flags(res.flags); |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5372 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5373 | if (status == 0) { |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5374 | clp->cl_clientid = res.clientid; |
| 5375 | clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R); |
| 5376 | if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R)) |
| 5377 | clp->cl_seqid = res.seqid; |
| 5378 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5379 | kfree(clp->cl_serverowner); |
| 5380 | clp->cl_serverowner = res.server_owner; |
| 5381 | res.server_owner = NULL; |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5382 | |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5383 | /* use the most recent implementation id */ |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5384 | kfree(clp->cl_implid); |
| 5385 | clp->cl_implid = res.impl_id; |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5386 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5387 | if (clp->cl_serverscope != NULL && |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5388 | !nfs41_same_server_scope(clp->cl_serverscope, |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5389 | res.server_scope)) { |
| 5390 | dprintk("%s: server_scope mismatch detected\n", |
| 5391 | __func__); |
| 5392 | set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state); |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5393 | kfree(clp->cl_serverscope); |
| 5394 | clp->cl_serverscope = NULL; |
Weston Andros Adamson | 78fe0f4 | 2011-05-31 19:05:47 -0400 | [diff] [blame] | 5395 | } |
| 5396 | |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5397 | if (clp->cl_serverscope == NULL) { |
Chuck Lever | 79d4e1f | 2012-05-21 22:44:31 -0400 | [diff] [blame] | 5398 | clp->cl_serverscope = res.server_scope; |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5399 | goto out; |
| 5400 | } |
Trond Myklebust | 32b0131 | 2012-05-26 13:41:04 -0400 | [diff] [blame] | 5401 | } else |
| 5402 | kfree(res.impl_id); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5403 | |
Chuck Lever | acdeb69 | 2012-05-21 22:46:16 -0400 | [diff] [blame] | 5404 | out_server_owner: |
| 5405 | kfree(res.server_owner); |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5406 | out_server_scope: |
Weston Andros Adamson | abe9a6d | 2012-02-16 11:17:05 -0500 | [diff] [blame] | 5407 | kfree(res.server_scope); |
| 5408 | out: |
Chuck Lever | 177313f | 2012-05-21 22:44:58 -0400 | [diff] [blame] | 5409 | if (clp->cl_implid != NULL) |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5410 | dprintk("NFS reply exchange_id: Server Implementation ID: " |
Weston Andros Adamson | 7d2ed9a | 2012-02-17 15:20:26 -0500 | [diff] [blame] | 5411 | "domain: %s, name: %s, date: %llu,%u\n", |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5412 | clp->cl_implid->domain, clp->cl_implid->name, |
Chuck Lever | 5915554 | 2012-05-21 22:44:41 -0400 | [diff] [blame] | 5413 | clp->cl_implid->date.seconds, |
| 5414 | clp->cl_implid->date.nseconds); |
Chuck Lever | 6bbb4ae | 2012-07-11 16:30:59 -0400 | [diff] [blame] | 5415 | dprintk("NFS reply exchange_id: %d\n", status); |
Benny Halevy | 99fe60d | 2009-04-01 09:22:29 -0400 | [diff] [blame] | 5416 | return status; |
| 5417 | } |
| 5418 | |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5419 | static int _nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5420 | struct rpc_cred *cred) |
| 5421 | { |
| 5422 | struct rpc_message msg = { |
| 5423 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID], |
| 5424 | .rpc_argp = clp, |
| 5425 | .rpc_cred = cred, |
| 5426 | }; |
| 5427 | int status; |
| 5428 | |
| 5429 | status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
| 5430 | if (status) |
Trond Myklebust | 02c6752 | 2012-06-07 13:45:53 -0400 | [diff] [blame] | 5431 | dprintk("NFS: Got error %d from the server %s on " |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5432 | "DESTROY_CLIENTID.", status, clp->cl_hostname); |
| 5433 | return status; |
| 5434 | } |
| 5435 | |
| 5436 | static int nfs4_proc_destroy_clientid(struct nfs_client *clp, |
| 5437 | struct rpc_cred *cred) |
| 5438 | { |
| 5439 | unsigned int loop; |
| 5440 | int ret; |
| 5441 | |
| 5442 | for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) { |
| 5443 | ret = _nfs4_proc_destroy_clientid(clp, cred); |
| 5444 | switch (ret) { |
| 5445 | case -NFS4ERR_DELAY: |
| 5446 | case -NFS4ERR_CLIENTID_BUSY: |
| 5447 | ssleep(1); |
| 5448 | break; |
| 5449 | default: |
| 5450 | return ret; |
| 5451 | } |
| 5452 | } |
| 5453 | return 0; |
| 5454 | } |
| 5455 | |
| 5456 | int nfs4_destroy_clientid(struct nfs_client *clp) |
| 5457 | { |
| 5458 | struct rpc_cred *cred; |
| 5459 | int ret = 0; |
| 5460 | |
| 5461 | if (clp->cl_mvops->minor_version < 1) |
| 5462 | goto out; |
| 5463 | if (clp->cl_exchange_flags == 0) |
| 5464 | goto out; |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 5465 | if (clp->cl_preserve_clid) |
| 5466 | goto out; |
Trond Myklebust | 6624553 | 2012-05-25 17:18:09 -0400 | [diff] [blame] | 5467 | cred = nfs4_get_exchange_id_cred(clp); |
| 5468 | ret = nfs4_proc_destroy_clientid(clp, cred); |
| 5469 | if (cred) |
| 5470 | put_rpccred(cred); |
| 5471 | switch (ret) { |
| 5472 | case 0: |
| 5473 | case -NFS4ERR_STALE_CLIENTID: |
| 5474 | clp->cl_exchange_flags = 0; |
| 5475 | } |
| 5476 | out: |
| 5477 | return ret; |
| 5478 | } |
| 5479 | |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5480 | struct nfs4_get_lease_time_data { |
| 5481 | struct nfs4_get_lease_time_args *args; |
| 5482 | struct nfs4_get_lease_time_res *res; |
| 5483 | struct nfs_client *clp; |
| 5484 | }; |
| 5485 | |
| 5486 | static void nfs4_get_lease_time_prepare(struct rpc_task *task, |
| 5487 | void *calldata) |
| 5488 | { |
| 5489 | int ret; |
| 5490 | struct nfs4_get_lease_time_data *data = |
| 5491 | (struct nfs4_get_lease_time_data *)calldata; |
| 5492 | |
| 5493 | dprintk("--> %s\n", __func__); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5494 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5495 | /* just setup sequence, do not trigger session recovery |
| 5496 | since we're invoked within one */ |
| 5497 | ret = nfs41_setup_sequence(data->clp->cl_session, |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5498 | &data->args->la_seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5499 | &data->res->lr_seq_res, task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5500 | |
| 5501 | BUG_ON(ret == -EAGAIN); |
| 5502 | rpc_call_start(task); |
| 5503 | dprintk("<-- %s\n", __func__); |
| 5504 | } |
| 5505 | |
| 5506 | /* |
| 5507 | * Called from nfs4_state_manager thread for session setup, so don't recover |
| 5508 | * from sequence operation or clientid errors. |
| 5509 | */ |
| 5510 | static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata) |
| 5511 | { |
| 5512 | struct nfs4_get_lease_time_data *data = |
| 5513 | (struct nfs4_get_lease_time_data *)calldata; |
| 5514 | |
| 5515 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 5516 | if (!nfs41_sequence_done(task, &data->res->lr_seq_res)) |
| 5517 | return; |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5518 | switch (task->tk_status) { |
| 5519 | case -NFS4ERR_DELAY: |
| 5520 | case -NFS4ERR_GRACE: |
| 5521 | dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status); |
| 5522 | rpc_delay(task, NFS4_POLL_RETRY_MIN); |
| 5523 | task->tk_status = 0; |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 5524 | /* fall through */ |
| 5525 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 5526 | rpc_restart_call_prepare(task); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5527 | return; |
| 5528 | } |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5529 | dprintk("<-- %s\n", __func__); |
| 5530 | } |
| 5531 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 5532 | static const struct rpc_call_ops nfs4_get_lease_time_ops = { |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5533 | .rpc_call_prepare = nfs4_get_lease_time_prepare, |
| 5534 | .rpc_call_done = nfs4_get_lease_time_done, |
| 5535 | }; |
| 5536 | |
| 5537 | int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo) |
| 5538 | { |
| 5539 | struct rpc_task *task; |
| 5540 | struct nfs4_get_lease_time_args args; |
| 5541 | struct nfs4_get_lease_time_res res = { |
| 5542 | .lr_fsinfo = fsinfo, |
| 5543 | }; |
| 5544 | struct nfs4_get_lease_time_data data = { |
| 5545 | .args = &args, |
| 5546 | .res = &res, |
| 5547 | .clp = clp, |
| 5548 | }; |
| 5549 | struct rpc_message msg = { |
| 5550 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME], |
| 5551 | .rpc_argp = &args, |
| 5552 | .rpc_resp = &res, |
| 5553 | }; |
| 5554 | struct rpc_task_setup task_setup = { |
| 5555 | .rpc_client = clp->cl_rpcclient, |
| 5556 | .rpc_message = &msg, |
| 5557 | .callback_ops = &nfs4_get_lease_time_ops, |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5558 | .callback_data = &data, |
| 5559 | .flags = RPC_TASK_TIMEOUT, |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5560 | }; |
| 5561 | int status; |
| 5562 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 5563 | nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0); |
Andy Adamson | 2050f0c | 2009-04-01 09:22:30 -0400 | [diff] [blame] | 5564 | dprintk("--> %s\n", __func__); |
| 5565 | task = rpc_run_task(&task_setup); |
| 5566 | |
| 5567 | if (IS_ERR(task)) |
| 5568 | status = PTR_ERR(task); |
| 5569 | else { |
| 5570 | status = task->tk_status; |
| 5571 | rpc_put_task(task); |
| 5572 | } |
| 5573 | dprintk("<-- %s return %d\n", __func__, status); |
| 5574 | |
| 5575 | return status; |
| 5576 | } |
| 5577 | |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5578 | static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags) |
| 5579 | { |
| 5580 | return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags); |
| 5581 | } |
| 5582 | |
| 5583 | static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl, |
| 5584 | struct nfs4_slot *new, |
| 5585 | u32 max_slots, |
| 5586 | u32 ivalue) |
| 5587 | { |
| 5588 | struct nfs4_slot *old = NULL; |
| 5589 | u32 i; |
| 5590 | |
| 5591 | spin_lock(&tbl->slot_tbl_lock); |
| 5592 | if (new) { |
| 5593 | old = tbl->slots; |
| 5594 | tbl->slots = new; |
| 5595 | tbl->max_slots = max_slots; |
| 5596 | } |
| 5597 | tbl->highest_used_slotid = -1; /* no slot is currently used */ |
| 5598 | for (i = 0; i < tbl->max_slots; i++) |
| 5599 | tbl->slots[i].seq_nr = ivalue; |
| 5600 | spin_unlock(&tbl->slot_tbl_lock); |
| 5601 | kfree(old); |
| 5602 | } |
| 5603 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5604 | /* |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5605 | * (re)Initialise a slot table |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5606 | */ |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5607 | static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs, |
| 5608 | u32 ivalue) |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5609 | { |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5610 | struct nfs4_slot *new = NULL; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5611 | int ret = -ENOMEM; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5612 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5613 | dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__, |
| 5614 | max_reqs, tbl->max_slots); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5615 | |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5616 | /* Does the newly negotiated max_reqs match the existing slot table? */ |
| 5617 | if (max_reqs != tbl->max_slots) { |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5618 | new = nfs4_alloc_slots(max_reqs, GFP_NOFS); |
Andy Adamson | 104aeba | 2010-01-14 17:45:10 -0500 | [diff] [blame] | 5619 | if (!new) |
| 5620 | goto out; |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5621 | } |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5622 | ret = 0; |
| 5623 | |
| 5624 | nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue); |
Andy Adamson | ac72b7b | 2009-04-01 09:22:37 -0400 | [diff] [blame] | 5625 | dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__, |
| 5626 | tbl, tbl->slots, tbl->max_slots); |
| 5627 | out: |
| 5628 | dprintk("<-- %s: return %d\n", __func__, ret); |
| 5629 | return ret; |
| 5630 | } |
| 5631 | |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5632 | /* Destroy the slot table */ |
| 5633 | static void nfs4_destroy_slot_tables(struct nfs4_session *session) |
| 5634 | { |
| 5635 | if (session->fc_slot_table.slots != NULL) { |
| 5636 | kfree(session->fc_slot_table.slots); |
| 5637 | session->fc_slot_table.slots = NULL; |
| 5638 | } |
| 5639 | if (session->bc_slot_table.slots != NULL) { |
| 5640 | kfree(session->bc_slot_table.slots); |
| 5641 | session->bc_slot_table.slots = NULL; |
| 5642 | } |
| 5643 | return; |
| 5644 | } |
| 5645 | |
Ricardo Labiaga | b73dafa | 2009-04-01 09:23:31 -0400 | [diff] [blame] | 5646 | /* |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5647 | * Initialize or reset the forechannel and backchannel tables |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5648 | */ |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5649 | static int nfs4_setup_session_slot_tables(struct nfs4_session *ses) |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5650 | { |
Trond Myklebust | f26468f | 2009-12-05 19:32:11 -0500 | [diff] [blame] | 5651 | struct nfs4_slot_table *tbl; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5652 | int status; |
Ricardo Labiaga | 050047c | 2009-04-01 09:23:32 -0400 | [diff] [blame] | 5653 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5654 | dprintk("--> %s\n", __func__); |
| 5655 | /* Fore channel */ |
| 5656 | tbl = &ses->fc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5657 | status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1); |
| 5658 | if (status) /* -ENOMEM */ |
| 5659 | return status; |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5660 | /* Back channel */ |
| 5661 | tbl = &ses->bc_slot_table; |
Trond Myklebust | f86f36a | 2012-02-14 20:33:19 -0500 | [diff] [blame] | 5662 | status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0); |
| 5663 | if (status && tbl->slots == NULL) |
| 5664 | /* Fore and back channel share a connection so get |
| 5665 | * both slot tables or neither */ |
| 5666 | nfs4_destroy_slot_tables(ses); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5667 | return status; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5668 | } |
| 5669 | |
| 5670 | struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) |
| 5671 | { |
| 5672 | struct nfs4_session *session; |
| 5673 | struct nfs4_slot_table *tbl; |
| 5674 | |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 5675 | session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5676 | if (!session) |
| 5677 | return NULL; |
Andy Adamson | 76db6d9 | 2009-04-01 09:22:38 -0400 | [diff] [blame] | 5678 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5679 | tbl = &session->fc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5680 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5681 | spin_lock_init(&tbl->slot_tbl_lock); |
Alexandros Batsakis | 689cf5c | 2009-12-14 21:27:56 -0800 | [diff] [blame] | 5682 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5683 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5684 | |
| 5685 | tbl = &session->bc_slot_table; |
Trond Myklebust | 45d43c2 | 2012-02-06 19:38:51 -0500 | [diff] [blame] | 5686 | tbl->highest_used_slotid = NFS4_NO_SLOT; |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5687 | spin_lock_init(&tbl->slot_tbl_lock); |
| 5688 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 5689 | init_completion(&tbl->complete); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5690 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5691 | session->session_state = 1<<NFS4_SESSION_INITING; |
| 5692 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5693 | session->clp = clp; |
| 5694 | return session; |
| 5695 | } |
| 5696 | |
| 5697 | void nfs4_destroy_session(struct nfs4_session *session) |
| 5698 | { |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5699 | struct rpc_xprt *xprt; |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5700 | struct rpc_cred *cred; |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5701 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5702 | cred = nfs4_get_exchange_id_cred(session->clp); |
| 5703 | nfs4_proc_destroy_session(session, cred); |
| 5704 | if (cred) |
| 5705 | put_rpccred(cred); |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5706 | |
| 5707 | rcu_read_lock(); |
| 5708 | xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt); |
| 5709 | rcu_read_unlock(); |
Andy Adamson | 5a0ffe5 | 2009-04-01 09:23:18 -0400 | [diff] [blame] | 5710 | dprintk("%s Destroy backchannel for xprt %p\n", |
Trond Myklebust | 2446ab6 | 2012-03-01 17:00:56 -0500 | [diff] [blame] | 5711 | __func__, xprt); |
| 5712 | xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS); |
Ricardo Labiaga | f8625a6 | 2009-04-01 09:23:33 -0400 | [diff] [blame] | 5713 | nfs4_destroy_slot_tables(session); |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 5714 | kfree(session); |
| 5715 | } |
| 5716 | |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5717 | /* |
| 5718 | * Initialize the values to be used by the client in CREATE_SESSION |
| 5719 | * If nfs4_init_session set the fore channel request and response sizes, |
| 5720 | * use them. |
| 5721 | * |
| 5722 | * Set the back channel max_resp_sz_cached to zero to force the client to |
| 5723 | * always set csa_cachethis to FALSE because the current implementation |
| 5724 | * of the back channel DRC only supports caching the CB_SEQUENCE operation. |
| 5725 | */ |
| 5726 | static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args) |
| 5727 | { |
| 5728 | struct nfs4_session *session = args->client->cl_session; |
| 5729 | unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz, |
| 5730 | mxresp_sz = session->fc_attrs.max_resp_sz; |
| 5731 | |
| 5732 | if (mxrqst_sz == 0) |
| 5733 | mxrqst_sz = NFS_MAX_FILE_IO_SIZE; |
| 5734 | if (mxresp_sz == 0) |
| 5735 | mxresp_sz = NFS_MAX_FILE_IO_SIZE; |
| 5736 | /* Fore channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5737 | args->fc_attrs.max_rqst_sz = mxrqst_sz; |
| 5738 | args->fc_attrs.max_resp_sz = mxresp_sz; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5739 | args->fc_attrs.max_ops = NFS4_MAX_OPS; |
Trond Myklebust | ef159e9 | 2012-02-06 19:50:40 -0500 | [diff] [blame] | 5740 | args->fc_attrs.max_reqs = max_session_slots; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5741 | |
| 5742 | dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5743 | "max_ops=%u max_reqs=%u\n", |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5744 | __func__, |
| 5745 | args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz, |
Mike Sager | 8e0d46e | 2009-12-17 12:06:26 -0500 | [diff] [blame] | 5746 | args->fc_attrs.max_ops, args->fc_attrs.max_reqs); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5747 | |
| 5748 | /* Back channel attributes */ |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5749 | args->bc_attrs.max_rqst_sz = PAGE_SIZE; |
| 5750 | args->bc_attrs.max_resp_sz = PAGE_SIZE; |
| 5751 | args->bc_attrs.max_resp_sz_cached = 0; |
| 5752 | args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS; |
| 5753 | args->bc_attrs.max_reqs = 1; |
| 5754 | |
| 5755 | dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u " |
| 5756 | "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n", |
| 5757 | __func__, |
| 5758 | args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz, |
| 5759 | args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops, |
| 5760 | args->bc_attrs.max_reqs); |
| 5761 | } |
| 5762 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5763 | 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] | 5764 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5765 | struct nfs4_channel_attrs *sent = &args->fc_attrs; |
| 5766 | struct nfs4_channel_attrs *rcvd = &session->fc_attrs; |
| 5767 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5768 | if (rcvd->max_resp_sz > sent->max_resp_sz) |
| 5769 | return -EINVAL; |
| 5770 | /* |
| 5771 | * Our requested max_ops is the minimum we need; we're not |
| 5772 | * prepared to break up compounds into smaller pieces than that. |
| 5773 | * So, no point even trying to continue if the server won't |
| 5774 | * cooperate: |
| 5775 | */ |
| 5776 | if (rcvd->max_ops < sent->max_ops) |
| 5777 | return -EINVAL; |
| 5778 | if (rcvd->max_reqs == 0) |
| 5779 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5780 | if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE) |
| 5781 | rcvd->max_reqs = NFS4_MAX_SLOT_TABLE; |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5782 | return 0; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5783 | } |
| 5784 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5785 | static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session) |
| 5786 | { |
| 5787 | struct nfs4_channel_attrs *sent = &args->bc_attrs; |
| 5788 | struct nfs4_channel_attrs *rcvd = &session->bc_attrs; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5789 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5790 | if (rcvd->max_rqst_sz > sent->max_rqst_sz) |
| 5791 | return -EINVAL; |
| 5792 | if (rcvd->max_resp_sz < sent->max_resp_sz) |
| 5793 | return -EINVAL; |
| 5794 | if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) |
| 5795 | return -EINVAL; |
| 5796 | /* These would render the backchannel useless: */ |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5797 | if (rcvd->max_ops != sent->max_ops) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5798 | return -EINVAL; |
Vitaliy Gusev | b4b9a0c | 2012-02-15 19:38:25 +0400 | [diff] [blame] | 5799 | if (rcvd->max_reqs != sent->max_reqs) |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5800 | return -EINVAL; |
| 5801 | return 0; |
| 5802 | } |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5803 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5804 | static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args, |
| 5805 | struct nfs4_session *session) |
| 5806 | { |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5807 | int ret; |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5808 | |
J. Bruce Fields | 43c2e88 | 2010-10-02 15:19:01 -0400 | [diff] [blame] | 5809 | ret = nfs4_verify_fore_channel_attrs(args, session); |
| 5810 | if (ret) |
| 5811 | return ret; |
| 5812 | return nfs4_verify_back_channel_attrs(args, session); |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5813 | } |
| 5814 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5815 | static int _nfs4_proc_create_session(struct nfs_client *clp, |
| 5816 | struct rpc_cred *cred) |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5817 | { |
| 5818 | struct nfs4_session *session = clp->cl_session; |
| 5819 | struct nfs41_create_session_args args = { |
| 5820 | .client = clp, |
| 5821 | .cb_program = NFS4_CALLBACK, |
| 5822 | }; |
| 5823 | struct nfs41_create_session_res res = { |
| 5824 | .client = clp, |
| 5825 | }; |
| 5826 | struct rpc_message msg = { |
| 5827 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION], |
| 5828 | .rpc_argp = &args, |
| 5829 | .rpc_resp = &res, |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5830 | .rpc_cred = cred, |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5831 | }; |
| 5832 | int status; |
| 5833 | |
| 5834 | nfs4_init_channel_attrs(&args); |
Andy Adamson | 0f91421 | 2009-04-01 09:23:16 -0400 | [diff] [blame] | 5835 | args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5836 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5837 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5838 | |
Andy Adamson | 8d35301 | 2009-04-01 09:22:32 -0400 | [diff] [blame] | 5839 | if (!status) |
| 5840 | /* Verify the session's negotiated channel_attrs values */ |
| 5841 | status = nfs4_verify_channel_attrs(&args, session); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5842 | if (!status) { |
| 5843 | /* Increment the clientid slot sequence id */ |
| 5844 | clp->cl_seqid++; |
| 5845 | } |
| 5846 | |
| 5847 | return status; |
| 5848 | } |
| 5849 | |
| 5850 | /* |
| 5851 | * Issues a CREATE_SESSION operation to the server. |
| 5852 | * It is the responsibility of the caller to verify the session is |
| 5853 | * expired before calling this routine. |
| 5854 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5855 | 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] | 5856 | { |
| 5857 | int status; |
| 5858 | unsigned *ptr; |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5859 | struct nfs4_session *session = clp->cl_session; |
| 5860 | |
| 5861 | dprintk("--> %s clp=%p session=%p\n", __func__, clp, session); |
| 5862 | |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5863 | status = _nfs4_proc_create_session(clp, cred); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5864 | if (status) |
| 5865 | goto out; |
| 5866 | |
Andy Adamson | aacd553 | 2011-11-09 13:58:21 -0500 | [diff] [blame] | 5867 | /* Init or reset the session slot tables */ |
| 5868 | status = nfs4_setup_session_slot_tables(session); |
| 5869 | dprintk("slot table setup returned %d\n", status); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5870 | if (status) |
| 5871 | goto out; |
| 5872 | |
| 5873 | ptr = (unsigned *)&session->sess_id.data[0]; |
| 5874 | dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__, |
| 5875 | clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]); |
Andy Adamson | fc93158 | 2009-04-01 09:22:31 -0400 | [diff] [blame] | 5876 | out: |
| 5877 | dprintk("<-- %s\n", __func__); |
| 5878 | return status; |
| 5879 | } |
| 5880 | |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5881 | /* |
| 5882 | * Issue the over-the-wire RPC DESTROY_SESSION. |
| 5883 | * The caller must serialize access to this routine. |
| 5884 | */ |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5885 | int nfs4_proc_destroy_session(struct nfs4_session *session, |
| 5886 | struct rpc_cred *cred) |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5887 | { |
Trond Myklebust | 848f5bd | 2012-05-25 17:51:23 -0400 | [diff] [blame] | 5888 | struct rpc_message msg = { |
| 5889 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION], |
| 5890 | .rpc_argp = session, |
| 5891 | .rpc_cred = cred, |
| 5892 | }; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5893 | int status = 0; |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5894 | |
| 5895 | dprintk("--> nfs4_proc_destroy_session\n"); |
| 5896 | |
| 5897 | /* session is still being setup */ |
| 5898 | if (session->clp->cl_cons_state != NFS_CS_READY) |
| 5899 | return status; |
| 5900 | |
Trond Myklebust | 1bd714f | 2011-04-24 14:29:33 -0400 | [diff] [blame] | 5901 | status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5902 | |
| 5903 | if (status) |
Trond Myklebust | 08106ac | 2012-06-05 10:08:24 -0400 | [diff] [blame] | 5904 | dprintk("NFS: Got error %d from the server on DESTROY_SESSION. " |
Andy Adamson | 0f3e66c | 2009-04-01 09:22:34 -0400 | [diff] [blame] | 5905 | "Session has been destroyed regardless...\n", status); |
| 5906 | |
| 5907 | dprintk("<-- nfs4_proc_destroy_session\n"); |
| 5908 | return status; |
| 5909 | } |
| 5910 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5911 | /* |
| 5912 | * With sessions, the client is not marked ready until after a |
| 5913 | * successful EXCHANGE_ID and CREATE_SESSION. |
| 5914 | * |
| 5915 | * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate |
| 5916 | * other versions of NFS can be tried. |
| 5917 | */ |
| 5918 | static int nfs41_check_session_ready(struct nfs_client *clp) |
| 5919 | { |
| 5920 | int ret; |
| 5921 | |
| 5922 | if (clp->cl_cons_state == NFS_CS_SESSION_INITING) { |
| 5923 | ret = nfs4_client_recover_expired_lease(clp); |
| 5924 | if (ret) |
| 5925 | return ret; |
| 5926 | } |
| 5927 | if (clp->cl_cons_state < NFS_CS_READY) |
| 5928 | return -EPROTONOSUPPORT; |
Trond Myklebust | 54ac471 | 2012-05-23 13:26:10 -0400 | [diff] [blame] | 5929 | smp_rmb(); |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5930 | return 0; |
| 5931 | } |
| 5932 | |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5933 | int nfs4_init_session(struct nfs_server *server) |
| 5934 | { |
| 5935 | struct nfs_client *clp = server->nfs_client; |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5936 | struct nfs4_session *session; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5937 | unsigned int rsize, wsize; |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5938 | |
| 5939 | if (!nfs4_has_session(clp)) |
| 5940 | return 0; |
| 5941 | |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5942 | session = clp->cl_session; |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5943 | spin_lock(&clp->cl_lock); |
| 5944 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
Trond Myklebust | 1055d76 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 5945 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5946 | rsize = server->rsize; |
| 5947 | if (rsize == 0) |
| 5948 | rsize = NFS_MAX_FILE_IO_SIZE; |
| 5949 | wsize = server->wsize; |
| 5950 | if (wsize == 0) |
| 5951 | wsize = NFS_MAX_FILE_IO_SIZE; |
Andy Adamson | 68bf05e | 2009-12-15 12:55:02 -0500 | [diff] [blame] | 5952 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5953 | session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead; |
| 5954 | session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead; |
| 5955 | } |
| 5956 | spin_unlock(&clp->cl_lock); |
Alexandros Batsakis | 2449ea2 | 2009-12-05 13:36:55 -0500 | [diff] [blame] | 5957 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5958 | return nfs41_check_session_ready(clp); |
Trond Myklebust | fccba80 | 2009-07-21 16:48:07 -0400 | [diff] [blame] | 5959 | } |
| 5960 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5961 | 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] | 5962 | { |
| 5963 | struct nfs4_session *session = clp->cl_session; |
| 5964 | int ret; |
| 5965 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5966 | spin_lock(&clp->cl_lock); |
| 5967 | if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) { |
| 5968 | /* |
| 5969 | * Do not set NFS_CS_CHECK_LEASE_TIME instead set the |
| 5970 | * DS lease to be equal to the MDS lease. |
| 5971 | */ |
| 5972 | clp->cl_lease_time = lease_time; |
| 5973 | clp->cl_last_renewal = jiffies; |
| 5974 | } |
| 5975 | spin_unlock(&clp->cl_lock); |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5976 | |
Trond Myklebust | 7b38c36 | 2012-05-23 13:23:31 -0400 | [diff] [blame] | 5977 | ret = nfs41_check_session_ready(clp); |
| 5978 | if (ret) |
| 5979 | return ret; |
| 5980 | /* Test for the DS role */ |
| 5981 | if (!is_ds_client(clp)) |
| 5982 | return -ENODEV; |
| 5983 | return 0; |
Andy Adamson | d83217c | 2011-03-01 01:34:17 +0000 | [diff] [blame] | 5984 | } |
| 5985 | EXPORT_SYMBOL_GPL(nfs4_init_ds_session); |
| 5986 | |
| 5987 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 5988 | /* |
| 5989 | * Renew the cl_session lease. |
| 5990 | */ |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5991 | struct nfs4_sequence_data { |
| 5992 | struct nfs_client *clp; |
| 5993 | struct nfs4_sequence_args args; |
| 5994 | struct nfs4_sequence_res res; |
| 5995 | }; |
| 5996 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 5997 | static void nfs41_sequence_release(void *data) |
| 5998 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 5999 | struct nfs4_sequence_data *calldata = data; |
| 6000 | struct nfs_client *clp = calldata->clp; |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6001 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6002 | if (atomic_read(&clp->cl_count) > 1) |
| 6003 | nfs4_schedule_state_renewal(clp); |
| 6004 | nfs_put_client(clp); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6005 | kfree(calldata); |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6006 | } |
| 6007 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6008 | static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6009 | { |
| 6010 | switch(task->tk_status) { |
| 6011 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6012 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
| 6013 | return -EAGAIN; |
| 6014 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6015 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6016 | } |
| 6017 | return 0; |
| 6018 | } |
| 6019 | |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6020 | static void nfs41_sequence_call_done(struct rpc_task *task, void *data) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6021 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6022 | struct nfs4_sequence_data *calldata = data; |
| 6023 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6024 | |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6025 | if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp)) |
| 6026 | return; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6027 | |
| 6028 | if (task->tk_status < 0) { |
| 6029 | dprintk("%s ERROR %d\n", __func__, task->tk_status); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6030 | if (atomic_read(&clp->cl_count) == 1) |
| 6031 | goto out; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6032 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6033 | if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) { |
| 6034 | rpc_restart_call_prepare(task); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6035 | return; |
| 6036 | } |
| 6037 | } |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6038 | dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred); |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6039 | out: |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6040 | dprintk("<-- %s\n", __func__); |
| 6041 | } |
| 6042 | |
| 6043 | static void nfs41_sequence_prepare(struct rpc_task *task, void *data) |
| 6044 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6045 | struct nfs4_sequence_data *calldata = data; |
| 6046 | struct nfs_client *clp = calldata->clp; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6047 | struct nfs4_sequence_args *args; |
| 6048 | struct nfs4_sequence_res *res; |
| 6049 | |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6050 | args = task->tk_msg.rpc_argp; |
| 6051 | res = task->tk_msg.rpc_resp; |
| 6052 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6053 | if (nfs41_setup_sequence(clp->cl_session, args, res, task)) |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6054 | return; |
| 6055 | rpc_call_start(task); |
| 6056 | } |
| 6057 | |
| 6058 | static const struct rpc_call_ops nfs41_sequence_ops = { |
| 6059 | .rpc_call_done = nfs41_sequence_call_done, |
| 6060 | .rpc_call_prepare = nfs41_sequence_prepare, |
Alexandros Batsakis | dc96aef | 2010-02-05 03:45:04 -0800 | [diff] [blame] | 6061 | .rpc_release = nfs41_sequence_release, |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6062 | }; |
| 6063 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6064 | 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] | 6065 | { |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6066 | struct nfs4_sequence_data *calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6067 | struct rpc_message msg = { |
| 6068 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE], |
| 6069 | .rpc_cred = cred, |
| 6070 | }; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6071 | struct rpc_task_setup task_setup_data = { |
| 6072 | .rpc_client = clp->cl_rpcclient, |
| 6073 | .rpc_message = &msg, |
| 6074 | .callback_ops = &nfs41_sequence_ops, |
| 6075 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT, |
| 6076 | }; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6077 | |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6078 | if (!atomic_inc_not_zero(&clp->cl_count)) |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6079 | return ERR_PTR(-EIO); |
Benny Halevy | dfb4f309 | 2010-09-24 09:17:01 -0400 | [diff] [blame] | 6080 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6081 | if (calldata == NULL) { |
Alexandros Batsakis | 7135840 | 2010-02-05 03:45:05 -0800 | [diff] [blame] | 6082 | nfs_put_client(clp); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6083 | return ERR_PTR(-ENOMEM); |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6084 | } |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6085 | nfs41_init_sequence(&calldata->args, &calldata->res, 0); |
Trond Myklebust | d5f8d3f | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6086 | msg.rpc_argp = &calldata->args; |
| 6087 | msg.rpc_resp = &calldata->res; |
| 6088 | calldata->clp = clp; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6089 | task_setup_data.callback_data = calldata; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6090 | |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6091 | return rpc_run_task(&task_setup_data); |
| 6092 | } |
| 6093 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6094 | 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] | 6095 | { |
| 6096 | struct rpc_task *task; |
| 6097 | int ret = 0; |
| 6098 | |
Trond Myklebust | 2f60ea6 | 2011-08-24 15:07:37 -0400 | [diff] [blame] | 6099 | if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0) |
| 6100 | return 0; |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6101 | task = _nfs41_proc_sequence(clp, cred); |
| 6102 | if (IS_ERR(task)) |
| 6103 | ret = PTR_ERR(task); |
| 6104 | else |
Trond Myklebust | bf294b4 | 2011-02-21 11:05:41 -0800 | [diff] [blame] | 6105 | rpc_put_task_async(task); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6106 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6107 | return ret; |
| 6108 | } |
| 6109 | |
| 6110 | static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred) |
| 6111 | { |
| 6112 | struct rpc_task *task; |
| 6113 | int ret; |
| 6114 | |
| 6115 | task = _nfs41_proc_sequence(clp, cred); |
| 6116 | if (IS_ERR(task)) { |
| 6117 | ret = PTR_ERR(task); |
| 6118 | goto out; |
| 6119 | } |
| 6120 | ret = rpc_wait_for_completion_task(task); |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6121 | if (!ret) { |
| 6122 | struct nfs4_sequence_res *res = task->tk_msg.rpc_resp; |
| 6123 | |
| 6124 | if (task->tk_status == 0) |
| 6125 | nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags); |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6126 | ret = task->tk_status; |
Trond Myklebust | b4410c2 | 2011-03-09 16:00:55 -0500 | [diff] [blame] | 6127 | } |
Trond Myklebust | 71ac6da | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6128 | rpc_put_task(task); |
| 6129 | out: |
| 6130 | dprintk("<-- %s status=%d\n", __func__, ret); |
| 6131 | return ret; |
Andy Adamson | fc01cea | 2009-04-01 09:22:36 -0400 | [diff] [blame] | 6132 | } |
| 6133 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6134 | struct nfs4_reclaim_complete_data { |
| 6135 | struct nfs_client *clp; |
| 6136 | struct nfs41_reclaim_complete_args arg; |
| 6137 | struct nfs41_reclaim_complete_res res; |
| 6138 | }; |
| 6139 | |
| 6140 | static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data) |
| 6141 | { |
| 6142 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6143 | |
Alexandros Batsakis | b257957 | 2009-12-14 21:27:57 -0800 | [diff] [blame] | 6144 | rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); |
Trond Myklebust | 035168ab | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6145 | if (nfs41_setup_sequence(calldata->clp->cl_session, |
| 6146 | &calldata->arg.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6147 | &calldata->res.seq_res, task)) |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6148 | return; |
| 6149 | |
| 6150 | rpc_call_start(task); |
| 6151 | } |
| 6152 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6153 | static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp) |
| 6154 | { |
| 6155 | switch(task->tk_status) { |
| 6156 | case 0: |
| 6157 | case -NFS4ERR_COMPLETE_ALREADY: |
| 6158 | case -NFS4ERR_WRONG_CRED: /* What to do here? */ |
| 6159 | break; |
| 6160 | case -NFS4ERR_DELAY: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6161 | rpc_delay(task, NFS4_POLL_RETRY_MAX); |
Andy Adamson | a8a4ae3 | 2011-05-03 13:43:03 -0400 | [diff] [blame] | 6162 | /* fall through */ |
| 6163 | case -NFS4ERR_RETRY_UNCACHED_REP: |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6164 | return -EAGAIN; |
| 6165 | default: |
Trond Myklebust | 0400a6b | 2011-03-09 16:00:53 -0500 | [diff] [blame] | 6166 | nfs4_schedule_lease_recovery(clp); |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6167 | } |
| 6168 | return 0; |
| 6169 | } |
| 6170 | |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6171 | static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data) |
| 6172 | { |
| 6173 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6174 | struct nfs_client *clp = calldata->clp; |
| 6175 | struct nfs4_sequence_res *res = &calldata->res.seq_res; |
| 6176 | |
| 6177 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 14516c3 | 2010-07-31 14:29:06 -0400 | [diff] [blame] | 6178 | if (!nfs41_sequence_done(task, res)) |
| 6179 | return; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6180 | |
Trond Myklebust | aa5190d | 2010-06-16 09:52:25 -0400 | [diff] [blame] | 6181 | if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) { |
| 6182 | rpc_restart_call_prepare(task); |
| 6183 | return; |
| 6184 | } |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6185 | dprintk("<-- %s\n", __func__); |
| 6186 | } |
| 6187 | |
| 6188 | static void nfs4_free_reclaim_complete_data(void *data) |
| 6189 | { |
| 6190 | struct nfs4_reclaim_complete_data *calldata = data; |
| 6191 | |
| 6192 | kfree(calldata); |
| 6193 | } |
| 6194 | |
| 6195 | static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = { |
| 6196 | .rpc_call_prepare = nfs4_reclaim_complete_prepare, |
| 6197 | .rpc_call_done = nfs4_reclaim_complete_done, |
| 6198 | .rpc_release = nfs4_free_reclaim_complete_data, |
| 6199 | }; |
| 6200 | |
| 6201 | /* |
| 6202 | * Issue a global reclaim complete. |
| 6203 | */ |
| 6204 | static int nfs41_proc_reclaim_complete(struct nfs_client *clp) |
| 6205 | { |
| 6206 | struct nfs4_reclaim_complete_data *calldata; |
| 6207 | struct rpc_task *task; |
| 6208 | struct rpc_message msg = { |
| 6209 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE], |
| 6210 | }; |
| 6211 | struct rpc_task_setup task_setup_data = { |
| 6212 | .rpc_client = clp->cl_rpcclient, |
| 6213 | .rpc_message = &msg, |
| 6214 | .callback_ops = &nfs4_reclaim_complete_call_ops, |
| 6215 | .flags = RPC_TASK_ASYNC, |
| 6216 | }; |
| 6217 | int status = -ENOMEM; |
| 6218 | |
| 6219 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 8535b2b | 2010-05-13 12:51:01 -0400 | [diff] [blame] | 6220 | calldata = kzalloc(sizeof(*calldata), GFP_NOFS); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6221 | if (calldata == NULL) |
| 6222 | goto out; |
| 6223 | calldata->clp = clp; |
| 6224 | calldata->arg.one_fs = 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6225 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6226 | nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0); |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6227 | msg.rpc_argp = &calldata->arg; |
| 6228 | msg.rpc_resp = &calldata->res; |
| 6229 | task_setup_data.callback_data = calldata; |
| 6230 | task = rpc_run_task(&task_setup_data); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6231 | if (IS_ERR(task)) { |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6232 | status = PTR_ERR(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6233 | goto out; |
| 6234 | } |
Andy Adamson | c34c32e | 2011-03-09 13:13:46 -0500 | [diff] [blame] | 6235 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6236 | if (status == 0) |
| 6237 | status = task->tk_status; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6238 | rpc_put_task(task); |
Dan Carpenter | acf82b8 | 2010-04-22 11:28:39 +0200 | [diff] [blame] | 6239 | return 0; |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6240 | out: |
| 6241 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6242 | return status; |
| 6243 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6244 | |
| 6245 | static void |
| 6246 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
| 6247 | { |
| 6248 | struct nfs4_layoutget *lgp = calldata; |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6249 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6250 | |
| 6251 | dprintk("--> %s\n", __func__); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6252 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in |
| 6253 | * right now covering the LAYOUTGET we are about to send. |
| 6254 | * However, that is not so catastrophic, and there seems |
| 6255 | * to be no way to prevent it completely. |
| 6256 | */ |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6257 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6258 | &lgp->res.seq_res, task)) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6259 | return; |
Fred Isaman | cf7d63f | 2011-01-06 11:36:25 +0000 | [diff] [blame] | 6260 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, |
| 6261 | NFS_I(lgp->args.inode)->layout, |
| 6262 | lgp->args.ctx->state)) { |
| 6263 | rpc_exit(task, NFS4_OK); |
| 6264 | return; |
| 6265 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6266 | rpc_call_start(task); |
| 6267 | } |
| 6268 | |
| 6269 | static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) |
| 6270 | { |
| 6271 | struct nfs4_layoutget *lgp = calldata; |
| 6272 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6273 | |
| 6274 | dprintk("--> %s\n", __func__); |
| 6275 | |
| 6276 | if (!nfs4_sequence_done(task, &lgp->res.seq_res)) |
| 6277 | return; |
| 6278 | |
| 6279 | switch (task->tk_status) { |
| 6280 | case 0: |
| 6281 | break; |
| 6282 | case -NFS4ERR_LAYOUTTRYLATER: |
| 6283 | case -NFS4ERR_RECALLCONFLICT: |
| 6284 | task->tk_status = -NFS4ERR_DELAY; |
| 6285 | /* Fall through */ |
| 6286 | default: |
| 6287 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6288 | rpc_restart_call_prepare(task); |
| 6289 | return; |
| 6290 | } |
| 6291 | } |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6292 | dprintk("<-- %s\n", __func__); |
| 6293 | } |
| 6294 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6295 | static size_t max_response_pages(struct nfs_server *server) |
| 6296 | { |
| 6297 | u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; |
| 6298 | return nfs_page_array_len(0, max_resp_sz); |
| 6299 | } |
| 6300 | |
| 6301 | static void nfs4_free_pages(struct page **pages, size_t size) |
| 6302 | { |
| 6303 | int i; |
| 6304 | |
| 6305 | if (!pages) |
| 6306 | return; |
| 6307 | |
| 6308 | for (i = 0; i < size; i++) { |
| 6309 | if (!pages[i]) |
| 6310 | break; |
| 6311 | __free_page(pages[i]); |
| 6312 | } |
| 6313 | kfree(pages); |
| 6314 | } |
| 6315 | |
| 6316 | static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags) |
| 6317 | { |
| 6318 | struct page **pages; |
| 6319 | int i; |
| 6320 | |
| 6321 | pages = kcalloc(size, sizeof(struct page *), gfp_flags); |
| 6322 | if (!pages) { |
| 6323 | dprintk("%s: can't alloc array of %zu pages\n", __func__, size); |
| 6324 | return NULL; |
| 6325 | } |
| 6326 | |
| 6327 | for (i = 0; i < size; i++) { |
| 6328 | pages[i] = alloc_page(gfp_flags); |
| 6329 | if (!pages[i]) { |
| 6330 | dprintk("%s: failed to allocate page\n", __func__); |
| 6331 | nfs4_free_pages(pages, size); |
| 6332 | return NULL; |
| 6333 | } |
| 6334 | } |
| 6335 | |
| 6336 | return pages; |
| 6337 | } |
| 6338 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6339 | static void nfs4_layoutget_release(void *calldata) |
| 6340 | { |
| 6341 | struct nfs4_layoutget *lgp = calldata; |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6342 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
| 6343 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6344 | |
| 6345 | dprintk("--> %s\n", __func__); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6346 | nfs4_free_pages(lgp->args.layout.pages, max_pages); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6347 | put_nfs_open_context(lgp->args.ctx); |
| 6348 | kfree(calldata); |
| 6349 | dprintk("<-- %s\n", __func__); |
| 6350 | } |
| 6351 | |
| 6352 | static const struct rpc_call_ops nfs4_layoutget_call_ops = { |
| 6353 | .rpc_call_prepare = nfs4_layoutget_prepare, |
| 6354 | .rpc_call_done = nfs4_layoutget_done, |
| 6355 | .rpc_release = nfs4_layoutget_release, |
| 6356 | }; |
| 6357 | |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6358 | struct pnfs_layout_segment * |
| 6359 | nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags) |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6360 | { |
| 6361 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6362 | size_t max_pages = max_response_pages(server); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6363 | struct rpc_task *task; |
| 6364 | struct rpc_message msg = { |
| 6365 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET], |
| 6366 | .rpc_argp = &lgp->args, |
| 6367 | .rpc_resp = &lgp->res, |
| 6368 | }; |
| 6369 | struct rpc_task_setup task_setup_data = { |
| 6370 | .rpc_client = server->client, |
| 6371 | .rpc_message = &msg, |
| 6372 | .callback_ops = &nfs4_layoutget_call_ops, |
| 6373 | .callback_data = lgp, |
| 6374 | .flags = RPC_TASK_ASYNC, |
| 6375 | }; |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6376 | struct pnfs_layout_segment *lseg = NULL; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6377 | int status = 0; |
| 6378 | |
| 6379 | dprintk("--> %s\n", __func__); |
| 6380 | |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6381 | lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags); |
| 6382 | if (!lgp->args.layout.pages) { |
| 6383 | nfs4_layoutget_release(lgp); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6384 | return ERR_PTR(-ENOMEM); |
Idan Kedar | 8554116 | 2012-08-02 11:47:10 +0300 | [diff] [blame] | 6385 | } |
| 6386 | lgp->args.layout.pglen = max_pages * PAGE_SIZE; |
| 6387 | |
Weston Andros Adamson | 35124a0 | 2011-03-24 16:48:21 -0400 | [diff] [blame] | 6388 | lgp->res.layoutp = &lgp->args.layout; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6389 | lgp->res.seq_res.sr_slot = NULL; |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6390 | nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6391 | task = rpc_run_task(&task_setup_data); |
| 6392 | if (IS_ERR(task)) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6393 | return ERR_CAST(task); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6394 | status = nfs4_wait_for_completion_rpc_task(task); |
Fred Isaman | c31663d | 2011-01-06 11:36:24 +0000 | [diff] [blame] | 6395 | if (status == 0) |
| 6396 | status = task->tk_status; |
| 6397 | if (status == 0) |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6398 | lseg = pnfs_layout_process(lgp); |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6399 | rpc_put_task(task); |
| 6400 | dprintk("<-- %s status=%d\n", __func__, status); |
Trond Myklebust | a0b0a6e | 2012-09-17 17:12:15 -0400 | [diff] [blame] | 6401 | if (status) |
| 6402 | return ERR_PTR(status); |
| 6403 | return lseg; |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6404 | } |
| 6405 | |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6406 | static void |
| 6407 | nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata) |
| 6408 | { |
| 6409 | struct nfs4_layoutreturn *lrp = calldata; |
| 6410 | |
| 6411 | dprintk("--> %s\n", __func__); |
| 6412 | if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6413 | &lrp->res.seq_res, task)) |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6414 | return; |
| 6415 | rpc_call_start(task); |
| 6416 | } |
| 6417 | |
| 6418 | static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata) |
| 6419 | { |
| 6420 | struct nfs4_layoutreturn *lrp = calldata; |
| 6421 | struct nfs_server *server; |
| 6422 | |
| 6423 | dprintk("--> %s\n", __func__); |
| 6424 | |
| 6425 | if (!nfs4_sequence_done(task, &lrp->res.seq_res)) |
| 6426 | return; |
| 6427 | |
| 6428 | server = NFS_SERVER(lrp->args.inode); |
| 6429 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
Trond Myklebust | d00c5d4 | 2011-10-19 12:17:29 -0700 | [diff] [blame] | 6430 | rpc_restart_call_prepare(task); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6431 | return; |
| 6432 | } |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6433 | dprintk("<-- %s\n", __func__); |
| 6434 | } |
| 6435 | |
| 6436 | static void nfs4_layoutreturn_release(void *calldata) |
| 6437 | { |
| 6438 | struct nfs4_layoutreturn *lrp = calldata; |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6439 | struct pnfs_layout_hdr *lo = lrp->args.layout; |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6440 | |
| 6441 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 849b286 | 2012-09-24 14:18:39 -0400 | [diff] [blame] | 6442 | spin_lock(&lo->plh_inode->i_lock); |
| 6443 | if (lrp->res.lrs_present) |
| 6444 | pnfs_set_layout_stateid(lo, &lrp->res.stateid, true); |
| 6445 | lo->plh_block_lgets--; |
| 6446 | spin_unlock(&lo->plh_inode->i_lock); |
Trond Myklebust | 70c3bd2 | 2012-09-18 20:51:13 -0400 | [diff] [blame] | 6447 | pnfs_put_layout_hdr(lrp->args.layout); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6448 | kfree(calldata); |
| 6449 | dprintk("<-- %s\n", __func__); |
| 6450 | } |
| 6451 | |
| 6452 | static const struct rpc_call_ops nfs4_layoutreturn_call_ops = { |
| 6453 | .rpc_call_prepare = nfs4_layoutreturn_prepare, |
| 6454 | .rpc_call_done = nfs4_layoutreturn_done, |
| 6455 | .rpc_release = nfs4_layoutreturn_release, |
| 6456 | }; |
| 6457 | |
| 6458 | int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp) |
| 6459 | { |
| 6460 | struct rpc_task *task; |
| 6461 | struct rpc_message msg = { |
| 6462 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN], |
| 6463 | .rpc_argp = &lrp->args, |
| 6464 | .rpc_resp = &lrp->res, |
| 6465 | }; |
| 6466 | struct rpc_task_setup task_setup_data = { |
| 6467 | .rpc_client = lrp->clp->cl_rpcclient, |
| 6468 | .rpc_message = &msg, |
| 6469 | .callback_ops = &nfs4_layoutreturn_call_ops, |
| 6470 | .callback_data = lrp, |
| 6471 | }; |
| 6472 | int status; |
| 6473 | |
| 6474 | dprintk("--> %s\n", __func__); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6475 | nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1); |
Benny Halevy | cbe8260 | 2011-05-22 19:52:37 +0300 | [diff] [blame] | 6476 | task = rpc_run_task(&task_setup_data); |
| 6477 | if (IS_ERR(task)) |
| 6478 | return PTR_ERR(task); |
| 6479 | status = task->tk_status; |
| 6480 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6481 | rpc_put_task(task); |
| 6482 | return status; |
| 6483 | } |
| 6484 | |
Andy Adamson | 7f11d8d | 2011-07-30 20:52:35 -0400 | [diff] [blame] | 6485 | /* |
| 6486 | * Retrieve the list of Data Server devices from the MDS. |
| 6487 | */ |
| 6488 | static int _nfs4_getdevicelist(struct nfs_server *server, |
| 6489 | const struct nfs_fh *fh, |
| 6490 | struct pnfs_devicelist *devlist) |
| 6491 | { |
| 6492 | struct nfs4_getdevicelist_args args = { |
| 6493 | .fh = fh, |
| 6494 | .layoutclass = server->pnfs_curr_ld->id, |
| 6495 | }; |
| 6496 | struct nfs4_getdevicelist_res res = { |
| 6497 | .devlist = devlist, |
| 6498 | }; |
| 6499 | struct rpc_message msg = { |
| 6500 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST], |
| 6501 | .rpc_argp = &args, |
| 6502 | .rpc_resp = &res, |
| 6503 | }; |
| 6504 | int status; |
| 6505 | |
| 6506 | dprintk("--> %s\n", __func__); |
| 6507 | status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, |
| 6508 | &res.seq_res, 0); |
| 6509 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6510 | return status; |
| 6511 | } |
| 6512 | |
| 6513 | int nfs4_proc_getdevicelist(struct nfs_server *server, |
| 6514 | const struct nfs_fh *fh, |
| 6515 | struct pnfs_devicelist *devlist) |
| 6516 | { |
| 6517 | struct nfs4_exception exception = { }; |
| 6518 | int err; |
| 6519 | |
| 6520 | do { |
| 6521 | err = nfs4_handle_exception(server, |
| 6522 | _nfs4_getdevicelist(server, fh, devlist), |
| 6523 | &exception); |
| 6524 | } while (exception.retry); |
| 6525 | |
| 6526 | dprintk("%s: err=%d, num_devs=%u\n", __func__, |
| 6527 | err, devlist->num_devs); |
| 6528 | |
| 6529 | return err; |
| 6530 | } |
| 6531 | EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist); |
| 6532 | |
Andy Adamson | b1f69b7 | 2010-10-20 00:18:03 -0400 | [diff] [blame] | 6533 | static int |
| 6534 | _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6535 | { |
| 6536 | struct nfs4_getdeviceinfo_args args = { |
| 6537 | .pdev = pdev, |
| 6538 | }; |
| 6539 | struct nfs4_getdeviceinfo_res res = { |
| 6540 | .pdev = pdev, |
| 6541 | }; |
| 6542 | struct rpc_message msg = { |
| 6543 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO], |
| 6544 | .rpc_argp = &args, |
| 6545 | .rpc_resp = &res, |
| 6546 | }; |
| 6547 | int status; |
| 6548 | |
| 6549 | dprintk("--> %s\n", __func__); |
Bryan Schumaker | 7c51305 | 2011-03-24 17:12:24 +0000 | [diff] [blame] | 6550 | 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] | 6551 | dprintk("<-- %s status=%d\n", __func__, status); |
| 6552 | |
| 6553 | return status; |
| 6554 | } |
| 6555 | |
| 6556 | int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev) |
| 6557 | { |
| 6558 | struct nfs4_exception exception = { }; |
| 6559 | int err; |
| 6560 | |
| 6561 | do { |
| 6562 | err = nfs4_handle_exception(server, |
| 6563 | _nfs4_proc_getdeviceinfo(server, pdev), |
| 6564 | &exception); |
| 6565 | } while (exception.retry); |
| 6566 | return err; |
| 6567 | } |
| 6568 | EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo); |
| 6569 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6570 | static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata) |
| 6571 | { |
| 6572 | struct nfs4_layoutcommit_data *data = calldata; |
| 6573 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6574 | |
| 6575 | if (nfs4_setup_sequence(server, &data->args.seq_args, |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6576 | &data->res.seq_res, task)) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6577 | return; |
| 6578 | rpc_call_start(task); |
| 6579 | } |
| 6580 | |
| 6581 | static void |
| 6582 | nfs4_layoutcommit_done(struct rpc_task *task, void *calldata) |
| 6583 | { |
| 6584 | struct nfs4_layoutcommit_data *data = calldata; |
| 6585 | struct nfs_server *server = NFS_SERVER(data->args.inode); |
| 6586 | |
| 6587 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 6588 | return; |
| 6589 | |
| 6590 | switch (task->tk_status) { /* Just ignore these failures */ |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6591 | case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */ |
| 6592 | case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */ |
| 6593 | case -NFS4ERR_BADLAYOUT: /* no layout */ |
| 6594 | case -NFS4ERR_GRACE: /* loca_recalim always false */ |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6595 | task->tk_status = 0; |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6596 | break; |
| 6597 | case 0: |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6598 | nfs_post_op_update_inode_force_wcc(data->args.inode, |
| 6599 | data->res.fattr); |
Trond Myklebust | e59d27e | 2012-03-27 18:22:19 -0400 | [diff] [blame] | 6600 | break; |
| 6601 | default: |
| 6602 | if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) { |
| 6603 | rpc_restart_call_prepare(task); |
| 6604 | return; |
| 6605 | } |
| 6606 | } |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6607 | } |
| 6608 | |
| 6609 | static void nfs4_layoutcommit_release(void *calldata) |
| 6610 | { |
| 6611 | struct nfs4_layoutcommit_data *data = calldata; |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6612 | struct pnfs_layout_segment *lseg, *tmp; |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6613 | unsigned long *bitlock = &NFS_I(data->args.inode)->flags; |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6614 | |
Andy Adamson | db29c08 | 2011-07-30 20:52:38 -0400 | [diff] [blame] | 6615 | pnfs_cleanup_layoutcommit(data); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6616 | /* Matched by references in pnfs_set_layoutcommit */ |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6617 | list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) { |
| 6618 | list_del_init(&lseg->pls_lc_list); |
| 6619 | if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, |
| 6620 | &lseg->pls_flags)) |
Trond Myklebust | 9369a43 | 2012-09-18 20:57:08 -0400 | [diff] [blame] | 6621 | pnfs_put_lseg(lseg); |
Peng Tao | a9bae56 | 2011-07-30 20:52:33 -0400 | [diff] [blame] | 6622 | } |
Peng Tao | 92407e7 | 2011-10-23 20:21:17 -0700 | [diff] [blame] | 6623 | |
| 6624 | clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock); |
| 6625 | smp_mb__after_clear_bit(); |
| 6626 | wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING); |
| 6627 | |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6628 | put_rpccred(data->cred); |
| 6629 | kfree(data); |
| 6630 | } |
| 6631 | |
| 6632 | static const struct rpc_call_ops nfs4_layoutcommit_ops = { |
| 6633 | .rpc_call_prepare = nfs4_layoutcommit_prepare, |
| 6634 | .rpc_call_done = nfs4_layoutcommit_done, |
| 6635 | .rpc_release = nfs4_layoutcommit_release, |
| 6636 | }; |
| 6637 | |
| 6638 | int |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6639 | nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6640 | { |
| 6641 | struct rpc_message msg = { |
| 6642 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT], |
| 6643 | .rpc_argp = &data->args, |
| 6644 | .rpc_resp = &data->res, |
| 6645 | .rpc_cred = data->cred, |
| 6646 | }; |
| 6647 | struct rpc_task_setup task_setup_data = { |
| 6648 | .task = &data->task, |
| 6649 | .rpc_client = NFS_CLIENT(data->args.inode), |
| 6650 | .rpc_message = &msg, |
| 6651 | .callback_ops = &nfs4_layoutcommit_ops, |
| 6652 | .callback_data = data, |
| 6653 | .flags = RPC_TASK_ASYNC, |
| 6654 | }; |
| 6655 | struct rpc_task *task; |
| 6656 | int status = 0; |
| 6657 | |
| 6658 | dprintk("NFS: %4d initiating layoutcommit call. sync %d " |
| 6659 | "lbw: %llu inode %lu\n", |
| 6660 | data->task.tk_pid, sync, |
| 6661 | data->args.lastbytewritten, |
| 6662 | data->args.inode->i_ino); |
| 6663 | |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6664 | nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1); |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6665 | task = rpc_run_task(&task_setup_data); |
| 6666 | if (IS_ERR(task)) |
| 6667 | return PTR_ERR(task); |
Andy Adamson | ef31153 | 2011-03-12 02:58:10 -0500 | [diff] [blame] | 6668 | if (sync == false) |
Andy Adamson | 863a3c6 | 2011-03-23 13:27:54 +0000 | [diff] [blame] | 6669 | goto out; |
| 6670 | status = nfs4_wait_for_completion_rpc_task(task); |
| 6671 | if (status != 0) |
| 6672 | goto out; |
| 6673 | status = task->tk_status; |
| 6674 | out: |
| 6675 | dprintk("%s: status %d\n", __func__, status); |
| 6676 | rpc_put_task(task); |
| 6677 | return status; |
| 6678 | } |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6679 | |
| 6680 | static int |
| 6681 | _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6682 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6683 | { |
| 6684 | struct nfs41_secinfo_no_name_args args = { |
| 6685 | .style = SECINFO_STYLE_CURRENT_FH, |
| 6686 | }; |
| 6687 | struct nfs4_secinfo_res res = { |
| 6688 | .flavors = flavors, |
| 6689 | }; |
| 6690 | struct rpc_message msg = { |
| 6691 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME], |
| 6692 | .rpc_argp = &args, |
| 6693 | .rpc_resp = &res, |
| 6694 | }; |
| 6695 | return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0); |
| 6696 | } |
| 6697 | |
| 6698 | static int |
| 6699 | nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6700 | struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors) |
| 6701 | { |
| 6702 | struct nfs4_exception exception = { }; |
| 6703 | int err; |
| 6704 | do { |
| 6705 | err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6706 | switch (err) { |
| 6707 | case 0: |
| 6708 | case -NFS4ERR_WRONGSEC: |
| 6709 | case -NFS4ERR_NOTSUPP: |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6710 | goto out; |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6711 | default: |
| 6712 | err = nfs4_handle_exception(server, err, &exception); |
| 6713 | } |
| 6714 | } while (exception.retry); |
Trond Myklebust | 05e9cfb | 2012-03-27 18:13:02 -0400 | [diff] [blame] | 6715 | out: |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6716 | return err; |
| 6717 | } |
| 6718 | |
| 6719 | static int |
| 6720 | nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle, |
| 6721 | struct nfs_fsinfo *info) |
| 6722 | { |
| 6723 | int err; |
| 6724 | struct page *page; |
| 6725 | rpc_authflavor_t flavor; |
| 6726 | struct nfs4_secinfo_flavors *flavors; |
| 6727 | |
| 6728 | page = alloc_page(GFP_KERNEL); |
| 6729 | if (!page) { |
| 6730 | err = -ENOMEM; |
| 6731 | goto out; |
| 6732 | } |
| 6733 | |
| 6734 | flavors = page_address(page); |
| 6735 | err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors); |
| 6736 | |
| 6737 | /* |
| 6738 | * Fall back on "guess and check" method if |
| 6739 | * the server doesn't support SECINFO_NO_NAME |
| 6740 | */ |
| 6741 | if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) { |
| 6742 | err = nfs4_find_root_sec(server, fhandle, info); |
| 6743 | goto out_freepage; |
| 6744 | } |
| 6745 | if (err) |
| 6746 | goto out_freepage; |
| 6747 | |
| 6748 | flavor = nfs_find_best_sec(flavors); |
| 6749 | if (err == 0) |
| 6750 | err = nfs4_lookup_root_sec(server, fhandle, info, flavor); |
| 6751 | |
| 6752 | out_freepage: |
| 6753 | put_page(page); |
| 6754 | if (err == -EACCES) |
| 6755 | return -EPERM; |
| 6756 | out: |
| 6757 | return err; |
| 6758 | } |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6759 | |
| 6760 | static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6761 | { |
| 6762 | int status; |
| 6763 | struct nfs41_test_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6764 | .stateid = stateid, |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6765 | }; |
| 6766 | struct nfs41_test_stateid_res res; |
| 6767 | struct rpc_message msg = { |
| 6768 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID], |
| 6769 | .rpc_argp = &args, |
| 6770 | .rpc_resp = &res, |
| 6771 | }; |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6772 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6773 | dprintk("NFS call test_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6774 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6775 | 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] | 6776 | if (status != NFS_OK) { |
| 6777 | dprintk("NFS reply test_stateid: failed, %d\n", status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6778 | return status; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6779 | } |
| 6780 | dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status); |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6781 | return -res.status; |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6782 | } |
| 6783 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6784 | /** |
| 6785 | * nfs41_test_stateid - perform a TEST_STATEID operation |
| 6786 | * |
| 6787 | * @server: server / transport on which to perform the operation |
| 6788 | * @stateid: state ID to test |
| 6789 | * |
| 6790 | * Returns NFS_OK if the server recognizes that "stateid" is valid. |
| 6791 | * Otherwise a negative NFS4ERR value is returned if the operation |
| 6792 | * failed or the state ID is not currently valid. |
| 6793 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6794 | static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6795 | { |
| 6796 | struct nfs4_exception exception = { }; |
| 6797 | int err; |
| 6798 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6799 | err = _nfs41_test_stateid(server, stateid); |
| 6800 | if (err != -NFS4ERR_DELAY) |
| 6801 | break; |
| 6802 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 7d97479 | 2011-06-02 14:59:08 -0400 | [diff] [blame] | 6803 | } while (exception.retry); |
| 6804 | return err; |
| 6805 | } |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6806 | |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6807 | static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6808 | { |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6809 | struct nfs41_free_stateid_args args = { |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6810 | .stateid = stateid, |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6811 | }; |
| 6812 | struct nfs41_free_stateid_res res; |
| 6813 | struct rpc_message msg = { |
| 6814 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID], |
| 6815 | .rpc_argp = &args, |
| 6816 | .rpc_resp = &res, |
| 6817 | }; |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6818 | int status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6819 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6820 | dprintk("NFS call free_stateid %p\n", stateid); |
Trond Myklebust | 9d12b21 | 2012-01-17 22:04:25 -0500 | [diff] [blame] | 6821 | nfs41_init_sequence(&args.seq_args, &res.seq_res, 0); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6822 | status = nfs4_call_sync_sequence(server->client, server, &msg, |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6823 | &args.seq_args, &res.seq_res, 1); |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6824 | dprintk("NFS reply free_stateid: %d\n", status); |
| 6825 | return status; |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6826 | } |
| 6827 | |
Chuck Lever | 38527b1 | 2012-07-11 16:30:23 -0400 | [diff] [blame] | 6828 | /** |
| 6829 | * nfs41_free_stateid - perform a FREE_STATEID operation |
| 6830 | * |
| 6831 | * @server: server / transport on which to perform the operation |
| 6832 | * @stateid: state ID to release |
| 6833 | * |
| 6834 | * Returns NFS_OK if the server freed "stateid". Otherwise a |
| 6835 | * negative NFS4ERR value is returned. |
| 6836 | */ |
Bryan Schumaker | 1cab065 | 2012-01-31 10:39:29 -0500 | [diff] [blame] | 6837 | static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid) |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6838 | { |
| 6839 | struct nfs4_exception exception = { }; |
| 6840 | int err; |
| 6841 | do { |
Chuck Lever | 377e507 | 2012-07-11 16:29:45 -0400 | [diff] [blame] | 6842 | err = _nfs4_free_stateid(server, stateid); |
| 6843 | if (err != -NFS4ERR_DELAY) |
| 6844 | break; |
| 6845 | nfs4_handle_exception(server, err, &exception); |
Bryan Schumaker | 9aeda35 | 2011-06-02 14:59:09 -0400 | [diff] [blame] | 6846 | } while (exception.retry); |
| 6847 | return err; |
| 6848 | } |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6849 | |
| 6850 | static bool nfs41_match_stateid(const nfs4_stateid *s1, |
| 6851 | const nfs4_stateid *s2) |
| 6852 | { |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6853 | if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6854 | return false; |
| 6855 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6856 | if (s1->seqid == s2->seqid) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6857 | return true; |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 6858 | if (s1->seqid == 0 || s2->seqid == 0) |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6859 | return true; |
| 6860 | |
| 6861 | return false; |
| 6862 | } |
| 6863 | |
Andy Adamson | 557134a | 2009-04-01 09:21:53 -0400 | [diff] [blame] | 6864 | #endif /* CONFIG_NFS_V4_1 */ |
| 6865 | |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6866 | static bool nfs4_match_stateid(const nfs4_stateid *s1, |
| 6867 | const nfs4_stateid *s2) |
| 6868 | { |
Trond Myklebust | f597c53 | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6869 | return nfs4_stateid_match(s1, s2); |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6870 | } |
| 6871 | |
| 6872 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6873 | static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6874 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6875 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6876 | .recover_open = nfs4_open_reclaim, |
| 6877 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6878 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6879 | .get_clid_cred = nfs4_get_setclientid_cred, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6880 | .detect_trunking = nfs40_discover_server_trunking, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6881 | }; |
| 6882 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6883 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6884 | static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6885 | .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, |
| 6886 | .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, |
| 6887 | .recover_open = nfs4_open_reclaim, |
| 6888 | .recover_lock = nfs4_lock_reclaim, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6889 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6890 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Ricardo Labiaga | fce5c83 | 2009-12-05 16:08:41 -0500 | [diff] [blame] | 6891 | .reclaim_complete = nfs41_proc_reclaim_complete, |
Chuck Lever | 05f4c35 | 2012-09-14 17:24:32 -0400 | [diff] [blame] | 6892 | .detect_trunking = nfs41_discover_server_trunking, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6893 | }; |
| 6894 | #endif /* CONFIG_NFS_V4_1 */ |
| 6895 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6896 | static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { |
Trond Myklebust | 7eff03a | 2008-12-23 15:21:43 -0500 | [diff] [blame] | 6897 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
Trond Myklebust | b79a4a1 | 2008-12-23 15:21:41 -0500 | [diff] [blame] | 6898 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6899 | .recover_open = nfs4_open_expired, |
| 6900 | .recover_lock = nfs4_lock_expired, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6901 | .establish_clid = nfs4_init_clientid, |
Andy Adamson | 90a1661 | 2009-04-01 09:22:48 -0400 | [diff] [blame] | 6902 | .get_clid_cred = nfs4_get_setclientid_cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6903 | }; |
| 6904 | |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6905 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6906 | static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6907 | .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, |
| 6908 | .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, |
Bryan Schumaker | f062eb6 | 2011-06-02 14:59:10 -0400 | [diff] [blame] | 6909 | .recover_open = nfs41_open_expired, |
| 6910 | .recover_lock = nfs41_lock_expired, |
Andy Adamson | 4d643d1 | 2009-12-04 15:52:24 -0500 | [diff] [blame] | 6911 | .establish_clid = nfs41_init_clientid, |
Andy Adamson | b4b8260 | 2009-04-01 09:22:49 -0400 | [diff] [blame] | 6912 | .get_clid_cred = nfs4_get_exchange_id_cred, |
Andy Adamson | 591d71c | 2009-04-01 09:22:47 -0400 | [diff] [blame] | 6913 | }; |
| 6914 | #endif /* CONFIG_NFS_V4_1 */ |
| 6915 | |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6916 | static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6917 | .sched_state_renewal = nfs4_proc_async_renew, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6918 | .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6919 | .renew_lease = nfs4_proc_renew, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6920 | }; |
| 6921 | |
| 6922 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 6923 | static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6924 | .sched_state_renewal = nfs41_proc_async_sequence, |
Andy Adamson | a7b7210 | 2009-04-01 09:22:46 -0400 | [diff] [blame] | 6925 | .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, |
Benny Halevy | 8e69514f | 2009-04-01 09:22:45 -0400 | [diff] [blame] | 6926 | .renew_lease = nfs4_proc_sequence, |
Benny Halevy | 29fba38 | 2009-04-01 09:22:44 -0400 | [diff] [blame] | 6927 | }; |
| 6928 | #endif |
| 6929 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6930 | static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { |
| 6931 | .minor_version = 0, |
| 6932 | .call_sync = _nfs4_call_sync, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6933 | .match_stateid = nfs4_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6934 | .find_root_sec = nfs4_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6935 | .reboot_recovery_ops = &nfs40_reboot_recovery_ops, |
| 6936 | .nograce_recovery_ops = &nfs40_nograce_recovery_ops, |
| 6937 | .state_renewal_ops = &nfs40_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6938 | }; |
| 6939 | |
| 6940 | #if defined(CONFIG_NFS_V4_1) |
| 6941 | static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { |
| 6942 | .minor_version = 1, |
| 6943 | .call_sync = _nfs4_call_sync_session, |
Trond Myklebust | 36281ca | 2012-03-04 18:13:56 -0500 | [diff] [blame] | 6944 | .match_stateid = nfs41_match_stateid, |
Bryan Schumaker | fca78d6 | 2011-06-02 14:59:07 -0400 | [diff] [blame] | 6945 | .find_root_sec = nfs41_find_root_sec, |
Trond Myklebust | c48f4f3 | 2010-06-16 09:52:27 -0400 | [diff] [blame] | 6946 | .reboot_recovery_ops = &nfs41_reboot_recovery_ops, |
| 6947 | .nograce_recovery_ops = &nfs41_nograce_recovery_ops, |
| 6948 | .state_renewal_ops = &nfs41_state_renewal_ops, |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6949 | }; |
| 6950 | #endif |
| 6951 | |
Trond Myklebust | 97dc135 | 2010-06-16 09:52:26 -0400 | [diff] [blame] | 6952 | const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = { |
| 6953 | [0] = &nfs_v4_0_minor_ops, |
| 6954 | #if defined(CONFIG_NFS_V4_1) |
| 6955 | [1] = &nfs_v4_1_minor_ops, |
| 6956 | #endif |
| 6957 | }; |
| 6958 | |
Bryan Schumaker | 73a7970 | 2012-07-16 16:39:12 -0400 | [diff] [blame] | 6959 | const struct inode_operations nfs4_dir_inode_operations = { |
| 6960 | .create = nfs_create, |
| 6961 | .lookup = nfs_lookup, |
| 6962 | .atomic_open = nfs_atomic_open, |
| 6963 | .link = nfs_link, |
| 6964 | .unlink = nfs_unlink, |
| 6965 | .symlink = nfs_symlink, |
| 6966 | .mkdir = nfs_mkdir, |
| 6967 | .rmdir = nfs_rmdir, |
| 6968 | .mknod = nfs_mknod, |
| 6969 | .rename = nfs_rename, |
| 6970 | .permission = nfs_permission, |
| 6971 | .getattr = nfs_getattr, |
| 6972 | .setattr = nfs_setattr, |
| 6973 | .getxattr = generic_getxattr, |
| 6974 | .setxattr = generic_setxattr, |
| 6975 | .listxattr = generic_listxattr, |
| 6976 | .removexattr = generic_removexattr, |
| 6977 | }; |
| 6978 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 6979 | static const struct inode_operations nfs4_file_inode_operations = { |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6980 | .permission = nfs_permission, |
| 6981 | .getattr = nfs_getattr, |
| 6982 | .setattr = nfs_setattr, |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 6983 | .getxattr = generic_getxattr, |
| 6984 | .setxattr = generic_setxattr, |
| 6985 | .listxattr = generic_listxattr, |
| 6986 | .removexattr = generic_removexattr, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6987 | }; |
| 6988 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 6989 | const struct nfs_rpc_ops nfs_v4_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6990 | .version = 4, /* protocol version */ |
| 6991 | .dentry_ops = &nfs4_dentry_operations, |
| 6992 | .dir_inode_ops = &nfs4_dir_inode_operations, |
J. Bruce Fields | 6b3b549 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 6993 | .file_inode_ops = &nfs4_file_inode_operations, |
Jeff Layton | 1788ea6 | 2011-11-04 13:31:21 -0400 | [diff] [blame] | 6994 | .file_ops = &nfs4_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6995 | .getroot = nfs4_proc_get_root, |
Bryan Schumaker | 281cad4 | 2012-04-27 13:27:45 -0400 | [diff] [blame] | 6996 | .submount = nfs4_submount, |
Bryan Schumaker | ff9099f2 | 2012-07-30 16:05:18 -0400 | [diff] [blame] | 6997 | .try_mount = nfs4_try_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6998 | .getattr = nfs4_proc_getattr, |
| 6999 | .setattr = nfs4_proc_setattr, |
| 7000 | .lookup = nfs4_proc_lookup, |
| 7001 | .access = nfs4_proc_access, |
| 7002 | .readlink = nfs4_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7003 | .create = nfs4_proc_create, |
| 7004 | .remove = nfs4_proc_remove, |
| 7005 | .unlink_setup = nfs4_proc_unlink_setup, |
Bryan Schumaker | 34e137c | 2012-03-19 14:54:41 -0400 | [diff] [blame] | 7006 | .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7007 | .unlink_done = nfs4_proc_unlink_done, |
| 7008 | .rename = nfs4_proc_rename, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7009 | .rename_setup = nfs4_proc_rename_setup, |
Bryan Schumaker | c6bfa1a | 2012-03-19 14:54:42 -0400 | [diff] [blame] | 7010 | .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare, |
Jeff Layton | d3d4152 | 2010-09-17 17:31:57 -0400 | [diff] [blame] | 7011 | .rename_done = nfs4_proc_rename_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7012 | .link = nfs4_proc_link, |
| 7013 | .symlink = nfs4_proc_symlink, |
| 7014 | .mkdir = nfs4_proc_mkdir, |
| 7015 | .rmdir = nfs4_proc_remove, |
| 7016 | .readdir = nfs4_proc_readdir, |
| 7017 | .mknod = nfs4_proc_mknod, |
| 7018 | .statfs = nfs4_proc_statfs, |
| 7019 | .fsinfo = nfs4_proc_fsinfo, |
| 7020 | .pathconf = nfs4_proc_pathconf, |
David Howells | e9326dc | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 7021 | .set_capabilities = nfs4_server_capabilities, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7022 | .decode_dirent = nfs4_decode_dirent, |
| 7023 | .read_setup = nfs4_proc_read_setup, |
Bryan Schumaker | 1abb5088 | 2012-06-20 15:53:47 -0400 | [diff] [blame] | 7024 | .read_pageio_init = pnfs_pageio_init_read, |
Bryan Schumaker | ea7c330 | 2012-03-19 14:54:40 -0400 | [diff] [blame] | 7025 | .read_rpc_prepare = nfs4_proc_read_rpc_prepare, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7026 | .read_done = nfs4_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7027 | .write_setup = nfs4_proc_write_setup, |
Bryan Schumaker | 57208fa | 2012-06-20 15:53:48 -0400 | [diff] [blame] | 7028 | .write_pageio_init = pnfs_pageio_init_write, |
Bryan Schumaker | c6cb80d | 2012-03-19 14:54:39 -0400 | [diff] [blame] | 7029 | .write_rpc_prepare = nfs4_proc_write_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7030 | .write_done = nfs4_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7031 | .commit_setup = nfs4_proc_commit_setup, |
Fred Isaman | 0b7c015 | 2012-04-20 14:47:39 -0400 | [diff] [blame] | 7032 | .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 7033 | .commit_done = nfs4_commit_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7034 | .lock = nfs4_proc_lock, |
J. Bruce Fields | e50a1c2 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 7035 | .clear_acl_cache = nfs4_zap_acl_attr, |
Trond Myklebust | 7fe5c39 | 2009-03-19 15:35:50 -0400 | [diff] [blame] | 7036 | .close_context = nfs4_close_context, |
Trond Myklebust | 2b48429 | 2010-09-17 10:56:51 -0400 | [diff] [blame] | 7037 | .open_context = nfs4_atomic_open, |
Bryan Schumaker | 011e2a7 | 2012-06-20 15:53:43 -0400 | [diff] [blame] | 7038 | .have_delegation = nfs4_have_delegation, |
Bryan Schumaker | 57ec14c | 2012-06-20 15:53:44 -0400 | [diff] [blame] | 7039 | .return_delegation = nfs4_inode_return_delegation, |
Bryan Schumaker | 6663ee7 | 2012-06-20 15:53:46 -0400 | [diff] [blame] | 7040 | .alloc_client = nfs4_alloc_client, |
Andy Adamson | 45a52a0 | 2011-03-01 01:34:08 +0000 | [diff] [blame] | 7041 | .init_client = nfs4_init_client, |
Bryan Schumaker | cdb7ece | 2012-06-20 15:53:45 -0400 | [diff] [blame] | 7042 | .free_client = nfs4_free_client, |
Bryan Schumaker | 1179acc | 2012-07-30 16:05:19 -0400 | [diff] [blame] | 7043 | .create_server = nfs4_create_server, |
| 7044 | .clone_server = nfs_clone_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7045 | }; |
| 7046 | |
Aneesh Kumar K.V | 64c2ce8 | 2010-12-09 11:35:25 +0000 | [diff] [blame] | 7047 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { |
| 7048 | .prefix = XATTR_NAME_NFSV4_ACL, |
| 7049 | .list = nfs4_xattr_list_nfs4_acl, |
| 7050 | .get = nfs4_xattr_get_nfs4_acl, |
| 7051 | .set = nfs4_xattr_set_nfs4_acl, |
| 7052 | }; |
| 7053 | |
| 7054 | const struct xattr_handler *nfs4_xattr_handlers[] = { |
| 7055 | &nfs4_xattr_nfs4_acl_handler, |
| 7056 | NULL |
| 7057 | }; |
| 7058 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7059 | /* |
| 7060 | * Local variables: |
| 7061 | * c-basic-offset: 8 |
| 7062 | * End: |
| 7063 | */ |